SpectralModel

class gammapy.spectrum.models.SpectralModel[source]

Bases: object

Spectral model base class.

Derived classes should store their parameters as ParameterList, see for example return pardict PowerLaw.

Methods Summary

__call__(energy) Call evaluate method of derived classes
copy()
energy_flux(emin, emax, **kwargs) Compute energy flux in given energy range.
energy_flux_error(emin, emax, **kwargs) Compute energy flux in given energy range with error propagation.
evaluate_error(energy) Evaluate spectral model with error propagation.
from_dict(val) Serialize from dict
integral(emin, emax, **kwargs) Integrate spectral model numerically.
integral_error(emin, emax, **kwargs) Integrate spectral model numerically with error propagation.
inverse(value[, emin, emax]) Return energy for a given function value of the spectral model.
plot(energy_range[, ax, energy_unit, ...]) Plot SpectralModel
plot_error(energy_range[, ax, energy_unit, ...]) Plot error SpectralModel
spectral_index(energy[, epsilon]) Compute spectral index at given energy using a local powerlaw approximation.
to_dict() Serialize to dict
to_sherpa([name]) Convert to Sherpa model

Methods Documentation

__call__(energy)[source]

Call evaluate method of derived classes

copy()[source]
energy_flux(emin, emax, **kwargs)[source]

Compute energy flux in given energy range.

\[G(E_{min}, E_{max}) = \int_{E_{min}}^{E_{max}}E \phi(E)dE\]
Parameters:

emin, emax : Quantity

Lower and upper bound of integration range.

**kwargs : dict

Keyword arguments passed to integrate_spectrum

energy_flux_error(emin, emax, **kwargs)[source]

Compute energy flux in given energy range with error propagation.

\[G(E_{min}, E_{max}) = \int_{E_{min}}^{E_{max}}E \phi(E)dE\]
Parameters:

emin, emax : Quantity

Lower bound of integration range.

**kwargs : dict

Keyword arguments passed to integrate_spectrum

Returns:

energy_flux, energy_flux_error : tuple of Quantity

Tuple of energy flux and energy flux error.

evaluate_error(energy)[source]

Evaluate spectral model with error propagation.

Parameters:

energy : quantity

Energy at which to evaluate.

Returns:

flux, flux_error : tuple of Quantity

Tuple of flux and flux error.

classmethod from_dict(val)[source]

Serialize from dict

integral(emin, emax, **kwargs)[source]

Integrate spectral model numerically.

\[F(E_{min}, E_{max}) = \int_{E_{min}}^{E_{max}}\phi(E)dE\]

kwargs are forwared to integrate_spectrum().

If array input for emin and emax is given you have to set intervals=True if you want the integral in each energy bin.

Parameters:

emin, emax : Quantity

Lower and upper bound of integration range.

**kwargs : dict

Keyword arguments passed to integrate_spectrum

integral_error(emin, emax, **kwargs)[source]

Integrate spectral model numerically with error propagation.

Parameters:

emin, emax : Quantity

Lower adn upper bound of integration range.

**kwargs : dict

Keyword arguments passed to integrate_spectrum

Returns:

integral, integral_error : tuple of Quantity

Tuple of integral flux and integral flux error.

inverse(value, emin=<Quantity 0.1 TeV>, emax=<Quantity 100.0 TeV>)[source]

Return energy for a given function value of the spectral model.

Uses numerical root finding algorithm.

Parameters:

value : Quantity

Function value of the spectral model.

emin : Quantity

Lower bracket value in case solution is not unique.

emax : Quantity

Upper bracket value in case solution is not unique.

plot(energy_range, ax=None, energy_unit='TeV', flux_unit='cm-2 s-1 TeV-1', energy_power=0, n_points=100, **kwargs)[source]

Plot SpectralModel

kwargs are forwarded to errorbar()

Parameters:

ax : Axes, optional

Axis

energy_range : Quantity

Plot range

energy_unit : str, Unit, optional

Unit of the energy axis

flux_unit : str, Unit, optional

Unit of the flux axis

energy_power : int, optional

Power of energy to multiply flux axis with

n_points : int, optional

Number of evaluation nodes

Returns:

ax : Axes, optional

Axis

plot_error(energy_range, ax=None, energy_unit='TeV', flux_unit='cm-2 s-1 TeV-1', energy_power=0, n_points=100, **kwargs)[source]

Plot error SpectralModel

kwargs are forwarded to fill_between()

Parameters:

ax : Axes, optional

Axis

energy_range : Quantity

Plot range

energy_unit : str, Unit, optional

Unit of the energy axis

flux_unit : str, Unit, optional

Unit of the flux axis

energy_power : int, optional

Power of energy to multiply flux axis with

n_points : int, optional

Number of evaluation nodes

Returns:

ax : Axes, optional

Axis

spectral_index(energy, epsilon=1e-05)[source]

Compute spectral index at given energy using a local powerlaw approximation.

Parameters:

energy : Quantity

Energy at which to estimate the index

epsilon : float

Fractional energy increment to use for determining the spectral index.

Returns:

index : float

Estimated spectral index.

to_dict()[source]

Serialize to dict

to_sherpa(name='default')[source]

Convert to Sherpa model

To be implemented by subclasses