GroupFLT

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

Bases: object

Main container for handling multiple grism exposures together

Parameters:
grism_files : list

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

sci_extn : int

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_files : list

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 ([]).

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

group_name : str

Name to apply to products produced by this group.

ref_file : None or str

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

ref_ext : 0

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

seg_file : None or str

Segmentation image filename.

shrink_segimage : bool

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

verbose : bool

Print verbose information.

cpu_count : int

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

catalog : str

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

Attributes:
catalog : Table

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

FLTs : list

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

grp.N : int

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

Attributes Summary

N
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 TBD
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
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
old_refine(id[, mag, poly_order, size, ds9, …]) TBD
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]) Save models and data files for fast regeneration.

Attributes Documentation

N
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_info : dict
verbose : bool
store : bool
mag_limit : float

Faint limit of objects to compute

coeffs : list

Polynomial coefficients of the continuum model

cpu_count : int

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

is_cgs : bool

Spectral models are in cgs units

model_kwargs : dict

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, psf_param_dict={})[source]

Compute model spectrum in all exposures TBD

Parameters:
id : type
center_rd : None
mag : type
size : type
store : type
spectrum_1d : type
get_beams : type
in_place : type
Returns:
TBD
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:
wave : float

Reference wavelength to center the output products

ref_header : Header

Reference header for setting the output WCS and image dimensions.

kernel : str, (‘square’ or ‘point’)

Drizzle kernel to use

pixfrac : float

Drizzle PIXFRAC (for kernel = ‘point’)

verbose : bool

Print information to terminal

Returns:
sci, wht : ndarray

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)[source]

Make model-subtracted drizzled images of each grism / PA

Parameters:
root : str

Rootname of the output files.

kernel : str

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

scale : float

Drizzle scale parameter, pixel scale in arcsec.

pixfrac : float

Drizzle “pixfrac”.

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.

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)[source]

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

Parameters:
id : int

Catalog ID of the object to extract.

size : int

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

center_rd : optional, (float, float)

Extract based on RA/Dec rather than catalog ID.

beam_id : type

Name of the order to extract.

min_overlap : float

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

min_valid_pix : int

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

min_mask : float

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_sens : float

See BeamCutout.

get_slice_header : bool

Passed to BeamCutout.

Returns:
beams : list

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

Object ID number.

target : str

Rootname for output files.

skip : bool

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

fcontam : float

Contamination weighting parameter.

save : bool

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)
diff : bool

Plot residual in final stack panel.

Returns:
hdu : HDUList

FITS HDU of the stacked spectra.

fig : Figure

Stack figure object.

old_refine(id, mag=-99, poly_order=1, size=30, ds9=None, verbose=True, max_coeff=2.5)[source]

TBD

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

Object ID to extract.

mag : float

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

poly_order : int

Order of the polynomial to fit.

size : int

Size of cutout to extract.

ds9 : DS9, optional

Display the refined models to DS9 as they are computed.

verbose : bool

Print information about the fit

max_coeff : float

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.

fcontam : float

Contamination weighting parameter.

templates : dict, 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:
ids : list

List of object IDs

mags : list

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

poly_order : int

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_coeff : float

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

ds9 : DS9, optional

Display the refined models to DS9 as they are computed.

verbose : bool

Print fit coefficients.

fcontam : float

Contamination weighting parameter.

wave : array

Wavelength array for the polynomial fit.

Returns:
Updates self.model in place.
save_full_data(warn=True)[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:
warn : bool

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

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