Spectrum Analysis

grizli.utils Module

Dumping ground for general utilities


RGBtoHex(vals[, rgbtype])

Converts RGB values in a variety of formats to Hex values.

apply_flt_dq(filename[, replace, verbose, ...])

Read and apply the compact exposure information file

argv_to_dict(argv[, defaults, dot_dict])

Convert a list of (simple) command-line arguments to a dictionary.

array_templates(templates[, wave, max_R, z, ...])

Return an array version of the templates that have all been interpolated to the same grid.

blot_nearest_exact(in_data, in_wcs, out_wcs)

Own blot function for blotting exact pixels without rescaling for input and output pixel size

bspline_templates(wave[, degree, df, ...])

B-spline basis functions, modeled after splines

calc_header_zeropoint(im[, ext])

Determine AB zeropoint from image header

catalog_area([ra, dec, make_plot, NMAX, ...])

Compute the surface area of a list of RA/DEC coordinates

catalog_mask(cat[, ecol, ...])

Compute a catalog mask for

cheb_templates(wave[, order, get_matrix, ...])

Chebyshev polynomial basis functions

column_string_operation(col, test[, method, ...])

Analogous to str.contains but for table column.

column_values_in_list(col, test_list)

Test if column elements "in" an iterable (e.g., a list of strings)

combine_phot_dict(phots[, templates, MW_EBV])

Combine photmetry dictionaries

compute_equivalent_widths(templates, coeffs, ...)

Compute template-fit emission line equivalent widths

compute_output_wcs(wcs_list[, pixel_scale, ...])

Compute output WCS that contains the full list of input WCS

convex_hull_wrapper(x, y)

Generate a convex hull from a list of points

ctime_to_iso(mtime[, format, strip_decimal, ...])

Convert time.ctime strings to ISO dates

detect_with_photutils(sci[, err, dq, seg, ...])

Use photutils to detect objects and make segmentation map

dot_templates(coeffs, templates[, z, max_R, ...])

Compute template sum analogous to np.dot(coeffs, templates).

drizzle_array_groups(sci_list, wht_list, ...)

Drizzle array data with associated wcs

drizzle_from_visit(visit[, output, pixfrac, ...])

Make drizzle mosaic from exposures in a visit dictionary

dump_flt_dq(filename[, replace, verbose])

Dump FLT/FLC header & DQ extensions to a compact file


Testing FSPS line templates

eval_bspline_templates(wave, bspl, coefs)

fetch_acs_wcs_files(beams_file[, bucket_name])

Fetch wcs files for a given beams.fits files

fetch_config_files([get_acs, get_sky, ...])

Config files needed for Grizli


Fetch a set of default HST calibration files

fetch_hst_calib([file, ftpdir, verbose, ...])


fetch_hst_calibs(flt_file[, ftpdir, ...])

TBD Fetch necessary calibration files needed for running calwf3 from STScI FTP


Download skyflat files

fetch_s3_url([url, file_func, ...])

Fetch file from an S3 bucket

fetch_wfpc2_calib([file, path, use_mast, ...])

Fetch static WFPC2 calibration file and run stsci.tools.convertwaiveredfits on it.

figure_timestamp(fig[, x, y, iso, ha, va, ...])

Add a timestamp to a figure output

fill_between_steps(x, y0, y1[, ax])

Make fill_between work like linestyle='steps-mid'.

fill_masked_covar(covar, mask)

Fill a covariance matrix in a larger array that had masked values

fix_flt_nan(flt_file[, bad_bit, verbose])

Fix NaN values in FLT files

flt_to_dict(fobj[, primary_keys, ...])

Parse basic elements from a FLT/FLC header to a dictionary

full_spectrum_wcsheader([center_wave, dlam, ...])

Make a WCS header for a 2D spectrum

generate_tempfilt(templates, filters[, ...])

get_Vizier_photometry(ra, dec[, templates, ...])

Fetch photometry from a Vizier catalog

