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
scindarray

Science data

err, dqndarray or None

Uncertainty and DQ data. Defaults to zero if None

headerHeader

Associated header with data that contains WCS information

wcsWCS or None

WCS solution to use. If None will derive from the header.

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’)

hdulistHDUList, 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)

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

wcsWCS

WCS of the data array

headerHeader

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 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.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

static add_padding_to_wcs(wcs_in, pad=(64, 256))[source]

Pad the appropriate WCS keywords

Parameters
wcs_inWCS

Input WCS

padint, int

Number of pixels to pad, in array order (axis2, axis1)

Returns
wcs_outWCS

Padded WCS

blot_from_hdu(hdu=None, segmentation=False, grow=3, interp='nearest')[source]

Blot a rectified reference image to detector frame

Parameters
hduImageHDU

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’}

Returns
blottednp.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
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].

returnsHDUList

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, 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
slice_objImageData

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, slyslice

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
hduImageHDU

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

Returns
new_hduImageHDU

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.mod_dq_bits

OK bits are defined as

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

For now generate an approximate SIP header for NIRISS/NIRCam

Parameters
hdulistHDUList

FITS HDU list

forcebool