astrobase.periodbase.zgls module¶
Contains the Zechmeister & Kurster (2002) Generalized LombScargle periodsearch algorithm implementation for periodbase.

astrobase.periodbase.zgls.
generalized_lsp_value
(times, mags, errs, omega)[source]¶ Generalized LSP value for a single omega.
The relations used are:
P(w) = (1/YY) * (YC*YC/CC + YS*YS/SS) where: YC, YS, CC, and SS are all calculated at T and where: tan 2omegaT = 2*CS/(CC  SS) and where: Y = sum( w_i*y_i ) C = sum( w_i*cos(wT_i) ) S = sum( w_i*sin(wT_i) ) YY = sum( w_i*y_i*y_i )  Y*Y YC = sum( w_i*y_i*cos(wT_i) )  Y*C YS = sum( w_i*y_i*sin(wT_i) )  Y*S CpC = sum( w_i*cos(w_T_i)*cos(w_T_i) ) CC = CpC  C*C SS = (1  CpC)  S*S CS = sum( w_i*cos(w_T_i)*sin(w_T_i) )  C*S
Parameters:  times,mags,errs (np.array) – The timeseries to calculate the periodogram value for.
 omega (float) – The frequency to calculate the periodogram value at.
Returns: periodogramvalue – The normalized periodogram at the specified test frequency omega.
Return type: float

astrobase.periodbase.zgls.
generalized_lsp_value_withtau
(times, mags, errs, omega)[source]¶ Generalized LSP value for a single omega.
This uses tau to provide an arbitrary timereference point.
The relations used are:
P(w) = (1/YY) * (YC*YC/CC + YS*YS/SS) where: YC, YS, CC, and SS are all calculated at T and where: tan 2omegaT = 2*CS/(CC  SS) and where: Y = sum( w_i*y_i ) C = sum( w_i*cos(wT_i) ) S = sum( w_i*sin(wT_i) ) YY = sum( w_i*y_i*y_i )  Y*Y YC = sum( w_i*y_i*cos(wT_i) )  Y*C YS = sum( w_i*y_i*sin(wT_i) )  Y*S CpC = sum( w_i*cos(w_T_i)*cos(w_T_i) ) CC = CpC  C*C SS = (1  CpC)  S*S CS = sum( w_i*cos(w_T_i)*sin(w_T_i) )  C*S
Parameters:  times,mags,errs (np.array) – The timeseries to calculate the periodogram value for.
 omega (float) – The frequency to calculate the periodogram value at.
Returns: periodogramvalue – The normalized periodogram at the specified test frequency omega.
Return type: float

astrobase.periodbase.zgls.
generalized_lsp_value_notau
(times, mags, errs, omega)[source]¶ This is the simplified version not using tau.
The relations used are:
W = sum (1.0/(errs*errs) ) w_i = (1/W)*(1/(errs*errs)) Y = sum( w_i*y_i ) C = sum( w_i*cos(wt_i) ) S = sum( w_i*sin(wt_i) ) YY = sum( w_i*y_i*y_i )  Y*Y YC = sum( w_i*y_i*cos(wt_i) )  Y*C YS = sum( w_i*y_i*sin(wt_i) )  Y*S CpC = sum( w_i*cos(w_t_i)*cos(w_t_i) ) CC = CpC  C*C SS = (1  CpC)  S*S CS = sum( w_i*cos(w_t_i)*sin(w_t_i) )  C*S D(omega) = CC*SS  CS*CS P(omega) = (SS*YC*YC + CC*YS*YS  2.0*CS*YC*YS)/(YY*D)
Parameters:  times,mags,errs (np.array) – The timeseries to calculate the periodogram value for.
 omega (float) – The frequency to calculate the periodogram value at.
Returns: periodogramvalue – The normalized periodogram at the specified test frequency omega.
Return type: float

astrobase.periodbase.zgls.
specwindow_lsp_value
(times, mags, errs, omega)[source]¶ This calculates the peak associated with the spectral window function for times and at the specified omega.
NOTE: this is classical LombScargle, not the Generalized LombScargle. mags and errs are silently ignored since we’re calculating the periodogram of the observing window function. These are kept to present a consistent external API so the pgen_lsp function below can call this transparently.
Parameters:  times,mags,errs (np.array) – The timeseries to calculate the periodogram value for.
 omega (float) – The frequency to calculate the periodogram value at.
Returns: periodogramvalue – The normalized periodogram at the specified test frequency omega.
Return type: float

