EDispMap

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

Bases: object

Energy dispersion map.

Parameters:
edisp_map : Map

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_map : Map, 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_energy_dispersion(pos=pos, e_reco=e_reco)

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

Methods Summary

from_hdulist(hdulist[, edisp_hdu, …]) Convert to HDUList.
get_energy_dispersion(self, position, e_reco) Get energy dispersion at a given position.
read(filename, \*\*kwargs) Read an edisp_map from file and create an EDispMap object
stack(self, other) Stack EdispMap with another one.
to_hdulist(self[, edisp_hdu, …]) Convert to HDUList.
write(self, filename[, overwrite]) Write to fits

Methods Documentation

classmethod from_hdulist(hdulist, edisp_hdu='EDISPMAP', edisp_hdubands='BANDSEDISP', exposure_hdu='EXPMAP', exposure_hdubands='BANDSEXP')[source]

Convert to HDUList.

Parameters:
edisp_hdu : str

Name or index of the HDU with the edisp_map data.

edisp_hdubands : str

Name or index of the HDU with the edisp_map BANDS table.

exposure_hdu : str

Name or index of the HDU with the exposure_map data.

exposure_hdubands : str

Name or index of the HDU with the exposure_map BANDS table.

get_energy_dispersion(self, position, e_reco, migra_step=0.005)[source]

Get energy dispersion at a given position.

Parameters:
position : SkyCoord

the target position. Should be a single coordinates

e_reco : Quantity

Reconstructed energy axis binning

migra_step : float

Integration step in migration

Returns:
edisp : EnergyDispersion

the energy dispersion (i.e. rmf object)

classmethod read(filename, **kwargs)[source]

Read an edisp_map from file and create an EDispMap object

stack(self, other)[source]

Stack EdispMap with another one.

The current EdispMap is unchanged and a new one is created and returned.

Parameters:
other : EDispMap

the edispmap to be stacked with this one.

Returns:
new : EDispMap

the stacked edispmap

to_hdulist(self, edisp_hdu='EDISPMAP', edisp_hdubands='BANDSEDISP', exposure_hdu='EXPMAP', exposure_hdubands='BANDSEXP')[source]

Convert to HDUList.

Parameters:
edisp_hdu : str

Name or index of the HDU with the edisp_map data.

edisp_hdubands : str

Name or index of the HDU with the edisp_map BANDS table.

exposure_hdu : str

Name or index of the HDU with the exposure_map data.

exposure_hdubands : str

Name or index of the HDU with the exposure_map BANDS table.

Returns:
hdu_list : HDUList
write(self, filename, overwrite=False, **kwargs)[source]

Write to fits