astrobase.lcfit.sinusoidal module

Light curve fitting routines for sinusoidal models:

astrobase.lcfit.sinusoidal.fourier_fit_magseries(times, mags, errs, period, fourierorder=None, fourierparams=None, fix_period=True, scale_errs_redchisq_unity=True, sigclip=3.0, magsarefluxes=False, plotfit=False, ignoreinitfail=True, verbose=True, curve_fit_kwargs=None)[source]

This fits a Fourier series to a mag/flux time series.

Parameters:
  • times,mags,errs (np.array) – The input mag/flux time-series to fit a Fourier cosine series to.
  • period (float) – The period to use for the Fourier fit.
  • fourierorder (None or int) – If this is an int, will be interpreted as the Fourier order of the series to fit to the input mag/flux times-series. If this is None and fourierparams is specified, fourierparams will be used directly to generate the fit Fourier series. If fourierparams is also None, this function will try to fit a Fourier cosine series of order 3 to the mag/flux time-series.
  • fourierparams (list of floats or None) –

    If this is specified as a list of floats, it must be of the form below:

    [fourier_amp1, fourier_amp2, fourier_amp3,...,fourier_ampN,
     fourier_phase1, fourier_phase2, fourier_phase3,...,fourier_phaseN]
    

    to specify a Fourier cosine series of order N. If this is None and fourierorder is specified, the Fourier order specified there will be used to construct the Fourier cosine series used to fit the input mag/flux time-series. If both are None, this function will try to fit a Fourier cosine series of order 3 to the input mag/flux time-series.

  • fix_period (bool) – If True, will fix the period with fitting the sinusoidal function to the phased light curve.
  • scale_errs_redchisq_unity (bool) – If True, the standard errors on the fit parameters will be scaled to make the reduced chi-sq = 1.0. This sets the absolute_sigma kwarg for the scipy.optimize.curve_fit function to False.
  • 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 for the fit to the mag/flux time-series and writes the plot to the path specified here.
  • ignoreinitfail (bool) – If this is True, ignores the initial failure to find a set of optimized Fourier parameters using the global optimization function and proceeds to do a least-squares fit anyway.
  • verbose (bool) – If True, will indicate progress and warn of any problems.
  • curve_fit_kwargs (dict or None) – If not None, this should be a dict containing extra kwargs to pass to the scipy.optimize.curve_fit function.
Returns:

This function returns a dict containing the model fit parameters, the minimized chi-sq value and the reduced chi-sq value. The form of this dict is mostly standardized across all functions in this module:

{
    'fittype':'fourier',
    'fitinfo':{
        'finalparams': the list of final model fit params,
        'finalparamerrs': list of errs for each model fit param,
        'fitmags': the model fit mags,
        'fitperiod': the fit period if this wasn't set to fixed,
        'fitepoch': this is times.min() for this fit type,
        'actual_fitepoch': time of minimum light from fit model
        ... other fit function specific keys ...
    },
    'fitchisq': the minimized value of the fit's chi-sq,
    'fitredchisq':the reduced chi-sq value,
    'fitplotfile': the output fit plot if fitplot is not None,
    'magseries':{
        'times':input times in phase order of the model,
        'phase':the phases of the model mags,
        'mags':input mags/fluxes in the phase order of the model,
        'errs':errs in the phase order of the model,
        'magsarefluxes':input value of magsarefluxes kwarg
    }
}

NOTE: the returned value of ‘fitepoch’ in the ‘fitinfo’ dict returned by this function is the time value of the first observation since this is where the LC is folded for the fit procedure. To get the actual time of minimum epoch as calculated by a spline fit to the phased LC, use the key ‘actual_fitepoch’ in the ‘fitinfo’ dict.

Return type:

dict