Geom#

class gammapy.maps.Geom#

Bases: abc.ABC

Map geometry base class.

See also: WcsGeom and HpxGeom

Attributes Summary

as_energy_true

If the geom contains an energy axis rename it to energy true

center_coord

center_pix

center_skydir

data_shape

Shape of the Numpy data array matching this geometry.

has_energy_axis

Whether geom has an energy axis

is_allsky

is_flat

Whether the geom non spatial axes have length 1, equivalent to an image.

is_image

Whether the geom is an image without extra dimensions.

Methods Summary

contains(coords)

Check if a given map coordinate is contained in the geometry.

contains_pix(pix)

Check if a given pixel coordinate is contained in the geometry.

coord_to_idx(coords[, clip])

Convert map coordinates to pixel indices.

coord_to_pix(coords)

Convert map coordinates to pixel coordinates.

copy(**kwargs)

Copy and overwrite given attributes.

crop(crop_width)

Crop the geometry at the edges.

data_nbytes([dtype])

Estimate memory usage in megabytes of the Numpy data array matching this geometry depending on the given type.

downsample(factor, axis_name)

Downsample the spatial dimension of the geometry by a given factor.

drop(axis_name)

Drop an axis from the geom.

energy_mask([energy_min, energy_max, ...])

Create a mask for a given energy range.

from_hdulist(hdulist[, hdu, hdu_bands])

Load a geometry object from a FITS HDUList.

get_coord([idx, flat])

Get the coordinate array for this geometry.

get_idx([idx, local, flat])

Get tuple of pixel indices for this geometry.

pad(pad_width, axis_name)

Pad the geometry at the edges.

pix_to_coord(pix)

Convert pixel coordinates to map coordinates.

pix_to_idx(pix[, clip])

Convert pixel coordinates to pixel indices.

rename_axes(names, new_names)

Rename axes contained in the geometry

replace_axis(axis)

Replace axis with a new one.

resample_axis(axis)

Resample geom to a new axis binning.

slice_by_idx(slices)

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

solid_angle()

Solid angle (Quantity in sr).

squash(axis_name)

Squash geom axis.

to_bands_hdu([hdu_bands, format])

to_cube(axes)

Append non-spatial axes to create a higher-dimensional geometry.

to_image()

Create 2D image geometry (drop non-spatial dimensions).

upsample(factor[, axis_name])

Upsample the spatial dimension of the geometry by a given factor.

Attributes Documentation

Methods Documentation

copy()#

Generic (shallow and deep) copying operations.

Interface summary:

import copy

x = copy.copy(y) # make a shallow copy of y x = copy.deepcopy(y) # make a deep copy of y

For module specific errors, copy.Error is raised.

The difference between shallow and deep copying is only relevant for compound objects (objects that contain other objects, like lists or class instances).

  • A shallow copy constructs a new compound object and then (to the extent possible) inserts the same objects into it that the original contains.

  • A deep copy constructs a new compound object and then, recursively, inserts copies into it of the objects found in the original.

Two problems often exist with deep copy operations that don’t exist with shallow copy operations:

  1. recursive objects (compound objects that, directly or indirectly, contain a reference to themselves) may cause a recursive loop

  2. because deep copy copies everything it may copy too much, e.g. administrative data structures that should be shared even between copies

Python’s deep copy operation avoids these problems by:

  1. keeping a table of objects already copied during the current copying pass

  2. letting user-defined classes override the copying operation or the set of components copied

This version does not copy types like module, class, function, method, nor stack trace, stack frame, nor file, socket, window, nor array, nor any similar types.

Classes can use the same interfaces to control copying that they use to control pickling: they can define methods called __getinitargs__(), __getstate__() and __setstate__(). See the documentation for module “pickle” for information on these methods.