ERIS Pipeline Reference Manual 1.9.2
sc_modsky.c File Reference
#include <sc_mpfit.h>
#include <sc_modsky.h>
#include <math.h>
#include <assert.h>

Go to the source code of this file.

Functions

cpl_error_code sc_modsky (cpl_table *scispec, cpl_table *skyspec, cpl_table *fitpar, const cpl_vector *sinc, const cpl_parameterlist *parlist)
 
cpl_error_code sc_modsky_modlines (cpl_table *skyspec, cpl_table *fitpar, const char grouptype)
 
cpl_error_code sc_modsky_moderrors (cpl_table *skyspec)
 
cpl_error_code sc_modsky_modwavegrid (cpl_table *skyspec, cpl_table *fitpar)
 
cpl_error_code sc_modsky_rebin (cpl_table *scispec, cpl_table *skyspec, const cpl_vector *sinc, const cpl_parameterlist *parlist)
 
cpl_error_code sc_modsky_getpixelshifts (cpl_table *skyspec, const cpl_table *scispec)
 
cpl_error_code sc_modsky_sincrebin (cpl_table *scispec, const char *scicol, const cpl_table *skyspec, const char *skycol, const cpl_vector *sinc)
 
cpl_error_code sc_modsky_calcdev (cpl_table *scispec)
 

Detailed Description

Routines related to the modification of the sky spectrum

Author
Stefan Noll & ESO In-Kind Team Innsbruck
Since
20 Feb 2011
Date
12 Jun 2014

Definition in file sc_modsky.c.

Function Documentation

◆ sc_modsky()

cpl_error_code sc_modsky ( cpl_table *  scispec,
cpl_table *  skyspec,
cpl_table *  fitpar,
const cpl_vector *  sinc,
const cpl_parameterlist *  parlist 
)

Modifies sky spectrum by scaling the different line groups and by changing the wavelength grid by means of a Chebyshev polynomial. The resulting spectrum is rebinned to match the wavelength grid of the science spectrum. Finally, weighted deviations between modified sky and science spectrum are computed, which is required for the ${\chi^2}$ derivation. Spectral lines with unreasonable ratios (probably due to an object emission line) are excluded from this computation.

INPUT:

Parameters
scispecCPL table with science spectrum
skyspecCPL table with sky spectrum and line group weights
fitparCPl table of fit parameters
sincCPL vector with damped sinc kernel
parlistgeneral CPL parameter list

OUTPUT:

Parameters
scispectable with science spectrum and adapted sky spectrum
skyspectable with original and modified sky spectrum

ERRORS:

  • none

Definition at line 53 of file sc_modsky.c.

References lastcall, sc_modsky_calcdev(), sc_modsky_moderrors(), sc_modsky_modlines(), sc_modsky_modwavegrid(), and sc_modsky_rebin().

Referenced by sc_mpfit(), and sc_mpfit_calcdev().

◆ sc_modsky_calcdev()

cpl_error_code sc_modsky_calcdev ( cpl_table *  scispec)

Computes weighted deviations between modified sky line spectrum and science line spectrum, which is required for the ${\chi^2}$ derivation. The weights used are combinations of the weights of the science and the rebinned sky spectrum and the ${\sigma}$-clipping results from sc_mpfit_modinitpar. Only line peaks can have non-zero weights.

INPUT:

Parameters
scispecCPL table with science spectrum and rebinned modified sky spectrum

OUTPUT:

Parameters
scispecscience spectrum table with weighted deviations between modified sky and science spectrum

ERRORS:

  • none

Definition at line 781 of file sc_modsky.c.

Referenced by sc_modsky().

◆ sc_modsky_getpixelshifts()

cpl_error_code sc_modsky_getpixelshifts ( cpl_table *  skyspec,
const cpl_table *  scispec 
)

Compares the wavelength grids of science and modified sky spectrum and writes the deviations in the temporary sky spectrum columns "mpix" and "dpix". For a pixel in the sky spectrum "mpix" gives the number of the pixel in the science spectrum with the smallest wavelength difference. "dpix" provides the subpixel shift of the sky spectrum relative to the science spectrum.

INPUT:

Parameters
skyspecCPL table with modified sky spectrum
scispecCPL table with science spectrum

OUTPUT:

Parameters
skyspecmodified sky spectrum with pixel shifts relative to science spectrum

ERRORS:

  • none

Definition at line 579 of file sc_modsky.c.

Referenced by sc_modsky_rebin().

◆ sc_modsky_moderrors()

cpl_error_code sc_modsky_moderrors ( cpl_table *  skyspec)

Modifies flux errors if a corresponding column is provided by the input sky spectrum table. The modification is related to the scaling of the line group fluxes, which was calculated by sc_modsky_modlines.

INPUT:

Parameters
skyspecCPL table with sky spectrum

OUTPUT:

Parameters
skyspecsky spectrum table with modified flux errors

