CutoutImage#
- class photutils.utils.CutoutImage(data, position, shape, mode='trim', fill_value=nan, copy=False)[source]#
Bases:
objectCreate 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 originaldataarray, otherwise the cutout array will contain a copy of the original data.- Parameters:
- data
ndarray The 2D data array from which to extract the cutout array.
- positiontuple of 2 ints
The
(y, x)position of the center of the cutout array with respect to thedataarray.- shapetuple of 2 ints
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 inputdataarray is sufficient. For the'strict'mode, the cutout array has to be fully contained within thedataarray, otherwise anPartialOverlapErroris raised. In all modes, non-overlapping arrays will raise aNoOverlapError. In'partial'mode, positions in the cutout array that do not overlap with thedataarray will be filled withfill_value. In'trim'mode only the overlapping elements are returned, thus the resulting cutout array may be smaller than the requestedshape.- fill_valuefloat or int, optional
If
mode='partial', the value to fill pixels in the cutout array that do not overlap with the inputdata.fill_valuemust have the samedtypeas the inputdataarray.- copybool, optional
If
False(default), then the cutout data will be a view into the originaldataarray. IfTrue, then the cutout data will hold a copy of the originaldataarray.
- data
Notes
If the cutout array is not fully contained within the input
dataarray andmode='partial'withfill_value=np.nan, then the inputdatamust have a float data type.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
The
BoundingBoxof the minimal rectangular region of the cutout array with respect to the cutout array.The
BoundingBoxof the minimal rectangular region of the cutout array with respect to the original array.A tuple of slice objects in axis order for the minimal bounding box of the cutout with respect to the cutout array.
A tuple of slice objects in axis order for the minimal bounding box of the cutout with respect to the original array.
A
ndarraycontaining the(x, y)integer index of the origin pixel of the cutout with respect to the original array.Attributes Documentation
- bbox_cutout#
The
BoundingBoxof 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
BoundingBoxof 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.