Skip to content

FitLinear and FitQuad

Pavol Gajdoš edited this page Feb 21, 2019 · 31 revisions

Classes are used for fitting a linear a quadratic trend on O-C diagram caused by mass transfer. It is also possible to calculate O-C values from observed times of minima (O ≡ tO). The class FitLinear could also be used for removing the linear trend in the data and then fit the only quadratic trend, see Example.

Functions and parameters of both classes are nearly identical. In the case, that some function is only in one function, it is highlighted.

Initialization

OCFit.FitLinear(t, t0, P, oc = None, err = None)

OCFit.FitQuad(t, t0, P, oc = None, err = None)

For initialization these classes, it is necessary to give observed times of minima (O) and linear ephemeris of minima, i. e. time of reference minimum and period. If the values of O-C are already calculated, they could be given as the next parameter. If not, they will be automatically calculated from given times. These values could be immediately used in other calculations, they are stored in variable oc. It is also possible to give errors or uncertainties of times of minima (and also O-Cs). Eventually, if there are given only weights of individual points, it is possible to enter error as an inverted value of weight.

Parameter Type Description
t numpy.array or list Observed times of minima (O).
t0 float Time of reference minimum.
P float Period of the system.
oc numpy.array or list, optional Calculated values of O-Cs in days.
err numpy.array or list, optional Errors of O-C values or times O.

Available functions

FitLinear

OCFit.FitLinear.FitLinear()

The basic function for fitting linear trend in O-C diagram. This function is only available in a class FitLinear. New values of linear ephemeris are written to variable params; their uncertainties are in variable params_err. The new times (C) are also calculated stored in variable tC and new values of O-C stored in variable new_oc.

Parameter Type Description
Output numpy.array New values of O-C calculated on the basis of new linear ephemeris in days.

FitQuad

OCFit.FitQuad.FitQuad()

The basic function to fit the quadratic trend in the O-C diagram. This function is only available in a class FitQuad. New values of Q and linear ephemeris are written to variable params; their uncertainties are in variable params_err. The new times (C) are also calculated stored in variable tC and new values of O-C stored in variable new_oc.

Parameter Type Description
Output numpy.array New values of O-C for calculated Q and linear ephemeris in days.

FitRobust

OCFit.FitLinear.FitRobust(n iter = 10)

OCFit.FitQuad.FitRobust(n iter = 10)

The function for fitting linear / quadratic trend in O-C diagrams using robust regression. It is suitable to use this function in cases if there are a lot of outlier points in the data. New values of fitted parameters are written to variable params; their uncertainties are in variable params_err. The new times (C) are also calculated stored in variable tC and new values of O-C stored in variable new_oc.

Parameter Type Description
n iter integer, optional Number of iterations.
Output numpy.array New values of O-C.

FitMCMC

OCFit.FitLinear.FitMCMC(n_iter , limits, steps, fit_params = None, burn = 0, binn = 1, visible = True, db = None)

OCFit.FitQuad.FitMCMC(n_iter , limits, steps, fit_params = None, burn = 0, binn = 1, visible = True, db = None)

The function for fitting linear / quadratic trend in O-C diagram using Monte Carlo (MC) method. Running of this function is possible only if the initial values of fitted parameters were calculated. They could be obtained from fitting using function FitLinear / FitQuad or FitRobust. New values of fitted parameters are written to variable params; their uncertainties are in variable params_err. The new times (C) are also calculated stored in variable tC and new values of O-C stored in variable new_oc.

More detail description of the Monte Carlo method is in a part about the class OCFit.

Parameter Type Description
n_iter float Number of MC steps.
limits dictionary Limits for fitted parameters.
steps dictionary The steps for fitted parameters.
fit_params list List of fitted parameters. Default value ['P', 't0'] or ['Q', 'P', 't0'].
burn float, optional Number of MC steps which will be reject from calculation.
binn float, optional The size of one block for binning.
db string, optional Name of file for saving MC sampling.
visible boolean, optional Display progress of fitting and summary of results from pymc.
Output numpy.array New values of O-C.

