fluxcal

sofia_redux.spectroscopy.fluxcal.fluxcal(spectra, atran, response=None, auto_shift=False, shift_limit=5.0, shift_subsample=10, model_order=1)[source]

Calibrate and telluric correct spectral flux.

The provided atmospheric transmission and response values are interpolated onto the wavelength range for each order. The correction curve is computed as transmission * response.

Optionally, an optimum wavelength shift for the 1D spectra, relative to the correction curve, may be computed by minimizing the residuals in the corrected spectrum. If the calculated shift is greater than 0.1 pixel and less than shift_limit, the spectrum is shifted by this amount, via a linear interpolation, along the wavelength dimension before correction.

The 1D spectral_flux and spectral error provided are divided by the correction curve. For the 2D spectral flux and error, each row is divided by the correction curve.

If multiple ATRAN data sets are provided, then the optimum correction will be determined by fitting a low order polynomial to the corrected 1D spectrum. The correction curve that produces the lowest chi-squared residuals on the fit is selected. The index of the ATRAN data set chosen is returned in the output dictionary, with key ‘atran_index’.

The calculated wavelength shift and the interpolated transmission, response, and response error are stored in the output dictionary, with keys ‘wave_shift’, ‘transmission’, ‘response’, and ‘response_error’, respectively.

Parameters:
spectradict

Spectra to calibrate.

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

Rectified 2D spectral flux image.

error -> numpy.ndarray (ns, nw)

Rectified 2D spectral error image.

wave -> numpy.ndarray (nw,)

Wavelength coordinates.

spectral_flux -> numpy.ndarray (nw,)

1D spectral flux.

spectral_error -> numpy.ndarray (nw,)

1D spectral error.

wave_shift -> float

Manual shift to apply in the wavelength dimension (pixels). If present and not None, will override the auto_shift parameter.

atrannumpy.ndarray or list of numpy.ndarray

A (2, nt) array; first element is the wavelength coordinate, second is the fractional transmission. If a list of arrays is provided, the optimum one will be selected.

responsedict, optional

The instrumental response for the order. If not provided, only the ATRAN correction will be applied.

Structure is:
order (int) -> dict
wave -> numpy.ndarray (nr,)

Wavelength coordinates. Need not match the spectral flux coordinates.

response -> numpy.ndarray (nr,)

Instrument response, in raw units/Jy.

error -> numpy.ndarray (nr,)

Error on the response.

auto_shiftbool, optional

If set, the spectrum cross-correlated with the response * transmission, and the calculated wavelength shift will be applied to the flux and error images and spectra.

shift_limitfloat, optional

Maximum wavelength shift to be applied by the auto_shift, in pixels.

shift_subsampleint, optional

Subsampling for wavelength shifts. Set to 1 to get whole pixel shifts only.

model_orderint, optional

Polynomial order for continuum model, used in optimizing wavelength shifts and ATRAN optimization.

Returns:
spectradict

Calibrated spectra.

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

Calibrated rectified 2D spectral flux image.

error -> numpy.ndarray (ns, nw)

Calibrated rectified 2D spectral error image.

wave -> numpy.ndarray (nw,)

Wavelength coordinates.

spectral_flux -> numpy.ndarray (nw,)

Calibrated 1D spectral flux.

spectral_error -> numpy.ndarray (nw,)

Calibrated 1D spectral error.

wave_shift -> float

Wavelength shift applied.

atran_index -> int

Index of the ATRAN data set selected.

transmission -> numpy.ndarray (nw,)

Transmission correction applied to flux.

response -> numpy.ndarray (nw,)

Response correction applied to flux.

response_error -> numpy.ndarray (nw,)

Error on the response.