-
Notifications
You must be signed in to change notification settings - Fork 101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Harmonic oscillation reduction #285
Harmonic oscillation reduction #285
Conversation
Hello @sarajamal57! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2021-05-27 22:37:18 UTC |
@sarajamal57 Reviving this long-neglected PR (sorry!). I've moved your changes into the existing lomb_scargle.py file -- does the diff here look right to you? And thanks again for your contribution! |
cesium/features/lomb_scargle.py
Outdated
@@ -3,7 +3,7 @@ | |||
from ._lomb_scargle import lomb_scargle | |||
|
|||
|
|||
def lomb_scargle_model(time, signal, error, sys_err=0.05, nharm=8, nfreq=3, tone_control=5.0): | |||
def lomb_scargle_model(time, signal, error, sys_err=0.05, nharm=8, nfreq=3, tone_control=5.0, opt_normalize=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra parameter needs a docstring entry
def rescale_lomb_model(norm_model, mmean, mscale): | ||
""" Rescale Lomb-Scargle model if compiled on normalized data. | ||
|
||
Parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docstring needs formatting
0adacac
to
536a05d
Compare
e6645c4
to
b8cc285
Compare
nfreq : int | ||
Number of frequencies to fit. | ||
opt_normalize : boolean, optional | ||
Defaults to False. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does opt_normalize do?
We also need tests for these new flags.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The normalization resolves the numerical overflow observed for instance in issue #284
Modified/Added functions
lomb_scargle_model()
rescale_lomb_model()
Procedure
If opt_normalize==False
, this refers to the original Lomb-Scargle periodogram function.
Otherwise:
Step 1 - the time-serie (TS) is normalized, and the (mean, std scale) are stored
Step 2 - Lomb-Scargle periodogram & the best fitted model are computed on the normalized (signal, error)
Step 3 - Results are scaled back to the original/raw format using the stored (mean, scale)
Step 1
In function lomb_scargle_model()
:
### Normalization ###
mmean = np.nanmean(signal)
mscale = np.nanstd(signal)
if opt_normalize:
signal = (signal-mmean)/mscale
error = error/mscale
Step 2
The lomb-scargle (LS) periodogram is estimated on the normalized time-serie (signal, associated error).
Step 3
The best fitted Lomb-Scargle model is rescaled back.
In function lomb_scargle_model()
:
current_fit = rescale_lomb_model(fit, mmean, mscale) if (opt_normalize&(i==0)) else fit
## function rescale_lomb_model() is used to rescale the best fitted model (computed on normalized TS)
The first component (i==0
) of var freq_fits
requires to re-inject the scale
if (opt_normalize&(i==0)):
model_dict['freq_fits'][-1]['resid']*=mscale
@sarajamal57 will you be able to add the tests/comments as per @stefanv's review? |
yes, will do, no problem ! |
2333327
to
eb22bd6
Compare
Closed in favor of #313 |
- Add the ability compute L-S models on normalized data. - Adds periodogram to the outputs (not just the features computed on the periodogram) Completed work by S. Jamal in PR #285 Co-authored-by: Sara Jamal <[email protected]> Co-authored-by: Ari Crellin-Quick <[email protected]>
To solve the overflow problem in issue #284 :
new py file
cesium/features/lomb_scargle_norm.py
incorporating inlomb_scargle_model()
if opt_normalize
fit_lomb_scargle()
rescale_lomb_model()
Notes
cesium/features/lomb_scargle_norm.py
not in the original source filecesium/features/lomb_scargle.py
Additional output
The full power spectrum and associated frequencies are added in the output dictionary in
fit_lomb_scargle()
[Lines 299-302]