GrismDisperser

class grizli.model.GrismDisperser(id=0, direct=None, segmentation=None, origin=[500, 500], xcenter=0.0, ycenter=0.0, pad=(0, 0), grow=1, beam='A', conf=['WFC3', 'F140W', 'G141'], scale=1.0, fwcpos=None, MW_EBV=0.0, yoffset=0, xoffset=None)[source]

Bases: object

Object for computing dispersed model spectra

Parameters
idint

Only consider pixels in the segmentation image with value id. Default of zero to match the default empty segmentation image.

directndarray

Direct image cutout in f_lambda units (i.e., e-/s times PHOTFLAM). Default is a trivial zeros array.

segmentationndarray (float32) or None

Segmentation image. If None, create a zeros array with the same shape as direct.

origin[int, int]

origin defines the lower left pixel index (y,x) of the direct cutout from a larger detector-frame image

xcenter, ycenterfloat, float

Sub-pixel centering of the exact center of the object, relative to the center of the thumbnail. Needed for getting exact wavelength grid correct for the extracted 2D spectra.

padint, int

Offset between origin = [0,0] and the true lower left pixel of the detector frame. This can be nonzero for cases where one creates a direct image that extends beyond the boundaries of the nominal detector frame to model spectra at the edges.

growint >= 1

Interlacing factor.

beamstr

Spectral order to compute. Must be defined in self.conf.beams

conf[str, str, str] or grismconf.aXeConf object.

Pre-loaded aXe-format configuration file object or if list of strings determine the appropriate configuration filename with grismconf.get_config_filename and load it.

scalefloat

Multiplicative factor to apply to the modeled spectrum from compute_model.

fwcposfloat

Rotation position of the NIRISS filter wheel

MW_EBVfloat

Galactic extinction

yoffsetfloat

Cross-dispersion offset to apply to the trace

xoffsetfloat

Dispersion offset to apply to the trace

Attributes
sh2-tuple

shape of the direct array

sh_beam2-tuple

computed shape of the 2D spectrum

segarray

segmentation array

lamarray

wavelength along the trace

ytracearray

y pixel center of the trace. Has same dimensions as sh_beam[1].

sensitivityarray

conversion factor from native e/s to f_lambda flux densities

lam_beam, ytrace_beam, sensitivity_beamarray

Versions of the above attributes defined for just the specific pixels of the pixel beam, not the full 2D extraction.

modelf, modelarray, ndarray

2D model spectrum. model is linked to modelf with “reshape”, the later which is a flattened 1D array where the fast calculations are actually performed.

modelndarray

2D model spectrum linked to modelf with reshape.

slx_parent, sly_parentslice

slices defined relative to origin to match the location of the computed 2D spectrum.

total_fluxfloat

Total f_lambda flux in the thumbail within the segmentation region.

Methods Summary

add_to_full_image(data, full_array)

Add spectrum cutout back to the full array

add_ytrace_offset(yoffset)

Add an offset in Y to the spectral trace

compute_model([id, thumb, spectrum_1d, ...])

Compute a model 2D grism spectrum

compute_model_psf([id, spectrum_1d, ...])

Compute model with PSF morphology template

contained_in_full_array(full_array)

Check if subimage slice is fully contained within larger array

cutout_from_full_image(full_array)

Get beam-sized cutout from a full image

get_PAM_value([verbose])

Apply Pixel Area Map correction to WFC3 effective PSF model

get_psf_sensitivity(wave, sensitivity)

Integrate the sensitivity curve to the wavelengths for the PSF model

init_extended_epsf()

Hacky code for adding extended component of the EPSFs

init_galactic_extinction([MW_EBV, R_V])

Initialize Fitzpatrick 99 Galactic extinction

init_optimal_profile([seg_ids])

Initilize optimal extraction profile

optimal_extract(data[, bin, ivar, weight])

Horne (1986) optimally-weighted 1D extraction

process_config()

Process grism config file

renormalize_epsf_model([spectrum_1d, verbose])

Ensure normalization correct

set_segmentation(seg_array)

Set Segmentation array and total_flux.

trace_extract(data[, r, bin, ivar, dy0])

Aperture extraction along the trace

twod_axis_labels([wscale, limits, mpl_axis])

Set 2D wavelength (x) axis labels based on spectral parameters

twod_xlim(x0[, x1, wscale, mpl_axis])

Set wavelength (x) axis limits on a 2D spectrum

x_init_epsf([flat_sensitivity, psf_params, ...])

Initialize ePSF fitting for point sources TBD

Methods Documentation

add_to_full_image(data, full_array)[source]

Add spectrum cutout back to the full array

data is added to full_array in place, so, for example, to subtract self.model from the full array, call the function with

>>> self.add_to_full_image(-self.model, full_array)
Parameters
datandarray shape self.sh_beam (e.g., self.model)

Spectrum cutout

full_arrayndarray

Full detector array, where the lower left pixel of data is given by origin.

add_ytrace_offset(yoffset)[source]

Add an offset in Y to the spectral trace

Parameters
yoffsetfloat

Y-offset to apply

compute_model(id=None, thumb=None, spectrum_1d=None, in_place=True, modelf=None, scale=None, is_cgs=False, apply_sensitivity=True, reset=True)[source]

Compute a model 2D grism spectrum

Parameters
idint

Only consider pixels in the segmentation image (self.seg) with values equal to id.

thumbndarray with shape = self.sh or None

Optional direct image. If None then use self.direct.

spectrum_1d[array, array] or None

Optional 1D template [wave, flux] to use for the 2D grism model. If None, then implicitly assumes flat f_lambda spectrum.

