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

Bases: object

Cutout spectral object from the full frame.

Parameters:
flt : GrismFLT

Parent FLT frame.

beam : GrismDisperser

Object and spectral order to consider

conf : grismconf.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_header : bool

TBD

fits_file : None 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_mask : TBD
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.

min_sens : float

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

Attributes:
grism, direct : ImageData (sliced)

Cutouts of the grism and direct images.

beam : GrismDisperser

High-level tools for computing dispersed models of the object

mask : array-like (bool)

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

fit_mask, DoF : array-like, int

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

ivar : array-like

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

model, modelf : array-like

2D and flattened versions of the object model array

contam : array-like

Contamination model

scif : array_like

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

flat_flam : array-like

Flattened version of the flat-flambda object model

poly_order : int

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]) 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, grism_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:
data : array-like

Put this data in the output HDU rather than empty zeros

Returns:
hdu : ImageHDU

Image HDU with header and data properties.

wcs : WCS

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:
data : array-like

Put this data in the output HDU rather than empty zeros

key : None

Key for WCS extension, passed to to_header.

Returns:
hdu : ImageHDU

Image HDU with header and data properties.

wcs : WCS

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

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

Parameters:
decimals : int or None

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

Returns:
dispersion_PA : float

PA (angle East of North) of the dispersion axis.

get_sky_coords()[source]

Get WCS coordinates of the center of the direct image

Returns:
ra, dec : float

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

Central wavelength to use for derived WCS.

Returns:
header : Header

FITS header

wcs : WCS

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:
flt : GrismFLT

Parent FLT frame.

beam : GrismDisperser

Object and spectral order to consider

conf : grismconf.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_header : bool

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

Order of the polynomial

fit_background : bool

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

Initialize from FITS file

Parameters:
file : str

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_data : dict

returned data from simple_line_fit. I.e.,

>>> fit_outputs = BeamCutout.simple_line_fit()
>>> fig = BeamCutout.show_simple_fit_results(fit_outputs)
Returns:
fig : Figure

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_outputs : tuple

returned data from simple_line_fit. I.e.,

>>> fit_outputs = BeamCutout.simple_line_fit()
>>> fig = BeamCutout.show_simple_fit_results(fit_outputs)
Returns:
fig : Figure

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

FWHM of the emission line

grid : list [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]
fitter : str, ‘lstsq’ or ‘sklearn’

Least-squares fitting function for determining template normalization coefficients.

order : int (>= 0)

Polynomial order to use for the continuum

Returns:
line_centers : length 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.

chi2 : array

Chi-squared evaluated at each line_centers[i]

ok_data : ndarray

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_model : ndarray

2D array with best-fit continuum + line model

best_model_cont : ndarray

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

best_line_center : float

wavelength where chi2 is minimized.

best_line_flux : float

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:
root : str

Output filename will be

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

with self.id zero-padded with 5 digits.

overwrite : bool

Overwrite existing file.

strip : bool

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_hdu : bool

Return HDUList rather than writing a file.

Returns:
hdu : HDUList

If get_hdu is True

outfile : str

If get_hdu is False, return the output filename.