Prewhitener
Prewhitener provides the core frequency-analysis and iterative
prewhitening functionality in Pyriod. It can be used independently
of the graphical interface.
Prewhitener
Bases: object
Perform iterative frequency analysis and prewhitening.
Prewhitener contains the core analysis state and fitting
functionality used by Pyriod. It can be used directly for
non-interactive analysis or passed to PyriodGUI to create
the interactive notebook interface.
| Parameters: |
|
|---|
| Attributes: |
|
|---|
set_frequency_sampling
set_frequency_sampling(frequency=None, oversample_factor=5, nyquist_factor=1, minfreq=None, maxfreq=None)
Set the frequency grid used for subsequent periodograms.
The grid may be supplied explicitly or generated at a specified oversampling factor over an automatically or explicitly bounded frequency range.
| Parameters: |
|
|---|
Notes
This method updates freqs but does not automatically recalculate
per_orig. Call compute_pers(orig=True) to recalculate the
original-light-curve periodogram on the new grid.
The approximate Nyquist frequency is calculated as 1 / (2 dt),
where dt is the median separation between adjacent observations.
This is exact only for evenly sampled data. nyquist_quality provides
a measure between 0 and 1 of how strongly the sampling produces
reflection about this approximate Nyquist frequency.
add_signal
add_signal(freq, amp=None, phase=None, fixfreq=False, fixamp=False, fixphase=False, include=True, brute=True, index=None)
Stage one or more independent sinusoidal signals for fitting.
Scalar arguments may be supplied for a single signal. For multiple signals, iterable arguments may be supplied; scalar values are repeated as needed.
| Parameters: |
|
|---|
| Raises: |
|
|---|
Notes
Signals are added to stagedvalues and do not become part of the
fitted model until fit_model() is called.
add_combination
add_combination(combostr, amp=None, phase=None, fixamp=False, fixphase=False, include=True, brute=True)
Stage one or more combination-frequency signals for fitting.
Combination frequencies are defined by arithmetic expressions involving existing staged signal labels. The combination expression is also used as the signal label.
| Parameters: |
|
|---|
Notes
Invalid combination expressions are reported to the Pyriod log and no combination signal is added.
remove_signals
remove_signals(indices)
Remove signals from the staged solution.
| Parameters: |
|
|---|
Notes
Combination signals that depend on a removed signal are also removed. Missing labels produce a warning in the Pyriod log.
Removing a staged signal does not remove it from the current fitted
model until fit_model() is called.
fit_model
fit_model()
Fit the staged sinusoidal model to the light curve.
The model is a sum of all signals in stagedvalues for which
include is True. Initial parameter values are taken from
stagedvalues. Signals marked with brute=True have their initial
phase estimated by brute-force sampling before optimization.
Independent signals are represented by free or fixed sinusoidal parameters. Combination-signal frequencies are constrained through lmfit expressions relating them to their constituent independent frequencies.
After a successful fit, fitted parameters are stored in fitvalues
and the complete lmfit result is stored in fit_result. The model
and residual periodograms are then recalculated.
Notes
If no signals are included, no optimization is performed and the fitted solution is reset to an empty table. If all included parameters are fixed, a warning is written to the log and no optimization is performed.
solution_table
solution_table(display_units=True, include_brute=True)
Return a copy of the current fitted signal table.
| Parameters: |
|
|---|
| Returns: |
|
|---|
staged_table
staged_table(display_units=True)
Return a copy of the signal parameters staged for the next model fit.
| Parameters: |
|
|---|
| Returns: |
|
|---|
sample_model
sample_model(time)
Evaluate the current fitted signal model at specified times.
| Parameters: |
|
|---|
| Returns: |
|
|---|
Notes
Evaluates the sinusoidal variations only and does not include an additive offset to match mean light curve flux.
calculate_significance_threshold
calculate_significance_threshold(multiplier=5, startfreq=0, endfreq=None, freqstep=100, winwidth=100, avgtype='mean', autorecalculate=False, **kwargs)
Estimate a frequency-dependent amplitude significance threshold.
The local noise level is estimated from the mean or median amplitude in
moving windows across per_resid. An interpolating function describing
this noise spectrum is stored in noise_spectrum. Multiplying it by
multiplier gives the significance threshold.
| Parameters: |
|
|---|
Notes
The settings used for the calculation are stored in
significance_settings. Signal-to-noise ratios in the fitted signal
table are updated using the resulting noise spectrum.
mask_indices
mask_indices(indices, threshold=30)
Mask selected light-curve points by index.
| Parameters: |
|
|---|
Notes
If no indices are supplied, the mask is unchanged and a warning is written to the Pyriod log.
Changing the mask recalculates the time shift and periodograms and
causes uptodate to become False until the model is refitted.
Use clear_mask() to restore all observations.
clear_mask
clear_mask()
Restore all masked light-curve points.
All values in the include column of lc are set to True. The
time shift and periodograms are recalculated, and the fitted model is
marked as out of date until it is refitted.
save_solution
save_solution(filename='Pyriod_solution.csv')
Save the current fitted signal solution to a CSV file.
| Parameters: |
|
|---|
Notes
Amplitudes and amplitude uncertainties are written in the current display amplitude unit.
load_solution
load_solution(filename='Pyriod_solution.csv')
Load a saved signal solution and stage it for fitting.
| Parameters: |
|
|---|
Notes
Loaded amplitudes are interpreted in the current amp_unit and
converted to internal units. The loaded values replace
stagedvalues but are not fitted automatically.
If the file does not exist, an error is written to the Pyriod log and no exception is raised.
log
log(message, level='info')
Record a message in the Pyriod log.
| Parameters: |
|
|---|
save_log
save_log(filename, overwrite=False)
Write the Pyriod log to a text file.
| Parameters: |
|
|---|
close
close(clear_data=True, collect=False)
Release resources owned by this Prewhitener.
| Parameters: |
|
|---|
Notes
After clear_data=True, this Prewhitener should be considered closed
and should not be used for further fitting or plotting.