Integrate periodogram algorithms better with TimeSeries object#8599
Integrate periodogram algorithms better with TimeSeries object#8599eteq merged 18 commits intoastropy:masterfrom
Conversation
52c3023 to
12c6d79
Compare
Codecov Report
@@ Coverage Diff @@
## master #8599 +/- ##
==========================================
+ Coverage 86.86% 86.94% +0.07%
==========================================
Files 396 400 +4
Lines 58937 59324 +387
Branches 1100 1100
==========================================
+ Hits 51198 51581 +383
- Misses 7098 7102 +4
Partials 641 641
Continue to review full report at Codecov.
|
|
@astrofrog - Quick comment prior to a full review: I am not a fan of the string keywords for arguments. What about instead having it be: periodogram = ts.periodogram(algorithm=BoxLeastSquares, column='sap_flux')Or even: periodogram = BoxLeastSquares.from_times_series(ts, column='sap_flux')? I could see adding the "string" keys later on, but I fear locking ourselves into a string based system |
12c6d79 to
6d95925
Compare
|
@eteq - I've gone with your approach of: |
eteq
left a comment
There was a problem hiding this comment.
Overall I'm happy with this now. A few relatively easy-to-implement changes to suggest though (hopefully mainly find-and-replace).
|
I think I'm still slightly in favour of |
|
@bsipocz - I personally also quite like the periodogram method, but let's discuss it again once 3.2 is out. |
|
Please rebase now that I merged #8591. |
…ocs to match the rest of the documentation
98dbdad to
53ed2aa
Compare
|
I am not as much a fan of |
923fb75 to
756ec6b
Compare
bsipocz
left a comment
There was a problem hiding this comment.
I would still like to take it to a spin, and check the html rendering, but here are some minor comments based on the github diff
astropy/timeseries/periodograms/lombscargle/tests/test_lombscargle.py
Outdated
Show resolved
Hide resolved
|
|
||
|
|
||
| @pytest.mark.parametrize('timedelta', [False, True]) | ||
| def test_absolute_times(data, timedelta): |
There was a problem hiding this comment.
since this test function is so similar to the one in BLS, I wonder whether it makes any sense to have only one parametrized for the different periodograms?
There was a problem hiding this comment.
There's some code in common but a lot of differences too in particular with respect to which methods are tested, and how the results are stored, so I'd rather keep it as is.
pllim
left a comment
There was a problem hiding this comment.
Doc build failed:
/home/circleci/project/docs/whatsnew/3.2.rst:41:Exception occurred in plotting 3-2-1
from /home/circleci/project/docs/whatsnew/3.2.rst:
Traceback (most recent call last):
File "/home/circleci/project/venv/lib/python3.6/site-packages/matplotlib/sphinxext/plot_directive.py", line 499, in run_code
exec(code, ns)
File "<string>", line 19, in <module>
AttributeError: 'TimeSeries' object has no attribute 'periodogram'
I would have liked to see if the rendered doc look as expected, given some changes in the plot directives and so on.
Also, note for whoever going to merge this, please make sure the remote data test (which is allowed to fail) actually passes for the remote data tests added here.
pllim
left a comment
There was a problem hiding this comment.
LGTM as a non-domain expert. I see the following weirdness in the rendered doc on CircleCI but probably out of scope here because they also occur elsewhere.
https://29818-2081289-gh.circle-artifacts.com/0/home/circleci/project/docs/_build/html/timeseries/index.html#reference-api -- The table listing looks weird; i.e., table looks squashed horizontally.
https://29818-2081289-gh.circle-artifacts.com/0/home/circleci/project/docs/_build/html/timeseries/lombscargle.html -- There are () right before the plots, not sure why. Same with the plot in https://29818-2081289-gh.circle-artifacts.com/0/home/circleci/project/docs/_build/html/whatsnew/3.2.html#whatsnew-3-2-timeseries
|
Yeah I'm not sure what's going on with the Sphinx issues, but we can try and debug over the next couple of weeks. I wonder if it's related to Sphinx 2.0. |
In #8591, I moved the periodogram classes from
astropy.statstoastropy.timeseries. In this PR, I want to make sure that users can seamlessly use the periodogram classes given a time series object.This PR actually does two main things:
It adapts the BLS and Lomb-Scargle algorithms so that they can optionally work with absolute rather than relative times. This means that parameters such as
transit_timereturn absoluteTimeobjects, and methods such as e.g.modelcan be given absolute times to evaluate the models on. I have fully preserved back-compatibility with just using relative times (with or without units). I have added an extensive test for both periodogram algorithms to make sure that they behave correctly when given absolute times.It then adds a
periodogrammethod on theTimeSeriesclass, which is a convenience to initialize eitherBoxLeastSquaresorLombScarglewith the correct arguments. Then instead of doing:users can just do:
I considered an alternative approach which would be to make it so that e.g.
BoxLeastSquarescan be initialized with a time series, but I decided not to implement this for the following reasons:compared with:
The advantage of just being able to do:
is that it avoids having to import the periodogram classes and initialize them manually, and provides a nice user-friendly API. This also transparently handles masking out e.g. NaN values before initializing the periodogram classes.
For the binned time series, I'm doing the same as for the sampled one, using the times at the center of the bins (this is mentioned in the docstring)
At the moment there is a little bit of code duplication between binned and sampled, and between BLS and Lomb-Scargle. My priority here is to make sure that things work as we want, and we can always find ways to reduce the duplication in future.
It might be worth writing a top-level docs page specifically about periodograms that then links to the two (or more in future) algorithms we have. Again, in the interest of getting this in to the feature freeze, I'm happy to try and improve the docs in the RC phase, since it would just be docs.
@dfm @mirca @joeldhartman @jakevdp - as the authors for the periodogram classes, I just wanted to give you a heads-up about the changes related to accepting absolute times.