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:
objectContainer for image data with WCS, etc.
- Parameters
- sci
ndarray Science data
- err, dq
ndarrayor None Uncertainty and DQ data. Defaults to zero if None
- header
Header Associated header with
datathat contains WCS information- wcs
WCSor None WCS solution to use. If
Nonewill derive from theheader.- photflamfloat
Multiplicative conversion factor to scale
datato set units to f_lambda flux density.- photplamfloat
Pivot wavelength for the photflam conversion factor.
- origin(int, int)
Origin of lower left pixel in detector coordinates
- pad(int, 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,dqfrom 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])Expand reference image to encompass the FLT image.
flag_negative([sigma])Flag negative data values with dq=4
get_HDUList([extver])Convert attributes and data arrays to a
HDUListget_common_slices(other[, verify_parent])Get slices of overlaps between two
ImageDataobjectsget_slice([slx, sly, get_slice_header])Return cutout version of the
ImageDataobjectget_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
- add_padding(pad=(64, 256))[source]¶
Pad the data array and update WCS keywords
- Parameters
- padint, int
Number of pixels to pad, in array order (axis2, axis1).
- 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_exactrather 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.headeralong with keywords for additional attributes. Will haveImageHDUextensions ‘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
ImageDataobjects- Parameters
- Returns
- self_slice, other_slicetuple
Tuple of slices for
selfandotherthat represent the overlapping regions of the two images.
- Raises
- IOError
If
verify_parentis True and the parent files ofselfandotherare not the same.
- get_slice(slx=slice(480, 520, None), sly=slice(480, 520, None), get_slice_header=True)[source]¶
Return cutout version of the
ImageDataobject- 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
WCSslicemethod doesn’t apply the slice to all of the necessary keywords. For example, SIP WCS also has aCRPIXreference pixel that needs to be offset along with the mainCRPIX.- Parameters
- slx, slyslice
Slices in x and y dimensions to extract
- Returns
- slice_wcs
WCS Sliced WCS object.
- slice_wcs
- 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.dataWCS to ensure the reference image is large enough to encompass the distorted image- verbosebool
Print messages about the cutout.
- hdu
- Returns
- new_hdu
ImageHDU Image clipped to encompass
self.data['SCI']+ margin ofextrapixels.- Make a cutout of the larger reference image around the desired FLT
- image to make blotting faster for large reference images.
- new_hdu