...offers free and open source algorithms to automagically remove trends from time-series data.
In Germanic mythology, Odin (/ˈoːðinː/ Old High German: Wōtan) is a widely revered god. He gave one of his eyes to Mimir in return for wisdom. Thus, in order to achieve a goal, one sometimes has to turn a blind eye. In Richard Wagner's "Der Ring des Nibelungen", Wotan is the King of the Gods (god of light, air, and wind) and a bass-baritone. According to Wagner, he is the "pinnacle of intelligence".
squared_exp Squared-exponential kernel, with option for iterative sigma-clipping
matern Matern 3/2 kernel, with option for iterative sigma-clipping
periodic Periodic kernel informed by a user-specified period (📑Example)
periodic_auto Periodic kernel informed by a Lomb-Scargle periodogram pre-search
Available features
window_length The length of the filter window in units of time (usually days).
break_tolerance If there are large gaps in time, especially with corresponding flux level offsets, the detrending is much improved when splitting the data into several sub-lightcurves and applying the filter to each individually. Comes with an empirical default and is fully adjustable.
edge_cutoff Trends near edges are less robust. Depending on the data, it may be beneficial to remove edges.
cval Tuning parameter for the robust estimators (see documentation)
return_trend If True, the method will return a tuple of two elements (flattened_flux, trend_flux) where trend_flux is the removed trend. Otherwise, it will only return flattened_flux.
step Evaluate the trend only at points this far apart and interpolate between them, for biweight, andrewsinewave, welsch and median. On long light curves at short cadence, window_length / 72 is 4-6x faster with almost the same trend (see documentation). Default: every point.
transit_mask Mask known transits during detrending (📑Example)
What method to choose?
It depends on your data and what you like to achieve (relevant xkcd). If possible, try it out! Use wotan with a selection of methods, iterate over their parameter space, and choose what gives the best results for your research.
If that is too much effort, you should first examine your data.
Is it mostly white (Gaussian) noise? Use a time-windowed sliding mean. This is the most efficient method for white noise.
With prominent outliers (such as transits or flares), use a robust time-windowed method such as the biweight. This is usually superior to the median or trimmed methods.
Are there (semi-) periodic trends? In addition to a time-windowed biweight, try a spline-based method. Experimenting with periodic GPs is worthwhile.
Installation
To install the released version, type
$ pip install wotan
which automatically installs numpy, numba and scipy if not present. Depending on the algorithm, additional dependencies exist:
huber, ramsay, and hampel depend on statsmodels
hspline and gp depend on scikit-learn
pspline depends on pygam
supersmoother depends on supersmoother
To install all additional dependencies, type $ pip install statsmodels scikit-learn supersmoother pygam.
For development: pip install -r tests/requirements-test.txt, then pytest runs the test suite (tests/README.md) and python benchmarks/bench.py --method biweight the benchmark (benchmarks/README.md). Note that numba's cache (*.nbi, *.nbc in __pycache__) does not track changes across files: after editing a compiled function that another one calls, delete the cache (find wotan -name "*.nb?" -delete), or the caller keeps the old code. Installed releases are not affected.
Originality
As all scientific work, wōtan is standing on the shoulders of giants. Particularly, many detrending methods are wrapped from existing packages. Original contributions include:
A time-windowed detrending master module with edge treatments and segmentation options
Robust location estimates using Newton-Raphson iteration to a precision threshold for Tukey's biweight, Andrew's sine wave, and the Welsch-Leclerc. This is probably a "first", which reduces jitter in the location estimate by ~10 ppm
Robustified (iterative sigma-clipping) penalized splines for automatic knot distance determination and outlier resistance
GP with a periodic kernel informed by a Lomb-Scargle periodogram pre-search
Bringing together many methods in one place in a common interface, with sensible defaults
Providing documentation, tutorials, and a paper which compares and benchmarks the methods
What's new in 2.0
Bugfixes: 31 bugs fixed (#70–#100), see BUGLOG.md. Highlights: the slider windows now include their last sample, masks work with any flux value, robust clipping is two-sided, lowess uses a window in time units, cosine/cofiam work for any time offset, pspline and rspline converge properly, and NaN/inf, unsorted time and invalid arguments are handled (with warnings instead of silent NaN trends).
Performance: all commonly used methods are faster, most of them by an order of magnitude (table below).
Test coverage: a pytest suite of 563 tests covers all detrending methods, the API, edge cases, a regression test for every fixed bug, checks against independent reference implementations, and the trends of a real Kepler light curve against stored references. Run it with pytest tests.
Speed
Speed in millions of data points per second for the Kepler-10 light curve (all 15 long-cadence quarters, 52k points), window_length=0.5 d, default parameters, 2 CPU cores (the parallel methods scale with the number of cores). Speed-up: geometric mean over the benchmark datasets, compared to 1.x. Reproduce with python benchmarks/bench.py --method <name>; details in benchmarks/RESULTS.md.
Method
Speed (million points per sec)
Speed-up
mean
34
19x
median
11
21x
biweight
5.0
60x
rspline
0.34
2.3x
lowess
0.33
9.1x
hspline
0.22
14x
cosine
0.11
1.1x
cofiam
0.037
1.6x
pspline
0.0003*
1.3x
* longest Kepler-10 segment (1,925 points)
Contributing
All my repositories embrace collaboration between humans and AI. Contributions are welcome, whether they are written by you, by an AI assistant, or by both together, and they will be handled promptly. Please open an issue or a pull request.