InfoMCMC

OCFit.FitLinear.InfoMCMC(db, eps = False, geweke = False)

OCFit.FitQuad.InfoMCMC(db, eps = False, geweke = False)

Function for detail analysis of MC sampling obtained by FitMCMC. It will be generated a plot with a trace of fitting and common plot with trace and histogram for each of the fitted parameters. An also, the file with brief information about sampling, obtained values and errors of the parameter will be created. It is also possible to plot figures for Geweke analysis (details in Geweke (1992)).

Few common figures for all fitted parameters will be generated, too. There are histograms, deviances, correlation plots and 2D histograms displaying the confidence regions. For 2D histograms, the function ConfInt is used, everyone else is generated by the class TraceAnalysis from PyAstronomy. The last output is a table with correlation coefficients between fitted parameters.

Parameter Type Description
db string Name of file with saved MC sampling.
eps boolean, optional Save figures also in eps format.
geweke boolean, optional Geweke analysis.

Epoch

OCFit.FitLinear.Epoch()

OCFit.FitQuad.Epoch()

Calculation of epoch of all observed minima. This function is called during the initialization of the class. Obtained epochs are saved to variable epoch.

Parameter Type Description
Output numpy.array Calculated epochs.

PhaseCurve

OCFit.FitLinear.PhaseCurve(P, t0, plot = False)

OCFit.FitLinear.PhaseCurve(P, t0, plot = False)

Calculation of phase curve on the basis of given linear ephemeris. The final phase curve could be display on a figure.

Parameter Type Description
P float Period.
t0 float Time of reference minimum.
plot boolean, optional Plot also a figure or only calculated phase curve.
Output numpy.array Phases and values of O-C.

CalcErr

OCFit.FitLinear.CalcErr()

OCFit.FitQuad.CalcErr()

Calculation of errors of input data on a basis of values of fitted parameters. This function could not be used before fitting the data. It could be done using the function FitLinear / FitQuad or FitRobust. For all point, the same error will be assigned. The size of error will be set that the value of reduced squared error chi2r will be equal to 1.

The function is good to use if there is the only linear / quadratic trend in the data. Subsequently, during the repeated fitting better values of errors of parameters are obtained. It is necessary to use this function before fitting using the MC method by function FitMCMC if the errors of input data were not given during initialization.

Parameter Type Description
Output numpy.array Calculated errors.

CorrectErr

OCFit.FitLinear.CorrectErr()

OCFit.FitQuad.CorrectErr()

Re-normalization of given errors of input data on a basis of values of fitted parameters. This function could not be used before fitting the data. It could be done using function FitLinear / FitQuad or FitRobust. The size of error will be set that the value of reduced squared error chi2r will be equal to 1. For plotting the figure, original values of errors are used.

The function is good to use if there is the only linear / quadratic trend in the data. Subsequently, during the repeated fitting better values of errors of parameters are obtained. It is useful to use this function before fitting using the MC method by function FitMCMC if the errors of input data are wrong calculated (under- or over-estimated).

Parameter Type Description
Output numpy.array Calculated errors.

AddWeight

OCFit.FitLinear.AddWeight(w)

OCFit.FitQuad.AddWeight(w)

Adding the weights and normalization of errors on a basis of values of fitted parameters. This function could not be used before fitting the data. It could be done using function FitLinear / FitQuad or FitRobust. The size of error will be set that the value of reduced squared error chi2r will be equal to 1.

The function is good to use if there is the only linear / quadratic trend in the data. Subsequently, during the repeated fitting better values of errors of parameters are obtained. It is necessary to use this function before fitting using the MC method by function FitMCMC.

Parameter Type Description
w numpy.array Weights of points.
Output numpy.array Calculated errors.

Summary

OCFit.FitLinear.Sumarry(name = None)

OCFit.FitQuad.Sumarry(name = None)

Summary of values and errors of fitted parameters. The output could be saved to file or written on screen.

Parameter Type Description
name string, optional Name of output file.

