astrobase.varbase.signals module

Contains functions to deal with masking and removing periodic signals in light curves.

astrobase.varbase.signals.prewhiten_magseries(times, mags, errs, whitenperiod, whitenparams, sigclip=3.0, magsarefluxes=False, plotfit=None, plotfitphasedlconly=True, rescaletomedian=True)[source]

Removes a periodic sinusoidal signal generated using whitenparams from the input magnitude time series.

Parameters:
  • times,mags,errs (np.array) – The input mag/flux time-series to prewhiten.
  • whitenperiod (float) – The period of the sinusoidal signal to remove.
  • whitenparams (list of floats) –

    This contains the Fourier amplitude and phase coefficients of the sinusoidal signal to remove:

    [ampl_1, ampl_2, ampl_3, ..., ampl_X,
     pha_1, pha_2, pha_3, ..., pha_X]
    

    where X is the Fourier order. These are usually the output of a previous Fourier fit to the light curve (from astrobase.lcfit.sinusoidal.fourier_fit_magseries() for example).

  • sigclip (float or int or sequence of two floats/ints or None) –

    If a single float or int, a symmetric sigma-clip will be performed using the number provided as the sigma-multiplier to cut out from the input time-series.

    If a list of two ints/floats is provided, the function will perform an ‘asymmetric’ sigma-clip. 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 10-sigma dimmings and greater than 3-sigma 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 sigma-clipping will be performed, and the time-series (with non-finite elems removed) will be passed through to the output.

  • magsarefluxes (bool) – If True, will treat the input values of mags as fluxes for purposes of plotting the fit and sig-clipping.
  • plotfit (str or False) – If this is a string, this function will make a plot showing the effect of the pre-whitening on the mag/flux time-series and write the plot to the path specified here.
  • plotfitphasedlconly (bool) – If True, will plot only the phased LC for showing the effect of pre-whitening, and skip plotting the unphased LC.
  • rescaletomedian (bool) – If this is True, then we add back the constant median term of the magnitudes to the final pre-whitened mag series.
Returns:

Returns a dict of the form:

{'wtimes':times array after pre-whitening,
 'wphase':phase array after pre-whitening,
 'wmags':mags array after pre-whitening,
 'werrs':errs array after pre-whitening,
 'whitenparams':the input pre-whitening params used,
 'whitenperiod':the input pre-whitening period used,
 'fitplotfile':the output plot file if plotfit was set}

Return type:

dict

astrobase.varbase.signals.gls_prewhiten(times, mags, errs, fourierorder=3, initfparams=None, startp_gls=None, endp_gls=None, stepsize=0.0001, autofreq=True, sigclip=30.0, magsarefluxes=False, nbestpeaks=5, nworkers=4, plotfits=None)[source]

Iterative pre-whitening of a magnitude series using the L-S periodogram.

This finds the best period, fits a fourier series with the best period, then whitens the time series with the best period, and repeats until nbestpeaks are done.

Parameters:
  • times,mags,errs (np.array) – The input mag/flux time-series to iteratively pre-whiten.
  • fourierorder (int) – The Fourier order of the sinusoidal signal to fit to the time-series and iteratively remove.
  • initfparams (list or None) –

    If this is provided, should be a list of Fourier amplitudes and phases in the following format:

    [ampl_1, ampl_2, ampl_3, ..., ampl_X,
     pha_1, pha_2, pha_3, ..., pha_X]
    

    where X is the Fourier order. These are usually the output of a previous Fourier fit to the light curve (from astrobase.lcfit.sinusoidal.fourier_fit_magseries() for example). You MUST provide ONE of fourierorder and initfparams, but not both. If both are provided or both are None, a sinusoidal signal of Fourier order 3 will be used by default.

  • endp_gls (startp_gls,) – If these are provided, will serve as input to the Generalized Lomb-Scargle function that will attempt to find the best nbestpeaks periods in the time-series. These set the minimum and maximum period to search for in the time-series.
  • stepsize (float) – The step-size 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().
  • sigclip (float or int or sequence of two floats/ints or None) –

    If a single float or int, a symmetric sigma-clip will be performed using the number provided as the sigma-multiplier to cut out from the input time-series.

    If a list of two ints/floats is provided, the function will perform an ‘asymmetric’ sigma-clip. 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 10-sigma dimmings and greater than 3-sigma 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 sigma-clipping will be performed, and the time-series (with non-finite elems removed) will be passed through to the output.

  • magsarefluxes (bool) – If the input measurement values in mags and errs are in fluxes, set this to True.
  • nbestpeaks (int) – The number of ‘best’ peaks to return from the periodogram results, starting from the global maximum of the periodogram peak values.
  • nworkers (int) – The number of parallel workers to use when calculating the periodogram.
  • plotfits (None or str) – If this is a str, should indicate the file to which a plot of the successive iterations of pre-whitening will be written to. This will contain a row of plots indicating the before/after states of the light curves for each round of pre-whitening.
Returns:

(bestperiods, plotfile) – This returns a list of the best periods (with the “highest” peak in the periodogram) after each round of pre-whitening is done. If plotfit is a str, will also return the path to the generated plot file.

Return type:

tuple

astrobase.varbase.signals.mask_signal(times, mags, errs, signalperiod, signalepoch, magsarefluxes=False, maskphases=(0, 0, 0.5, 1.0), maskphaselength=0.1, plotfit=None, plotfitphasedlconly=True, sigclip=30.0)[source]

This removes repeating signals in the magnitude time series.

Useful for masking planetary transit signals in light curves to search for other variability.

A small worked example of using this and prewhiten_magseries above:

https://github.com/waqasbhatti/astrobase/issues/77#issuecomment-463803558

Parameters:
  • times,mags,errs (np.array) – The input mag/flux time-series to run the masking on.
  • signalperiod (float) – The period of the signal to mask.
  • signalepoch (float) – The epoch of the signal to mask.
  • magsarefluxes (bool) – Set to True if mags is actually an array of fluxes.
  • maskphases (sequence of floats) – This defines which phase values will be masked. For each item in this sequence, this function will mask a length of phase given by maskphaselength centered on each maskphases value, and remove all LC points in these regions from the light curve.
  • maskphaselength (float) – The length in phase to mask for each phase value provided in maskphases.
  • plotfit (str or None) – If provided as a str, indicates the output plot file.
  • plotfitphasedlconly (bool) – If True, will only plot the effect of masking the signal as requested on the phased LC. If False, will also plot the unphased LC.
  • sigclip (float or int or sequence of two floats/ints or None) –

    If a single float or int, a symmetric sigma-clip will be performed using the number provided as the sigma-multiplier to cut out from the input time-series.

    If a list of two ints/floats is provided, the function will perform an ‘asymmetric’ sigma-clip. 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 10-sigma dimmings and greater than 3-sigma 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 sigma-clipping will be performed, and the time-series (with non-finite elems removed) will be passed through to the output.