get_common_slices(a_origin, a_shape, ...)

Get slices of overlaps between two rectangular grids

get_filter_obsmode([filter, acs_chip, ...])

Derive pysynphot obsmode keyword from a filter name, where UVIS filters end in 'u'

get_fits_slices(file1, file2)

Get overlapping slices of FITS files

get_flt_footprint(flt_file[, extensions, ...])

Compute footprint of all SCI extensions of an HST exposure

get_flt_info([files, columns, translate, ...])

Extract header information from a list of FLT files

get_hst_filter(header, **kwargs)

Deprecated: use grizli.utils.parse_filter_from_header


Get a dictionary of common emission line wavelengths and line ratios

get_photom_scale(header[, verbose])

Get tabulated scale factor

get_spectrum_AB_mags(spectrum[, bandpasses])

Integrate a pysynphot spectrum through filter bandpasses


Add Polygon 'footprint' attributes to visit dict.

get_wcs_pscale(wcs[, set_attribute])

Get correct pscale from a WCS object

get_wcs_slice_header(wcs, slx, sly)



Create a new WCS with half the pixel scale of another that can be block-averaged 2x2

header_keys_from_filelist(fits_files[, ...])

Dump header keywords to a Table

hull_area(x, y)

Return the area of a convex hull of a list of points

hull_edge_mask(x, y[, pad, pad_is_absolute, ...])

Compute geometrical edge mask for points within a convex hull

jwst_crds_photom_scale(hdul[, context, ...])

Scale factors between different JWST CRDS_CONTEXT

jwst_snowblind_mask(rate_file[, ...])

Update JWST DQ mask with snowblind.

load_beta_templates([wave, betas])

Step-function templates with f_lambda ~ (wave/1216.)**beta

load_phoenix_stars([logg_list, teff_list, ...])

Load Phoenix stellar templates

load_quasar_templates([broad_fwhm, ...])

Make templates suitable for fitting broad-line quasars

load_sdss_pca_templates([file, smooth])

Load SDSS eigen templates

load_templates([fwhm, line_complexes, ...])

Generate a list of templates for fitting to the grism spectra

log_comment(LOGFILE, comment[, verbose, ...])

Log a message to a file, optionally including a date tag

log_exception(LOGFILE, traceback[, verbose, ...])

Log exception information to a file, or print to screen

log_function_arguments(LOGFILE, frame[, ...])

Log local variables, e.g., parameter arguements to a file

log_scale_ds9(im[, lexp, cmap, scale])

Scale an array like ds9 log scaling

log_zgrid([zr, dz])

Make a logarithmically spaced redshift grid


Make Alf + FSPS template

make_filter_footprint([filter_size, ...])

Make a footprint for image filtering

make_maximal_wcs(files[, pixel_scale, ...])

Compute an ImageHDU with a footprint that contains all of files

make_spectrum_wcsheader([center_wave, dlam, ...])

Make a WCS header for a 2D spectrum

make_wcsheader([ra, dec, size, pixscale, ...])

Make a celestial WCS header

mast_query_from_file_list([files, os_open])

Generate a MAST query on datasets in a list.

mod_dq_bits(value[, okbits, badbits, verbose])

Modify bit flags from a DQ array

mode_statistic(data[, percentiles])

Get modal value of a distribution of data following Connor et al. 2017 https://arxiv.org/pdf/1709.01925.pdf.

multiprocessing_ndfilter(data, filter_func)

Cut up a large array and send slices to scipy.ndimage filters

niriss_ghost_mask(im[, init_thresh, ...])

Make a mask for NIRISS imaging ghosts


Normalized NMAD=1.4826022 * median_absolute_deviation


Wrapper for astropy.time.now


Set of 3.3 um PAH lines from Li et al. 2020.

pah_line_template(wave_grid[, center_um, fwhm])

Make a template for a broad PAH line with a Drude profile

parse_filter_from_header(header[, ...])

Get simple filter name out of an HST/JWST image header.

