FOVCubeBackgroundModel¶
-
class
gammapy.background.
FOVCubeBackgroundModel
(counts_cube=None, livetime_cube=None, background_cube=None)[source]¶ Bases:
object
Field of view (FOV) cube background model.
Container class for cube background model (X, Y, energy). (X, Y) are detector coordinates (a.k.a. nominal system coordinates). This class defines 3 cubes of type
FOVCube
:- counts_cube: to store the counts (a.k.a. events) that participate in the model creation.
- livetime_cube: to store the livetime correction.
- background_cube: to store the background model.
The class defines methods to define the binning, fill and smooth of the background cube models.
Parameters: counts_cube :
FOVCube
, optionalFOVCube to store counts.
livetime_cube :
FOVCube
, optionalFOVCube to store livetime correction.
background_cube :
FOVCube
, optionalFOVCube to store background model.
Methods Summary
compute_rate
()Compute background_cube from count_cube and livetime_cube. define_cube_binning
(observation_table[, method])Define cube binning (E, Y, X). fill_obs
(observation_table, data_store)Fill events and compute corresponding livetime. read
(filename[, format])Read cube background model from fits file. set_cube_binning
(detx_edges, dety_edges, …)Set cube binning from function parameters. smooth
()Smooth background cube model. write
(outfile[, format])Write cube to FITS file. Methods Documentation
-
classmethod
define_cube_binning
(observation_table, method='default')[source]¶ Define cube binning (E, Y, X).
The shape of the cube (number of bins on each axis) depends on the number of observations. The binning is slightly altered in case a different method as the default one is used. In the michi method:
- Minimum energy (i.e. lower boundary of cube energy binning) is equal to minimum energy threshold of all observations in the group.
Parameters: observation_table :
ObservationTable
Observation list to use for the michi binning.
data_dir : str
Data directory
method : {‘default’, ‘michi’}, optional
Bg cube model calculation method to apply.
Returns: bg_cube_model :
FOVCubeBackgroundModel
FOVCube background model object.
-
fill_obs
(observation_table, data_store)[source]¶ Fill events and compute corresponding livetime.
Get data files corresponding to the observation list, histogram the counts and the livetime and fill the corresponding cube containers.
Parameters: observation_table :
ObservationTable
Observation list to use for the histogramming.
data_store :
DataStore
Data store
-
classmethod
read
(filename, format='table')[source]¶ Read cube background model from fits file.
Several input formats are accepted, depending on the value of the format parameter:
- table (default and preferred format): all 3 cubes as
HDUList
ofBinTableHDU
- image (alternative format): bg cube saved as
PrimaryHDU
, with the energy binning stored asBinTableHDU
The counts and livetime cubes are optional.
This method calls
read
, forwarding all arguments.Parameters: filename : str
Name of file with the cube.
format : str, optional
Format of the cube to read.
Returns: bg_cube_model :
FOVCubeBackgroundModel
FOVCube background model object.
- table (default and preferred format): all 3 cubes as
-
classmethod
set_cube_binning
(detx_edges, dety_edges, energy_edges)[source]¶ Set cube binning from function parameters.
Parameters: detx_edges :
Angle
Spatial bin edges vector (low and high) for the cubes. X coordinate.
dety_edges :
Angle
Spatial bin edges vector (low and high) for the cubes. Y coordinate.
energy_edges :
Quantity
Energy bin edges vector (low and high) for the cubes.
Returns: bg_cube_model :
FOVCubeBackgroundModel
FOVCube background model object.
-
smooth
()[source]¶ Smooth background cube model.
Smooth method:
slice model in energy bins: 1 image per energy bin
calculate integral of the image
determine times to smooth (N) depending on number of entries (counts) used to fill the cube
smooth image N times with root TH2::Smooth default smoothing kernel: k5a
k5a = [ [ 0, 0, 1, 0, 0 ], [ 0, 2, 2, 2, 0 ], [ 1, 2, 5, 2, 1 ], [ 0, 2, 2, 2, 0 ], [ 0, 0, 1, 0, 0 ] ]
Reference: https://root.cern.ch/root/html/TH2.html#TH2:Smooth
scale with the cocient of the old integral div by the new integral
fill the values of the image back in the cube
-
write
(outfile, format='table', **kwargs)[source]¶ Write cube to FITS file.
Several output formats are accepted, depending on the value of the format parameter:
- table (default and preferred format): all 3 cubes as
HDUList
ofBinTableHDU
- image (alternative format): bg cube saved as
PrimaryHDU
, with the energy binning stored asBinTableHDU
The counts and livetime cubes are optional.
This method calls
writeto
, forwarding the kwargs arguments.Parameters: outfile : str
Name of file to write.
format : str, optional
Format of the cube to write.
kwargs
Extra arguments for the corresponding
astropy.io.fits
writeto
method.- table (default and preferred format): all 3 cubes as