Sersic model fitting

SphotModel, ModelFitter, ModelScaleFitter and the optimiser dispatchers (iNM, dual-annealing, triple-annealing, L-BFGS-B polish).

class sphot.fitting.SphotModel(*args: Any, **kwargs: Any)[source]

Bases: PSFConvolvedModel2D

parse_params(theta)[source]

a helper function to parse coordinates to all relevant sub-models.

list_to_params(theta)[source]

convert a list of free parameters to the full model parameter array

set_fixed_params(fixed_params)[source]
get_bounds()[source]
set_conditions(list_of_conditions)[source]

Set condition functions.

Parameters:

list_of_conditions (list of 2-tuple) – list of conditions, each as a 2-tuple. Each tuple (a, b) is evaluated as a >= b. Either entry of the tuple can be a parameter name or a numerical value. For example, [('r_eff', 10), ('r_eff_1', 'r_eff_0')] returns True iff r_eff >= 10 AND r_eff_1 >= r_eff_0.

class sphot.fitting.ModelFitter(model, cutoutdata, **kwargs)[source]

Bases: object

A fitter class to perform Sersic model fitting to data.

standardize_params(params)[source]

normalize parameters to be between 0 and 1.

unstandardize_params(params)[source]

convert back normalized parameters to the physical scale

eval_model(standardized_params)[source]

render the model image based on the given parameters

calc_chi2(standardized_params, iterinfo='', print_val=False, chi2_min_allowed=1e-10)[source]
fit(method='iterative_NM', fit_to='data', **kwargs)[source]
class sphot.fitting.ModelScaleFitter(model, cutoutdata, base_params=None, **kwargs)[source]

Bases: ModelFitter

scale_params(flux_scale)[source]

a helper function to scale the parameters based on the flux scale

calc_chi2(flux_scale, iterinfo='', print_val=False, chi2_min_allowed=1e-10)[source]
fit(method='iterative_NM', fit_to='data', **kwargs)[source]
sphot.fitting.iterative_NM(func, args, x0, bounds, rtol_init=0.001, rtol_iter=0.0001, rtol_convergence=1e-06, xrtol=1, max_iter=20, maxfev_eachiter=100, progress=None, progress_text='Running iNM...', **kwargs)[source]

Iterative Nelder-Mead minimization. The original implementation by Scipy tends to miss the global minimum. Rather than setting the tolerance to be small, the success rate tends to be higher when the tolerance is set to be larger and the minimization is run multiple times.

sphot.fitting.save_bestfit_params(cutoutdata, bestfit_sersic_params_physical)[source]