ERRORS:

  • none

Definition at line 246 of file sc_modsky.c.

References lastcall.

Referenced by sc_modsky().

◆ sc_modsky_modlines()

cpl_error_code sc_modsky_modlines ( cpl_table *  skyspec,
cpl_table *  fitpar,
const char  grouptype 
)

Modifies sky spectrum by scaling the different line groups of a given type. The group-specific factors are taken from the fit parameter table fitpar. The pixel-specific weights of the different line groups have been added to the sky spectrum by sc_weights.

INPUT:

Parameters
skyspecCPL table with sky spectrum and line group weights
fitparCPl table of fit parameters
grouptypeline group type (either 'A' or 'B')

OUTPUT:

Parameters
skyspecsky spectrum table with modified line fluxes

ERRORS:

  • none

Definition at line 122 of file sc_modsky.c.

References nfev, and SC_LENLINE.

Referenced by sc_modsky().

◆ sc_modsky_modwavegrid()

cpl_error_code sc_modsky_modwavegrid ( cpl_table *  skyspec,
cpl_table *  fitpar 
)

Modifies sky spectrum by changing the wavelength grid by means of a Chebyshev polynomial. The degree of this polynomial is provided by the general parameter cheby_max and should be at least 1. If -1 is given, the wavelength correction is skipped. The coefficients are provided by the fit parameter table fitpar. Only coefficients with fit flag = 1 are considered. The polynomial is applied to a temporary, normalised wavelength grid that ranges from -1 to 1.

INPUT:

Parameters
skyspecCPL sky spectrum table with modified line fluxes
fitparCPl table of fit parameters

OUTPUT:

Parameters
skyspecsky spectrum table with modified line fluxes and modified wavelength grid

ERRORS:

  • none

Definition at line 296 of file sc_modsky.c.

References nfev, and SC_THERMIRLIM.

Referenced by sc_modsky().

◆ sc_modsky_rebin()

cpl_error_code sc_modsky_rebin ( cpl_table *  scispec,
cpl_table *  skyspec,
const cpl_vector *  sinc,
const cpl_parameterlist *  parlist 
)

Rebins the modified sky spectrum (continuum, line flux, and possible flux errors) to the wavelength grid of the science spectrum by means of either a summation of fractional input pixel contributions to the output pixels or a convolution with an asymmetric, exponentially-damped sinc kernel (default), which avoids undesired line broadening. The rebinning approach is provided by the integer parameter REBINTYPE of the general parameter list. The results are written into the science spectrum table. The weight is rebinned in a traditional way to avoid negative values. Another difference is the handling of weight = 0, which is substituted in the sky spectrum table by a minimum weight depending on the factor SC_RELMAXERR. In the science spectrum table, the resulting weight is then converted back to weight = 0 if it is below a threshold. This approach allows one to consider rebinned pixels with only a small contribution from an initial sky pixel with weight = 0.

INPUT:

Parameters
scispecCPL table with science spectrum
skyspecCPL table with modified sky spectrum
sincCPL vector with damped sinc kernel
parlistgeneral CPL parameter list

OUTPUT:

Parameters
scispecscience spectrum table with rebinned modified sky spectrum

ERRORS:

  • none

Definition at line 436 of file sc_modsky.c.

References lastcall, sc_basic_rebin(), sc_modsky_getpixelshifts(), sc_modsky_sincrebin(), SC_RELMAXERR, and SC_TOL.

Referenced by sc_modsky().

◆ sc_modsky_sincrebin()

cpl_error_code sc_modsky_sincrebin ( cpl_table *  scispec,
const char *  scicol,
const cpl_table *  skyspec,
const char *  skycol,
const cpl_vector *  sinc 
)

Uses a convolution with a damped sinc kernel to rebin the data of the column skycol in the sky spectrum to the wavelength grid of the science spectrum. The differences in the wavelength grids have to be provided by the columns "mpix" and "dpix" (see sc_modsky_getpixelshifts). The output is written to the column scicol in the science spectrum. Taking an exponentially-damped sinc function for the rebinning avoids an increase of the FWHM of spectral lines, which would significantly deteriorate any fit. For pixels of the convolution kernel for the science spectrum outside of the wavelength range of the sky spectrum, the flux of the first or last pixel of the sky spectrum is taken.

INPUT:

Parameters
scispecCPL table with science spectrum
scicolcolumn name for rebinned fluxes
skyspecCPL table with modified sky spectrum and columns "mpix" and "dpix"
skycolcolumn name for input fluxes
sincCPL vector with damped sinc kernel

OUTPUT:

Parameters
scispecscience spectrum table with rebinned modified sky spectrum

ERRORS:

  • none

Definition at line 640 of file sc_modsky.c.

References SC_SINCNBIN, and SC_SINCRAD_PRECOMP.

Referenced by sc_modsky_rebin().