parse_flt_files([files, info, uniquename, ...])

Read header information from a list of exposures and parse out groups based on filter/target/orientation.

parse_grism_associations(exposure_groups, info)

Get associated lists of grism and direct exposures


Parse s3 path string

parse_visit_overlaps(visits[, buffer])

Find overlapping visits/filters to make combined mosaics

patch_from_polygon(polygon, **kwargs)

Generate the Path object from PatchPolygon


Patch to fix inconsistency with drizzlepac=3.2.1 and photutils>1.0, where The latter is needed for jwst=1.3.2

photfnu_from_photflam(photflam, photplam)


pixel_polygon_mask(polygon, shape[, wcs])

Make a mask points in a 2D array inside a polygon

polynomial_templates(wave[, ref_wave, ...])

radec_to_targname([ra, dec, round_arcsec, ...])

Turn decimal degree coordinates into a string with rounding.

read_catalog(file[, sextractor, format])

Wrapper around gread.

read_gzipped_header([file, BLOCK, NMAX, ...])

Read primary header from a (potentially large) zipped FITS file


Remove all Text annotations from fig.axes.

reproject_faster(input_hdu, output[, pad])

Speed up reproject module with array slices of the input image


version-safe matrix inversion using np.linalg or np.matrix.I

safe_nanmedian_filter(data[, filter_kwargs, ...])

Run nanmedian filter on data

set_warnings([numpy_level, astropy_level])

Set global numpy and astropy warnings

simple_LCDM([Om0, Ode0, H0, Ob0, Tcmb0, name])

Simple LambdaCDM cosmology

sip_rot90(input, rot[, reverse, verbose, ...])

Rotate a SIP WCS by increments of 90 degrees using direct transformations between x / y coordinates

split_poly_template(templ[, ref_wave, order])

Multiply a single template by polynomial bases to effectively generate a polynomial multiplicative correction that can be fit with linear least squares.

split_spline_template(templ[, ...])

Multiply a single template by spline bases to effectively generate a spline multiplicative correction that can be fit with linear least squares.

split_visit(visit[, visit_split_shift, ...])

Check if files in a visit have large shifts and split them otherwise

step_templates([wlim, bin_steps, R, round, ...])

Step-function templates for easy binning

strip_header_keys(header[, comment, ...])

Strip header keywords


Symlink templates from module to $GRIZLI/templates as part of the initial setup Parameters ---------- force : bool Force link files even if they already exist.

synphot_encircled_energy([obsmode, sp, ...])

Compute encircled energy curves with pysynphot

synphot_zeropoint([obsmode, radius])

Compute synphot for a specific aperture

tabulate_encircled_energy([aper_radii, ...])

to_header(wcs[, add_naxis, relax, key])

Modify astropy.wcs.WCS.to_header to produce more keywords

transform_wcs(in_wcs[, translation, ...])

Update WCS with shift, rotation, & scale


Return trapezoid rule coefficients, useful for numerical integration using a dot product

wcs_from_header(header[, relax])

Initialize WCS from a Header



Tools for handling WFC3/IR Effective PSF

GTable([data, masked, names, dtype, meta, ...])

Extend Table class with more automatic IO and other helper methods.

HubbleXYZ([spt_file, param_dict])

Helper to compute HST geocentric coordinates from orbital parameters

MW_F99(a_v[, r_v])

Wrapper around the specutils.extinction / extinction modules, which are called differently

SRegion(inp[, label, wrap])

Helper class for parsing an S_REGION strings and general polygon tools

SpectrumTemplate([wave, flux, central_wave, ...])

Container for template spectra.

Unique(array[, verbose])

Helper for unique items in an array

WCSFootprint(wcs[, ext, label])

Helper functions for dealing with WCS footprints

WCSMapAll(input, output[, origin])

Sample class to demonstrate how to define a coordinate transformation

grizli.grismconf Module

Demonstrate aXe trace polynomials.

