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.
If a WCS object is input, then the returned object will also contain a copy of the original WCS, but updated for the cutout array.
For example usage, see 2D Cutout Images.
Warning
The cutout WCS object does not currently handle cases where the input WCS object contains distortion lookup tables described in the FITS WCS distortion paper.
Parameters: | data : ndarray
position : tuple or SkyCoord
size : int, array-like, Quantity
wcs : WCS, optional
mode : {‘trim’, ‘partial’, ‘strict’}, optional
fill_value : number, optional
copy : bool, optional
|
---|---|
Returns: | result : Cutout2D
|
Examples
>>> import numpy as np
>>> from astropy.nddata.utils import Cutout2D
>>> from astropy import units as u
>>> data = np.arange(20.).reshape(5, 4)
>>> cutout1 = Cutout2D(data, (2, 2), (3, 3))
>>> print(cutout1.data)
[[ 5. 6. 7.]
[ 9. 10. 11.]
[ 13. 14. 15.]]
>>> print(cutout1.center_original)
(2.0, 2.0)
>>> print(cutout1.center_cutout)
(1.0, 1.0)
>>> print(cutout1.origin_original)
(1, 1)
>>> cutout2 = Cutout2D(data, (2, 2), 3)
>>> print(cutout2.data)
[[ 5. 6. 7.]
[ 9. 10. 11.]
[ 13. 14. 15.]]
>>> size = u.Quantity([3, 3], u.pixel)
>>> cutout3 = Cutout2D(data, (0, 0), size)
>>> print(cutout3.data)
[[ 0. 1.]
[ 4. 5.]]
>>> cutout4 = Cutout2D(data, (0, 0), (3 * u.pixel, 3))
>>> print(cutout4.data)
[[ 0. 1.]
[ 4. 5.]]
>>> cutout5 = Cutout2D(data, (0, 0), (3, 3), mode='partial')
>>> print(cutout5.data)
[[ nan nan nan]
[ nan 0. 1.]
[ nan 4. 5.]]
Attributes Summary
bbox_cutout | The bounding box ((ymin, ymax), (xmin, xmax)) of the minimal rectangular region of the cutout array with respect to the cutout array. |
bbox_original | The bounding box ((ymin, ymax), (xmin, xmax)) of the minimal rectangular region of the cutout array with respect to the original array. |
center_cutout | The central (x, y) position of the cutout array with respect to the cutout array. |
center_original | The central (x, y) position of the cutout array with respect to the original array. |
origin_cutout | The (x, y) index of the origin pixel of the cutout with respect to the cutout array. |
origin_original | The (x, y) index of the origin pixel of the cutout with respect to the original array. |
position_cutout | The (x, y) position index (rounded to the nearest pixel) in the cutout array. |
position_original | The (x, y) position index (rounded to the nearest pixel) in the original array. |
Methods Summary
plot_on_original([ax, fill]) | Plot the cutout region on a matplotlib Axes instance. |
to_cutout_position(original_position) | Convert an (x, y) position in the original large array to the (x, y) position in the cutout array. |
to_original_position(cutout_position) | Convert an (x, y) position in the cutout array to the original (x, y) position in the original large array. |
Attributes Documentation
The bounding box ((ymin, ymax), (xmin, xmax)) 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.
The bounding box ((ymin, ymax), (xmin, xmax)) 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.
The central (x, y) position of the cutout array with respect to the cutout array. For mode='partial', the central position is calculated for the valid (non-filled) cutout values.
The central (x, y) position of the cutout array with respect to the original array. For mode='partial', the central position is calculated for the valid (non-filled) cutout values.
The (x, y) index of the origin pixel of the cutout with respect to the cutout array. For mode='partial', the origin pixel is calculated for the valid (non-filled) cutout values.
The (x, y) index of the origin pixel of the cutout with respect to the original array. For mode='partial', the origin pixel is calculated for the valid (non-filled) cutout values.
The (x, y) position index (rounded to the nearest pixel) in the cutout array.
The (x, y) position index (rounded to the nearest pixel) in the original array.
Methods Documentation
Plot the cutout region on a matplotlib Axes instance.
Parameters: | ax : matplotlib.axes.Axes instance, optional
fill : bool, optional
kwargs : optional
|
---|---|
Returns: | ax : matplotlib.axes.Axes instance
|
Convert an (x, y) position in the original large array to the (x, y) position in the cutout array.
Parameters: | original_position : tuple
|
---|---|
Returns: | cutout_position : tuple
|
Convert an (x, y) position in the cutout array to the original (x, y) position in the original large array.
Parameters: | cutout_position : tuple
|
---|---|
Returns: | original_position : tuple
|