|
ERIS Pipeline Reference Manual 1.9.2
|
Go to the source code of this file.
Data Structures | |
| struct | _scvars_ |
| struct | _scpars_ |
| #define | SC_DEFERRVAL 9.99 |
| #define | SC_CORRFAC_MIN 0.01 |
| #define | SC_CORRFAC_MAX 100. |
| #define | SC_MINNLIN 3 |
| #define | SC_MAXRELFAC 2. |
| #define | SC_MAXPARERR 0.5 |
| typedef struct _scvars_ | scvars |
| typedef struct _scpars_ | scpars |
| int | nfev |
| cpl_boolean | lastcall |
| cpl_error_code | sc_mpfit (mp_result *result, cpl_table *scispec, cpl_table *skyspec, cpl_table *fitpar, const cpl_parameterlist *parlist) |
| int | sc_mpfit_calcdev (int m, int n, double *p, double *dy, double **dvec, void *vars) |
| cpl_error_code | sc_mpfit_modinitpar (cpl_table *fitpar, cpl_table *scispec, cpl_table *skyspec, const cpl_parameterlist *parlist) |
| cpl_error_code | sc_mpfit_setpar (scpars *fitpars, const cpl_table *fitpar, const char fittype) |
| cpl_error_code | sc_mpfit_allocmempar (scpars *fitpars, const int npar) |
| cpl_error_code | sc_mpfit_freemempar (scpars *fitpars) |
| cpl_error_code | sc_mpfit_allocmemresult (mp_result *result, const int m, const int n) |
| cpl_error_code | sc_mpfit_initresult (mp_result *result, const int m, const int n) |
| cpl_error_code | sc_mpfit_copyresult (mp_result *outresult, const mp_result *inresult) |
| cpl_error_code | sc_mpfit_freememresult (mp_result *result) |
| cpl_error_code | sc_mpfit_substbadfitpar (cpl_table *fitpar, const cpl_table *initfitpar, const cpl_parameterlist *parlist) |
Header for routines related to the handling of CMPFIT
Definition in file sc_mpfit.h.
| #define SC_CORRFAC_MAX 100. |
Maximum correction factor for line groups
Definition at line 69 of file sc_mpfit.h.
| #define SC_CORRFAC_MIN 0.01 |
Minimum correction factor for line groups
Definition at line 67 of file sc_mpfit.h.
| #define SC_DEFERRVAL 9.99 |
Default error value (taken if no specific error is available)
Definition at line 65 of file sc_mpfit.h.
| #define SC_MAXPARERR 0.5 |
Maximum relative uncertainty of fit parameters for line flux correction (otherwise the initial parameter value is taken)
Definition at line 77 of file sc_mpfit.h.
| #define SC_MAXRELFAC 2. |
Maximum relative deviation between correction factor of a system A group with less than SC_MINNLIN lines and the system mean
Definition at line 74 of file sc_mpfit.h.
| #define SC_MINNLIN 3 |
Minimum number of valid lines for a save line group
Definition at line 71 of file sc_mpfit.h.
Structure for holding the fit parameters and their constraints
| n | number of parameters |
| p | parameter vector for fitting |
| pars | structure for parameter constraints |
Structure for holding the spectral data and the driver file parameters
| scispec | CPL table with science spectrum |
| skyspec | CPL table with sky spectrum and line group weights |
| fitpar | CPL table with fit parameters |
| sinc | CPL vector with damped sinc kernel |
| parlist | general CPL parameter list |
| cpl_error_code sc_mpfit | ( | mp_result * | result, |
| cpl_table * | scispec, | ||
| cpl_table * | skyspec, | ||
| cpl_table * | fitpar, | ||
| const cpl_parameterlist * | parlist | ||
| ) |
Handles the fitting routine CMPFIT (see mpfit.c for details on the fitting algorithm).
Needs the science line spectrum plus error-related weights, the sky line spectrum plus error-related and line group weights, and descriptions, fit flags, and initial values of the fit parameters provided by a dedicated table and the general parameter list.
The input data are used to compute a modified sky line spectrum which is compared to the science line spectrum by deriving a vector of weighted deviations. The sky spectrum is optimised by an initial estimate of line group specific correction factors from the ratio of science and sky line spectrum for selected, suitable line pixels. As next step this estimate is repeated to improve the clipping of unsuitable pixels. Finally, CMPFIT is called for a selection of line group fit parameters which were flagged as crucial for a further fit improvement by the previous flux correction estimate.
The agreement of the wavelength grids of the science and sky spectrum is improved by the fit of a Chebyshev polynomial by means of CMPFIT. For obtaining an optimal polynomial the degree is increased iteratively. For this reason, the fit plan described above is usually repeated multiple times. After the first cycle the initial estimate is substituted by the fit of the wavelength grid. In each run the degree of the Chebyshev polynomial for the wavelength correction is increased by 1 (exception: constant and linear term are considered together) and the best-fit parameters of the previous run are used as input. If 

