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.- direct
ndarray
Direct image cutout in f_lambda units (i.e., e-/s times PHOTFLAM). Default is a trivial zeros array.
- segmentation
ndarray
(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 thedirect
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
- seg
array
segmentation array
- lam
array
wavelength along the trace
- ytrace
array
y pixel center of the trace. Has same dimensions as sh_beam[1].
- sensitivity
array
conversion factor from native e/s to f_lambda flux densities
- lam_beam, ytrace_beam, sensitivity_beam
array
Versions of the above attributes defined for just the specific pixels of the pixel beam, not the full 2D extraction.
- modelf, model
array
,ndarray
2D model spectrum.
model
is linked tomodelf
with “reshape”, the later which is a flattened 1D array where the fast calculations are actually performed.- model
ndarray
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
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 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 tofull_array
in place, so, for example, to subtractself.model
from the full array, call the function with>>> self.add_to_full_image(-self.model, full_array)
- 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 toid
.- thumb
ndarray
with shape =self.sh
or None Optional direct image. If
None
then useself.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
andself.modelf
, otherwise put the output in a clean array or preformedmodelf
.- modelf
array
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
- model
ndarray
If
in_place
is False, returns the 2D model spectrum. Otherwise the result is stored inself.model
andself.modelf
.
- model
- 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_array
ndarray
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.
- full_array
- Returns
- cutout
ndarray
Array with dimensions of
self.model
.
- cutout
- get_psf_sensitivity(wave, sensitivity)[source]¶
Integrate the sensitivity curve to the wavelengths for the PSF model
- 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
.
- Sets
- optimal_extract(data, bin=0, ivar=1.0, weight=1.0)[source]¶
Horne (1986) optimally-weighted 1D extraction
- Parameters
- Returns
- 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
.
- 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 shapeself.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
- 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 interpolateself.beam.lam_beam
between x0*wscale and x1*wscale.- mpl_axis
matplotlib.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.
- Nothing if
- 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_axis
matplotlib.axes._axes.Axes
Plotting axis to place the labels.
- Returns
- Nothing if
mpl_axis
is supplied else pixels the desired wavelength - limits.
- Nothing if