Plot

OCFit.FitLinear.Plot(name = None, no_plot = 0, no_plot_err = 0, eps = False, oc_min = True, time_type = 'JD', offset = 2400000, trans = True, title = None, epoch = False, min_type = False, weight = None, trans_weight = False, bw = False, double_ax = False, fig_size = None)

OCFit.FitQuad.Plot(name = None, no_plot = 0, no_plot_err = 0, eps = False, oc_min = True, time_type = 'JD', offset = 2400000, trans = True, title = None, epoch = False, min_type = False, weight = None, trans_weight = False, bw = False, double_ax = False, fig_size = None)

Plotting original values of O-C and linear / quadratic fit. It is possible to save the figure to png file (eventually also to eps) or only display it on the screen. Outlier points or points with big error could not be plotted. Values of O-C could be displayed in minutes or in days. It is possible to set different type of Julian date displayed on x-label. The date could be transformed by subtraction of given offset. If the date was already transformed before, it is necessary to disable transformation of x-values (trans = False) but the value of the used offset is suitable to set due to the label on the x-axis. It is also possible to use epochs on the x-axis or also have two axes with Julian dates and epochs together. In the case, if the values of O-C of primary and also secondary minima are available, it is possible to distinguish it using the parameter min_type = True. Primary minima are displayed be full circle and the secondary by an empty circle. If the weights of points are available, they could be shown on the figures by entering them to weight. Weights are divided into these categories: 0-3, 3-5, 5-8, 8-10. In the case, that the weights are not in this interval, it is necessary to transform them by setting trans_weight = True. If the errors of data points were set up during initialization of the class and now the weights are given to weight, there will be plotted figure on according to given weights without error bars.

Parameter Type Description
name string, optional Name of file (without extension) where the figure will be saved.
no_plot integer, optional Number of outlier points which will not be plotted.
no_plot_err integer, optional Number of points with the biggest errors which will not be plotted.
eps boolean, optional Save figure also to eps file. (It is necessary to set the name to variable name!)
oc_min boolean, optional Values of O-C display in minutes, not in days.
time_type string, optional Type of Julian date (JD, HJD, BJD).
offset float, optional Value of offset of dates due to shortening values on x axis.
trans boolean, optional Transform x values by the offset.
title string, optional Title of the figure.
epoch boolean, optional Axis x in epochs.
min_type boolean, optional Distinguishing primary and secondary minima.
weight numpy.array, optional Weights of points.
trans_weight boolean, optional Transformation of weights to the range 0 – 10.
bw boolean, optional Black and white figure.
double_ax boolean, optional Double x axis - dates + epochs.
fig_size tuple, optional Custom figure size - e.g. (12,6).

PlotRes

OCFit.FitLinear.PlotRes(name = None, no_plot = 0, no_plot_err = 0, eps = False, oc_min = True, time_type = 'JD', offset = 2400000, trans = True, title = None, epoch = False, min_type = False, weight = None, trans_weight = False, bw = False, double_ax = False, fig_size = None)

OCFit.FitQuad.PlotRes(name = None, no_plot = 0, no_plot_err = 0, eps = False, oc_min = True, time_type = 'JD', offset = 2400000, trans = True, title = None, epoch = False, min_type = False, weight = None, trans_weight = False, bw = False, double_ax = False, fig_size = None)

Plotting the new values of O-C calculated for values of fitted parameters. It is possible to save figure to png file (eventually also to eps) or only display it on the screen. Outlier points or points with big error could not be plotted. Values of O-C could be displayed in minutes or in days. It is possible to set different type of Julian date displayed on x-label. The date could be transformed by subtraction of given offset. If the date was already transformed before, it is necessary to disable transformation of x-values (trans = False) but the value of the used offset is suitable to set due to the label on the x-axis. It is also possible to use epochs on the x-axis or also have two axes with Julian dates and epochs together. In the case, if the values of O-C of primary and also secondary minima are available, it is possible to distinguish it using the parameter min_type = True. Primary minima are displayed be full circle and the secondary by an empty circle. If the weights of points are available, they could be shown on the figures by entering them to weight. Weights are divided into these categories: 0-3, 3-5, 5-8, 8-10. In the case, that the weights are not in this interval, it is necessary to transform them by setting trans_weight = True. If the errors of data points were set up during initialization of the class and now the weights are given to weight, there will be plotted figure on according to given weights without error bars.

