CutoutImage

class photutils.utils.CutoutImage(data, position, shape, mode='trim', fill_value=nan, copy=False)[source]

Bases: object

Create a cutout object from a 2D array.

The returned object will contain a 2D cutout array. If copy=False (default), the cutout array is a view into the original data array, otherwise the cutout array will contain a copy of the original data.

Parameters:
datandarray

The 2D data array from which to extract the cutout array.

position2 tuple

The (y, x) position of the center of the cutout array with respect to the data array.

shape2 tuple of int

The shape of the cutout array along each axis in (ny, nx) order.

mode{‘trim’, ‘partial’, ‘strict’}, optional

The mode used for creating the cutout data array. For the 'partial' and 'trim' modes, a partial overlap of the cutout array and the input data array is sufficient. For the 'strict' mode, the cutout array has to be fully contained within the data array, otherwise an PartialOverlapError is raised. In all modes, non-overlapping arrays will raise a NoOverlapError. In 'partial' mode, positions in the cutout array that do not overlap with the data array will be filled with fill_value. In 'trim' mode only the overlapping elements are returned, thus the resulting cutout array may be smaller than the requested shape.

fill_valuefloat or int, optional

If mode='partial', the value to fill pixels in the cutout array that do not overlap with the input data. fill_value must have the same dtype as the input data array.

copybool, optional

If False (default), then the cutout data will be a view into the original data array. If True, then the cutout data will hold a copy of the original data array.

Examples

>>> import numpy as np
>>> from photutils.utils import CutoutImage
>>> data = np.arange(20.0).reshape(5, 4)
>>> cutout = CutoutImage(data, (2, 2), (3, 3))
>>> print(cutout.data)  
[[ 5.  6.  7.]
 [ 9. 10. 11.]
 [13. 14. 15.]]
>>> cutout2 = CutoutImage(data, (0, 0), (3, 3), mode='partial')
>>> print(cutout2.data)  
[[nan nan nan]
 [nan  0.  1.]
 [nan  4.  5.]]

Attributes Summary

bbox_cutout

The BoundingBox of the minimal rectangular region of the cutout array with respect to the cutout array.

bbox_original

The BoundingBox of the minimal rectangular region of the cutout array with respect to the original array.

slices_cutout

A tuple of slice objects in axis order for the minimal bounding box of the cutout with respect to the cutout array.

slices_original

A tuple of slice objects in axis order for the minimal bounding box of the cutout with respect to the original array.

xyorigin

A ndarray containing the (x, y) integer index of the origin pixel of the cutout with respect to the original array.

Attributes Documentation

bbox_cutout

The BoundingBox of the minimal rectangular region of the cutout array with respect to the cutout array.

For mode='partial', the bounding box indices are for the valid (non-filled) cutout values.

bbox_original

The BoundingBox of the minimal rectangular region of the cutout array with respect to the original array.

For mode='partial', the bounding box indices are for the valid (non-filled) cutout values.

slices_cutout

A tuple of slice objects in axis order for the minimal bounding box of the cutout with respect to the cutout array.

For mode='partial', the slices are for the valid (non-filled) cutout values.

slices_original

A tuple of slice objects in axis order for the minimal bounding box of the cutout with respect to the original array.

For mode='partial', the slices are for the valid (non-filled) cutout values.

xyorigin

A ndarray containing the (x, y) integer index of the origin pixel of the cutout with respect to the original array.

The origin index will be negative for cutouts with partial overlaps.