BeamCutout

class grizli.model.BeamCutout(flt=None, beam=None, conf=None, get_slice_header=True, fits_file=None, scale=1.0, contam_sn_mask=[10, 3], min_mask=0.01, min_sens=0.08, mask_resid=True, isJWST=False, restore_medfilt=False)[source]

Bases: object

Cutout spectral object from the full frame.

Parameters
fltGrismFLT

Parent FLT frame.

beamGrismDisperser

Object and spectral order to consider

confgrismconf.aXeConf

Pre-computed configuration file. If not specified will regenerate based on header parameters, which might be necessary for multiprocessing parallelization and pickling.

get_slice_headerbool

TBD

fits_fileNone or str

Optional FITS file containing the beam information, rather than reading directly from a GrismFLT object with the flt and beam paremters. Load with load_fits.

contam_sn_maskTBD
min_maskfloat

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

min_sensfloat

Minimum sensitivity relative to the maximum for a given grism above which pixels are included in the fit.

Attributes
grism, directImageData (sliced)

Cutouts of the grism and direct images.

beamGrismDisperser

High-level tools for computing dispersed models of the object

maskarray-like (bool)

Basic mask where grism DQ > 0 | ERR == 0 | SCI == 0.

fit_mask, DoFarray-like, int

Additional mask, DoF is fit_mask.sum() representing the effective degrees of freedom for chi-squared.

ivararray-like

Inverse variance array, taken from grism 1/ERR^2

model, modelfarray-like

2D and flattened versions of the object model array

contamarray-like

Contamination model

scifarray_like

Flattened version of grism['SCI'] - contam.

flat_flamarray-like

Flattened version of the flat-flambda object model

poly_orderint

Order of the polynomial model

Attributes Summary

trace_table

Table of trace parameters.

Methods Summary

compute_model([use_psf])

Link to self.beam.compute_model

full_2d_wcs([data])

Get trace WCS of the 2D spectrum

get_2d_wcs([data, key])

Get simplified WCS of the 2D spectrum

get_dispersion_PA([decimals, local])

Compute exact PA of the dispersion axis, including tilt of the trace and the FLT WCS

get_sky_coords()

Get WCS coordinates of the center of the direct image

get_wavelength_wcs([wavelength])

Compute celestial WCS of the 2D spectrum array for a specified central wavelength

init_epsf([center, tol, yoff, skip, ...])

Initialize ePSF fitting for point sources TBD

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

Initialize from data objects

init_poly_coeffs([poly_order, fit_background])

Initialize arrays for polynomial fits to the spectrum

load_fits(file[, conf, direct_extn, ...])

Initialize from FITS file

show_redshift_fit(fit_data)

Make a plot based on results from simple_line_fit.

show_simple_fit_results(fit_outputs)

Make a plot based on results from simple_line_fit.

simple_line_fit([fwhm, grid, fitter, poly_order])

Function to fit a Gaussian emission line and a polynomial continuum

write_fits([root, overwrite, strip, ...])

Write attributes and data to FITS file

Attributes Documentation

trace_table

Table of trace parameters. Trace is unit-indexed.

Methods Documentation

compute_model(use_psf=True, **kwargs)[source]

Link to self.beam.compute_model

self.beam is a GrismDisperser object.

full_2d_wcs(data=None)[source]

Get trace WCS of the 2D spectrum

Parameters
dataarray-like

Put this data in the output HDU rather than empty zeros

Returns
hduImageHDU

Image HDU with header and data properties.

wcsWCS

WCS appropriate for the 2D spectrum with spatial (y) and spectral (x) axes.

Note

Assumes linear dispersion and trace functions!

get_2d_wcs(data=None, key=None)[source]

Get simplified WCS of the 2D spectrum

Parameters
dataarray-like

Put this data in the output HDU rather than empty zeros

keyNone

Key for WCS extension, passed to to_header.

Returns
hduImageHDU

Image HDU with header and data properties.

wcsWCS

WCS appropriate for the 2D spectrum with spatial (y) and spectral (x) axes.

Note

Assumes linear dispersion and trace functions!

get_dispersion_PA(decimals=0, local=False)[source]

Compute exact PA of the dispersion axis, including tilt of the trace and the FLT WCS

Parameters
decimalsint or None

Number of decimal places to round to, passed to round. If None, then don’t round.

localbool

Compute local PA of a given beam, otherwise use global WCS

Returns
dispersion_PAfloat

PA (angle East of North) of the increasing-wavelength dispersion axis.

get_sky_coords()[source]

Get WCS coordinates of the center of the direct image

Returns
ra, decfloat

Center coordinates of the beam thumbnail in decimal degrees

get_wavelength_wcs(wavelength=13000.0)[source]

