GroupFLT

class grizli.multifit.GroupFLT(grism_files=[], sci_extn=1, direct_files=[], pad=(64, 256), group_name='group', ref_file=None, ref_ext=0, seg_file=None, shrink_segimage=True, verbose=True, cpu_count=0, catalog='', polyx=[0.3, 5.3], MW_EBV=0.0, bits=None, use_jwst_crds=False)[source]

Bases: object

Main container for handling multiple grism exposures together

Parameters
grism_fileslist

List of grism exposures (typically WFC3/IR “FLT” or ACS/UVIS “FLC” files). These can be from different grisms and/or orients.

sci_extnint

Science extension to extract from the files in grism_files. For WFC3/IR this can only be 1, though for the two-chip instruments WFC3/UVIS and ACS/WFC3 this can be 1 or 2.

direct_fileslist

List of direct exposures (typically WFC3/IR “FLT” or ACS/UVIS “FLC” files). This list should either be empty or should correspond one-to-one with entries in the grism_files list, i.e., from an undithered pair of direct and grism exposures. If such pairs weren’t obtained or if you simply wish to ignore them and just use the ref_file reference image, set to an empty list ([]).

padint, int

Padding in pixels to apply around the edge of the detector to allow modeling of sources that fall off of the nominal FOV. For this to work requires using a ref_file reference image that covers this extra area. Specified in array axis order (pady, padx)

group_namestr

Name to apply to products produced by this group.

ref_fileNone or str

Undistorted reference image filename, e.g., a drizzled mosaic covering the area around a given grism exposure.

ref_ext0

FITS extension of the reference file where to find the image itself.

seg_fileNone or str

Segmentation image filename.

shrink_segimagebool

Do some preprocessing on the segmentation image to speed up the blotting to the distorted frame of the grism exposures. Not used.

verbosebool

Print verbose information.

cpu_countint

Use parallelization if > 0. If equal to zero, then use the maximum number of available cores.

catalogstr

Catalog filename assocated with seg_file. These are typically generated with “SExtractor”, but the source of the files themselves isn’t critical.

polyxlist

Wavelength range for polynomial fits.

MW_EBVfloat

Galactic extinction to apply to the models. Not used.

bitsint

Bitmask to apply to the segmentation image. Not used.

use_jwst_crdsbool

Use the JWST CRDS system to get the WCS information.

Attributes
catalogTable

The table read in with from the above file specified in catalog.

FLTslist

List of GrismFLT objects generated from each of the files in the grism_files list.

grp.Nint

Number of grism files (i.e., len(FLTs).)

Attributes Summary

N

Number of grism files.

Ngrism

Dictionary containing number of exposures by grism.

PA

Available PAs in each grism.

grisms

Available grisms.

Methods Summary

compute_full_model([fit_info, verbose, ...])

Compute continuum models of all sources in an FLT

compute_single_model(id[, center_rd, mag, ...])

Compute model spectrum in all exposures

drizzle_full_wavelength([wave, ref_header, ...])

Drizzle FLT frames recentered at a specified wavelength

drizzle_grism_models([root, kernel, scale, ...])

Make model-subtracted drizzled images of each grism / PA

extend(new[, verbose])

Add another GroupFLT instance to self

find_source_along_trace(line_ra, line_dec)

Given a sky position in the (artificial) dispersed image frame, find sources that would disperse to that position.

get_beams(id[, size, center_rd, beam_id, ...])

Extract 2D spectra "beams" from the GroupFLT exposures.

make_stack(id[, size, target, skip, ...])

Make drizzled 2D stack for a given object

refine(id[, mag, poly_order, size, ds9, ...])

Fit polynomial to extracted spectrum of single object to use for contamination model.

refine_list([ids, mags, poly_order, ...])

Refine contamination model for list of objects.

save_full_data([warn, verbose])

Save models and data files for fast regeneration.

subtract_median_filter([filter_size, ...])

Remove a median filter calculated along the dispersion axis.

subtract_sep_background([mask_threshold, ...])

Remove a 2D background from grism exposures with sep.Background.

Attributes Documentation

N

Number of grism files.

Ngrism

Dictionary containing number of exposures by grism.

PA

Available PAs in each grism.

grisms

Available grisms.

Methods Documentation

compute_full_model(fit_info=None, verbose=True, store=False, mag_limit=25, coeffs=[1.2, -0.5], cpu_count=0, is_cgs=False, model_kwargs={'compute_size': True})[source]

