EnergyDispersion2D

class gammapy.irf.EnergyDispersion2D(axes, data=0, unit='', meta=None, interp_kwargs=None)[source]

Bases: gammapy.irf.core.IRF

Offset-dependent energy dispersion matrix.

Data format specification: EDISP_2D

Parameters
energy_axis_trueMapAxis

True energy axis

migra_axisMapAxis

Energy migration axis

offset_axisMapAxis

Field of view offset axis

datandarray

Energy dispersion probability density

See also

EnergyDispersion

Examples

Read energy dispersion IRF from disk:

>>> from gammapy.maps import MapAxis
>>> from gammapy.irf import EnergyDispersion2D
>>> filename = '$GAMMAPY_DATA/hess-dl3-dr1/data/hess_dl3_dr1_obs_id_020136.fits.gz'
>>> edisp2d = EnergyDispersion2D.read(filename, hdu="EDISP")

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

>>> energy = MapAxis.from_bounds(0.1, 20, nbin=60, unit="TeV", interp="log").edges
>>> edisp = edisp2d.to_edisp_kernel(offset='1.2 deg', energy=energy, energy_true=energy)

Attributes Summary

axes

MapAxes

data

default_interp_kwargs

is_offset_dependent

Whether the IRF depends on offset

is_pointlike

Whether the IRF is pointlike of full containment.

quantity

Quantity

required_axes

tag

unit

Map unit (Unit)

Methods Summary

cumsum(axis_name)

Compute cumsum along a given axis

evaluate([method])

Evaluate IRF

from_gauss(energy_axis_true, migra_axis, …)

Create Gaussian energy dispersion matrix (EnergyDispersion2D).

from_hdulist(hdulist[, hdu, format])

Create from HDUList.

from_table(table[, format])

Read from Table.

integral(axis_name, **kwargs)

Compute integral along a given axis

integrate_log_log(axis_name, **kwargs)

Integrate along a given axis.

interp_missing_data(axis_name)

Interpolate missing data along a given axis

normalize()

Normalise energy dispersion

pad(pad_width, axis_name, **kwargs)

Pad irf along a given axis.

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, energy_true])

Plot energy dispersion for given offset and true energy.

read(filename[, hdu, format])

Read from file.

to_edisp_kernel(offset[, energy_true, energy])

Detector response R(Delta E_reco, Delta E_true)

to_hdulist([format])

to_table([format])

Convert to table

to_table_hdu([format])

Convert to BinTableHDU.

write(filename, *args, **kwargs)

Write IRF to fits.

Attributes Documentation

axes

MapAxes

data
default_interp_kwargs = {'bounds_error': False, 'fill_value': 0.0}
is_offset_dependent

Whether the IRF depends on offset

is_pointlike

Whether the IRF is pointlike of full containment.

quantity

Quantity

required_axes = ['energy_true', 'migra', 'offset']
tag = 'edisp_2d'
unit

Map unit (Unit)

Methods Documentation

cumsum(axis_name)

Compute cumsum along a given axis

Parameters
axis_namestr

Along which axis to integrate.

Returns
irfIRF

Cumsum IRF

evaluate(method=None, **kwargs)

Evaluate IRF

Parameters
**kwargsdict

Coordinates at which to evaluate the IRF

methodstr {‘linear’, ‘nearest’}, optional

Interpolation method

Returns
arrayQuantity

Interpolated values

classmethod from_gauss(energy_axis_true, migra_axis, offset_axis, bias, sigma, pdf_threshold=1e-06)[source]

Create Gaussian energy dispersion matrix (EnergyDispersion2D).

The output matrix will be Gaussian in (energy_true / energy).

The bias and sigma should be either floats or arrays of same dimension than energy_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
energy_axis_trueMapAxis

True energy axis

migra_axisQuantity

Migra axis

offset_axisQuantity

Bin edges of offset

biasfloat or ndarray

Center of Gaussian energy dispersion, bias

sigmafloat or ndarray

RMS width of Gaussian energy dispersion, resolution.

pdf_thresholdfloat, optional

Zero suppression threshold

classmethod from_hdulist(hdulist, hdu=None, format='gadf-dl3')

Create from HDUList.

Parameters
hdulistHDUList

HDU list

hdustr

HDU name

format{“gadf-dl3”}

Format specification

Returns
irfIRF

IRF class

classmethod from_table(table, format='gadf-dl3')

Read from Table.

Parameters
tableTable

Table with irf data

format{“gadf-dl3”}

Format specification

Returns
irfIRF

IRF class.

integral(axis_name, **kwargs)

Compute integral along a given axis

This method uses interpolation of the cumulative sum.

Parameters
axis_namestr

Along which axis to integrate.

**kwargsdict

Coordinates at which to evaluate the IRF

Returns
arrayQuantity

Returns 2D array with axes offset

integrate_log_log(axis_name, **kwargs)

Integrate along a given axis.

This method uses log-log trapezoidal integration.

Parameters
axis_namestr

Along which axis to integrate.

**kwargsdict

Coordinates at which to evaluate the IRF

Returns
arrayQuantity

Returns 2D array with axes offset

interp_missing_data(axis_name)

Interpolate missing data along a given axis

normalize()[source]

Normalise energy dispersion

pad(pad_width, axis_name, **kwargs)

Pad irf along a given axis.

Parameters
pad_width{sequence, array_like, int}

Number of pixels padded to the edges of each axis.

axis_namestr

Which axis to downsample. By default spatial axes are padded.

**kwargsdict

Keyword argument forwarded to pad

Returns
irfIRF

Padded irf

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
axAxes, optional

Axis

offsetAngle, optional

Offset

add_cbarbool

Add a colorbar to the plot.

kwargsdict

Keyword arguments passed to pcolormesh.

Returns
axAxes

Axis

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

Plot energy dispersion for given offset and true energy.

Parameters
axAxes, optional

Axis

offsetAngle, optional

Offset

energy_trueQuantity, optional

True energy

**kwargsdict

Keyword arguments forwarded to plot

Returns
axAxes

Axis

classmethod read(filename, hdu=None, format='gadf-dl3')

Read from file.

Parameters
filenamestr or Path

Filename

hdustr

HDU name

format{“gadf-dl3”}

Format specification

Returns
irfIRF

IRF class

to_edisp_kernel(offset, energy_true=None, energy=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
offsetAngle

Offset

energy_trueQuantity, None

True energy axis

energyQuantity

Reconstructed energy axis

Returns
edispEDispKernel

Energy dispersion matrix

to_hdulist(format='gadf-dl3')
to_table(format='gadf-dl3')

Convert to table

Parameters
format{“gadf-dl3”}

Format specification

Returns
tableTable

IRF data table

to_table_hdu(format='gadf-dl3')

Convert to BinTableHDU.

Parameters
format{“gadf-dl3”}

Format specification

Returns
hduBinTableHDU

IRF data table hdu

write(filename, *args, **kwargs)

Write IRF to fits.

Calls writeto, forwarding all arguments.