Background2D#

class gammapy.irf.Background2D(axes, data=0, unit='', is_pointlike=False, fov_alignment=FoVAlignment.RADEC, meta=None, interp_kwargs=None)[source]#

Bases: gammapy.irf.background.BackgroundIRF

Background 2D.

Data format specification: BKG_2D

Parameters
axeslist of MapAxis or MapAxes object

Required data axes: [“energy”, “offset”] in the given order.

datandarray

Data array.

unitstr or Unit

Data unit usually s^-1 MeV^-1 sr^-1.

metadict

Metadata dictionary.

Attributes Summary

axes

MapAxes.

data

default_interp_kwargs

Default Interpolation kwargs to extrapolate.

default_unit

fov_alignment

Alignment of the field of view coordinate axes, see FoVAlignment.

has_offset_axis

Whether the IRF explicitly depends on offset.

is_pointlike

Whether the IRF is pointlike of full containment.

quantity

Quantity as a Quantity object.

required_axes

tag

unit

Map unit as a Unit object.

Methods Summary

cumsum(axis_name)

Compute cumsum along a given axis.

evaluate([method])

Evaluate IRF.

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.

is_allclose(other[, rtol_axes, atol_axes])

Compare two data IRFs for equivalency.

normalize(axis_name)

Normalise data in place along a given axis.

pad(pad_width, axis_name, **kwargs)

Pad IRF along a given axis.

peek([figsize])

Quick-look summary plots.

plot([ax, add_cbar, axes_loc, kwargs_colorbar])

Plot energy offset dependence of the background model.

plot_at_energy([energy, add_cbar, ncols, ...])

Plot the background rate in FoV coordinates at a given energy.

plot_energy_dependence([ax, offset])

Plot background rate versus energy for a given offset.

plot_offset_dependence([ax, energy])

Plot background rate versus offset for a given energy.

plot_spectrum([ax])

Plot angle integrated background rate versus energy.

read(filename[, hdu, format])

Read from file.

slice_by_idx(slices)

Slice sub IRF from IRF object.

to_3d()

Convert to Background3D.

to_hdulist([format])

Write the HDU list.

to_table([format])

Convert to table.

to_table_hdu([format])

Convert to BinTableHDU.

to_unit(unit)

Convert IRF to different unit.

write(filename, *args, **kwargs)

Write IRF to fits.

Attributes Documentation

axes#

MapAxes.

data#
default_interp_kwargs = {'bounds_error': False, 'fill_value': 0.0, 'values_scale': 'log'}#

Default Interpolation kwargs to extrapolate.

default_unit = Unit("1 / (MeV s sr)")#
fov_alignment#

Alignment of the field of view coordinate axes, see FoVAlignment.

has_offset_axis#

Whether the IRF explicitly depends on offset.

is_pointlike#

Whether the IRF is pointlike of full containment.

quantity#

Quantity as a Quantity object.

required_axes = ['energy', 'offset']#
tag = 'bkg_2d'#
unit#

Map unit as a Unit object.

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_hdulist(hdulist, hdu=None, format='gadf-dl3')#

Create from HDUList.

Parameters
hdulistHDUList

HDU list.

hdustr

HDU name.

format{“gadf-dl3”}

Format specification. Default is “gadf-dl3”.

Returns
irfIRF

IRF class.

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

Read from Table.

Parameters
tableTable

Table with background data.

format{“gadf-dl3”}

Format specification. Default is “gadf-dl3”.

Returns
bkgBackground2D or Background2D

Background 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.

is_allclose(other, rtol_axes=0.001, atol_axes=1e-06, **kwargs)#

Compare two data IRFs for equivalency.

Parameters
otherIRF

The IRF to compare against.

rtol_axesfloat, optional

Relative tolerance for the axis comparison. Default is 1e-3.

atol_axesfloat, optional

Absolute tolerance for the axis comparison. Default is 1e-6.