Compute continuum models of all sources in an FLT

Parameters
fit_infodict

Dictionary of the fitting information.

verbosebool

Print verbose information to the terminal.

storebool

Store the model in the flt object.

mag_limitfloat

Faint limit of objects to compute

coeffslist

Polynomial coefficients of the continuum model

cpu_countint

Number of CPUs to use for parallel processing. If 0, then get from multiprocessing.cpu_count.

is_cgsbool

Spectral models are in cgs units

model_kwargsdict

Keywords to pass to the compute_model_orders method of the GrismFLT objects.

Returns
Sets object_dispersers and model attributes on items in
self.FLTs
compute_single_model(id, center_rd=None, mag=-99, size=-1, store=False, spectrum_1d=None, is_cgs=False, get_beams=None, in_place=True, min_size=26, psf_param_dict={})[source]

Compute model spectrum in all exposures

Parameters
idint

Catalog ID of the object to extract.

center_rdoptional, (float, float)

Extract based on RA/Dec rather than catalog ID.

magfloat

Magnitude of the object.

sizeint

Half-size of the 2D spectrum to extract, along cross-dispersion axis.

storebool

Store the model in the flt object.

spectrum_1dlist

1D spectrum to fit.

is_cgsbool

Spectrum is in cgs units.

get_beamslist

List of beam IDs to extract.s

in_placebool

Compute the model in place.

min_sizeint

Minimum size for the 2D spectrum to extract.

psf_param_dictdict

Dictionary of PSF parameters to pass to the Beam objects.

Returns
if get_beams:
out_beamslist

List of BeamCutout objects.

else:
statusbool

True if the model was computed successfully

drizzle_full_wavelength(wave=14000.0, ref_header=None, kernel='point', pixfrac=1.0, verbose=True, offset=[0, 0], fcontam=0.0)[source]

Drizzle FLT frames recentered at a specified wavelength

Script computes polynomial coefficients that define the dx and dy offsets to a specific dispersed wavelengh relative to the reference position and adds these to the SIP distortion keywords before drizzling the input exposures to the output frame.

Parameters
wavefloat

Reference wavelength to center the output products

ref_headerHeader

Reference header for setting the output WCS and image dimensions.

kernelstr, (‘square’ or ‘point’)

Drizzle kernel to use

pixfracfloat

Drizzle PIXFRAC (for kernel = ‘point’)

verbosebool

Print information to terminal

offset[float, float]

Offset to apply to the polynomial fit to the SIP coefficients.

fcontamfloat

Contamination weighting parameter.

Returns
sci, whtndarray

Drizzle science and weight arrays with dimensions set in ref_header.

drizzle_grism_models(root='grism_model', kernel='square', scale=0.1, pixfrac=1, make_figure=True, fig_xsize=10, write_ctx=False)[source]

Make model-subtracted drizzled images of each grism / PA

Parameters
rootstr

Rootname of the output files.

kernelstr

Drizzle kernel e.g., (‘square’, ‘point’).

scalefloat

Drizzle scale parameter, pixel scale in arcsec.

pixfracfloat

Drizzle “pixfrac”.

make_figurebool

Make a figure of the output.

fig_xsizefloat

Size of the figure.

write_ctxbool

Write the context image to the FITS header.

extend(new, verbose=True)[source]

Add another GroupFLT instance to self

This function appends the exposures if a separate GroupFLT instance to the current instance. You might do this, for example, if you generate separate GroupFLT instances for different grisms and reference images with different filters.

Parameters
newGroupFLT

The GroupFLT instance to add to the current one.

verbosebool

Print verbose information to the terminal.

find_source_along_trace(line_ra, line_dec)[source]

Given a sky position in the (artificial) dispersed image frame, find sources that would disperse to that position.

Parameters
line_ra, line_decfloat

RA, Dec of the source to find.

Returns
NoneTBD
get_beams(id, size=10, center_rd=None, beam_id='A', min_overlap=0.1, min_valid_pix=10, min_mask=0.01, min_sens=0.08, mask_resid=True, get_slice_header=True, show_exception=False)[source]

Extract 2D spectra “beams” from the GroupFLT exposures.

Parameters
idint

Catalog ID of the object to extract.

sizeint

Half-size of the 2D spectrum to extract, along cross-dispersion axis.

