EnergyDispersion2D

class gammapy.irf.EnergyDispersion2D(e_true_lo, e_true_hi, migra_lo, migra_hi, offset_lo, offset_hi, data, interp_kwargs=None, meta=None)[source]

Bases: object

Offset-dependent energy dispersion matrix.

Data format specification: EDISP_2D

Parameters:
e_true_lo, e_true_hi : Quantity

True energy axis binning

migra_lo, migra_hi : ndarray

Energy migration axis binning

offset_lo, offset_hi : Angle

Field of view offset axis binning

data : ndarray

Energy dispersion probability density

See also

EnergyDispersion

Examples

Read energy dispersion IRF from disk:

>>> from gammapy.irf import EnergyDispersion2D
>>> from gammapy.utils.energy import EnergyBounds
>>> filename = '$GAMMAPY_DATA/tests/irf/hess/pa/hess_edisp_2d_023523.fits.gz'
>>> edisp2d = EnergyDispersion2D.read(filename, hdu='ENERGY DISPERSION')
>>> print(edisp2d)
EnergyDispersion2D
NDDataArray summary info
e_true         : size =    15, min =  0.125 TeV, max = 80.000 TeV
migra          : size =   100, min =  0.051, max = 10.051
offset         : size =     6, min =  0.125 deg, max =  2.500 deg
Data           : size =  9000, min =  0.000, max =  3.405

Create energy dispersion matrix (EnergyDispersion) for a given field of view offset and energy binning:

>>> energy = EnergyBounds.equal_log_spacing(0.1,20,60, 'TeV')
>>> edisp = edisp2d.to_energy_dispersion(offset='1.2 deg', e_reco=energy, e_true=energy)
>>> print(edisp)
EnergyDispersion
NDDataArray summary info
e_true         : size =    60, min =  0.105 TeV, max = 19.136 TeV
e_reco         : size =    60, min =  0.105 TeV, max = 19.136 TeV
Data           : size =  3600, min =  0.000, max =  0.266

Attributes Summary

default_interp_kwargs Default Interpolation kwargs for NDDataArray.

Methods Summary

from_gauss(e_true, migra, bias, sigma, offset) Create Gaussian energy dispersion matrix (EnergyDispersion2D).
from_hdulist(hdulist[, hdu]) Create from HDUList.
from_table(table) Create from Table.
get_response(offset, e_true[, e_reco, …]) Detector response R(Delta E_reco, E_true)
peek([figsize]) Quick-look summary plots.
plot_bias([ax, offset, add_cbar]) Plot migration as a function of true energy for a given offset.
plot_migration([ax, offset, e_true, migra]) Plot energy dispersion for given offset and true energy.
read(filename[, hdu]) Read from FITS file.
to_energy_dispersion(offset[, e_true, e_reco]) Detector response R(Delta E_reco, Delta E_true)
to_fits([name]) Convert to BinTable.
to_table() Convert to Table.

Attributes Documentation

default_interp_kwargs = {'bounds_error': False, 'fill_value': None}

Default Interpolation kwargs for NDDataArray. Extrapolate.

Methods Documentation

classmethod from_gauss(e_true, migra, bias, sigma, offset, pdf_threshold=1e-06)[source]

Create Gaussian energy dispersion matrix (EnergyDispersion2D).

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

The bias and sigma should be either floats or arrays of same dimension than e_true. bias refers to the mean value of the migra distribution minus one, i.e. bias=0 means no bias.

Note that, the output matrix is flat in offset.

Parameters:
e_true : Quantity, BinnedDataAxis

Bin edges of true energy axis

migra : Quantity, BinnedDataAxis

Bin edges of migra axis

bias : float or ndarray

Center of Gaussian energy dispersion, bias

sigma : float or ndarray

RMS width of Gaussian energy dispersion, resolution

offset : Quantity, BinnedDataAxis

Bin edges of offset

pdf_threshold : float, optional

Zero suppression threshold

classmethod from_hdulist(hdulist, hdu='edisp_2d')[source]

Create from HDUList.

classmethod from_table(table)[source]

Create from Table.

get_response(offset, e_true, e_reco=None, migra_step=0.005)[source]

Detector response R(Delta E_reco, E_true)

Probability to reconstruct a given true energy in a given reconstructed energy band. In each reco bin, you integrate with a riemann sum over the default migra bin of your analysis.

Parameters:
e_true : Energy

True energy

e_reco : EnergyBounds, None

Reconstructed energy axis

offset : Angle

Offset

migra_step : float

Integration step in migration

Returns:
rv : ndarray

Redistribution vector

peek(figsize=(15, 5))[source]

Quick-look summary plots.

Parameters:
figsize : (float, float)

Size of the resulting plot

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

Plot migration as a function of true energy for a given offset.

Parameters:
ax : Axes, optional

Axis

offset : Angle, optional

Offset

add_cbar : bool

Add a colorbar to the plot.

kwargs : dict

Keyword arguments passed to pcolormesh.

Returns:
ax : Axes

Axis

plot_migration(ax=None, offset=None, e_true=None, migra=None, **kwargs)[source]

Plot energy dispersion for given offset and true energy.

Parameters:
ax : Axes, optional

Axis

offset : Angle, optional

Offset

e_true : Energy, optional

True energy

migra : array, list, optional

Migration nodes

Returns:
ax : Axes

Axis

classmethod read(filename, hdu='edisp_2d')[source]

Read from FITS file.

Parameters:
filename : str

File name

to_energy_dispersion(offset, e_true=None, e_reco=None)[source]

Detector response R(Delta E_reco, Delta E_true)

Probability to reconstruct an energy in a given true energy band in a given reconstructed energy band

Parameters:
offset : Angle

Offset

e_true : EnergyBounds, None

True energy axis

e_reco : EnergyBounds

Reconstructed energy axis

Returns:
edisp : EnergyDispersion

Energy dispersion matrix

to_fits(name='ENERGY DISPERSION')[source]

Convert to BinTable.

to_table()[source]

Convert to Table.