Background3D

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

Bases: gammapy.irf.background.BackgroundIRF

Background 3D.

Data format specification: BKG_3D

Parameters
axeslist of MapAxis or MapAxes object

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

datandarray

Data array.

unitstr or Unit

Data unit usuually s^-1 MeV^-1 sr^-1

metadict

Meta data

Examples

Here’s an example you can use to learn about this class:

>>> from gammapy.irf import Background3D
>>> filename = '$GAMMAPY_DATA/cta-1dc/caldb/data/cta/1dc/bcf/South_z20_50h/irf_file.fits'
>>> bkg_3d = Background3D.read(filename, hdu='BACKGROUND')
>>> print(bkg_3d)
Background3D
------------

  axes  : ['energy', 'fov_lon', 'fov_lat']
  shape : (21, 36, 36)
  ndim  : 3
  unit  : 1 / (MeV s sr)
  dtype : >f4

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_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(axis_name)

Normalise data in place along a given axis.

pad(pad_width, axis_name, **kwargs)

Pad irf along a given axis.

peek([figsize])

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

Plot the background rate in Field of view coordinates at a given energy.

read(filename[, hdu, format])

Read from file.

to_2d()

Convert to Background2D.

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, 'values_scale': 'log'}
is_offset_dependent

Whether the IRF depends on offset

is_pointlike

Whether the IRF is pointlike of full containment.

quantity

Quantity

required_axes = ['energy', 'fov_lon', 'fov_lat']
tag = 'bkg_3d'
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_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 background data

format{“gadf-dl3”}

Format specification

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

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

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

**kwargsdict

Keyword argument forwarded to pad

Returns
irfIRF

Padded irf

peek(figsize=(10, 8))[source]
plot_at_energy(energy=None, add_cbar=True, ncols=3, figsize=None, **kwargs)[source]

Plot the background rate in Field of view coordinates at a given energy.

Parameters
energyQuantity

list of Energy

ax: `~matplotlib.axes.Axes`, optional

Axis

add_cbarbool

Add color bar?

ncolsint

Number of columns to plot

**kwargsdict

Keyword arguments passed to pcolormesh.

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_2d()[source]

Convert to Background2D.

This takes the values at Y = 0 and X >= 0.

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.