RegionMask

class regions.RegionMask(data, bbox)[source]

Bases: object

Class for a region mask.

Parameters:
data : array_like

A 2D array of a region mask representing the fractional overlap of the region on the pixel grid. This should be the full-sized (i.e. not truncated) array that is the direct output of one of the low-level “geometry” functions.

bbox : regions.BoundingBox

The bounding box for the region.

Examples

Usage examples are provided in the Computing overlap masks section of the docs.

Attributes Summary

shape The shape of the mask data array.

Methods Summary

cutout(self, data[, fill_value, copy]) Create a cutout from the input data over the mask bounding box, taking any edge effects into account.
multiply(self, data[, fill_value]) Multiply the region mask with the input data, taking any edge effects into account.
to_image(self, shape) Return an image of the mask in a 2D array of the given shape, taking any edge effects into account.

Attributes Documentation

shape

The shape of the mask data array.

Methods Documentation

cutout(self, data, fill_value=0.0, copy=False)[source]

Create a cutout from the input data over the mask bounding box, taking any edge effects into account.

Parameters:
data : array_like

A 2D array on which to apply the region mask.

fill_value : float, optional

The value used to fill pixels where the region mask does not overlap with the input data. The default is 0.

copy : bool, optional

If True then the returned cutout array will always be hold a copy of the input data. If False and the mask is fully within the input data, then the returned cutout array will be a view into the input data. In cases where the mask partially overlaps or has no overlap with the input data, the returned cutout array will always hold a copy of the input data (i.e. this keyword has no effect).

Returns:
result : ndarray or None

A 2D array cut out from the input data representing the same cutout region as the region mask. If there is a partial overlap of the region mask with the input data, pixels outside of the data will be assigned to fill_value. None is returned if there is no overlap of the region with the input data.

multiply(self, data, fill_value=0.0)[source]

Multiply the region mask with the input data, taking any edge effects into account.

The result is a mask-weighted cutout from the data.

Parameters:
data : array_like or Quantity

The 2D array to multiply with the region mask.

fill_value : float, optional

The value is used to fill pixels where the region mask does not overlap with the input data. The default is 0.

Returns:
result : ndarray or None

A 2D mask-weighted cutout from the input data. If there is a partial overlap of the region mask with the input data, pixels outside of the data will be assigned to fill_value before being multipled with the mask. None is returned if there is no overlap of the region with the input data.

to_image(self, shape)[source]

Return an image of the mask in a 2D array of the given shape, taking any edge effects into account.

Parameters:
shape : tuple of int

The (ny, nx) shape of the output array.

Returns:
result : ndarray

A 2D array of the mask.