**kwargsdict

Keywords passed to numpy.allclose.

Returns
is_allclosebool

Whether the IRF is all close.

normalize(axis_name)#

Normalise data in place along a given axis.

Parameters
axis_namestr

Along which axis to normalize.

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

Axis to downsample. By default, spatial axes are padded.

**kwargsdict

Keyword argument forwarded to pad.

Returns
irfIRF

Padded IRF.

peek(figsize=(10, 8))[source]#

Quick-look summary plots.

plot(ax=None, add_cbar=True, axes_loc=None, kwargs_colorbar=None, **kwargs)[source]#

Plot energy offset dependence of the background model.

Parameters
axAxes, optional

Matplotlib axes. Default is None.

add_cbarbool, optional

Add a colorbar to the plot. Default is True.

axes_locdict, optional

Keyword arguments passed to append_axes.

kwargs_colorbardict, optional

Keyword arguments passed to colorbar.

kwargsdict

Keyword arguments passed to pcolormesh.

Returns
axAxes

Matplotlib axes.

plot_at_energy(energy=<Quantity 1. TeV>, add_cbar=True, ncols=3, figsize=None, **kwargs)[source]#

Plot the background rate in FoV coordinates at a given energy.

Parameters
energyQuantity, optional

List of energy. Default is 1 TeV.

add_cbarbool, optional

Add color bar. Default is True.

ncolsint, optional

Number of columns to plot. Default is 3.

figsizetuple, optional

Figure size. Default is None.

**kwargsdict

Keyword arguments passed to pcolormesh.

plot_energy_dependence(ax=None, offset=None, **kwargs)[source]#

Plot background rate versus energy for a given offset.

Parameters
axAxes, optional

Matplotlib axes. Default is None.

offsetAngle, optional

Offset. Default is None.

kwargsdict

Forwarded to plt.plot().

Returns
axAxes

Matplotlib axes.

plot_offset_dependence(ax=None, energy=None, **kwargs)[source]#

Plot background rate versus offset for a given energy.

Parameters
axAxes, optional

Matplotlib axes. Default is None.

energyQuantity, optional

Energy. Default is None.

Returns
axAxes

Matplotlib axes.

plot_spectrum(ax=None, **kwargs)[source]#

Plot angle integrated background rate versus energy.

Parameters
axAxes, optional

Matplotlib axes. Default is None.

**kwargsdict

Keyword arguments forwarded to plot.

Returns
axAxes

Matplotlib axes.

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

Read from file.

Parameters
filenamestr or Path

Filename.

hdustr

HDU name.

format{“gadf-dl3”}, optional

Format specification. Default is “gadf-dl3”.

Returns
irfIRF

IRF class.

slice_by_idx(slices)#

Slice sub IRF from IRF object.

Parameters
slicesdict

Dictionary of axes names and slice object pairs. Contains one element for each non-spatial dimension. Axes not specified in the dictionary are kept unchanged.

Returns
slicedIRF

Sliced IRF object.

to_3d()[source]#

Convert to Background3D.

to_hdulist(format='gadf-dl3')#

Write the HDU list.

Parameters
format{“gadf-dl3”}, optional

Format specification. Default is “gadf-dl3”.

to_table(format='gadf-dl3')#

Convert to table.

Parameters
format{“gadf-dl3”}, optional

Format specification. Default is “gadf-dl3”.

Returns
tableTable

IRF data table.

to_table_hdu(format='gadf-dl3')#

Convert to BinTableHDU.

Parameters
format{“gadf-dl3”}, optional

Format specification. Default is “gadf-dl3”.

Returns
hduBinTableHDU

IRF data table HDU.

to_unit(unit)#

Convert IRF to different unit.

Parameters
unitUnit or str

New unit.

Returns
irfIRF

IRF with new unit and converted data.

write(filename, *args, **kwargs)#

Write IRF to fits.

Calls writeto, forwarding all arguments.