astrobase.periodbase.zgls.
pgen_lsp
(times, mags, errs, magsarefluxes=False, startp=None, endp=None, stepsize=0.0001, autofreq=True, nbestpeaks=5, periodepsilon=0.1, sigclip=10.0, nworkers=None, workchunksize=None, glspfunc=<function _glsp_worker_withtau>, verbose=True)[source]¶ This calculates the generalized LombScargle periodogram.
Uses the algorithm from Zechmeister and Kurster (2009).
Parameters:  times,mags,errs (np.array) – The mag/flux timeseries with associated measurement errors to run the periodfinding on.
 magsarefluxes (bool) – If the input measurement values in mags and errs are in fluxes, set this to True.
 startp,endp (float or None) – The minimum and maximum periods to consider for the transit search.
 stepsize (float) – The stepsize in frequency to use when constructing a frequency grid for the period search.
 autofreq (bool) – If this is True, the value of stepsize will be ignored and the
astrobase.periodbase.get_frequency_grid()
function will be used to generate a frequency grid based on startp, and endp. If these are None as well, startp will be set to 0.1 and endp will be set to times.max()  times.min().  nbestpeaks (int) – The number of ‘best’ peaks to return from the periodogram results, starting from the global maximum of the periodogram peak values.
 periodepsilon (float) – The fractional difference between successive values of ‘best’ periods when sorting by periodogram power to consider them as separate periods (as opposed to part of the same periodogram peak). This is used to avoid broad peaks in the periodogram and make sure the ‘best’ periods returned are all actually independent.
 sigclip (float or int or sequence of two floats/ints or None) –
If a single float or int, a symmetric sigmaclip will be performed using the number provided as the sigmamultiplier to cut out from the input timeseries.
If a list of two ints/floats is provided, the function will perform an ‘asymmetric’ sigmaclip. The first element in this list is the sigma value to use for fainter flux/mag values; the second element in this list is the sigma value to use for brighter flux/mag values. For example, sigclip=[10., 3.], will sigclip out greater than 10sigma dimmings and greater than 3sigma brightenings. Here the meaning of “dimming” and “brightening” is set by physics (not the magnitude system), which is why the magsarefluxes kwarg must be correctly set.
If sigclip is None, no sigmaclipping will be performed, and the timeseries (with nonfinite elems removed) will be passed through to the output.
 nworkers (int) – The number of parallel workers to use when calculating the periodogram.
 workchunksize (None or int) – If this is an int, will use chunks of the given size to break up the work for the parallel workers. If None, the chunk size is set to 1.
 glspfunc (Python function) – The worker function to use to calculate the periodogram. This can be used to make this function calculate the timeseries sampling window function instead of the timeseries measurements’ GLS periodogram by passing in _glsp_worker_specwindow instead of the default _glsp_worker_withtau function.
 verbose (bool) – If this is True, will indicate progress and details about the frequency grid used for the period search.
Returns: This function returns a dict, referred to as an lspinfo dict in other astrobase functions that operate on periodogram results. This is a standardized format across all astrobase periodfinders, and is of the form below:
{'bestperiod': the best period value in the periodogram, 'bestlspval': the periodogram peak associated with the best period, 'nbestpeaks': the input value of nbestpeaks, 'nbestlspvals': nbestpeakssize list of best period peak values, 'nbestperiods': nbestpeakssize list of best periods, 'lspvals': the full array of periodogram powers, 'periods': the full array of periods considered, 'method':'gls' > the name of the periodfinder method, 'kwargs':{ dict of all of the input kwargs for recordkeeping}}
Return type: dict

astrobase.periodbase.zgls.
specwindow_lsp
(times, mags, errs, magsarefluxes=False, startp=None, endp=None, stepsize=0.0001, autofreq=True, nbestpeaks=5, periodepsilon=0.1, sigclip=10.0, nworkers=None, glspfunc=<function _glsp_worker_specwindow>, verbose=True)[source]¶ This calculates the spectral window function.
Wraps the pgen_lsp function above to use the specific worker for calculating the windowfunction.
Parameters:  times,mags,errs (np.array) – The mag/flux timeseries with associated measurement errors to run the periodfinding on.
 magsarefluxes (bool) – If the input measurement values in mags and errs are in fluxes, set this to True.
 startp,endp (float or None) – The minimum and maximum periods to consider for the transit search.
 stepsize (float) – The stepsize in frequency to use when constructing a frequency grid for the period search.
 autofreq (bool) – If this is True, the value of stepsize will be ignored and the
