MapAxes#
- class gammapy.maps.MapAxes(axes, n_spatial_axes=None)[source]#
Bases:
Sequence
MapAxis container class.
- Parameters:
- axeslist of
MapAxis
List of map axis objects.
- axeslist of
Attributes Summary
Center coordinates.
Whether axes is flat.
Whether axes is unidimensional.
Generator that iterates over axes and their shape.
Names of the axes.
Primary extra axis, defined as the longest one.
Reverse axes order.
Shapes of the axes.
Methods Summary
assert_names
(required_names[, allow_extra])Assert required axis names and order.
Bin axes volume.
coord_to_idx
(coord[, clip])Transform from axis to pixel indices.
coord_to_pix
(coord)Transform from axis to pixel coordinates.
copy
()Initialize a new map axes instance by copying each axis.
count
(value)downsample
(factor, axis_name)Downsample axis by a given factor.
drop
(axis_name)Drop an axis.
from_default
(axes[, n_spatial_axes])Make a sequence of
MapAxis
objects.from_table
(table[, format])Create MapAxes from table.
from_table_hdu
(hdu[, format])Create MapAxes from BinTableHDU.
get_coord
([mode, axis_name])Get axes coordinates.
index
(axis_name)Get index in list.
index_data
(axis_name)Get data index of the axes.
is_allclose
(other, **kwargs)Check if other map axes are all close.
pad
(axis_name, pad_width)Pad axis.
pix_to_coord
(pix)Convert pixel coordinates to map coordinates.
pix_to_idx
(pix[, clip])Convert pixel to pixel indices.
rename_axes
(names, new_names)Rename the axes.
replace
(axis)Replace a given axis.
resample
(axis)Resample axis binning.
slice_by_idx
(slices)Create a new geometry by slicing the non-spatial axes.
squash
(axis_name)Squash axis.
to_header
([format])Convert axes to FITS header.
to_table
([format])Convert axes to table.
to_table_hdu
([format, hdu_bands])Make FITS table columns for map axes.
upsample
(factor, axis_name)Upsample axis by a given factor.
Attributes Documentation
- center_coord#
Center coordinates.
- is_flat#
Whether axes is flat.
- is_unidimensional#
Whether axes is unidimensional.
- iter_with_reshape#
Generator that iterates over axes and their shape.
- names#
Names of the axes.
- reverse#
Reverse axes order.
- shape#
Shapes of the axes.
Methods Documentation
- assert_names(required_names, allow_extra=False)[source]#
Assert required axis names and order.
- Parameters:
- required_nameslist of str
Required names.
- allow_extrabool
Allow extra axes beyond required ones.
- coord_to_idx(coord, clip=True)[source]#
Transform from axis to pixel indices.
- Parameters:
- Returns:
- pixtuple of
ndarray
Array of pixel indices values.
- pixtuple of
- count(value) integer -- return number of occurrences of value #
- downsample(factor, axis_name)[source]#
Downsample axis by a given factor.
- Parameters:
- factorint
Downsampling factor.
- axis_namestr
Axis to downsample.
- Returns:
- axes
MapAxes
Map axes.
- axes
- drop(axis_name)[source]#
Drop an axis.
- Parameters:
- axis_namestr
Name of the axis to remove.
- Returns:
- axes
MapAxes
Axes without the
axis_name
.
- axes
- classmethod from_table_hdu(hdu, format='gadf')[source]#
Create MapAxes from BinTableHDU.
- Parameters:
- hdu
BinTableHDU
Bin table HDU.
- format{“gadf”, “gadf-dl3”, “fgst-ccube”, “fgst-template”, “fgst-bexcube”, “ogip-arf”}
Format to use. Default is “gadf”.
- hdu
- Returns:
- axes
MapAxes
Map axes object.
- axes
- get_coord(mode='center', axis_name=None)[source]#
Get axes coordinates.
- Parameters:
- mode{“center”, “edges”}
Coordinate center or edges. Default is “center”.
- axis_namestr, optional
Axis name for which mode=’edges’ applies. Default is None.
- Returns:
- coordsdict of
Quantity
. Map coordinates as a dictionary.
- coordsdict of
- index_data(axis_name)[source]#
Get data index of the axes.
- Parameters:
- axis_namestr
Name of the axis.
- Returns:
- idxint
Data index.
- is_allclose(other, **kwargs)[source]#
Check if other map axes are all close.
- Parameters:
- other
MapAxes
Other map axes.
- **kwargsdict, optional
Keyword arguments forwarded to
is_allclose
- other
- Returns:
- is_allclosebool
Whether other axes are all close.
- pad(axis_name, pad_width)[source]#
Pad axis.
- Parameters:
- axis_namestr
Name of the axis to pad.
- pad_widthint or tuple of int
Pad width.
- Returns:
- axes
MapAxes
Axes with squashed axis.
- axes
- pix_to_coord(pix)[source]#
Convert pixel coordinates to map coordinates.
- Parameters:
- pixtuple
Tuple of pixel coordinates.
- Returns:
- coordstuple
Tuple of map coordinates.
- replace(axis)[source]#
Replace a given axis. In order to be replaced, the name of the new axis must match the name of the old axis.
- Parameters:
- axis
MapAxis
Map axis.
- axis
- Returns:
- axesMapAxes
Map axes.
- resample(axis)[source]#
Resample axis binning.
This method groups the existing bins into a new binning.
- slice_by_idx(slices)[source]#
Create a new geometry by slicing the non-spatial axes.
- Parameters:
- slicesdict
Dictionary of axes names and integers or
slice
object pairs. Contains one element for each non-spatial dimension. For integer indexing the corresponding axes is dropped from the map. Axes not specified in the dictionary are kept unchanged.
- Returns:
- axes
MapAxes
Sliced axes.
- axes
Examples
>>> import astropy.units as u >>> from astropy.time import Time >>> from gammapy.maps import MapAxis, MapAxes, TimeMapAxis >>> energy_axis = MapAxis.from_energy_bounds(1*u.TeV, 3*u.TeV, 6) >>> time_ref = Time("1999-01-01T00:00:00.123456789") >>> time_axis = TimeMapAxis( ... edges_min=[0, 1, 3] * u.d, ... edges_max=[0.8, 1.9, 5.4] * u.d, ... reference_time=time_ref, ... ) >>> axes = MapAxes([energy_axis, time_axis]) >>> slices = {"energy": slice(0, 3), "time": slice(0, 1)} >>> sliced_axes = axes.slice_by_idx(slices)
- squash(axis_name)[source]#
Squash axis.
- Parameters:
- axis_namestr
Axis to squash.
- Returns:
- axes
MapAxes
Axes with squashed axis.
- axes
- to_header(format='gadf')[source]#
Convert axes to FITS header.
- Parameters:
- format{“gadf”}
Header format. Default is “gadf”.
- Returns:
- header
Header
FITS header.
- header
- to_table(format='gadf')[source]#
Convert axes to table.
- Parameters:
- format{“gadf”, “gadf-dl3”, “fgst-ccube”, “fgst-template”, “ogip”, “ogip-sherpa”, “ogip-arf”, “ogip-arf-sherpa”} # noqa E501
Format to use. Default is “gadf”.
- Returns:
- table
Table
Table with axis data.
- table
- to_table_hdu(format='gadf', hdu_bands=None)[source]#
Make FITS table columns for map axes.
- Parameters:
- format{“gadf”, “fgst-ccube”, “fgst-template”}
Format to use. Default is “gadf”.
- hdu_bandsstr, optional
Name of the bands HDU to use. Default is None.
- Returns:
- hdu
BinTableHDU
Bin table HDU.
- hdu