EDispMap

class gammapy.irf.EDispMap(edisp_map, exposure_map)[source]

Bases: gammapy.irf.irf_map.IRFMap

Energy dispersion map.

Parameters
edisp_mapMap

the input Energy Dispersion Map. Should be a Map with 2 non spatial axes. migra and true energy axes should be given in this specific order.

exposure_mapMap, optional

Associated exposure map. Needs to have a consistent map geometry.

Examples

import numpy as np
from astropy import units as u
from astropy.coordinates import SkyCoord
from gammapy.maps import WcsGeom, MapAxis
from gammapy.irf import EnergyDispersion2D, EffectiveAreaTable2D
from gammapy.cube import make_edisp_map, make_map_exposure_true_energy

# Define energy dispersion map geometry
energy_axis = MapAxis.from_edges(np.logspace(-1, 1, 4), unit="TeV", name="energy")
migra_axis = MapAxis.from_edges(np.linspace(0, 3, 100), name="migra")
pointing = SkyCoord(0, 0, unit="deg")
max_offset = 4 * u.deg
geom = WcsGeom.create(
    binsz=0.25 * u.deg,
    width=10 * u.deg,
    skydir=pointing,
    axes=[migra_axis, energy_axis],
)

# Extract EnergyDispersion2D from CTA 1DC IRF
filename = "$GAMMAPY_DATA/cta-1dc/caldb/data/cta/1dc/bcf/South_z20_50h/irf_file.fits"
edisp2D = EnergyDispersion2D.read(filename, hdu="ENERGY DISPERSION")
aeff2d = EffectiveAreaTable2D.read(filename, hdu="EFFECTIVE AREA")

# Create the exposure map
exposure_geom = geom.to_image().to_cube([energy_axis])
exposure_map = make_map_exposure_true_energy(pointing, "1 h", aeff2d, exposure_geom)

# create the EDispMap for the specified pointing
edisp_map = make_edisp_map(edisp2D, pointing, geom, max_offset, exposure_map)

# Get an Energy Dispersion (1D) at any position in the image
pos = SkyCoord(2.0, 2.5, unit="deg")
e_reco = np.logspace(-1.0, 1.0, 10) * u.TeV
edisp = edisp_map.get_edisp_kernel(pos=pos, e_reco=e_reco)

# Write map to disk
edisp_map.write("edisp_map.fits")

Attributes Summary

edisp_map

Methods Summary

copy(self)

Copy IRF map

cutout(self, position, width[, mode])

Cutout IRF map.

from_diagonal_response(energy_axis_true[, …])

Create an allsky EDisp map with diagonal response.

from_geom(geom)

Create edisp map from geom.

from_hdulist(hdulist[, hdu, hdu_bands, …])

Create from HDUList.

get_edisp_kernel(self, position, e_reco)

Get energy dispersion at a given position.

read(filename)

Read an IRF_map from file and create corresponding object

sample_coord(self, map_coord[, random_state])

Apply the energy dispersion corrections on the coordinates of a set of simulated events.

stack(self, other[, weights])

Stack IRF map with another one in place.

to_edisp_kernel_map(self, energy_axis)

Convert to map with edisp kernels

to_hdulist(self)

Convert to HDUList.

write(self, filename[, overwrite])

Write IRF map to fits

Attributes Documentation

edisp_map

Methods Documentation

copy(self)

Copy IRF map

cutout(self, position, width, mode='trim')

Cutout IRF map.

Parameters
positionSkyCoord

Center position of the cutout region.

widthtuple of Angle

Angular sizes of the region in (lon, lat) in that specific order. If only one value is passed, a square region is extracted.

mode{‘trim’, ‘partial’, ‘strict’}

Mode option for Cutout2D, for details see Cutout2D.

Returns
cutoutIRFMap

Cutout IRF map.

classmethod from_diagonal_response(energy_axis_true, migra_axis=None)[source]

Create an allsky EDisp map with diagonal response.

Parameters
energy_axis_trueMapAxis

True energy axis

migra_axisMapAxis

Migra axis

Returns
edisp_mapEDispMap

Energy dispersion map.

classmethod from_geom(geom)[source]

Create edisp map from geom.

By default a diagonal edisp matrix is created.

Parameters
geomGeom

Edisp map geometry.

Returns
edisp_mapEDispMap

Energy dispersion map.

classmethod from_hdulist(hdulist, hdu=None, hdu_bands=None, exposure_hdu=None, exposure_hdu_bands=None)

Create from HDUList.

Parameters
hdulistHDUList

HDU list.

hdustr

Name or index of the HDU with the IRF map.

hdu_bandsstr

Name or index of the HDU with the IRF map BANDS table.

exposure_hdustr

Name or index of the HDU with the exposure map data.

exposure_hdu_bandsstr

Name or index of the HDU with the exposure map BANDS table.

Returns
irf_mapIRFMap

IRF map.

get_edisp_kernel(self, position, e_reco)[source]

Get energy dispersion at a given position.

Parameters
positionSkyCoord

the target position. Should be a single coordinates

e_recoQuantity

Reconstructed energy axis binning

Returns
edispEnergyDispersion

the energy dispersion (i.e. rmf object)

classmethod read(filename)

Read an IRF_map from file and create corresponding object

sample_coord(self, map_coord, random_state=0)[source]

Apply the energy dispersion corrections on the coordinates of a set of simulated events.

Parameters
map_coordMapCoord object.

Sequence of coordinates and energies of sampled events.

random_state{int, ‘random-seed’, ‘global-rng’, RandomState}

Defines random number generator initialisation. Passed to get_random_state.

Returns
MapCoord.

Sequence of Edisp-corrected coordinates of the input map_coord map.

stack(self, other, weights=None)

Stack IRF map with another one in place.

Parameters
otherIRFMap

Energy dispersion map to be stacked with this one.

weightsMap

Map with stacking weights.

to_edisp_kernel_map(self, energy_axis)[source]

Convert to map with edisp kernels

Parameters
e_recoMapAxis

Reconstructed enrgy axis.

Returns
edispEDispKernelMap

Energy dispersion kernel map.

to_hdulist(self)

Convert to HDUList.

Returns
hdu_listHDUList

HDU list.

write(self, filename, overwrite=False, **kwargs)

Write IRF map to fits