nddata_cutout2d¶
- astroimtools.utils.nddata_cutout2d(nddata, position, size, mode='trim', fill_value=nan)[source]¶
Create a 2D cutout of a
NDDataobject.Specifically, cutouts will made for the
nddata.dataandnddata.mask(if present) arrays. Ifnddata.wcsexists, then it will also be updated.Note that cutouts will not be made for
nddata.uncertainty(if present) because they are general objects and not arrays.- Parameters:
- nddata
NDData The 2D
NDDatafrom which the cutout is taken.- positiontuple or
SkyCoord The position of the cutout array’s center with respect to the
nddata.dataarray. The position can be specified either as a(x, y)tuple of pixel coordinates or aSkyCoord, in which casenddata.wcsmust exist.- sizeint, array-like,
Quantity The size of the cutout array along each axis. If
sizeis a scalar number or a scalarQuantity, then a square cutout ofsizewill be created. Ifsizehas two elements, they should be in(ny, nx)order. Scalar numbers insizeare assumed to be in units of pixels.sizecan also be aQuantityobject or containQuantityobjects. SuchQuantityobjects must be in pixel or angular units. For all cases,sizewill be converted to an integer number of pixels, rounding the the nearest integer. See themodekeyword for additional details on the final cutout size.- 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 inputnddata.dataarray is sufficient. For the'strict'mode, the cutout array has to be fully contained within thenddata.dataarray, 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 thenddata.dataarray will be filled withfill_value. In'trim'mode only the overlapping elements are returned, thus the resulting cutout array may be smaller than the requestedsize.- fill_valuenumber, optional
If
mode='partial', the value to fill pixels in the cutout array that do not overlap with the inputnddata.data.fill_valuemust have the samedtypeas the inputnddata.dataarray.
- nddata
- Returns:
Examples
>>> from astropy.nddata import NDData >>> import astropy.units as u >>> from astroimtools import nddata_cutout2d >>> data = np.random.random((500, 500)) >>> unit = u.electron / u.s >>> mask = (data > 0.7) >>> meta = {'exptime': 1234 * u.s} >>> nddata = NDData(data, mask=mask, unit=unit, meta=meta) >>> cutout = nddata_cutout2d(nddata, (100, 100), (10, 10)) >>> cutout.data.shape (10, 10) >>> cutout.mask.shape (10, 10) >>> cutout.unit Unit("electron / s")