Compute celestial WCS of the 2D spectrum array for a specified central wavelength

This essentially recenters the celestial SIP WCS such that the desired wavelength was at the object position as observed in the direct image (which has associated geometric distortions etc).

Parameters
wavelengthfloat

Central wavelength to use for derived WCS.

Returns
headerHeader

FITS header

wcsWCS

Derived celestial WCS

init_epsf(center=None, tol=0.001, yoff=0.0, skip=1.0, flat_sensitivity=False, psf_params=None, N=4, get_extended=False, only_centering=True)[source]

Initialize ePSF fitting for point sources TBD

init_from_input(flt, beam, conf=None, get_slice_header=True)[source]

Initialize from data objects

Parameters
fltGrismFLT

Parent FLT frame.

beamGrismDisperser

Object and spectral order to consider

confgrismconf.aXeConf

Pre-computed configuration file. If not specified will regenerate based on header parameters, which might be necessary for multiprocessing parallelization and pickling.

get_slice_headerbool

Get full header of the sliced data. Costs some overhead so can be skipped if full header information isn’t required.

Returns
Loads attributes to self.
init_poly_coeffs(poly_order=1, fit_background=True)[source]

Initialize arrays for polynomial fits to the spectrum

Provides capabilities of fitting n-order polynomials to observed spectra rather than galaxy/stellar templates.

Parameters
poly_orderint

Order of the polynomial

fit_backgroundbool

Compute additional arrays for allowing the background to be fit along with the polynomial coefficients.

Returns
Polynomial parameters stored in attributes y_poly, n_poly, …
load_fits(file, conf=None, direct_extn=1, grism_extn=2, restore_medfilt=False)[source]

Initialize from FITS file

Parameters
filestr

FITS file to read (as output from write_fits).

Returns
Loads attributes to self.
show_redshift_fit(fit_data)[source]

Make a plot based on results from simple_line_fit.

Parameters
fit_datadict

returned data from simple_line_fit. I.e.,

>>> fit_outputs = BeamCutout.simple_line_fit()
>>> fig = BeamCutout.show_simple_fit_results(fit_outputs)
Returns
figFigure

Figure object that can be optionally written to a hardcopy file.

show_simple_fit_results(fit_outputs)[source]

Make a plot based on results from simple_line_fit.

Parameters
fit_outputstuple

returned data from simple_line_fit. I.e.,

>>> fit_outputs = BeamCutout.simple_line_fit()
>>> fig = BeamCutout.show_simple_fit_results(fit_outputs)
Returns
figFigure

Figure object that can be optionally written to a hardcopy file.

simple_line_fit(fwhm=48.0, grid=[11200.0, 16500.0, 1, 4], fitter='lstsq', poly_order=3)[source]

Function to fit a Gaussian emission line and a polynomial continuum

Parameters
fwhmfloat

FWHM of the emission line

gridlist [l0, l1, dl, skip]

The base wavelength array will be generated like

>>> wave = np.arange(l0, l1, dl)

and lines will be generated every skip wavelength grid points:

>>> line_centers = wave[::skip]
fitterstr, ‘lstsq’ or ‘sklearn’

Least-squares fitting function for determining template normalization coefficients.

orderint (>= 0)

Polynomial order to use for the continuum

Returns
line_centerslength N array

emission line center positions

coeffs(N, M) ndarray where M = (poly_order+1+1)

Normalization coefficients for the continuum and emission line templates.

chi2array

Chi-squared evaluated at each line_centers[i]

ok_datandarray

Boolean mask of pixels used for the Chi-squared calculation. Consists of non-masked DQ pixels, non-zero ERR pixels and pixels where self.model > 0.03*self.model.max() for the flat-spectrum model.

best_modelndarray

2D array with best-fit continuum + line model

best_model_contndarray

2D array with Best-fit continuum-only model.

best_line_centerfloat

wavelength where chi2 is minimized.

best_line_fluxfloat

Emission line flux where chi2 is minimized

write_fits(root='beam_', overwrite=True, strip=False, include_model=True, get_hdu=False, get_trace_table=True)[source]

Write attributes and data to FITS file

Parameters
rootstr

Output filename will be

‘{root}_{self.id}.{self.grism.filter}.{self.beam}.fits’

with self.id zero-padded with 5 digits.

overwritebool

Overwrite existing file.

stripbool

Strip out extensions that aren’t totally necessary for regenerating the ImageData object. That is, strip out the direct image SCI, ERR, and DQ extensions if REF is defined. Also strip out MODEL.

get_hdubool

Return HDUList rather than writing a file.

Returns
hduHDUList

If get_hdu is True

outfilestr

If get_hdu is False, return the output filename.