Source Cutouts¶
A module that provides tools for creating and mapping image cutouts.
| Author: | Mihai Cara (for help, contact HST Help Desk) |
|---|---|
| License: | LICENSE |
-
class
subpixal.cutout.Cutout(data, wcs, blc=(0, 0), trc=None, dq=None, weight=None, src_id=0, data_units='rate', exptime=1, mode='strict', fillval=nan)[source]¶ This is a class designed to facilitate work with image cutouts. It holds both information about the cutout (location in the image) as well as information about the image and source: source ID, exposure time, image units,
WCS, etc.This class also provides convinience tools for creating cutouts, saving them to or loading from files, and for converting pixel coordinates to world coordinates (and vice versa) using cutout’s pixel grid while preserving all distortion corrections from image’s
WCS.Parameters: - data: numpy.ndarray
Image data from which the cutout will be extracted.
- wcs: astropy.wcs.WCS
World Coordinate System object describing coordinate transformations from image’s pixel coordinates to world coordinates.
- blc: tuple of two int
Bottom-Left Corner coordinates
(x, y)in thedataof the cutout to be extracted.- trc: tuple of two int, None, optional
Top-Right Corner coordinates
(x, y)in thedataof the cutout to be extracted. Pixel with the coordinatestrcis included. Whentrcis set toNone,trcis set to the shape of thedataimage:(nx, ny).- dq: numpy.ndarray
Data quality array associated with image data. If provided, this array will be cropped the same way as image data and stored within the
Cutoutobject.- weight: numpy.ndarray
Weight array associated with image data. If provided, this array will be cropped the same way as image data and stored within the
Cutoutobject.- src_id : any type, None
Anything that can be used to associate the source being extracted with a record in a catalog. This value is simply stored within the
Catalogobject.- data_units: {‘counts’, ‘rate’}, optional
Indicates the type of data units: count-like or rate-like (counts per unit of time). This provides the information necessary for unit conversion when needed.
- exptime: float, optional
Exposure time of image
imdata.- mode: {‘strict’, ‘fill’}
Allowed overlap between extraction rectangle for the cutout and the input image. When
modeis'strict'then aPartialOverlapErrorerror will be raised if the extraction rectangle is not completely within the boundaries of input image. Whenmodeis'fill', then parts of the cutout that are outside the boundaries of the input image will be filled with the value specified by thefillvalparameter.- fillval: scalar
All elements of the cutout that are outside the input image will be assigned this value. This parameter is ignored when
modeis set to'strict'.
Raises: - `NoOverlapError`
When cutout is completely outside of the input image.
- `PartialOverlapError`
When cutout only partially overlaps input image and
modeis set to'strict'.
-
DEFAULT_ACCURACY= 1e-05¶
-
DEFAULT_MAXITER= 50¶
-
DEFAULT_QUIET= True¶
-
blc¶ Set/Get coordinate of the bottom-left corner.
-
data¶ Get image data.
-
data_units¶ Get/Set image data units. Possible values are: ‘rate’ or ‘counts’.
-
dq¶ Set/Get cutout’s data quality.
-
dx¶ Set/Get displacement of the image grid along the
X-axis in pixels.
-
dy¶ Set/Get displacement of the image grid along the
Y-axis in pixels.
-
exptime¶ Get/Set exposure time.
-
extraction_slice¶ Get slice object that shows the slice in the input data array used to extract the cutout.
-
get_bbox(wrt='orig')[source]¶ Get a
numpy.ndarrayof pixel coordinates of vertices of the bounding box. The returned array has the shape(4, 2)and contains the coordinates of the outer corners of pixels (centers of pixels are considered to have integer coordinates).Parameters: - wrt : {‘orig’, ‘blc’, ‘world’}, optional
-
height¶ Get width of the cutout.
-
insertion_slice¶ Get slice object that shows the slice in the cutout data array into which image data were placed. This slice coincides with the entire cutout data array when
modeis'strict'but can point to a smaller region whenmodeis'fill'.
-
mask¶ Set/Get cutout’s mask.
-
naxis¶ Get FITS
NAXISproperty of the cutout.
-
pscale¶ Get pixel scale in the tangent plane at the reference point.
-
src_id¶ Set/Get source ID.
-
trc¶ Set/Get coordinate of the top-right corner.
-
wcs¶ Get image’s WCS from which the cutout was extracted.
-
weight¶ Set/Get cutout’s pixel weight.
-
width¶ Get width of the cutout.
-
subpixal.cutout.create_primary_cutouts(catalog, segmentation_image, imdata, imwcs, imdq=None, imweight=None, data_units='counts', exptime=1, pad=1)[source]¶ A function for creating first-order cutouts from a (drizzle-)combined image given a source catalog and a segmentation image.
Parameters: - catalog : SourceCatalog, astropy.table.Table
A table of sources which need to be extracted.
catalogmust contain a column named'id'which contains IDs of segments from thesegmentation_image.- segmentation_image: numpy.ndarray
A 2D segmentation image identifying sources from the catalog in
imdata.- imdata: numpy.ndarray
Image data array.
- imwcs: astropy.wcs.WCS
World coordinate system of image
imdata.- imdq: numpy.ndarray, None, optional
Data quality array corresponding to
imdata.- imweight: numpy.ndarray, None, optional
Pixel weight array corresponding to
imdata.- data_units: {‘counts’, ‘rate’}, optional
Indicates the type of data units: count-like or rate-like (counts per unit of time). This provides the information necessary for unit conversion when needed.
- exptime: float, optional
Exposure time of image
imdata.- pad: int, optional
Number of pixels to pad around the minimal rectangle enclosing a source segmentation.
Returns: - segments : list of Cutout
A list of extracted
Cutouts.
-
subpixal.cutout.create_cutouts(primary_cutouts, segmentation_image, drz_data, drz_wcs, flt_data, flt_wcs, drz_dq=None, drz_weight=None, drz_data_units='rate', drz_exptime=1, flt_dq=None, flt_weight=None, flt_data_units='counts', flt_exptime=1, pad=2)[source]¶ A function for mapping “primary cutouts” (cutouts formed form a drizzle-combined image) to “input images” (generally speaking, distorted images) and some other “drizzle-combined” image. This “other” drizzle-combined image may be the same image used to create primary cutouts.
This function performs the following mapping/cutout extractions:
>
primary_cutouts->imcutouts->drz_cutoutsThat is, this function takes as input
primary_cutoutsand finds equivalent cutouts in the “input” (distorted) “flt” image. Then it takes the newly foundimcutoutscutouts and finds/extracts equivalent cutouts in the “drz” (usually distortion-corrected) image. Fundamentally, this function first callscreate_input_image_cutoutsto createimcutoutsand then it callsdrz_from_input_cutoutsto createdrz_cutouts.Parameters: - primary_cutouts : list of Cutout
A list of
Cutouts that need to be mapped to another image.- segmentation_image: numpy.ndarray
A 2D segmentation image identifying sources from the catalog in
imdata. This is used for creating boolean mask ofbad(not within a segmentation region) pixels.- drz_data: numpy.ndarray
Image data array of “drizzle-combined” image.
- drz_wcs: astropy.wcs.WCS
World coordinate system of “drizzle-combined” image.
- flt_data: numpy.ndarray
Image data array of “distorted” image (input to the drizzle).
- flt_wcs: astropy.wcs.WCS
World coordinate system of “distorted” image.
- drz_dq: numpy.ndarray, None, optional
Data quality array corresponding to
drz_data.- drz_weight: numpy.ndarray, None, optional
Pixel weight array corresponding to
drz_data.- drz_data_units: {‘counts’, ‘rate’}, optional
Indicates the type of data units for the
drz_data: count-like or rate-like (counts per unit of time). This provides the information necessary for unit conversion when needed.- drz_exptime: float, optional
Exposure time of image
drz_data.- flt_dq: numpy.ndarray, None, optional
Data quality array corresponding to
flt_data.- flt_weight: numpy.ndarray, None, optional
Pixel weight array corresponding to
flt_data.- flt_data_units: {‘counts’, ‘rate’}, optional
Indicates the type of data units for the
flt_data: count-like or rate-like (counts per unit of time). This provides the information necessary for unit conversion when needed.- flt_exptime: float, optional
Exposure time of image
flt_data.- pad: int, optional
Number of pixels to pad around the minimal rectangle enclosing a mapped cutout (a cutout to be extracted).
Returns: - flt_cutouts : list of Cutout
A list of
Cutouts extracted from theflt_data. These cutouts are large enough to enclose cutouts from the inputprimary_cutoutswhenpad=1(to make sure even partial pixels are included).- drz_cutouts : list of Cutout
A list of extracted
Cutouts from thedrz_data. These cutouts are large enough to enclose cutouts from theflt_cutoutswhenpad=1(to make sure even partial pixels are included).