ImageData¶
- class grizli.model.ImageData(sci=None, err=None, dq=None, header=None, wcs=None, photflam=1.0, photplam=1.0, origin=[0, 0], pad=(0, 0), process_jwst_header=True, instrument='WFC3', filter='G141', pupil=None, module=None, hdulist=None, restore_medfilt=False, sci_extn=1, fwcpos=None)[source]¶
Bases:
object
Container for image data with WCS, etc.
- Parameters
- sci
ndarray
Science data
- err, dq
ndarray
or None Uncertainty and DQ data. Defaults to zero if None
- header
Header
Associated header with
data
that contains WCS information- wcs
WCS
or None WCS solution to use. If
None
will derive from theheader
.- photflamfloat
Multiplicative conversion factor to scale
data
to set units to f_lambda flux density. If data is grism spectra, then use photflam=1- origin[int, int]
Origin of lower left pixel in detector coordinates
- padint,int
Padding to apply to the image dimensions in numpy axis order
- process_jwst_headerbool
If the image is detected as coming from JWST NIRISS or NIRCAM, generate the necessary header WCS keywords
- instrumentstr
Instrument where the image came from
- filterstr
Filter from the image header. For WFC3 and NIRISS this is the dispersing element
- pupilstr
Pupil from the image header (JWST instruments). For NIRISS this is the blocking filter and for NIRCAM this is the dispersing element
- modulestr
Instrument module for NIRCAM (‘A’ or ‘B’)
- hdulist
HDUList
, optional If specified, read
sci
,err
,dq
from the HDU list from a FITS file, e.g., WFC3 FLT.- sci_extnint
Science EXTNAME to read from the HDUList, for example,
sci
= hdulist[‘SCI’,`sci_extn`].- fwcposfloat
Filter wheel encoder position (NIRISS)
- sci
- Attributes
- parent_filestr
Filename of the parent from which the data were extracted
- datadict
Dictionary to store pixel data, with keys ‘SCI’, ‘DQ’, and ‘ERR’. If a reference image has been supplied and processed, will also have an entry ‘REF’. The data arrays can also be addressed with the
__getitem__
method, i.e.,>>> self = ImageData(...) >>> print np.median(self['SCI'])
- padint, int
Additional padding around the nominal image dimensions in numpy array order
- wcs
WCS
WCS of the data array
- header
Header
FITS header
- filter, instrument, photflam, photplam, APZPstr, float
Parameters taken from the header
- ref_file, ref_photlam, ref_photplam, ref_filterstr, float
Corresponding parameters for the reference image, if necessary.
Methods Summary
add_padding
([pad])Pad the data array and update WCS keywords
add_padding_to_wcs
(wcs_in[, pad])Pad the appropriate WCS keywords
blot_from_hdu
([hdu, segmentation, grow, interp])Blot a rectified reference image to detector frame
expand_hdu
([hdu, verbose])TBD
flag_negative
([sigma])Flag negative data values with dq=4
get_HDUList
([extver])Convert attributes and data arrays to a
HDUList
get_common_slices
(other[, verify_parent])Get slices of overlaps between two
ImageData
objectsget_slice
([slx, sly, get_slice_header])Return cutout version of the
ImageData
objectget_slice_wcs
(wcs[, slx, sly])Get slice of a WCS including higher orders like SIP and DET2IM
get_wcs
([pc2cd])Get WCS from header
shrink_large_hdu
([hdu, extra, verbose])Shrink large image mosaic to speed up blotting
unset_dq
()Flip OK data quality bits using utils.mod_dq_bits
update_jwst_wcsheader
(hdulist[, force])For now generate an approximate SIP header for NIRISS/NIRCam
Methods Documentation
- blot_from_hdu(hdu=None, segmentation=False, grow=3, interp='nearest')[source]¶
Blot a rectified reference image to detector frame
- Parameters
- hdu
ImageHDU
HDU of the reference image
- segmentationbool, False
If True, treat the reference image as a segmentation image and preserve the integer values in the blotting.
If specified as number > 1, then use
blot_nearest_exact
rather than a hacky pixel area ratio method to blot integer segmentation maps.- growint, default=3
Number of pixels to dilate the segmentation regions
- interpstr,
Form of interpolation to use when blotting float image pixels. Valid options: {‘nearest’, ‘linear’, ‘poly3’, ‘poly5’ (default), ‘spline3’, ‘sinc’}
- hdu
- Returns
- blotted
np.ndarray
Blotted array with the same shape and WCS as
self.data['SCI']
.
- blotted
- flag_negative(sigma=-3)[source]¶
Flag negative data values with dq=4
- Parameters
- sigmafloat
Threshold for setting bad data
- Returns
- n_negativeint
Number of flagged negative pixels
- If
self.data['ERR']
is zeros, do nothing.
- get_HDUList(extver=1)[source]¶
Convert attributes and data arrays to a
HDUList
- Parameters
- extverint, float, str
value to use for the ‘EXTVER’ header keyword. For example, with extver=1, the science extension can be addressed with the index
HDU['SCI',1]
.- returns
HDUList
HDUList with header keywords copied from
self.header
along with keywords for additional attributes. Will haveImageHDU
extensions ‘SCI’, ‘ERR’, and ‘DQ’, as well as ‘REF’ if a reference file had been supplied.
- get_common_slices(other, verify_parent=True)[source]¶
Get slices of overlaps between two
ImageData
objects
- get_slice(slx=slice(480, 520, None), sly=slice(480, 520, None), get_slice_header=True)[source]¶
Return cutout version of the
ImageData
object- Parameters
- slx, slyslice
Slices in x and y dimensions to extract
- get_slice_headerbool
Compute the full header of the slice. This takes a bit of time and isn’t necessary in all cases so can be omitted if only the sliced data are of interest and the header isn’t needed.
- Returns
- static get_slice_wcs(wcs, slx=slice(480, 520, None), sly=slice(480, 520, None))[source]¶
Get slice of a WCS including higher orders like SIP and DET2IM
The normal
WCS
slice
method doesn’t apply the slice to all of the necessary keywords. For example, SIP WCS also has aCRPIX
reference pixel that needs to be offset along with the mainCRPIX
.- Parameters
- slx, slyslice
Slices in x and y dimensions to extract
- shrink_large_hdu(hdu=None, extra=100, verbose=False)[source]¶
Shrink large image mosaic to speed up blotting
- Parameters
- hdu
ImageHDU
Input reference HDU
- extraint
Extra border to put around
self.data
WCS to ensure the reference image is large enough to encompass the distorted image
- hdu
- Returns
- new_hdu
ImageHDU
Image clipped to encompass
self.data['SCI']
+ margin ofextra
pixels.- Make a cutout of the larger reference image around the desired FLT
- image to make blotting faster for large reference images.
- new_hdu