center_rdoptional, (float, float)

Extract based on RA/Dec rather than catalog ID.

beam_idtype

Name of the order to extract.

min_overlapfloat

Fraction of the spectrum along wavelength axis that has one or more valid pixels.

min_valid_pixint

Minimum number of valid pixels (beam.fit_mask == True) in 2D spectrum.

min_maskfloat

Minimum factor relative to the maximum pixel value of the flat f-lambda model where the 2D cutout data are considered good. Passed through to BeamCutout.

min_sensfloat

See BeamCutout.

mask_residbool

Passed to BeamCutout.

get_slice_headerbool

Passed to BeamCutout.

show_exceptionbool

Print exceptions when they occur.

Returns
beamslist

List of BeamCutout objects.

make_stack(id, size=20, target='grism', skip=True, fcontam=1.0, scale=1, save=True, kernel='point', pixfrac=1, diff=True)[source]

Make drizzled 2D stack for a given object

Parameters
idint

Object ID number.

sizeint

Size of the cutout.

targetstr

Rootname for output files.

skipbool

If True and the stack PNG file already exists, don’t proceed.

fcontamfloat

Contamination weighting parameter.

scalefloat

Drizzle scale.

savebool

Save the figure and FITS HDU to files with names like

>>> img_file = '{0}_{1:05d}.stack.png'.format(target, id)
>>> fits_file = '{0}_{1:05d}.stack.fits'.format(target, id)
kernelstr

Drizzle kernel.

pixfracfloat

Drizzle pixfrac parameter.

diffbool

Plot residual in final stack panel.

Returns
hduHDUList

FITS HDU of the stacked spectra.

figFigure

Stack figure object.

refine(id, mag=-99, poly_order=3, size=30, ds9=None, verbose=True, max_coeff=2.5, fcontam=0.5, templates=None)[source]

Fit polynomial to extracted spectrum of single object to use for contamination model.

Parameters
idint

Object ID to extract.

magfloat

Object magnitude. Determines which orders to extract; see compute_model_orders.

poly_orderint

Order of the polynomial to fit.

sizeint

Size of cutout to extract.

ds9DS9, optional

Display the refined models to DS9 as they are computed.

verbosebool

Print information about the fit

max_coefffloat

The script computes the implied flux of the polynomial template at the pivot wavelength of the direct image filters. If this flux is greater than max_coeff times the observed flux in the direct image, then the polynomal fit is considered bad.

fcontamfloat

Contamination weighting parameter.

templatesdict, optional

Precomputed template dictionary. If None then compute polynomial templates with order poly_order.

Returns
Updates self.model in place.
refine_list(ids=[], mags=[], poly_order=3, mag_limits=[16, 24], max_coeff=5, ds9=None, verbose=True, fcontam=0.5, wave=array([2.00000000e-01, 2.52723232e+02, 5.05246465e+02, 7.57769697e+02, 1.01029293e+03, 1.26281616e+03, 1.51533939e+03, 1.76786263e+03, 2.02038586e+03, 2.27290909e+03, 2.52543232e+03, 2.77795556e+03, 3.03047879e+03, 3.28300202e+03, 3.53552525e+03, 3.78804848e+03, 4.04057172e+03, 4.29309495e+03, 4.54561818e+03, 4.79814141e+03, 5.05066465e+03, 5.30318788e+03, 5.55571111e+03, 5.80823434e+03, 6.06075758e+03, 6.31328081e+03, 6.56580404e+03, 6.81832727e+03, 7.07085051e+03, 7.32337374e+03, 7.57589697e+03, 7.82842020e+03, 8.08094343e+03, 8.33346667e+03, 8.58598990e+03, 8.83851313e+03, 9.09103636e+03, 9.34355960e+03, 9.59608283e+03, 9.84860606e+03, 1.01011293e+04, 1.03536525e+04, 1.06061758e+04, 1.08586990e+04, 1.11112222e+04, 1.13637455e+04, 1.16162687e+04, 1.18687919e+04, 1.21213152e+04, 1.23738384e+04, 1.26263616e+04, 1.28788848e+04, 1.31314081e+04, 1.33839313e+04, 1.36364545e+04, 1.38889778e+04, 1.41415010e+04, 1.43940242e+04, 1.46465475e+04, 1.48990707e+04, 1.51515939e+04, 1.54041172e+04, 1.56566404e+04, 1.59091636e+04, 1.61616869e+04, 1.64142101e+04, 1.66667333e+04, 1.69192566e+04, 1.71717798e+04, 1.74243030e+04, 1.76768263e+04, 1.79293495e+04, 1.81818727e+04, 1.84343960e+04, 1.86869192e+04, 1.89394424e+04, 1.91919657e+04, 1.94444889e+04, 1.96970121e+04, 1.99495354e+04, 2.02020586e+04, 2.04545818e+04, 2.07071051e+04, 2.09596283e+04, 2.12121515e+04, 2.14646747e+04, 2.17171980e+04, 2.19697212e+04, 2.22222444e+04, 2.24747677e+04, 2.27272909e+04, 2.29798141e+04, 2.32323374e+04, 2.34848606e+04, 2.37373838e+04, 2.39899071e+04, 2.42424303e+04, 2.44949535e+04, 2.47474768e+04, 2.50000000e+04]))[source]

