extspec

sofia_redux.spectroscopy.extspec.extspec(rectimg, profile=None, spatial_map=None, optimal=False, sub_background=True, fix_bad=False, bgorder=2, threshold=5.0, sum_function=None, error_function=None, verbose=False)[source]

Extracts spectra from a rectified spectral image.

For each column (wavelength) in each order:

  1. (optional) Remove background using spatial regions identified in the aperture mask.

  2. (optional) Use the spatial model in spatial_map or profile to remove bad pixels.

  3. Extract the spectral value for that column using either the standard or optimal extraction algorithm.

Standard Extraction: If bad pixels were identified via the spatial model, they are replaced by the value of the spatial model at that wavelength. The spectral value for a given aperture is then taken as the sum of all pixels lying on the aperture.

Optimal Extraction: The spectral value for each aperture is taken by taking a mean of the column weighted by the spatial model, for pixels identified as the aperture radius in the aperture mask. Bad pixels are ignored.

Parameters:
rectimgdict

Rectified image data with aperture definitions. The aperture mask is as produced by the sofia_redux.spectroscopy.mkapmask function.

Structure is:
order (int) -> dict
image -> numpy.ndarray (ns, nw)

Rectified order image.

variance -> numpy.ndarray (ns, nw)

Rectified variance for image.

wave -> numpy.ndarray (nw,)

Wavelength coordinates.

spatial -> numpy.ndarray (ns,)

Spatial coordinates.

mask -> numpy.ndarray (ns, nw)

Boolean bad pixel mask (True = good).

bitmask -> numpy.ndarray (ns, nw)

Bit-set mask. 1=nonlinear pixel.

apmask -> numpy.ndarray (ns, nw)

Aperture mask.

apsign -> list of {1, -1}, optional

Aperture signs for each aperture. Must match the number of apertures in the aperture mask if provided. All aperture signs are assumed positive if not provided.

profiledict, optional

Median spatial profile for each order.

Structure is:

order (int) -> numpy.ndarray (ns,)

spatial_mapdict, optional

2D spatial map for each order. If provided, profile is ignored.

Structure is:

order (int) -> numpy.ndarray (ns, nw)

optimalbool, optional

If set, optimal extraction is used.

sub_backgroundbool, optional

If set, background regions identified in the aperture mask are fit and subtracted from each column. If set, profile or spatial_map must be provided.

fix_badbool, optional

If set, bad pixels will be fixed in the 2D spectral image. For standard extraction, the fixed pixels will be used to calculate the extracted flux. For optimal extraction, the fixed pixels will be ignored.

bgorderint, optional

Background fitting order.

thresholdfloat, optional

Robust threshold for background fits, in number of sigma.

sum_functionfunction, optional

Function to use as sum over aperture, when optimal=False. Default is np.nansum(flux * weights). The provided function should accept one two array arguments (flux and weights).

error_functionfunction, optional

Function to use for error propagation, given variance input, when optimal=False. Default is np.sqrt(np.nansum(flux * weights)). The provided function should accept two array arguments (variance and weights).

verbosebool, optional

If set, columns that fail background fit or optimal extraction will generate warnings for the log.

Returns:
spectradict
order (int) -> dict
spectranumpy.ndarray of float (n_apertures, 4, n_spec)
Each order contains a single array where:

array[aperture, 0] = wavelength array[aperture, 1] = flux array[aperture, 2] = error array[aperture, 3] = bit-set mask