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 originaldata
array, 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.
- position2 tuple
The
(y, x)
position of the center of the cutout array with respect to thedata
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 inputdata
array is sufficient. For the'strict'
mode, the cutout array has to be fully contained within thedata
array, otherwise anPartialOverlapError
is raised. In all modes, non-overlapping arrays will raise aNoOverlapError
. In'partial'
mode, positions in the cutout array that do not overlap with thedata
array 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_value
must have the samedtype
as the inputdata
array.- copybool, optional
If
False
(default), then the cutout data will be a view into the originaldata
array. IfTrue
, then the cutout data will hold a copy of the originaldata
array.
- data
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
BoundingBox
of the minimal rectangular region of the cutout array with respect to the cutout array.The
BoundingBox
of 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
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.