EnergyBounds

class gammapy.utils.energy.EnergyBounds[source]

Bases: gammapy.utils.energy.Energy

EnergyBounds array.

This is a Energy sub-class that adds convenience methods to handle common tasks for energy bin edges arrays, like FITS I/O or generating arrays of bin centers.

See Energy handling in Gammapy for further information.

Parameters:

energy : array, scalar, Quantity

EnergyBounds

unit : UnitBase, str

The unit of the values specified for the energy. This may be any string that Unit understands, but it is better to give an actual unit object.

Attributes Summary

bands Width of the energy bins.
boundaries Energy range.
log_centers Log centers of the energy bounds.
lower_bounds Lower energy bin edges.
nbins The number of bins.
upper_bounds Upper energy bin edges.

Methods Summary

bin(i) Return energy bin edges (zero-based numbering).
contains(energy) Check of energy is contained in boundaries.
equal_log_spacing(emin, emax, nbins[, unit]) EnergyBounds with equal log-spacing (EnergyBounds).
find_energy_bin(energy) Find the bins that contain the specified energy values.
from_dict(d) Read dict representing an energy range.
from_ebounds(hdu) Read EBOUNDS fits extension (EnergyBounds).
from_lower_and_upper_bounds(lower, upper[, unit]) EnergyBounds from lower and upper bounds (EnergyBounds).
from_rmf_matrix(hdu) Read MATRIX fits extension (EnergyBounds).
to_dict() Construct dict representing an energy range.

Attributes Documentation

bands

Width of the energy bins.

boundaries

Energy range.

log_centers

Log centers of the energy bounds.

lower_bounds

Lower energy bin edges.

nbins

The number of bins.

upper_bounds

Upper energy bin edges.

Methods Documentation

bin(i)[source]

Return energy bin edges (zero-based numbering).

Parameters:

i : int

Energy bin

contains(energy)[source]

Check of energy is contained in boundaries.

Parameters:

energy : Energy

Array of energies to test

classmethod equal_log_spacing(emin, emax, nbins, unit=None)[source]

EnergyBounds with equal log-spacing (EnergyBounds).

If no unit is given, it will be taken from emax.

Parameters:

emin : Quantity, float

Lowest energy bin

emax : Quantity, float

Highest energy bin

bins : int

Number of bins

unit : UnitBase, str, None

Energy unit

find_energy_bin(energy)[source]

Find the bins that contain the specified energy values.

Parameters:

energy : Energy

Array of energies to search for.

Returns:

bin_index : ndarray

Indices of the energy bins containing the specified energies.

classmethod from_dict(d)[source]

Read dict representing an energy range.

classmethod from_ebounds(hdu)[source]

Read EBOUNDS fits extension (EnergyBounds).

Parameters:

hdu: `~astropy.io.fits.BinTableHDU`

EBOUNDS extensions.

classmethod from_lower_and_upper_bounds(lower, upper, unit=None)[source]

EnergyBounds from lower and upper bounds (EnergyBounds).

If no unit is given, it will be taken from upper.

Parameters:

lower,upper : Quantity, float

Lowest and highest energy bin

unit : UnitBase, str, None

Energy units

classmethod from_rmf_matrix(hdu)[source]

Read MATRIX fits extension (EnergyBounds).

Parameters:

hdu: `~astropy.io.fits.BinTableHDU`

MATRIX extensions.

to_dict()[source]

Construct dict representing an energy range.