MapAxes

class gammapy.maps.MapAxes(axes)[source]

Bases: collections.abc.Sequence

MapAxis container class.

Parameters
axeslist of MapAxis

List of map axis objects.

Attributes Summary

names

Names of the axes

shape

Shape of the axes

Methods Summary

coord_to_idx(coord[, clip])

Transform from axis to pixel indices.

coord_to_pix(coord)

Transform from axis to pixel coordinates.

count(value)

downsample(factor, axis_name)

Downsample axis by a given factor

drop(axis_name)

Drop an axis.

from_default(axes)

Make a sequence of MapAxis objects.

from_table_hdu(hdu[, format])

Create MapAxes from BinTableHDU

index(axis_name)

Get index in list

index_data(axis_name)

Get data index of the axes

pix_to_coord(pix)

Convert pixel coordinates to map coordinates.

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([header])

Convert axes to FITS header

to_table([format])

Convert axes to table

to_table_hdu([format, prefix])

Make FITS table columns for map axes.

upsample(factor, axis_name)

Upsample axis by a given factor

Attributes Documentation

names

Names of the axes

shape

Shape of the axes

Methods Documentation

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.

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)[source]

Make a sequence of MapAxis objects.

classmethod from_table_hdu(hdu, format=None)[source]

Create MapAxes from BinTableHDU

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

pix_to_coord(pix)[source]

Convert pixel coordinates to map coordinates.

Parameters
pixtuple

Tuple of pixel coordinates.

Returns
coordstuple

Tuple of map coordinates.

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(header=None)[source]

Convert axes to FITS header

Parameters
headerHeader

If a header is provided it is extended with the information. Otherwise a new one is created.

Returns
headerHeader

FITS header.

to_table(format=None)[source]

Convert axes to table

Parameters
format{“gadf-dl3”}

Format to use.

Returns
tableTable

Table with axis data

to_table_hdu(format=None, prefix=None)[source]

Make FITS table columns for map axes.

Parameters
format{“gadf”, “fgst-ccube”, “fgst-template”}

Format to use.

prefixstr

HDU name prefix 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