|Documentation||Package Evaluator||Build Status||Code Coverage|
Another Julia package that provides tools to perform spectral analysis of
DSP.jl, but its methods
require that the signal has been sampled at equally spaced times. Instead, the
Lomb–Scargle periodogram enables you to analyze unevenly sampled data as well,
which is a fairly common case in astronomy, a field where this periodogram is
The algorithms used in this package are reported in the following papers:
The package provides facilities to:
All these features are thoroughly described in the full documentation, see below. Here we only give basic information.
The complete manual of
LombScargle.jl is available at
https://giordano.github.io/LombScargle.jl/stable/. It has detailed explanation of all
functions provided by the package and more examples than what you will find
here, also with some plots.
LombScargle.jl is available for Julia 0.7 and later versions, and can be
Julia built-in package manager.
In a Julia session run the commands
julia> using Pkg julia> Pkg.update() julia> Pkg.add("LombScargle")
Older versions are also available for Julia 0.4-0.6.
After installing the package, you can start using it with
julia> using LombScargle
The module defines a new
LombScargle.Periodogram data type, which, however, is
not exported because you will most probably not need to directly manipulate such
objects. This data type holds both the frequency and the power vectors of the
The main function provided by the package is
lombscargle(times, signal[, errors])
which returns a
LombScargle.Periodogram. The only mandatory arguments are:
times: the vector of observation times
signal: the vector of observations associated with
All these vectors must have the same length. The only optional argument is:
errors: the uncertainties associated to each
signalpoint. This vector must have the same length as
Besides the two arguments introduced above,
lombscargle has a number of other
optional keywords in order to choose the right algorithm to use and tweak the
periodogram. For the description of all these arguments see the complete
If the signal has uncertainties, the
signal vector can also be a vector of
Measurement objects (from
Measurements.jl package), in
which case you need not to pass a separate
errors vector for the uncertainties
of the signal. You can create arrays of
Measurement objects with the
measurement function, see
Measurements.jl manual at
https://juliaphysics.github.io/Measurements.jl/latest/ for more details.
LombScargle.plan function you can pre-plan a periodogram and save
time and memory for the actual computation of the periodogram. See
the manual for
Here is an example of a noisy periodic signal (
sin(π*t) + 1.5*cos(2π*t))
sampled at unevenly spaced times.
julia> using LombScargle julia> ntimes = 1001 1001 # Observation times julia> t = range(0.01, stop=10pi, length=ntimes) 0.01:0.03140592653589793:31.41592653589793 # Randomize times julia> t += step(t)*rand(ntimes); # The signal julia> s = sinpi.(t) .+ 1.5 .* cospi.(2t) .+ rand(ntimes); # Pre-plan the periodogram (see the documentation) julia> plan = LombScargle.plan(t, s); # Compute the periodogram julia> pgram = lombscargle(plan)
You can plot the result, for example with
Plots package. Use
function to get the frequency grid and the power of the periodogram as a
using Plots plot(freqpower(pgram)...)
The generalised Lomb–Scargle periodogram (used when the
true) is able to handle a signal with uncertainties, and they will
be used as weights in the algorithm. The uncertainties can be passed either as
the third optional argument
lombscargle or by providing this
function with a
signal vector of type
using Measurements, Plots ntimes = 1001 t = range(0.01, stop=10pi, length=ntimes) s = sinpi.(2t) errors = rand(0.1:1e-3:4.0, ntimes) plot(freqpower(lombscargle(t, s, errors, maximum_frequency=1.5))...) plot(freqpower(lombscargle(t, measurement(s, errors), maximum_frequency=1.5))...)
A pre-planned periodogram in
LombScargle.jl computed in single thread mode
with the fast method is more than 2.9 times faster than the implementation of
the same algorithm provided by Astropy, and more than 4.5 times faster if 4 FFTW
threads are used (on machines with at least 4 physical CPUs).
The following plot shows a comparison between the times needed to compute a
periodogram for a signal with N datapoints using
LombScargle.jl, with 1 or 4
flags = FFTW.MEASURE for better performance), and the
single-threaded Astropy implementation. (Julia version: 0.7.0-DEV.2309,
LombScargle.jl version: 0.3.1; Python version: 3.5.4; Astropy
version: 2.0.2. CPU: Intel(R) Core(TM) i7-4700MQ.)
Note that this comparison is unfair, as Astropy doesn’t support pre-planning a
periodogram nor exploiting multi-threading. A non-planned periodogram in single
thread mode in
LombScargle.jl is still twice faster than Astropy.
The package is developed at https://github.com/JuliaAstro/LombScargle.jl. There you can submit bug reports, make suggestions, and propose pull requests.
The ChangeLog of the package is available in NEWS.md file in top directory.
LombScargle.jl package is licensed under the BSD 3-clause "New" or
"Revised" License. The original author is Mosè Giordano.
This package adapts the implementation in Astropy of the the fast Lomb–Scargle method by Press & Rybicki (1989). We claim no endorsement nor promotion by the Astropy Team.
16 days ago