MapAxis¶
-
class
gammapy.maps.
MapAxis
(nodes, interp='lin', name='', node_type='edges', unit='')[source]¶ Bases:
object
Class representing an axis of a map.
Provides methods for transforming to/from axis and pixel coordinates. An axis is defined by a sequence of node values that lie at the center of each bin. The pixel coordinate at each node is equal to its index in the node array (0, 1, ..). Bin edges are offset by 0.5 in pixel coordinates from the nodes such that the lower/upper edge of the first bin is (-0.5,0.5).
- Parameters
- nodes
ndarray
orQuantity
Array of node values. These will be interpreted as either bin edges or centers according to
node_type
.- interpstr
Interpolation method used to transform between axis and pixel coordinates. Valid options are ‘log’, ‘lin’, and ‘sqrt’.
- namestr
Axis name
- node_typestr
Flag indicating whether coordinate nodes correspond to pixel edges (node_type = ‘edge’) or pixel centers (node_type = ‘center’). ‘center’ should be used where the map values are defined at a specific coordinate (e.g. differential quantities). ‘edge’ should be used where map values are defined by an integral over coordinate intervals (e.g. a counts histogram).
- unitstr
String specifying the data units.
- nodes
Attributes Summary
Array of bin widths.
Return array of bin centers.
Return array of bin edges.
Interpolation scale of the axis.
Name of the axis.
Return number of bins.
Return number of bins.
Return node type (‘center’ or ‘edge’).
Return coordinate axis unit.
Methods Summary
append
(axis)Append another map axis to this axis
coord_to_idx
(coord[, clip])Transform from axis coordinate to bin index.
coord_to_pix
(coord)Transform from axis to pixel coordinates.
copy
(**kwargs)Copy
MapAxis
instance and overwrite given attributes.downsample
(factor)Downsample map axis by a given factor.
from_bounds
(lo_bnd, hi_bnd, nbin, **kwargs)Generate an axis object from a lower/upper bound and number of bins.
from_edges
(edges, **kwargs)Generate an axis object from a sequence of bin edges.
from_energy_bounds
(energy_min, energy_max, nbin)Make an energy axis.
from_energy_edges
(energy_edges[, unit, …])Make an energy axis from adjacent edges.
from_nodes
(nodes, **kwargs)Generate an axis object from a sequence of nodes (bin centers).
from_stack
(axes)Create a map axis by merging a list of other map axes.
from_table
(table[, format, idx, column_prefix])Instanciate MapAxis from table HDU
from_table_hdu
(hdu[, format, idx])Instanciate MapAxis from table HDU
group_table
(edges)Compute bin groups table for the map axis, given coarser bin edges.
is_aligned
(other[, atol])Check if other map axis is aligned.
pix_to_coord
(pix)Transform from pixel to axis coordinates.
round
(coord[, clip])Round coord to nearest axis edge.
slice
(idx)Create a new axis object by extracting a slice from this axis.
squash
()Create a new axis object by squashing the axis into one bin.
to_header
(header[, format])Create FITS header
to_table
([format])Convert
Quantity
to OGIPEBOUNDS
extension.to_table_hdu
([format])Convert
Quantity
to OGIPEBOUNDS
extension.upsample
(factor)Upsample map axis by a given factor.
Attributes Documentation
-
bin_width
¶ Array of bin widths.
-
center
¶ Return array of bin centers.
-
edges
¶ Return array of bin edges.
-
interp
¶ Interpolation scale of the axis.
-
is_energy_axis
¶
-
name
¶ Name of the axis.
-
nbin
¶ Return number of bins.
-
nbin_per_decade
¶ Return number of bins.
-
node_type
¶ Return node type (‘center’ or ‘edge’).
-
unit
¶ Return coordinate axis unit.
Methods Documentation
-
append
(axis)[source]¶ Append another map axis to this axis
Name, interp type and node type must agree between the axes. If the node type is “edges”, the edges must be contiguous and non-overlapping.
-
copy
(**kwargs)[source]¶ Copy
MapAxis
instance and overwrite given attributes.- Parameters
- **kwargsdict
Keyword arguments to overwrite in the map axis constructor.
- Returns
- copy
MapAxis
Copied map axis.
- copy
-
downsample
(factor)[source]¶ Downsample map axis by a given factor.
When down-sampling each n-th (given by the factor) bin is selected from the axis while preserving the axis limits. For node type “edges” this requires nbin to be dividable by the factor, for node type “center” this requires nbin - 1 to be dividable by the factor.
- Parameters
- factorint
Downsampling factor.
- Returns
- axis
MapAxis
Downsampled map axis.
- axis
-
classmethod
from_bounds
(lo_bnd, hi_bnd, nbin, **kwargs)[source]¶ Generate an axis object from a lower/upper bound and number of bins.
If node_type = ‘edge’ then bounds correspond to the lower and upper bound of the first and last bin. If node_type = ‘center’ then bounds correspond to the centers of the first and last bin.
- Parameters
- lo_bndfloat
Lower bound of first axis bin.
- hi_bndfloat
Upper bound of last axis bin.
- nbinint
Number of bins.
- interp{‘lin’, ‘log’, ‘sqrt’}
Interpolation method used to transform between axis and pixel coordinates. Default: ‘lin’.
-
classmethod
from_edges
(edges, **kwargs)[source]¶ Generate an axis object from a sequence of bin edges.
This method should be used to construct an axis where the bin edges should lie at specific values (e.g. a histogram). The number of bins will be one less than the number of edges.
- Parameters
- edges
ndarray
Axis bin edges.
- interp{‘lin’, ‘log’, ‘sqrt’}
Interpolation method used to transform between axis and pixel coordinates. Default: ‘lin’.
- edges
-
classmethod
from_energy_bounds
(energy_min, energy_max, nbin, unit=None, per_decade=False, name=None, node_type='edges')[source]¶ Make an energy axis.
Used frequently also to make energy grids, by making the axis, and then using
axis.center
oraxis.edges
.
-
classmethod
from_energy_edges
(energy_edges, unit=None, name=None, interp='log')[source]¶ Make an energy axis from adjacent edges.
-
classmethod
from_nodes
(nodes, **kwargs)[source]¶ Generate an axis object from a sequence of nodes (bin centers).
This will create a sequence of bins with edges half-way between the node values. This method should be used to construct an axis where the bin center should lie at a specific value (e.g. a map of a continuous function).
- Parameters
- nodes
ndarray
Axis nodes (bin center).
- interp{‘lin’, ‘log’, ‘sqrt’}
Interpolation method used to transform between axis and pixel coordinates. Default: ‘lin’.
- nodes
-
classmethod
from_stack
(axes)[source]¶ Create a map axis by merging a list of other map axes.
If the node type is “edges” the bin edges in the provided axes must be contiguous and non-overlapping.
-
classmethod
from_table
(table, format='ogip', idx=0, column_prefix='')[source]¶ Instanciate MapAxis from table HDU
-
classmethod
from_table_hdu
(hdu, format='ogip', idx=0)[source]¶ Instanciate MapAxis from table HDU
- Parameters
- hdu
BinTableHDU
Table HDU
- format{“ogip”, “ogip-arf”, “fgst-ccube”, “fgst-template”}
Format specification
- idxint
Column index of the axis.
- hdu
- Returns
- axis
MapAxis
Map Axis
- axis
-
is_aligned
(other, atol=0.02)[source]¶ Check if other map axis is aligned.
Two axes are aligned if their center coordinate values map to integers on the other axes as well and if the interpolation modes are equivalent.
- Parameters
- other
MapAxis
Other map axis.
- atolfloat
Absolute numerical tolerance for the comparison measured in bins.
- other
- Returns
- alignedbool
Whether the axes are aligned
-
slice
(idx)[source]¶ Create a new axis object by extracting a slice from this axis.
- Parameters
- idxslice
Slice object selecting a subselection of the axis.
- Returns
- axis
MapAxis
Sliced axis object.
- axis
-
squash
()[source]¶ Create a new axis object by squashing the axis into one bin.
- Returns
- axis
MapAxis
Sliced axis object.
- axis
-
to_table
(format='ogip')[source]¶ Convert
Quantity
to OGIPEBOUNDS
extension.The ‘ogip-sherpa’ format is equivalent to ‘ogip’ but uses keV energy units.
- Parameters
- format{“ogip”, “ogip-sherpa”, “gadf-dl3”}
Format specification
- Returns
- table
Table
Table HDU
- table
-
to_table_hdu
(format='ogip')[source]¶ Convert
Quantity
to OGIPEBOUNDS
extension.The ‘ogip-sherpa’ format is equivalent to ‘ogip’ but uses keV energy units.
- Parameters
- format{“ogip”, “ogip-sherpa”}
Format specification
- Returns
- hdu
BinTableHDU
Table HDU
- hdu
-
upsample
(factor)[source]¶ Upsample map axis by a given factor.
When up-sampling for each node specified in the axis, the corresponding number of sub-nodes are introduced and preserving the initial nodes. For node type “edges” this results in nbin * factor new bins. For node type “center” this results in (nbin - 1) * factor + 1 new bins.
- Parameters
- factorint
Upsampling factor.
- Returns
- axis
MapAxis
Usampled map axis.
- axis