FluxPointsFitter

class gammapy.spectrum.FluxPointsFitter(stat='chi2', optimizer='simplex', error_estimator='covar', ul_handling='ignore')[source]

Bases: object

Fit a set of flux points with a parametric model.

Parameters:

optimizer : {‘simplex’, ‘moncar’, ‘gridsearch’}

Select optimizer

error_estimator : {‘covar’}

Select error estimator

ul_handling : {‘ignore’}

How to handle flux point upper limits in the fit

Examples

Load flux points from file and fit with a power-law model:

from astropy import units as u
from gammapy.spectrum import FluxPoints, FluxPointsFitter
from gammapy.spectrum.models import PowerLaw

filename = '$GAMMAPY_EXTRA/test_datasets/spectrum/flux_points/diff_flux_points.fits'
flux_points = FluxPoints.read(filename)

model = PowerLaw(
    index=2. * u.Unit(''),
    amplitude=1e-12 * u.Unit('cm-2 s-1 TeV-1'),
    reference=1. * u.TeV,
)

fitter = FluxPointsFitter()
result = fitter.run(flux_points, model)
print(result['best_fit_model'])

Methods Summary

dof(data, model) Degrees of freedom.
estimate_errors(data, model) Estimate errors on best fit parameters.
fit(data, model) Fit given model to data.
run(data, model) Run all fitting adn extra information steps.
statval(data, model) Compute statval for given model and data.

Methods Documentation

dof(data, model)[source]

Degrees of freedom.

Parameters:

model : SpectralModel

Spectral model

estimate_errors(data, model)[source]

Estimate errors on best fit parameters.

fit(data, model)[source]

Fit given model to data.

Parameters:

model : SpectralModel

Spectral model (with fit start parameters)

Returns:

best_fit_model : SpectralModel

Best fit model

run(data, model)[source]

Run all fitting adn extra information steps.

Parameters:

data : list of FluxPoints

Flux points.

model : SpectralModel

Spectral model

Returns:

result : OrderedDict

Dictionary with fit results and debug output.

statval(data, model)[source]

Compute statval for given model and data.

Parameters:

model : SpectralModel

Spectral model