TransitModelFit#
- class stellarphot.transit_fitting.TransitModelFit[source]#
Bases:
objectTransit model fits to observed light curves.
The underlying transit light curve is computed with pytransit’s RoadRunnerModel using a quadratic limb-darkening law and a circular orbit. The fit is performed with lmfit.
- Attributes:
- params
lmfit.Parameters The transit model parameters:
t0,period,rp(planet radius in stellar radii),a(orbital radius in stellar radii),inclination(degrees),limb_u1/limb_u2(quadratic limb-darkening coefficients) and the linear trend coefficientsairmass_trend,width_trendandspp_trend. Read or set values, bounds and whether a parameter is fit through the standard lmfit attributes, e.g.mod.params["rp"].value,mod.params["t0"].vary,mod.params["a"].minand, after a fit,mod.params["rp"].stderr.- fit_result
lmfit.minimizer.MinimizerResultor None Result of the most recent call to
fit, including fit statistics likebicandnvarys.Noneuntilfithas been run.- times, airmass, width, spp, data, weightsarray-like or None
Independent variables and data for the fit; see the property docstrings.
- params
Notes
The orbit is always circular; there is no eccentricity parameter.
Trend fitting is opt-in: the trend coefficients default to
vary=Falseeven when a covariate (airmass, width, sky per pixel) is set. Enable them viaTransitModelOptions, directly (e.g.mod.params["airmass_trend"].vary = True) or withcompare_detrend_options(apply_best=True).Examples
Fit a transit, detrending against airmass:
mod = TransitModelFit() mod.setup_model(t0=2455001.5, depth=12.1, duration=0.15, period=3.5) mod.times = times mod.data = fluxes mod.weights = 1 / flux_errors mod.airmass = airmass mod.params["airmass_trend"].vary = True result = mod.fit() print(mod.params["rp"].value, mod.params["rp"].stderr) print(result.bic) # Which detrending parameters does the BIC favor? bic_table = mod.compare_detrend_options()
Attributes Summary
airmass : array-like
data : array-like
spp : array-like
times : array-like
weights : array-like
Methods Summary
compare_detrend_options([apply_best])Compare, via the Bayesian Information Criterion, fits with every on/off combination of the trend parameters whose covariate is set.
data_light_curve([data, detrend_by])Function to return data light curve, optionally detrended by one or more parameters.
fit()Fit the model to the data and update
paramswith the best-fit values and uncertainties.model_light_curve([at_times, detrend_by])Calculate the light curve corresponding to the model, optionally detrended by one or more parameters.
setup_model(*[, binned_data, t0, depth, ...])Configure a transit model for fitting.
Attributes Documentation
- airmass#
- airmassarray-like
Airmass at each time. Must be set before fitting.
- data#
- dataarray-like
Observed fluxes. Must be set before fitting.
- spp#
- spparray-like
Sky per pixel at each time. Must be set before fitting.
- times#
- timesarray-like
Times at which the light curve is observed. Must be set before fitting.
- width#
- weightsarray-like
Weights to use for fitting. If not provided, all weights are set to 1.
Methods Documentation
- compare_detrend_options(apply_best=False)[source]#
Compare, via the Bayesian Information Criterion, fits with every on/off combination of the trend parameters whose covariate is set.
Each candidate fit runs on a copy of
params— with the trends in the combination varying, and the others fixed at zero — so this method does not change the state of the model.- Parameters:
- apply_bestbool, optional
If True, apply the lowest-BIC combination to
params(each trend in the winning combination is varied, the others are zeroed and fixed) and runfit.
- Returns:
astropy.table.TableOne row per combination with a bool column per available trend (
airmass,width,spp) and aBICcolumn, sorted by ascending BIC (best first).
- data_light_curve(data=None, detrend_by=None)[source]#
Function to return data light curve, optionally detrended by one or more parameters.
- Parameters:
- dataarray-like, optional
Data to use for calculating the light curve. If not provided, the data used for fitting will be used.
- detrend_bystr or list of str
Parameter(s) to detrend by. If
None, no detrending is done. If'all', all parameters that are set will be used for detrending.
- Returns:
- dataarray-like
Data light curve, detrended if requested.
- fit()[source]#
Fit the model to the data and update
paramswith the best-fit values and uncertainties.- Returns:
lmfit.minimizer.MinimizerResultThe full fit result, also stored as
fit_result. Includes fit statistics likebic.
- Raises:
- ValueError
If the times or the data have not been set. If the fit itself raises,
paramsandfit_resultare left untouched.
- model_light_curve(at_times=None, detrend_by=None)[source]#
Calculate the light curve corresponding to the model, optionally detrended by one or more parameters.
- Parameters:
- at_timesarray-like
Times at which to calculate the model. If not provided, the times used for fitting will be used. Because the airmass/width/spp trend covariates are reused as-is,
at_timesmust have the same length as the model’s times; a mismatched length raisesValueError.- detrend_bystr or list of str
Parameter(s) to detrend by. If
None, no detrending is done. If'all', all parameters that are set will be used for detrending.
- Returns:
- modelarray-like
Model light curve.
- setup_model(*, binned_data=None, t0=0, depth=0, duration=0, period=1, inclination=90, airmass_trend=0.0, width_trend=0.0, spp_trend=0.0, model_options=None)[source]#
Configure a transit model for fitting. The
durationanddepthare used to estimate underlying fit parameters; they are not themselves fit parameters. Any previous parameter settings are reset to their defaults before the new values are applied.All arguments are keyword-only.
- Parameters:
- binned_data
astropy.timeseries.BinnedTimeSeries, optional Binned time series to load the times, data, weights and covariates from.
- t0float
Time of the center of the transit. Can be in any units but should be consistent with the units for the
periodand for the times used for fitting.- depthfloat
Depth of the transit in parts per thousand. If zero (the default), the planet radius
rpis left at its default starting value instead of being estimated.- durationfloat
Duration of the transit, in the same units as
t0andperiod. If zero (the default), the orbital radiusais left at its default starting value instead of being estimated. Must be smaller than theperiod.- periodfloat
Period of the planet. Should be in the same units as
t0and times used for fitting.- inclinationfloat
Inclination of the orbit, in degrees.
- airmass_trendfloat, optional
Coefficient for a linear trend in airmass.
- width_trendfloat
Coefficient for a linear trend in stellar width.
- spp_trendfloat
Coefficient for a linear trend in sky per pixel.
- model_optionsTransitModelOptions, optional
Options for the transit model fit, mapped onto the
varyflags (and, fort0, the bounds) of the parameters.
- binned_data
- Returns:
- None
Sets values for the model parameters.
- Raises:
- ValueError
If
durationis not smaller thanperiod.