SpectrumFitResult

class gammapy.spectrum.SpectrumFitResult(model, fit_range=None, statname=None, statval=None, stat_per_bin=None, npred_src=None, npred_bkg=None, background_model=None, fluxes=None, flux_errors=None, obs=None)[source]

Bases: object

Class representing the result of a spectral fit

TODO: This only supports WStat fits at the moment. Find a solution to display also Cash fits (flag, subclass).

Parameters:

model : SpectralModel

Best-fit model

fit_range : Quantity

Energy range of the spectral fit

statname : str, optional

Statistic used for the fit

statval : float, optional

Final fit statistic

stat_per_bin : float, optional

Fit statistic value per bin

npred_src : array-like, optional

Source counts predicted by the fit

npred_bkg : array-like, optional

Background counts predicted by the fit

background_model : SpectralModel

Best-fit background model

flux_at_1TeV : dict, optional

Flux for the fitted model at 1 TeV

flux_at_1TeV_err : dict, optional

Error on the flux for the fitted model at 1 TeV

obs : SpectrumObservation

Input data used for the fit

Attributes Summary

expected_background_counts CountsSpectrum of predicted background counts
expected_on_counts CountsSpectrum of predicted on counts
expected_source_counts CountsSpectrum of predicted source counts
residuals Residuals

Methods Summary

butterfly([energy, flux_unit]) Compute butterfly.
from_dict(val)
from_yaml(filename) Create cls from YAML file
info() Print summary info.
plot(**kwargs) Standard debug plot.
plot_counts(ax) Plot predicted and detected counts.
plot_residuals(ax) Plot residuals.
to_dict() Convert to dict
to_table([energy_unit, flux_unit]) Convert to Table
to_yaml(filename[, mode]) Write YAML file

Attributes Documentation

expected_background_counts

CountsSpectrum of predicted background counts

expected_on_counts

CountsSpectrum of predicted on counts

expected_source_counts

CountsSpectrum of predicted source counts

residuals

Residuals

Prediced on counts - expected on counts

Methods Documentation

butterfly(energy=None, flux_unit='TeV-1 cm-2 s-1')[source]

Compute butterfly.

Parameters:

energy : Quantity, optional

Energies at which to evaluate the butterfly.

flux_unit : str

Flux unit for the butterfly.

Returns:

butterfly : SpectrumButterfly

Butterfly object.

classmethod from_dict(val)[source]
classmethod from_yaml(filename)[source]

Create cls from YAML file

Parameters:

filename : str, Path

File to read

info()[source]

Print summary info.

plot(**kwargs)[source]

Standard debug plot.

Plot ON counts in comparison to model.

plot_counts(ax)[source]

Plot predicted and detected counts.

plot_residuals(ax)[source]

Plot residuals.

to_dict()[source]

Convert to dict

to_table(energy_unit='TeV', flux_unit='cm-2 s-1 TeV-1', **kwargs)[source]

Convert to Table

Produce overview table containing the most important parameters

to_yaml(filename, mode='w')[source]

Write YAML file

Parameters:

filename : str

File to write

mode : str

Write mode