Initial code taken from (Brammer, Pirzkal, & Ryan 2014), which contains a detailed explanation how the grism configuration parameters and coefficients are defined and evaluated.



Get field-dependent coefficients in aXe format from an astropy.modeling.polynomial.Polynomial2D model

crds_reffiles([instrument, filter, pupil, ...])

Get WFSS reffiles from CRDS

download_jwst_crds_references([instruments, ...])

Run crds_reffiles with filter and grism combinations to prefetch a bunch of reference files

get_config_filename([instrume, filter, ...])

Generate a config filename based on the instrument, filter & grism combination.

load_grism_config(conf_file[, warnings])

Load parameters from an aXe configuration file

show_available_nircam_versions([filter, ...])

Show all available versions of the NIRCAM Grism config files


CRDSGrismConf([file, get_photom, context])

Helper object to replicate grismconf config files from CRDS products

JwstDispersionTransform([instrument, ...])

Rotate NIRISS and NIRCam coordinates such that slitless dispersion has wavelength increasing towards +x.


Dictionary that remembers insertion order


Transform GRISMCONF-format configuration files to grizli convention of wavelength increasing towards +x


Read an aXe-compatible configuration file

grizli.model Module

Model grism spectra in individual FLTs


BeamCutout([flt, beam, conf, ...])

Cutout spectral object from the full frame.

GrismDisperser([id, direct, segmentation, ...])

Object for computing dispersed model spectra

GrismFLT([grism_file, sci_extn, ...])

Scripts for modeling of individual grism FLT images

ImageData([sci, err, dq, header, wcs, ...])

Container for image data with WCS, etc.

grizli.multifit Module

Functionality for manipulating multiple grism exposures simultaneously


drizzle_2d_spectrum(beams[, data, wlimit, ...])

Drizzle 2D spectrum from a list of beams

drizzle_2d_spectrum_wcs(beams[, data, ...])

Drizzle 2D spectrum from a list of beams

drizzle_to_wavelength(beams[, wcs, ra, dec, ...])

Drizzle a cutout at a specific wavelength from a list of BeamCutout objects



show_drizzle_HDU(hdu[, diff, ...])

Make a figure from the multiple extensions in the drizzled grism file.


GroupFLT([grism_files, sci_extn, ...])

Main container for handling multiple grism exposures together

MultiBeam(beams[, group_name, fcontam, psf, ...])

Tools for dealing with multiple BeamCutout instances

grizli.fitting Module

Tools for fitting spectra with templates.


compute_cdf_percentiles(fit[, cdf_sigmas])

Compute tabulated percentiles of the CDF for a (lossy) compressed version of the redshift PDF.

compute_sps_params([full, cosmology, Om0, ...])

full_sed_plot(mb, tfit[, zfit, bin, minor, ...])

Make a separate plot showing photometry and the spectrum

make_summary_catalog([target, sextractor, ...])

refit_beams([root, append, id, keep_dict, ...])

Regenerate a MultiBeam object selecting only certiain PAs

run_all(id[, t0, t1, fwhm, zr, dz, fitter, ...])

Run the full template-fitting procedure

run_all_parallel(id[, get_output_data, ...])

Wrapper function for grizli.fitting.run_all that preloads all keyword options from a stored file.

show_drizzled_lines(line_hdu[, ...])

Make a figure with the drizzled line maps



Base class for StackFitter and MultiBeam spectrum fitting objects

Catalog tools

grizli.catalog Module

Catalog table tools


table_to_radec(table[, output])

Make a "radec" ascii file with ra, dec columns from a table object

table_to_regions(table[, output, comment, ...])

Make a DS9 region file from a table object

randomize_segmentation_labels(seg[, ...])

Randomize labels on a segmentation image for easier visualization

get_ukidss_catalog([ra, dec, radius, ...])

Query for objects in the UKIDSS catalogs

get_sdss_catalog([ra, dec, radius])

Query for objects in the SDSS photometric catalog

get_twomass_catalog([ra, dec, radius, catalog])

