MulensModel.event module

class MulensModel.event.Event(datasets=None, model=None, coords=None)

Bases: object

Combines a microlensing model with data. Allows calculating chi^2 and making a number of plots.

Arguments :

datasets: MulensData or list of MulensData objects

Datasets that will be linked to the event. These datasets will be used for chi^2 calculation, plotting etc.
model: Model
Microlensing model that will be linked to the event. In order to get chi^2 for different sets of model parameters you should keep a single Model instance and change parameters for this model (i.e., do not provide separate Model instances).

coords: str, Coordinates, or astropy.SkyCoord

Coordinates of the event. If str, then needs format accepted by astropy.SkyCoord e.g., '18:00:00 -30:00:00'.
Attributes :
best_chi2: float
Smallest value returned by get_chi2().
best_chi2_parameters: dict
Parameters that gave smallest chi2.
sum_function: str
Function used for adding chi^2 contributions. Can be either ‘math.fsum’ (default value) or ‘numpy.sum’. The former is slightly slower and more accurate, which may be important for large datasets.

The datasets can be in magnitude or flux spaces. When we calculate chi^2 we do it in the same space as the dataset considered. If dataset is in magnitude space and model results in negative flux, then we calculate chi^2 in flux space but only for the epochs with negative model flux.

datasets

a list of MulensData instances.

data_ref

Reference data set for scaling the model fluxes to (for plotting). May be set as a MulensData object or an index (int). Default is the first data set.

model

an instance of Model

coords

see Coordinates

reset_best_chi2()

Reset best_chi2 attribute and its parameters (best_chi2_parameters).

get_chi2(fit_blending=None)

Calculates chi^2 of current model by fitting for source and blending fluxes.

Parameters :
fit_blending: boolean, optional
If True, then the blend flux is a free parameter. If False, the blend flux is fixed at zero. Default is the same as MulensModel.fit.Fit.fit_fluxes().
Returns :
chi2: float
Chi^2 value
get_chi2_for_dataset(index_dataset, fit_blending=None)

Calculates chi^2 for a single dataset

Parameters :
index_dataset: int
index that specifies for which dataset the chi^2 is requested
fit_blending: boolean, optional
Are we fitting for blending flux? If not then blending flux is fixed to 0. Default is the same as MulensModel.fit.Fit.fit_fluxes().
Returns :
chi2: float
chi2 for dataset[index_dataset].
get_chi2_per_point(fit_blending=None)

Calculates chi^2 for each data point of the current model by fitting for source and blending fluxes.

Parameters :
fit_blending: boolean, optional
Are we fitting for blending flux? If not then blending flux is fixed to 0. Default is the same as MulensModel.fit.Fit.fit_fluxes().
Returns :
chi2: list of np.ndarray
Chi^2 contribution from each data point, e.g. chi2[data_num][k] returns the chi2 contribution from the k-th point of dataset data_num.
Example :

Assumming event is instance of Event class to get chi2 for 10-th point point of 0-th dataset.

chi2 = event.get_chi2_per_point()
print(chi2[0][10])
chi2_gradient(parameters, fit_blending=None)

Calculate chi^2 gradient (also called Jacobian), i.e., \(d chi^2/d parameter\).

Parameters :
parameters: str or list, required
Parameters with respect to which gradient is calculated. Currently accepted parameters are: t_0, u_0, t_eff, t_E, pi_E_N, and pi_E_E. The parameters for which you request gradient must be defined in py:attr:~model.
fit_blending: boolean, optional
Are we fitting for blending flux? If not then blending flux is fixed to 0. Default is the same as MulensModel.fit.Fit.fit_fluxes().
Returns :
gradient: float or np.ndarray
chi^2 gradient
get_ref_fluxes(data_ref=None)

Get source and blending fluxes for the reference dataset. See MulensModel.model.Model.get_ref_fluxes() for details.

plot_model(**kwargs)

Plot the model light curve in magnitudes. See MulensModel.model.Model.plot_lc() for details.

plot_data(**kwargs)

Plot the data scaled to the model. See MulensModel.model.Model.plot_data() for details.

plot_residuals(**kwargs)

Plot the residuals (in magnitudes) of the model. See MulensModel.model.Model.plot_residuals() for details.

plot_source_for_datasets(**kwargs)

Plot source positions for all linked datasets. See MulensModel.model.Model.plot_source_for_datasets() for details.

clean_data()

masks outlying datapoints. Not Implemented.

estimate_model_params()

estimates model parameters without fitting them. Not Implemented.