SpectrumFitResult

class gammapy.spectrum.SpectrumFitResult(model, fit_range=None, statname=None, statval=None, stat_per_bin=None, npred=None, obs=None)[source]

Bases: object

Result of a SpectrumFit.

All fit results should be accessed via this class.

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 : array-like, optional

Counts predicted by the fit

obs : SpectrumObservation

Input data used for the fit

Attributes Summary

expected_source_counts Predicted source counts (CountsSpectrum).
fit_range
model
npred
obs
residuals Residuals (predicted source - excess).
stat_per_bin
statname
statval

Methods Summary

butterfly([energy, flux_unit]) Compute butterfly table.
from_dict(val) Create from dict.
from_yaml(filename) Create from YAML file.
plot(**kwargs) Plot counts and residuals in two panels.
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 to YAML file.

Attributes Documentation

expected_source_counts

Predicted source counts (CountsSpectrum).

fit_range
model
npred
obs
residuals

Residuals (predicted source - excess).

stat_per_bin
statname
statval

Methods Documentation

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

Compute butterfly table.

Parameters:

energy : Quantity, optional

Energies at which to evaluate the butterfly.

flux_unit : str

Flux unit for the butterfly.

Returns:

table : Table

Butterfly info in table (cols: ‘energy’, ‘flux’, ‘flux_lo’, ‘flux_hi’)

classmethod from_dict(val)[source]

Create from dict.

classmethod from_yaml(filename)[source]

Create from YAML file.

Parameters:

filename : str, Path

File to read

plot(**kwargs)[source]

Plot counts and residuals in two panels.

Calls plot_counts and plot_residuals.

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 to YAML file.

Parameters:

filename : str

File to write

mode : str

Write mode