get_irsa_catalog([ra, dec, tab, radius, ...])

Query for objects in the AllWISE source catalog

get_gaia_radec_at_time(gaia_tbl[, date, format])

Use apply_space_motion to compute GAIA positions at a specific observation date


Get translation of Vizier GAIA DR2 columns.

get_gaia_DR2_vizier([ra, dec, radius, max, ...])

Query GAIA catalog from Vizier

gaia_dr2_conesearch_query([ra, dec, radius, max])

Generate a query string for the TAP servers TBD

get_gaia_DR2_catalog([ra, dec, radius, ...])

Query GAIA DR2 astrometric catalog

gen_tap_box_query([ra, dec, radius, ...])

Generate a query string for the NOAO Legacy Survey TAP server

query_tap_catalog([ra, dec, radius, ...])

Query NOAO Catalog holdings

get_hubble_source_catalog([ra, dec, radius, ...])

Query NOAO Source Catalog, which is aligned to GAIA DR1.

get_nsc_catalog([ra, dec, radius, corners, ...])

Query NOAO Source Catalog, which is aligned to GAIA DR1.

get_desdr1_catalog([ra, dec, radius, ...])

Query DES DR1 Catalog from Vizier

get_skymapper_catalog([ra, dec, radius, ...])

Get Skymapper DR1 from Vizier

get_vexas_catalog([ra, dec, radius, ...])

VEXAS DR2 from vizier

get_vhs_catalog([ra, dec, radius, corners, ...])

VEXAS DR2 from vizier

get_panstarrs_catalog([ra, dec, radius, ...])

Get PS1 from Vizier

get_radec_catalog([ra, dec, radius, ...])

Decide what reference astrometric catalog to use

Pipeline tools

grizli.pipeline.default_params Module

Parameter handling with YAML



get_yml_parameters([local_file, ...])

Read default parameters from the YAML file in grizli/data

safe_yaml_loader(yamlfile[, loaders])

Try different YAML loaders


Test if aws s3 is available

write_params_to_yml(kwargs[, output_file, ...])

Write grizli parameters to a file

grizli.pipeline.auto_script Module

Automatic processing scripts for grizli



Clean unneeded files after the field preparation


Convert a visits.npy file to visits.yaml

count_grism_exposures(phot, groups[, ...])

Count number of grism exposures that contain objects in a catalog

create_path_dict([root, home, raw, prep, ...])

Generate path dict.

drizzle_overlaps(field_root[, filters, ...])

Drizzle filter groups based on precomputed image associations

exposure_report(root[, log])

Save exposure info to webpage & json file

extract([field_root, maglim, prior, MW_EBV, ...])

fetch_files([field_root, HOME_PATH, paths, ...])

Fully automatic script for fetching exposure files

field_psf([root, PREP_PATH, RAW_PATH, ...])

Generate PSFs for the available filters in a given field

field_rgb([root, xsize, output_dpi, ...])

RGB image of the field mosaics


Fill field mosaics with the average value taken from other filters so that all images have the same coverage

find_visit_file([root, path])

Find the yaml or npy visits file, return None if neither found

fine_alignment([field_root, HOME_PATH, ...])

Try fine alignment from visit-based SourceExtractor catalogs

generate_fit_params([field_root, fitter, ...])

Generate a parameter dictionary for passing to the fitting script

get_extra_data([root, HOME_PATH, ...])

Not used [2023]

get_miri_flat_by_date(file[, tsplit, verbose])

MIRI flats computed by date

get_rgb_filters(filter_list[, force_ir, ...])

Compute which filters to use to make an RGB cutout

get_visit_exposure_footprints([root, ...])

Add exposure-level footprints to the visit dictionary

go([root, HOME_PATH, RAW_PATH, PREP_PATH, ...])

Run the full pipeline for a given target

grism_prep([field_root, PREP_PATH, ...])

Contamination model pipeline for grism exposures

load_GroupFLT([field_root, PREP_PATH, ...])