Refine contamination model for list of objects. Loops over refine.

Parameters
idslist

List of object IDs

magslist

Magnitudes to to along with IDs. If ids and mags not specified, then get the ID list from self.catalog['MAG_AUTO'].

poly_orderint

Order of the polynomial fit to the spectra.

mag_limits[float, float]

Magnitude limits of objects to fit from self.catalog['MAG_AUTO'] when ids and mags not set.

max_coefffloat

Fit is considered bad when one of the coefficients is greater than this value. See refine.

ds9DS9, optional

Display the refined models to DS9 as they are computed.

verbosebool

Print fit coefficients.

fcontamfloat

Contamination weighting parameter.

wavearray

Wavelength array for the polynomial fit.

Returns
Updates self.model in place.
save_full_data(warn=True, verbose=False)[source]

Save models and data files for fast regeneration.

The filenames of the outputs are generated from the input grism exposure filenames with the following:

>>> file = 'ib3701ryq_flt.fits'
>>> sci_extn = 1
>>> new_root = '.{0:02d}.GrismFLT.fits'.format(sci_extn)
>>>
>>> save_file = file.replace('_flt.fits', new_root)
>>> save_file = save_file.replace('_flc.fits', new_root)
>>> save_file = save_file.replace('_cmb.fits', new_root)
>>> save_file = save_file.replace('_rate.fits', new_root)

It will also save data to a pickle file:

>>> pkl_file = save_file.replace('.fits', '.pkl')
Parameters
warnbool

Print a warning and skip if an output file is already found to exist.

verbosebool

Print verbose information to the terminal.

Notes

The save filename format was changed May 9, 2017 to the format like ib3701ryq.01.GrismFLT.fits from ib3701ryq_GrismFLT.fits to both allow easier filename parsing and also to allow for instruments that have multiple SCI extensions in a single calibrated file (e.g., ACS and WFC3/UVIS).

subtract_median_filter(filter_size=71, filter_central=10, revert=True, filter_footprint=None, subtract_model=False, second_pass_filtering=False, box_filter_sn=3, box_filter_width=3, put_model_in_median=False, verbose=True, mask_sn_threshold=None, mask_sn_dilate_iters=5)[source]

Remove a median filter calculated along the dispersion axis.

Parameters
filter_sizeint

Size of the median filter.

filter_centralint

Mask the central filter_central pixels of the filter.

revertbool

Add the background back to the science array.

filter_footprintndarray

Custom footprint for the median filter.

subtract_modelbool

Subtract the model before filtering.

second_pass_filteringbool

Run a second pass of filtering, masking pixels that show significant residuals (e.g. strong emission lines).

box_filter_snfloat

S/N threshold for the box filter.

box_filter_widthint

Width of the box filter.

put_model_in_medianbool

Put the model back in the median filter.

verbosebool

Print verbose information to the terminal.

mask_sn_thresholdfloat

Mask pixels with S/N greater than this threshold.

mask_sn_dilate_itersint

Number of iterations to dilate the mask.

subtract_sep_background(mask_threshold=3, mask_iter=3, bw=256, bh=256, fw=3, fh=3, revert=True, **kwargs)[source]

Remove a 2D background from grism exposures with sep.Background.

Parameters
mask_thresholdfloat

S/N threshold to mask sources.

mask_iterint

Number of iterations to mask sources.

bw, bhint

Background mesh width and height.

fw, fhint

Filter width and height.

revertbool

Add the background back to the science array.