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, process_jwst_header=True, instrument='WFC3', filter='G141', pupil=None, module=None, hdulist=None, 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 the header.

photflam : float

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

pad : int

Padding to apply to the image dimensions

process_jwst_header : bool

If the image is detected as coming from JWST NIRISS or NIRCAM, generate the necessary header WCS keywords

instrument : str

Instrument where the image came from

filter : str

Filter from the image header. For WFC3 and NIRISS this is the dispersing element

pupil : str

Pupil from the image header (JWST instruments). For NIRISS this is the blocking filter and for NIRCAM this is the dispersing element

module : str

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_extn : int

Science EXTNAME to read from the HDUList, for example, sci = hdulist[‘SCI’,`sci_extn`].

fwcpos : float

Filter wheel encoder position (NIRISS)

Attributes:
parent_file : str

Filename of the parent from which the data were extracted

data : dict

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'])
pad : int

Additional padding around the nominal image dimensions

wcs : WCS

WCS of the data array

header : Header

FITS header

filter, instrument, photflam, photplam, APZP : str, float

Parameters taken from the header

ref_file, ref_photlam, ref_photplam, ref_filter : str, 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 objects
get_slice([slx, sly, get_slice_header]) Return cutout version of the ImageData object
get_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.unset_dq_bits
update_jwst_wcsheader(hdulist[, force]) For now generate an approximate SIP header for NIRISS/NIRCam

Methods Documentation

add_padding(pad=200)[source]

Pad the data array and update WCS keywords

static add_padding_to_wcs(wcs_in, pad=200)[source]

Pad the appropriate WCS keywords

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

segmentation : bool, 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.

grow : int, default=3

Number of pixels to dilate the segmentation regions

interp : str,

Form of interpolation to use when blotting float image pixels. Valid options: {‘nearest’, ‘linear’, ‘poly3’, ‘poly5’ (default), ‘spline3’, ‘sinc’}

Returns:
blotted : np.ndarray

Blotted array with the same shape and WCS as self.data['SCI'].

expand_hdu(hdu=None, verbose=True)[source]

TBD

flag_negative(sigma=-3)[source]

Flag negative data values with dq=4

Parameters:
sigma : float

Threshold for setting bad data

Returns:
n_negative : int

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:
extver : int, 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 have ImageHDU 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, sly : slice

Slices in x and y dimensions to extract

get_slice_header : bool

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:
slice_obj : ImageData

New ImageData object of the sliced subregion

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 a CRPIX reference pixel that needs to be offset along with the main CRPIX.

Parameters:
slx, sly : slice

Slices in x and y dimensions to extract

get_wcs(pc2cd=False)[source]

Get WCS from header

shrink_large_hdu(hdu=None, extra=100, verbose=False)[source]

Shrink large image mosaic to speed up blotting

Parameters:
hdu : ImageHDU

Input reference HDU

extra : int

Extra border to put around self.data WCS to ensure the reference image is large enough to encompass the distorted image

Returns:
new_hdu : ImageHDU

Image clipped to encompass self.data['SCI'] + margin of extra pixels.

Make a cutout of the larger reference image around the desired FLT
image to make blotting faster for large reference images.
unset_dq()[source]

Flip OK data quality bits using utils.unset_dq_bits

OK bits are defined as

>>> okbits_instrument = {'WFC3': 32+64+512, # blob OK
                         'NIRISS': 0,
                         'WFIRST': 0,
                         'WFI': 0}
update_jwst_wcsheader(hdulist, force=False)[source]

For now generate an approximate SIP header for NIRISS/NIRCam

Parameters:
hdulist : HDUList

FITS HDU list

force : bool