MapAxes#

class gammapy.maps.MapAxes(axes, n_spatial_axes=None)[source]#

Bases: collections.abc.Sequence

MapAxis container class.

Parameters
axeslist of MapAxis

List of map axis objects.

Attributes Summary

center_coord

Center coordinates

is_flat

Whether axes is flat

is_unidimensional

Whether axes is unidimensional

iter_with_reshape

Iterate by shape

names

Names of the axes

primary_axis

Primary extra axis, defined as the one longest

reverse

Reverse axes order

shape

Shape of the axes

Methods Summary

assert_names(required_names)

Assert required axis names and order

bin_volume()

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()

Init 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 axes

pix_to_coord(pix)

Convert pixel coordinates to map coordinates.

pix_to_idx(pix[, clip])

Convert pix to idx

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#

Iterate by shape

names#

Names of the axes

primary_axis#

Primary extra axis, defined as the one longest

Returns
axisMapAxis

Map axis

reverse#

Reverse axes order

shape#

Shape of the axes

Methods Documentation

assert_names(required_names)[source]#

Assert required axis names and order

Parameters
required_nameslist of str

Required

bin_volume()[source]#

Bin axes volume

Returns
bin_volumeQuantity

Bin volume

coord_to_idx(coord, clip=True)[source]#

Transform from axis to pixel indices.

Parameters
coorddict of ndarray or MapCoord

Array of axis coordinate values.

Returns
pixtuple of ndarray

Array of pixel indices values.

coord_to_pix(coord)[source]#

Transform from axis to pixel coordinates.

Parameters
coorddict of ndarray

Array of axis coordinate values.

Returns
pixtuple of ndarray

Array of pixel coordinate values.

copy()[source]#

Init map axes instance by copying each axis.

count(value) integer -- return number of occurrences of value#
downsample(factor, axis_name)[source]#

Downsample axis by a given factor

Parameters
factorint

Upsampling factor.

axis_namestr

Axis to upsample.

Returns
axesMapAxes

Map axes

drop(axis_name)[source]#

Drop an axis.

Parameters
axis_namestr

Name of the axis to remove.

Returns
axesMapAxes

Axes with squashed axis.

classmethod from_default(axes, n_spatial_axes=None)[source]#

Make a sequence of MapAxis objects.

classmethod from_table(table, format='gadf')[source]#

Create MapAxes from table

Parameters
tableTable

Bin table HDU

format{“gadf”, “gadf-dl3”, “fgst-ccube”, “fgst-template”, “fgst-bexcube”, “ogip-arf”}

Format to use.

Returns
axesMapAxes

Map axes object

classmethod from_table_hdu(hdu, format='gadf')[source]#

Create MapAxes from BinTableHDU

Parameters
hduBinTableHDU

Bin table HDU

Returns
axesMapAxes

Map axes object

get_coord(mode='center', axis_name=None)[source]#

Get axes coordinates

Parameters
mode{“center”, “edges”}

Coordinate center or edges

axis_namestr

Axis name for which mode=’edges’ applies

Returns
coordsdict of Quanity

Map coordinates

index(axis_name)[source]#

Get index in list

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
otherMapAxes

Other map axes

**kwargsdict

Keyword arguments forwarded to is_allclose

Returns
is_allclosebool

Whether other axes are all close

pad(axis_name, pad_width)[source]#

Pad axes

Parameters
axis_namestr

Name of the axis to pad.

pad_widthint or tuple of int

Pad width

Returns
axesMapAxes

Axes with squashed axis.

pix_to_coord(pix)[source]#

Convert pixel coordinates to map coordinates.

Parameters
pixtuple

Tuple of pixel coordinates.

Returns
coordstuple

Tuple of map coordinates.

pix_to_idx(pix, clip=False)[source]#

Convert pix to idx

Parameters
pixtuple of ndarray

Pixel coordinates.

clipbool

Choose whether to clip indices to the valid range of the axis. If false then indices for coordinates outside the axi range will be set -1.

Returns
idxtuple ndarray

Pixel indices.

rename_axes(names, new_names)[source]#

Rename the axes.

Parameters
nameslist or str

Names of the axes

new_nameslist or str

New names of the axes (list must be of same length than names).

Returns
axesMapAxes

Renamed Map axes object

replace(axis)[source]#

Replace a given axis

Parameters
axisMapAxis

Map axis

Returns
axesMapAxes

Map axe

resample(axis)[source]#

Resample axis binning.

This method groups the existing bins into a new binning.

Parameters
axisMapAxis

New map axis.

Returns
axesMapAxes

Axes object with resampled axis.

slice_by_idx(slices)[source]#

Create a new geometry by slicing the non-spatial axes.

Parameters
slicesdict

Dict 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 dict are kept unchanged.

Returns
geomGeom

Sliced geometry.

squash(axis_name)[source]#

Squash axis.

Parameters
axis_namestr

Axis to squash.

Returns
axesMapAxes

Axes with squashed axis.

to_header(format='gadf')[source]#

Convert axes to FITS header

Parameters
format{“gadf”}

Header format

Returns
headerHeader

FITS 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”}

Format to use.

Returns
tableTable

Table with axis data

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.

hdu_bandsstr

Name of the bands HDU to use.

Returns
hduBinTableHDU

Bin table HDU.

upsample(factor, axis_name)[source]#

Upsample axis by a given factor

Parameters
factorint

Upsampling factor.

axis_namestr

Axis to upsample.

Returns
axesMapAxes

Map axes