MulensModel.fitdata module¶
- class MulensModel.fitdata.FitData(model=None, dataset=None, fix_blend_flux=False, fix_source_flux=False, fix_source_flux_ratio=False)¶
Bases:
object
Performs a least squares linear fit for given dataset and model to determine the source flux(es) and (optionally) blend flux. After creating the object, you must run
update()
to perform the linear fit for the fluxes and calculate the chi2. To perform the linear fit without calculating chi2, you can runfit_fluxes()
. If you change anything in the object, e.g. the model parameters, you must re-runupdate()
orfit_fluxes()
.- Arguments :
- model:
Model
object The model to fit to the data.
- dataset:
MulensData
object A single photometric dataset to be fitted.
- fix_blend_flux: False or float, optional
Default is False, i.e. allow the blend flux to be a free parameter. If set to a float, it will fix the blend value to that value.
- fix_source_flux: False, float, or list, optional
Default is False, i.e. allow the source flux to be a free parameter. If set to a float, it will fix the source value to that value. For binary source models, a list should be used to set the fluxes of the individual sources or fix one and not the other, e.g. [2.3, False] would fix source_flux_0 to 2.3 but allow a free fit to source_flux_1.
- fix_source_flux_ratio: False or float, optional
For binary source models, source_flux_ratio is the flux ratio between two components, i.e., source_flux_ratio = source_flux_1 / source_flux_0 Default is False, i.e. allow the source flux to be a free parameter. If set to a float, it will fix the source value to that value.
- model:
- update(bad=False)¶
Calculate the best-fit source and blend fluxes as well as the chi2.
- Parameters :
- bad: bool
Default is False. If True recalculates the data magnification for each point to ensure that there are values even for bad datapoints.
No returns.
- fit_fluxes()¶
Execute the linear least squares fit to determine the fitted fluxes. Sets the values of
source_fluxes
,blend_flux
, and (if applicable)source_flux
.Does not calculate chi2. To fit for the fluxes and calculate chi2, run
update()
.No parameters.
No returns.
- get_data_magnification(bad=False)¶
Calculates the model magnification for each data point.
- Parameters :
- bad: boolean
If True, calculates the magnification for all points. If False, only calculates the magnification for good data points. Values for bad data points are set to 0. Default is False.
- Returns :
- data_magnification: np.ndarray
The model magnification evaluated for each datapoint. If there is more than one source, the magnification of each source is reported separately.
- get_model_fluxes(bad=False)¶
Calculate model in flux space.
- Parameters :
- bad: bool
Default is False. If True recalculates the data magnification for each point to ensure that the values for bad datapoints are calculated (otherwise, they are set to the magnitude of the blend).
- Returns :
- model_flux: np.ndarray
The model flux evaluated for each datapoint.
- get_model_magnitudes(**kwargs)¶
Calculate model in magnitude space
- Parameters :
**kwargs
:
- Returns :
- model_mag: np.ndarray
The model magnitude evaluated for each datapoint.
- scale_fluxes(source_flux, blend_flux)¶
- Rescale the data fluxes to an arbitrary flux scale:
flux = source_flux_0 * (data.flux - blend_flux) / source_flux flux += blend_flux_0 err_flux = source_flux_0 * data.err_flux / source_flux
- Parameters :
- source_flux: float, list, np.array
Flux of the source in the desired system. If n_sources > 1 and source_flux has more than one element, the elements are summed to produce the overall scaling flux.
- blend_flux: float
Flux of the blend in the desired system
- Returns :
- flux: np.ndarray
Fluxes from the data rescaled to the desired system.
- err_flux: np.ndarray
Uncertainties of fluxes from the data rescaled to the desired system.
- get_residuals(phot_fmt=None, source_flux=None, blend_flux=None, bad=False)¶
Calculate the residuals for each datapoint relative to the model.
- Parameters :
- phot_fmt: str, optional
specify whether the residuals should be returned in magnitudes (‘mag’) or in flux (‘flux’). Default is ‘mag’. If ‘scaled’, will return the residuals in magnitudes scaled to source_flux, blend_flux.
- source_flux, blend_flux: float
reference source and blend fluxes for scaling the residuals
- bad: bool
Default is False. If True recalculates the data magnification for each point to ensure that there are values even for bad datapoints.
- Returns :
- residuals: np.ndarray
the residuals for the corresponding dataset.
- errorbars: np.ndarray
the scaled errorbars for each point. For plotting errorbars for the residuals.
- get_chi2_gradient(parameters)¶
Fits fluxes and calculates 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
, andpi_E_E
. The parameters for which you request gradient must be defined in py:attr:~model.
- Returns :
- gradient: float or np.ndarray
chi^2 gradient
- calculate_chi2_gradient(parameters)¶
Calculates chi^2 gradient (also called Jacobian), i.e., \(d chi^2/d parameter\) WITHOUT refitting for the fluxes. Saves computations if, e.g., you want to retrieve both py:attr:~chi2 and py:attr:~chi2_gradient.
- 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
, andpi_E_E
. The parameters for which you request gradient must be defined in py:attr:~model.
- Returns :
- gradient: float or np.ndarray
chi^2 gradient
- get_d_A_d_params_for_point_lens_model(parameters)¶
Calculate d A / d parameters for a point lens model.
- Parameters :
- parameters: list
List of the parameters to take derivatives with respect to.
- Returns :
- dA_dparam: dict
Keys are parameter names from parameters argument above. Values are the partial derivatives for that parameter evaluated at each data point.
- get_d_A_d_rho()¶
Calculate d A / d rho for a point lens model.
No Inputs
- Returns :
- dA_drho: np.array
Values are the partial derivatives for rho evaluated at each data point.
- get_dataset_trajectory()¶
Retrieve a
Trajectory
object. If thedataset
has an ephemerides_file, apply it to the Trajectory, even if it is not part of themodel
.No parameters.
- Returns :
- trajectory:
Trajectory
Trajectory for given dataset.
- trajectory:
- get_d_A_d_u_for_PSPL_model()¶
- get_d_A_d_u_for_FSPL_model()¶
- get_d_A_d_u_for_point_lens_model()¶
- property chi2_gradient¶
float or np.ndarray
Previously calculated chi^2 gradient (also called Jacobian), i.e., \(d chi^2/d parameter\). See
get_chi2_gradient()
andcalculate_chi2_gradient()
.Gives None if the chi2 gradient was not previously calculated using one of the functions mentioned above.
- property chi2¶
float The total chi2 for the fitted dataset. Good points only. See
good
.If None, you need to run
update()
to execute the linear fit and calculate the chi2.
- property chi2_per_point¶
np.ndarray
The chi^2 contribution from each data point, e.g.,
chi2_per_point[k]
returns the chi2 contribution from the k-th point ofdataset
. Includes bad datapoints.If None, you need to run
update()
to execute the linear fit and calculate the chi2.
- property source_flux¶
float
The fitted source flux. Only defined for models with a single source. See also
source_fluxes
If None, you need to run
fit_fluxes()
orupdate()
to execute the linear fit.
- property source_fluxes¶
np.array
The fitted source flux(es).
If None, you need to run
fit_fluxes()
orupdate()
to execute the linear fit.
- property blend_flux¶
float
The fitted blend flux or the value set by fix_blend_flux (see Keywords).
If None, you need to run
fit_fluxes()
orupdate()
to execute the linear fit.
- property source_flux_ratio¶
float
source_flux_ratio = source_flux_1 / source_flux_0
i.e., the ratio of the fitted source fluxes or the value set by fix_source_flux_ratio (see Keywords).
If None, you need to run
fit_fluxes()
orupdate()
to execute the linear fit.
- property dataset¶
-
A single photometric dataset to be fitted.
- property data_magnification¶
Returns previously calculated magnifications. To calculate the magnifications (e.g., if something changed in the model), use
get_data_magnification()
.- Returns :
- data_magnification: np.ndarray
The model magnification evaluated for each datapoint. If there is more than one source, the magnification of each source is reported separately.
- property magnification_curve¶
Returns previously calculated magnification curve.
- property magnification_curves¶
Returns previously calculated magnification curves.
- Returns :
tuple of :py:class:`~MulensModel.magnification.MagnificationCurve objects, i.e., the model magnification curve evaluated for each datapoint.
- property gamma¶
float
Limb-darkening coefficient for this fit. Set by
bandpass
andget_limb_coeff_gamma()
.