Information on the fit quality is written into a special results structure. The CPL table with the science line spectrum is supplemented by the best-fit sky line spectrum and the weighted deviations taken for the 
INPUT:
| scispec | CPL table with science spectrum |
| skyspec | CPL table with sky spectrum and line group weights |
| fitpar | CPL table of fit parameters |
| parlist | general CPL parameter list |
OUTPUT:
| result | CMPFIT structure for fit results |
| scispec | CPL table with science and best-fit modified sky spectrum |
| fitpar | fit parameter table with best-fit values |
ERRORS:
Definition at line 60 of file sc_mpfit.c.
References lastcall, sc_basic_calcsinc(), sc_basic_copytable_content(), SC_DEFERRVAL, SC_LENLINE, SC_MAXLEN, sc_modsky(), sc_mpfit_allocmempar(), sc_mpfit_allocmemresult(), sc_mpfit_calcdev(), sc_mpfit_copyresult(), sc_mpfit_freemempar(), sc_mpfit_freememresult(), sc_mpfit_initresult(), sc_mpfit_modinitpar(), sc_mpfit_setpar(), and sc_mpfit_substbadfitpar().
Referenced by sc_skycorr_fit().
| cpl_error_code sc_mpfit_allocmempar | ( | scpars * | fitpars, |
| const int | npar | ||
| ) |
Allocates memory for an scpars structure.
INPUT:
| npar | number of fit parameters |
OUTPUT:
| fitpars | scpars structure containing npar fit parameters |
ERRORS:
Definition at line 1264 of file sc_mpfit.c.
References SC_LENLINE, and SC_MAXLEN.
Referenced by sc_mpfit().
| cpl_error_code sc_mpfit_allocmemresult | ( | mp_result * | result, |
| const int | m, | ||
| const int | n | ||
| ) |
Allocates memory for fit residuals and parameter errors in the CMPFIT results structure.
INPUT:
| m | number of data points |
| n | number of parameters |
OUTPUT:
| result | CMPFIT structure for fit results with allocated memory for residuals and parameter errors |
ERRORS:
Definition at line 1373 of file sc_mpfit.c.
References SC_MAXLEN.
Referenced by sc_mpfit().
| int sc_mpfit_calcdev | ( | int | m, |
| int | n, | ||
| double * | p, | ||
| double * | dy, | ||
| double ** | dvec, | ||
| void * | vars | ||
| ) |
User function for CMPFIT. Provides spectral data and fit parameters to sc_modsky. Gets weighted deviations between the modified sky line spectrum and the science line spectrum from sc_modsky. The syntax of the function is predefined by CMPFIT.
INPUT:
| m | number of data points |
| n | number of parameters |
| p | array of fit parameters |
| dvec | derivatives (not used) |
| vars | private data -> observed spectrum and driver file parameters |
OUTPUT:
| dy | array of residuals ([model - obs. spectrum] * weight) |
ERRORS:
Definition at line 517 of file sc_mpfit.c.
References nfev, and sc_modsky().
Referenced by sc_mpfit().
| cpl_error_code sc_mpfit_copyresult | ( | mp_result * | outresult, |
| const mp_result * | inresult | ||
| ) |
Copies content of CMPFIT structure for fit results.
INPUT:
| inresult | CMPFIT structure for fit results |
OUTPUT:
| outresult | copied CMPFIT structure for fit results |
ERRORS:
Definition at line 1461 of file sc_mpfit.c.
Referenced by sc_mpfit().
| cpl_error_code sc_mpfit_freemempar | ( | scpars * | fitpars | ) |
Frees memory occupied by an scpars structure.
INPUT:
| fitpars | scpars structure with fit parameters |
OUTPUT:
| fitpars | scpars structure without allocated memory |
ERRORS:
Definition at line 1333 of file sc_mpfit.c.
Referenced by sc_mpfit().
| cpl_error_code sc_mpfit_freememresult | ( | mp_result * | result | ) |
Frees memory occupied by a CMPFIT structure for fit residuals and parameter errors. Memory allocated for carrying the covariance matrix is not freed.
INPUT:
| result | CMPFIT structure for fit results with allocated memory for residuals and parameter errors |
OUTPUT:
| result | CMPFIT structure for fit results without memory for residuals and parameter errors |
ERRORS:
Definition at line 1502 of file sc_mpfit.c.
Referenced by sc_mpfit(), and sc_skycorr_fit().
| cpl_error_code sc_mpfit_initresult | ( | mp_result * | result, |
| const int | m, | ||
| const int | n | ||
| ) |
Initialises CMPFIT structure for fit results.
INPUT:
| result | CMPFIT structure for fit results |
| m | number of data points |
| n | number of parameters |
OUTPUT:
| result | initialised CMPFIT structure for fit results |
ERRORS:
Definition at line 1420 of file sc_mpfit.c.
Referenced by sc_mpfit().
| cpl_error_code sc_mpfit_modinitpar | ( | cpl_table * | fitpar, |
| cpl_table * | scispec, | ||
| cpl_table * | skyspec, | ||
| const cpl_parameterlist * | parlist | ||
| ) |
Optimises initial fit parameters for line groups by considering the mean ratio of group-specific line fluxes in the science and sky spectrum. The pixels identified as line peaks in the science spectrum (see sc_specdiss_find_emissionlines) and those at a distance of not more than FWHM / 2 (computed by sc_fwhmest) from these peaks are taken for the ratio calculation only. Moreover, outliers (e.g. object lines) indicating a deviation of the ratio of more than siglim 

