Background3D#
- class gammapy.irf.Background3D(axes, data=0, unit='', is_pointlike=False, fov_alignment=FoVAlignment.RADEC, meta=None, interp_kwargs=None)[source]#
Bases:
BackgroundIRFBackground 3D.
Data format specification: BKG_3D.
- Parameters:
- axeslist of
MapAxisorMapAxes - Required axes (in the given order) are:
energy (reconstructed energy axis)
fov_lon (field of view longitude)
fov_lon (field of view latitude)
- data
ndarray Data array.
- unitstr or
Unit Data unit usually
s^-1 MeV^-1 sr^-1.- fov_alignment
FoVAlignment The orientation of the field of view coordinate system.
- metadict
Metadata dictionary.
- axeslist of
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
MapAxes.Default Interpolation kwargs to extrapolate.
Alignment of the field of view coordinate axes, see
FoVAlignment.Whether the IRF explicitly depends on offset.
Whether the IRF is pointlike of full containment.
Quantity as a
Quantityobject.Map unit as a
Unitobject.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_at_energy([energy, add_cbar, ncols, ...])Plot the background rate in FoV coordinates at a given energy.
read(filename[, hdu, format])Read from file.
slice_by_idx(slices)Slice sub IRF from IRF object.
to_2d()Convert to
Background2D.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.
- required_axes = ['energy', 'fov_lon', 'fov_lat']#
- tag = 'bkg_3d'#
Methods Documentation
- cumsum(axis_name)#
Compute cumsum along a given axis.
- Parameters:
- axis_namestr
Along which axis to integrate.
- Returns:
- irf
IRF Cumsum IRF.
- irf
- evaluate(method=None, **kwargs)#
Evaluate IRF.
- Parameters:
- **kwargsdict
Coordinates at which to evaluate the IRF.
- methodstr {‘linear’, ‘nearest’}, optional
Interpolation method.
- Returns:
- array
Quantity Interpolated values.
- array
- classmethod from_hdulist(hdulist, hdu=None, format='gadf-dl3')#
Create from
HDUList.- Parameters:
- hdulist
HDUList HDU list.
- hdustr
HDU name.
- format{“gadf-dl3”}
Format specification. Default is “gadf-dl3”.
- hdulist
- Returns:
- irf
IRF IRF class.
- irf
- classmethod from_table(table, format='gadf-dl3')#
Read from
Table.- Parameters:
- table
Table Table with background data.
- format{“gadf-dl3”}
Format specification. Default is “gadf-dl3”.
- table
- Returns:
- bkg
Background2DorBackground2D Background IRF class.
- bkg
- 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:
- array
Quantity Returns 2D array with axes offset.
- array
- 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:
- array
Quantity Returns 2D array with axes offset.
- array
- 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:
- other
IRF 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.
- other
- 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.
- peek(figsize=(10, 8))[source]#
Quick-look summary plots.
- Parameters:
- figsizetuple, optional
Size of the figure. Default is (10, 8).
- plot_at_energy(energy=<Quantity 1. TeV>, add_cbar=True, ncols=3, figsize=None, axes_loc=None, kwargs_colorbar=None, **kwargs)[source]#
Plot the background rate in FoV coordinates at a given energy.
- Parameters:
- energy
Quantity, optional List of energies. 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.
- axes_locdict, optional
Keyword arguments passed to
append_axes.- kwargs_colorbardict, optional
Keyword arguments passed to
colorbar.- **kwargsdict
Keyword arguments passed to
pcolormesh.
- energy
- classmethod read(filename, hdu=None, format='gadf-dl3')#
Read from file.
- slice_by_idx(slices)#
Slice sub IRF from IRF object.
- to_2d()[source]#
Convert to
Background2D.This takes the values at Y = 0 and X >= 0.
- 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:
- table
Table IRF data table.
- table
- to_table_hdu(format='gadf-dl3')#
Convert to
BinTableHDU.- Parameters:
- format{“gadf-dl3”}, optional
Format specification. Default is “gadf-dl3”.
- Returns:
- hdu
BinTableHDU IRF data table HDU.
- hdu