Parameter Type Description
name string, optional Name of file (without extension) where the figure will be saved.
no_plot integer, optional Number of outlier points which will not be plotted.
no_plot_err integer, optional Number of points with the biggest errors which will not be plotted.
eps boolean, optional Save figure also to eps file. (It is necessary to set the name to variable name!)
oc_min boolean, optional Values of O-C display in minutes, not in days.
time_type string, optional Type of Julian date (JD, HJD, BJD).
offset float, optional Value of offset of dates due to shortening values on x axis.
trans boolean, optional Transform x values by the offset.
title string, optional Title of the figure.
epoch boolean, optional Axis x in epochs.
min_type boolean, optional Distinguishing primary and secondary minima.
weight numpy.array, optional Weights of points.
trans_weight boolean, optional Transformation of weights to the range 0 – 10.
bw boolean, optional Black and white figure.
double_ax boolean, optional Double x axis - dates + epochs.
fig_size tuple, optional Custom figure size - e.g. (12,6).

SaveOC

OCFit.FitLinear.SaveOC(name, weight = None)

OCFit.FitQuad.SaveOC(name, weight = None)

Saving original values of O-C calculated from given linear ephemeris to file. The data are in columns: observed times of minima, epochs, values of O-C, errors (if given) or weight (if given).

Parameter Type Description
name string Name of output file.
weight numpy.array, optional Weights of data points.

SaveRes

OCFit.FitLinear.SaveRes(name, weight = None)

OCFit.FitQuad.SaveRes(name, weight = None)

Saving residue (new values of O-C) calculated from values of fitted parameters to file. The data are in columns: observed times of minima, epochs, values of O-C, errors (if given) or weight (if given).

Parameter Type Description
name string Name of output file.
weight numpy.array, optional Weights of data points.

Example

Example of work with both classes with simulated data. Data from the file is simply to load using function numpy.loadtxt.

from OCFit import FitQuad, FitLinear

import numpy as np

#generate data

E = np.arange(0, 100, 1) #epochs

#simulation of observed times

t = 1e-5*E**2+15*E + 1540.4 + np.random.normal(scale = 0.01, size = E.shape)

err = 0.01*np.ones(E.shape) #errors of 'observed' times

#usage of FitLinear to first estimation of linear ephemeris

#initialization using estiamtion (original values) of linear ephemeris

#for long time range of observation, the value of period has to be close

#to the right value, otherwise the primary and secondary minims could be mixed

lin = FitLinear(t, 1540, 15.01, err = err)

oc = lin.oc #O-C calculated from original ephemeris

lin.FitLinear() #linear fit

lin.FitRobust() #fitting using robust regression

lin.Summary() #summary of parameters

err = lin.CorrectErr() #re-normalization of errors

oc = lin.FitRobust() #fitting using robust regression

lin.Summary() #summary of parameters

#plotting figures

#plot of original values of O-C with fit, without transformation of x axis

lin.Plot(trans = False)

#plot of residual O-C, without transformation of x axis

lin.PlotRes(trans = False)

#usage of class FitQuad

#as estimation of linear ephemeris the resault from FitLinear are used

#new values of O-C are only fitted

quad = FitQuad(t, lin.t0, lin.P, oc = oc, err = err)

oc = quad.oc #O-C calculated from original ephemeris

quad.FitQuad() #quadratic fit

quad.FitRobust() #fitting using robust regression

quad.Summary() #summary of parameters

#plotting figures

#plot of original values of O-C with fit, without transformation of x axis

quad.Plot(trans = False)

#plot of residual O-C, without transformation of x axis

quad.PlotRes(trans = False)

Clone this wiki locally