RegionGeom¶
-
class
gammapy.maps.RegionGeom(region, axes=None, wcs=None)[source]¶ Bases:
gammapy.maps.GeomMap geometry representing a region on the sky.
- Parameters
Attributes Summary
Center skydir
Shape of the Numpy data array matching this geometry.
Width of bounding box of the region
Methods Summary
bin_volume(self)contains(self, coords)Check if a given map coordinate is contained in the geometry.
contains_pix(self, pix)Check if a given pixel coordinate is contained in the geometry.
coord_to_idx(self, coords[, clip])Convert map coordinates to pixel indices.
coord_to_pix(self, coords)Convert map coordinates to pixel coordinates.
coord_to_tuple(self, coord)Generate a coordinate tuple compatible with this geometry.
copy(self, \*\*kwargs)Copy and overwrite given attributes.
create(region, \*\*kwargs)Create region.
crop(self)Crop the geometry at the edges.
downsample(self, factor, axis)Downsample the spatial dimension of the geometry by a given factor.
energy_mask(self[, emin, emax])Create a mask for a given energy range.
from_hdulist(hdulist[, format])Read region table and convert it to region list.
get_axis_by_name(self, name)Get an axis by name (case in-sensitive).
get_axis_index_by_name(self, name)Get an axis index by name (case in-sensitive).
get_coord(self[, frame])Get map coordinates from the geometry.
get_idx(self)Get tuple of pixel indices for this geometry.
make_bands_hdu(self[, hdu, hdu_skymap, conv])pad(self)Pad the geometry at the edges.
pix_to_coord(self, pix)Convert pixel coordinates to map coordinates.
pix_to_idx(self, pix[, clip])Convert pixel coordinates to pixel indices.
separation(self, position)slice_by_idx(self, slices)Create a new geometry by slicing the non-spatial axes.
solid_angle(self)Solid angle (
Quantityinsr).to_cube(self, axes)Append non-spatial axes to create a higher-dimensional geometry.
to_image(self)Create 2D image geometry (drop non-spatial dimensions).
union(self, other)Stack a RegionGeom by making the union
upsample(self, factor, axis)Upsample the spatial dimension of the geometry by a given factor.
Attributes Documentation
-
axes¶
-
axes_names¶
-
binsz= 0.01¶
-
center_coord¶
-
center_pix¶
-
center_skydir¶ Center skydir
-
data_shape¶ Shape of the Numpy data array matching this geometry.
-
frame¶
-
is_allsky= False¶
-
is_hpx= False¶
-
is_image= False¶
-
projection= 'TAN'¶
-
region¶
-
wcs¶
-
width¶ Width of bounding box of the region
Methods Documentation
-
contains_pix(self, pix)¶ Check if a given pixel coordinate is contained in the geometry.
- Parameters
- pixtuple
Tuple of pixel coordinates.
- Returns
- containment
ndarray Bool array.
- containment
-
coord_to_idx(self, coords, clip=False)¶ Convert map coordinates to pixel indices.
- Parameters
- coordstuple or
MapCoord Coordinate values in each dimension of the map. This can either be a tuple of numpy arrays or a MapCoord object. If passed as a tuple then the ordering should be (longitude, latitude, c_0, …, c_N) where c_i is the coordinate vector for axis i.
- clipbool
Choose whether to clip indices to the valid range of the geometry. If false then indices for coordinates outside the geometry range will be set -1.
- coordstuple or
- Returns
- pixtuple
Tuple of pixel indices in image and band dimensions. Elements set to -1 correspond to coordinates outside the map.
-
coord_to_pix(self, coords)[source]¶ Convert map coordinates to pixel coordinates.
- Parameters
- coordstuple
Coordinate values in each dimension of the map. This can either be a tuple of numpy arrays or a MapCoord object. If passed as a tuple then the ordering should be (longitude, latitude, c_0, …, c_N) where c_i is the coordinate vector for axis i.
- Returns
- pixtuple
Tuple of pixel coordinates in image and band dimensions.
-
coord_to_tuple(self, coord)¶ Generate a coordinate tuple compatible with this geometry.
- Parameters
- coord
MapCoord
- coord
-
copy(self, **kwargs)¶ Copy and overwrite given attributes.
- Parameters
- **kwargsdict
Keyword arguments to overwrite in the map geometry constructor.
- Returns
- copy
Geom Copied map geometry.
- copy
-
classmethod
create(region, **kwargs)[source]¶ Create region.
- Parameters
- Returns
- geom
RegionGeom Region geometry
- geom
-
crop(self)[source]¶ Crop the geometry at the edges.
- Parameters
- crop_width{sequence, array_like, int}
Number of values cropped from the edges of each axis.
- Returns
- geom
Geom Cropped geometry.
- geom
-
downsample(self, factor, axis)[source]¶ Downsample the spatial dimension of the geometry by a given factor.
- Parameters
- factorint
Downsampling factor.
- axisstr
Axis to downsample.
- Returns
- geom
Geom Downsampled geometry.
- geom
-
energy_mask(self, emin=None, emax=None)¶ Create a mask for a given energy range.
The energy bin must be fully contained to be included in the mask.
-
classmethod
from_hdulist(hdulist, format='ogip')[source]¶ Read region table and convert it to region list.
-
get_axis_by_name(self, name)¶ Get an axis by name (case in-sensitive).
- Parameters
- namestr
Name of the requested axis
- Returns
- axis
MapAxis Axis
- axis
-
get_axis_index_by_name(self, name)¶ Get an axis index by name (case in-sensitive).
- Parameters
- namestr
Axis name
- Returns
- indexint
Axis index
-
get_coord(self, frame=None)[source]¶ Get map coordinates from the geometry.
- Returns
- coord
MapCoord Map coordinate object.
- coord
-
get_idx(self)[source]¶ Get tuple of pixel indices for this geometry.
Returns all pixels in the geometry by default. Pixel indices for a single image plane can be accessed by setting
idxto the index tuple of a plane.- Parameters
- idxtuple, optional
A tuple of indices with one index for each non-spatial dimension. If defined only pixels for the image plane with this index will be returned. If none then all pixels will be returned.
- localbool
Flag to return local or global pixel indices. Local indices run from 0 to the number of pixels in a given image plane.
- flatbool, optional
Return a flattened array containing only indices for pixels contained in the geometry.
- Returns
- idxtuple
Tuple of pixel index vectors with one vector for each dimension.
-
make_bands_hdu(self, hdu=None, hdu_skymap=None, conv=None)¶
-
pad(self)[source]¶ Pad the geometry at the edges.
- Parameters
- pad_width{sequence, array_like, int}
Number of values padded to the edges of each axis.
- Returns
- geom
Geom Padded geometry.
- geom
-
pix_to_coord(self, pix)[source]¶ Convert pixel coordinates to map coordinates.
- Parameters
- pixtuple
Tuple of pixel coordinates.
- Returns
- coordstuple
Tuple of map coordinates.
-
pix_to_idx(self, pix, clip=False)[source]¶ Convert pixel coordinates to pixel indices.
Returns -1 for pixel coordinates that lie outside of the map.
- Parameters
- pixtuple
Tuple of pixel coordinates.
- clipbool
Choose whether to clip indices to the valid range of the geometry. If false then indices for coordinates outside the geometry range will be set -1.
- Returns
- idxtuple
Tuple of pixel indices.
-
slice_by_idx(self, slices)¶ Create a new geometry by slicing the non-spatial axes.
-
to_cube(self, axes)[source]¶ Append non-spatial axes to create a higher-dimensional geometry.
This will result in a new geometry with N+M dimensions where N is the number of current dimensions and M is the number of axes in the list.
- Parameters
- axeslist
Axes that will be appended to this geometry.
- Returns
- geom
Geom Map geometry.
- geom