EnergyDispersion

class gammapy.irf.EnergyDispersion(e_true_lo, e_true_hi, e_reco_lo, e_reco_hi, data, interp_kwargs=None, meta=None)[source]

Bases: object

Energy dispersion matrix.

see RMF file

Parameters:

e_true_lo : Quantity

Lower bin edges of true energy axis

e_true_hi : Quantity

Upper bin edges of true energy axis

e_reco_lo : Quantity

Lower bin edges of reconstruced energy axis

e_reco_hi : Quantity

Upper bin edges of reconstruced energy axis

data : array_like

2-dim energy dispersion matrix

Attributes Summary

default_interp_kwargs Default Interpolation kwargs for NDDataArray.
e_reco
e_true
pdf_matrix PDF matrix ndarray

Methods Summary

apply(data[, e_reco, e_true]) Apply energy dispersion.
from_gauss(e_true, e_reco[, sigma, ...]) Create Gaussian EnergyDispersion matrix.
from_hdulist(hdulist[, hdu1, hdu2]) Create EnergyDispersion object from HDUList.
get_bias(e_true) Get reconstruction bias for a given true energy
get_resolution(e_true) Get energy resolution for a given true energy
pdf_in_safe_range(lo_threshold, hi_threshold) PDF matrix with bins outside threshold set to 0
plot_bias([ax]) Plot reconstruction bias.
plot_matrix([ax, show_energy, add_cbar]) Plot PDF matrix.
read(filename[, hdu1, hdu2]) Read from file
to_hdulist(**kwargs) Convert RM to FITS HDU list format.
to_sherpa(name) Return DataARF
to_table() Convert to Table.
write(filename, **kwargs)

Attributes Documentation

default_interp_kwargs = {'fill_value': 0, 'method': 'nearest', 'bounds_error': False}

Default Interpolation kwargs for NDDataArray. Fill zeros and do not interpolate

e_reco
e_true
pdf_matrix

PDF matrix ndarray

Rows (first index): True Energy Columns (second index): Reco Energy

Methods Documentation

apply(data, e_reco=None, e_true=None)[source]

Apply energy dispersion.

Computes the matrix product of data (which typically is model flux or counts in true energy bins) with the energy dispersion matrix.

Parameters:

data : array_like

1-dim data array.

Returns:

convolved_data : array

1-dim data array after multiplication with the energy dispersion matrix

classmethod from_gauss(e_true, e_reco, sigma=0.2, pdf_threshold=1e-06)[source]

Create Gaussian EnergyDispersion matrix.

The output matrix will be Gaussian in log(e_true / e_reco)

TODO: extend to have a vector of bias various true energies. TODO: extend to have vector of resolution for various true energies. TODO: give formula: Gaussian in log(e_reco) TODO: add option to add poisson noise

Parameters:

e_true : Quantity, BinnedDataAxis

Bin edges of true energy axis

e_reco : Quantity, BinnedDataAxis

Bin edges of reconstructed energy axis

sigma : float, optional

RMS width of Gaussian energy dispersion, resolution

pdf_threshold : float, optional

Zero suppression threshold

classmethod from_hdulist(hdulist, hdu1='MATRIX', hdu2='EBOUNDS')[source]

Create EnergyDispersion object from HDUList.

Parameters:

hdulist : HDUList

HDU list with MATRIX and EBOUNDS extensions.

hdu1 : str, optional

HDU containing the energy dispersion matrix, default: MATRIX

hdu2 : str, optional

HDU containing the energy axis information, default, EBOUNDS

get_bias(e_true)[source]

Get reconstruction bias for a given true energy

Bias is defined as

\[\frac{E_{reco}-E_{true}}{E_{true}}\]
Parameters:

e_true : Quantity

True energy

get_resolution(e_true)[source]

Get energy resolution for a given true energy

Resolution is the 1 sigma containment of the energy dispersion PDF.

Parameters:

e_true : Quantity

True energy

pdf_in_safe_range(lo_threshold, hi_threshold)[source]

PDF matrix with bins outside threshold set to 0

Parameters:

lo_threshold : Quantity

Low reco energy threshold

hi_threshold : Quantity

High reco energy threshold

plot_bias(ax=None, **kwargs)[source]

Plot reconstruction bias.

see get_bias()

Parameters:

ax : Axes, optional

Axis

plot_matrix(ax=None, show_energy=None, add_cbar=False, **kwargs)[source]

Plot PDF matrix.

Parameters:

ax : Axes, optional

Axis

show_energy : Quantity, optional

Show energy, e.g. threshold, as vertical line

add_cbar : bool

Add a colorbar to the plot.

Returns:

ax : Axes

Axis

classmethod read(filename, hdu1='MATRIX', hdu2='EBOUNDS', **kwargs)[source]

Read from file

Parameters:

filename : Path, str

File to read

hdu1 : str, optional

HDU containing the energy dispersion matrix, default: MATRIX

hdu2 : str, optional

HDU containing the energy axis information, default, EBOUNDS

to_hdulist(**kwargs)[source]

Convert RM to FITS HDU list format.

Parameters:

header : Header

Header to be written in the fits file.

energy_unit : str

Unit in which the energy is written in the HDU list

Returns:

hdulist : HDUList

RMF in HDU list format.

Notes

For more info on the RMF FITS file format see: http://heasarc.gsfc.nasa.gov/docs/heasarc/caldb/docs/summary/cal_gen_92_002_summary.html

to_sherpa(name)[source]

Return DataARF

Parameters:

name : str

Instance name

to_table()[source]

Convert to Table.

The output table is in the OGIP RMF format. http://heasarc.gsfc.nasa.gov/docs/heasarc/caldb/docs/memos/cal_gen_92_002/cal_gen_92_002.html#Tab:1

write(filename, **kwargs)[source]