The routine prepares the use of CMPFIT. Apart from the start values for the line flux correction factors, the selected line peak pixels are also set for the fitting procedure. No other pixels are considered for the 
INPUT:
| fitpar | CPL table of fit parameters |
| scispec | CPL table with science spectrum |
| skyspec | CPL table with sky spectrum |
| parlist | input CPL parameter list |
OUTPUT:
| fitpar | fit parameter table with adapted start values for line groups |
ERRORS:
Definition at line 577 of file sc_mpfit.c.
References sc_basic_clipmean(), SC_CORRFAC_MAX, SC_CORRFAC_MIN, SC_DEFERRVAL, SC_LENLINE, SC_MAXRELFAC, and SC_MINNLIN.
Referenced by sc_mpfit().
| cpl_error_code sc_mpfit_setpar | ( | scpars * | fitpars, |
| const cpl_table * | fitpar, | ||
| const char | fittype | ||
| ) |
Provides a vector of parameters which are variables of the CMPFIT fitting process. Moreover, constraints for these parameters are delivered by the CMPFIT structure mp_par. Both objects are returned by a container structure. The parameter information is taken from the fit parameter table fitpar. The input parameter fittype decides whether line groups ('l') or the wavelength grid ('w') are fitted.
INPUT:
| fitpar | CPL table of fit parameters |
| fittype | 'l' for line groups or 'w' for wavelength grid |
OUTPUT:
| fitpars | structure containing the fit parameters |
ERRORS:
Definition at line 1186 of file sc_mpfit.c.
References SC_CORRFAC_MAX, SC_CORRFAC_MIN, SC_LENLINE, SC_MAXLEN, and SC_TOL.
Referenced by sc_mpfit().
| cpl_error_code sc_mpfit_substbadfitpar | ( | cpl_table * | fitpar, |
| const cpl_table * | initfitpar, | ||
| const cpl_parameterlist * | parlist | ||
| ) |
Substitutes bad fits of flux correction factors by value of initial estimate. Bad fits are recognised by a relative uncertainty greater than SC_MAXPARERR. If the A group fits of a system are identified as bad, then all B group fits of this system are also rejected. On the other hand, B groups are not touched if the A group fits of the same system are sufficiently good. The fit uncertainties of the substituted parameters are set to SC_DEFERRVAL.
INPUT:
| fitpar | CPL table with best fit parameters |
| initfitpar | CPL table with initial estimates of fit parameters |
| parlist | general CPL parameter list |
OUTPUT:
| fitpar | fit parameter table with initial estimates and no fit errors for substituted parameters |
ERRORS:
Definition at line 1537 of file sc_mpfit.c.
References SC_DEFERRVAL, and SC_MAXPARERR.
Referenced by sc_mpfit().
|
extern |
Last modsky call?
Definition at line 53 of file sc_mpfit.c.
Referenced by sc_modsky(), sc_modsky_moderrors(), sc_modsky_rebin(), and sc_mpfit().
|
extern |
Number of fitting function calls
Definition at line 51 of file sc_mpfit.c.
Referenced by sc_modsky_modlines(), sc_modsky_modwavegrid(), and sc_mpfit_calcdev().