Initialize a GroupFLT object from exposures in a working directory.


Load fine_alignment result

load_visit_info([root, path, verbose])

Load visit info from a visits.npy or visits.yaml file


Load a {root}_visits.yaml file

make_combined_mosaics(root[, fix_stars, ...])

Drizzle combined mosaics

make_directories([root, HOME_PATH, paths])

Make RAW, Prep, Persistence, Extractions directories

make_filter_combinations(root[, weight_fnu, ...])

Combine ir/opt mosaics manually scaling a specific zeropoint


Make region files where wht images nonzero

make_reference_wcs(info[, files, output, ...])

Make a reference image WCS based on the grism exposures

make_report(root[, gzipped_links, xsize, ...])

Make HTML report of the imaging and grism data products

make_rgb_thumbnails([root, ids, maglim, ...])

Make RGB thumbnails in working directory

manual_alignment([field_root, HOME_PATH, ...])

Manual visit alignment

mask_IR_psf_spikes([visit, mag_lim, cat, ...])

Mask 45-degree diffraction spikes around bright stars for WFC3/IR

multiband_catalog([field_root, threshold, ...])

Make a detection catalog and run aperture photometry on all available filter images with the SourceExtractor clone sep.

parse_visits([files, field_root, RAW_PATH, ...])

Organize exposures into "visits" by filter / position / PA / epoch

photutils_catalog([field_root, threshold, ...])

Make a detection catalog with SourceExtractor and then measure photometry with photutils.

preprocess([field_root, HOME_PATH, ...])

Preprocessing script

refine_model_with_fits([field_root, grp, ...])

Refine the full-field grism models with the best fit spectra from individual extractions.

remove_bad_expflag([field_root, HOME_PATH, ...])

Remove FLT files in RAW directory with bad EXPFLAG values, which usually corresponds to failed guide stars.

save_fine_yaml(visits, fit[, yaml_file])

Save results from fine_alignment


update_wcs_headers_with_fine(field_root[, ...])

Update grism headers with the fine shifts


Parse footprint objects from YAML visit dictionary


Make visit dictionary cleaner for writing to YAML

write_visit_info(visits, groups, info[, ...])

Write visit association files

grizli.pipeline.photoz Module

Helpers for working with eazy-py.


apply_catalog_corrections(root[, ...])

Aperture and background corrections to photometric catalog

eazy_photoz(root[, force, object_only, ...])

fix_aperture_corrections(tab[, verbose, ...])

June 2020: Reapply total corrections using fixed bug for the kron total corrections where the necessary pixel scale wasn't used.

get_external_catalog(phot[, filter_file, ...])

Fetch photometry from vizier

show_all_thumbnails([label, filters, ...])

Show individual filter and RGB thumbnails

show_from_ds9(ds9, self, zout[, use_sky])


EazyPhot(photoz[, grizli_templates, zgrid, ...])



Some basic tools for simulating HST/JWST/Roman grism data. See multimission_simulaation.ipynb for some examples.

grizli.fake_image Module

Tools for generating very basic fake images for HST/JWST/Roman simulations


make_fake_image(header[, output, ...])

Use the header from NIRISS, WFC3/IR or WFIRST/Roman and make an FLT-like image that grizli can read as a reference.


Use pandeia to calculate a Roman/G150 configuration file and sensitivity curve for grizli

nircam_header([ra, dec, pa_aper, filter, ...])

Make JWST/NIRCAM image header

niriss_header([ra, dec, pa_aper, filter, grism])

Make JWST/NIRISS image header

roman_header([ra, dec, pa_aper, naxis])

Make WFIRST/Roman WFI header

roman_hls_image([exptime, nexp, background, ...])

Make a simple FITS file for a Roman High Latitude Survey Image

rotate_CD_matrix(cd, pa_aper)

Rotate CD matrix

wfc3ir_header([ra, dec, pa_aper, flt, filter])

Make HST/WFC3-IR image header


Alias to roman_header