astrobase.periodbase.get_frequency_grid()
function will be used to generate a frequency grid based on startp, and endp. If these are None as well, startp will be set to 0.1 and endp will be set to times.max()  times.min().  nbestpeaks (int) – The number of ‘best’ peaks to return from the periodogram results, starting from the global maximum of the periodogram peak values.
 periodepsilon (float) – The fractional difference between successive values of ‘best’ periods when sorting by periodogram power to consider them as separate periods (as opposed to part of the same periodogram peak). This is used to avoid broad peaks in the periodogram and make sure the ‘best’ periods returned are all actually independent.
 sigclip (float or int or sequence of two floats/ints or None) –
If a single float or int, a symmetric sigmaclip will be performed using the number provided as the sigmamultiplier to cut out from the input timeseries.
If a list of two ints/floats is provided, the function will perform an ‘asymmetric’ sigmaclip. The first element in this list is the sigma value to use for fainter flux/mag values; the second element in this list is the sigma value to use for brighter flux/mag values. For example, sigclip=[10., 3.], will sigclip out greater than 10sigma dimmings and greater than 3sigma brightenings. Here the meaning of “dimming” and “brightening” is set by physics (not the magnitude system), which is why the magsarefluxes kwarg must be correctly set.
If sigclip is None, no sigmaclipping will be performed, and the timeseries (with nonfinite elems removed) will be passed through to the output.
 nworkers (int) – The number of parallel workers to use when calculating the periodogram.
 glspfunc (Python function) – The worker function to use to calculate the periodogram. This is used to used to make the pgen_lsp function calculate the timeseries sampling window function instead of the timeseries measurements’ GLS periodogram by passing in _glsp_worker_specwindow instead of the default _glsp_worker function.
 verbose (bool) – If this is True, will indicate progress and details about the frequency grid used for the period search.
Returns: This function returns a dict, referred to as an lspinfo dict in other astrobase functions that operate on periodogram results. This is a standardized format across all astrobase periodfinders, and is of the form below:
{'bestperiod': the best period value in the periodogram, 'bestlspval': the periodogram peak associated with the best period, 'nbestpeaks': the input value of nbestpeaks, 'nbestlspvals': nbestpeakssize list of best period peak values, 'nbestperiods': nbestpeakssize list of best periods, 'lspvals': the full array of periodogram powers, 'periods': the full array of periods considered, 'method':'win' > the name of the periodfinder method, 'kwargs':{ dict of all of the input kwargs for recordkeeping}}
Return type: dict

astrobase.periodbase.zgls.
probability_peak_exceeds_value
(times, peakval)[source]¶ This calculates the probability that periodogram values exceed the given peak value.
This is from page 3 of Zechmeister and Kurster (2009):
Prob(p > p_best) = (1 − p_best)**((N−3)/2)
where:
p_best is the peak value in consideration N is the number of times
Note that this is for the default normalization of the periodogram, e.g. P_normalized = P(omega), such that P represents the sample variance (see Table 1).
Parameters:  lspvals (np.array) – The periodogram power value array.
 peakval (float) – A single peak value to calculate the probability for.
Returns: prob – The probability value.
Return type: float

astrobase.periodbase.zgls.
analytic_false_alarm_probability
(lspinfo, times, conservative_nfreq_eff=True, peakvals=None, inplace=True)[source]¶ This returns the analytic false alarm probabilities for periodogram peak values.
The calculation follows that on page 3 of Zechmeister & Kurster (2009):
FAP = 1 − [1 − Prob(z > z0)]**M
where:
M is the number of independent frequencies Prob(z > z0) is the probability of peak with value > z0 z0 is the peak value we're evaluating
Parameters:  lspinfo (dict) – The dict returned by the
pgen_lsp()
function.  times (np.array) – The times for which the periodogram result in
lspinfo
was calculated.  conservative_nfreq_eff (bool) –
If True, will follow the prescription given in SchwarzenbergCzerny (2003):
http://adsabs.harvard.edu/abs/2003ASPC..292..383S
and estimate the effective number of independent frequences M_eff as:
min(N_obs, N_freq, DELTA_f/delta_f)
 peakvals (sequence or None) – The peak values for which to evaluate the falsealarm probability. If
None, will calculate this for each of the peak values in the
nbestpeaks
key of thelspinfo
dict.  inplace (bool) – If True, puts the results of the FAP calculation into the
lspinfo
dict as a list available aslspinfo['falsealarmprob']
.
Returns: The calculated false alarm probabilities for each of the peak values in
peakvals
.Return type: list
 lspinfo (dict) – The dict returned by the