in_placebool

If True, put the 2D model in self.model and self.modelf, otherwise put the output in a clean array or preformed modelf.

modelfarray with shape = self.sh_beam

Preformed (flat) array to which the 2D model is added, if in_place is False.

scalefloat or None

Multiplicative factor to apply to the modeled spectrum.

is_cgsbool

Units of spectrum_1d fluxes are f_lambda cgs.

Returns
modelndarray

If in_place is False, returns the 2D model spectrum. Otherwise the result is stored in self.model and self.modelf.

compute_model_psf(id=None, spectrum_1d=None, in_place=True, is_cgs=False, apply_sensitivity=True)[source]

Compute model with PSF morphology template

contained_in_full_array(full_array)[source]

Check if subimage slice is fully contained within larger array

cutout_from_full_image(full_array)[source]

Get beam-sized cutout from a full image

Parameters
full_arrayndarray

Array of the size of the parent array from which the cutout was extracted. If possible, the function first tries the slices with

>>> sub = full_array[self.sly_parent, self.slx_parent]

and then computes smaller slices for cases where the beam spectrum falls off the edge of the parent array.

Returns
cutoutndarray

Array with dimensions of self.model.

get_PAM_value(verbose=False)[source]

Apply Pixel Area Map correction to WFC3 effective PSF model

http://www.stsci.edu/hst/wfc3/pam/pixel_area_maps

get_psf_sensitivity(wave, sensitivity)[source]

Integrate the sensitivity curve to the wavelengths for the PSF model

init_extended_epsf()[source]

Hacky code for adding extended component of the EPSFs

init_galactic_extinction(MW_EBV=0.0, R_V=3.1)[source]

Initialize Fitzpatrick 99 Galactic extinction

Parameters
MW_EBVfloat

Local E(B-V)

R_Vfloat

Relation between specific and total extinction, a_v = r_v * ebv.

Returns
Sets self.MW_F99 attribute, which is a callable function that
returns the extinction for a supplied array of wavelengths.
If MW_EBV <= 0, then sets self.MW_F99 = None.
init_optimal_profile(seg_ids=None)[source]

Initilize optimal extraction profile

optimal_extract(data, bin=0, ivar=1.0, weight=1.0)[source]

Horne (1986) optimally-weighted 1D extraction

Parameters
datandarray with shape self.sh_beam

2D data to extract

binint, optional

Simple boxcar averaging of the output 1D spectrum

ivarfloat or ndarray with shape self.sh_beam

Inverse variance array or scalar float that multiplies the optimal weights

weightTBD
Returns
wave, opt_flux, opt_rmsarray

wave is the wavelength of 1D array opt_flux is the optimally-weighted 1D extraction opt_rms is the weighted uncertainty of the 1D extraction

All are optionally binned in wavelength if bin > 1.

process_config()[source]

Process grism config file

Parameters
none
Returns
Sets attributes that define how the dispersion is computed. See the
attributes list for GrismDisperser.
renormalize_epsf_model(spectrum_1d=None, verbose=False)[source]

Ensure normalization correct

set_segmentation(seg_array)[source]

Set Segmentation array and total_flux.

trace_extract(data, r=0, bin=0, ivar=1.0, dy0=0)[source]

Aperture extraction along the trace

Parameters
dataarray-like

Data array with dimenions equivalent to those of self.model

rint

Radius of of the aperture to extract, in pixels. The extraction will be performed from -r to +r pixels below and above the central pixel of the trace.

binint, optional

Simple boxcar averaging of the output 1D spectrum

ivarfloat or ndarray with shape self.sh_beam

Inverse variance array or scalar float that multiplies the optimal weights

dy0float

Central pixel to extract, relative to the central pixel of the trace

Returns
wave, opt_flux, opt_rmsarray
wave is the wavelength of 1D array
opt_flux is the 1D aperture extraction
opt_rms is the uncertainty of the 1D extraction, derived from

the sum of the pixel variances within the aperture

All are optionally binned in wavelength if bin > 1.
twod_axis_labels(wscale=10000.0, limits=None, mpl_axis=None)[source]

Set 2D wavelength (x) axis labels based on spectral parameters

Parameters
wscalefloat

Scale factor to divide from the wavelength units. The default value of 1.e4 results in wavelength ticks in microns.

limitsNone, list = [x0, x1, dx]

Will automatically use the whole wavelength range defined by the spectrum. To change, specify limits = [x0, x1, dx] to interpolate self.beam.lam_beam between x0*wscale and x1*wscale.

mpl_axismatplotlib.axes._axes.Axes

Plotting axis to place the labels, e.g.,

>>> fig = plt.figure()
>>> mpl_axis = fig.add_subplot(111)
Returns
Nothing if mpl_axis is supplied, else pixels and wavelengths of the
tick marks.
twod_xlim(x0, x1=None, wscale=10000.0, mpl_axis=None)[source]

Set wavelength (x) axis limits on a 2D spectrum

Parameters
x0float or list/tuple of floats

minimum or (min,max) of the plot limits

x1float or None

max of the plot limits if x0 is a float

wscalefloat

Scale factor to divide from the wavelength units. The default value of 1.e4 results in wavelength ticks in microns.

mpl_axismatplotlib.axes._axes.Axes

Plotting axis to place the labels.

Returns
Nothing if mpl_axis is supplied else pixels the desired wavelength
limits.
x_init_epsf(flat_sensitivity=False, psf_params=None, psf_filter='F140W', yoff=0.0, skip=0.5, get_extended=False, seg_mask=True)[source]

Initialize ePSF fitting for point sources TBD