ERIS Pipeline Reference Manual 1.9.2
eris_ifu_wavecal_static.h
1/* $Id$
2 *
3 * This file is part of the ERIS Pipeline
4 * Copyright (C) 2002,2003 European Southern Observatory
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#ifndef ERISP_ERIS_ERIS_IFU_WAVE_H_
22#define ERISP_ERIS_ERIS_IFU_WAVE_H_
23
24#ifdef HAVE_CONFIG_H
25#include <config.h>
26#endif
27
28/*-----------------------------------------------------------------------------
29 Includes
30 -----------------------------------------------------------------------------*/
31
32#include <math.h>
33
34#include <cpl.h>
35#include <hdrl.h>
36#include "eris_ifu_functions.h"
37
38/*-----------------------------------------------------------------------------
39 Define
40 -----------------------------------------------------------------------------*/
41// DEGREE: degree of the polynomial
42// FIRST_FIT: fit of isolated lines in collapsed slitlet spectra
43// COLUMN_FIT: final fit of reference lines in wavecal image columns
44// SMOOTH_FIT: cross fitting of the column fits
45#define FIRST_FIT_DEGREE 2
46#define COLUMN_FIT_DEGREE 3
47#define SMOOTH_FIT_DEGREE 2
48
49//define central wavelengths and pixel dispersions for each grating
50
51#define CENTRALLAMBDA_K_SPIFFI 2.2
52#define DISPERSION_K_SPIFFI 0.000245
53#define CENTRALLAMBDA_H_SPIFFI 1.65
54#define DISPERSION_H_SPIFFI 0.000195
55#define CENTRALLAMBDA_J_SPIFFI 1.25
56#define DISPERSION_J_SPIFFI 0.000145
57#define CENTRALLAMBDA_HK_SPIFFI 1.95
58#define DISPERSION_HK_SPIFFI 0.0005
59
60#define CENTRALLAMBDA_J_LOW 1.253
61#define DISPERSION_J_LOW 1.52e-04
62#define CENTRALLAMBDA_J_SHORT 1.185
63#define DISPERSION_J_SHORT 7.85e-05
64#define CENTRALLAMBDA_J_MIDDLE 1.264
65#define DISPERSION_J_MIDDLE 7.83e-05
66#define CENTRALLAMBDA_J_LONG 1.344
67#define DISPERSION_J_LONG 7.80e-05
68#define CENTRALLAMBDA_H_LOW 1.656
69#define DISPERSION_H_LOW 2.02e-04
70#define CENTRALLAMBDA_H_SHORT 1.561
71#define DISPERSION_H_SHORT 9.79e-05
72#define CENTRALLAMBDA_H_MIDDLE 1.667
73#define DISPERSION_H_MIDDLE 9.75e-05
74#define CENTRALLAMBDA_H_LONG 1.760
75#define DISPERSION_H_LONG 9.72e-05
76#define CENTRALLAMBDA_K_LOW 2.207
77#define DISPERSION_K_LOW 2.54e-04
78#define CENTRALLAMBDA_K_SHORT 2.074
79#define DISPERSION_K_SHORT 1.31e-04
80#define CENTRALLAMBDA_K_MIDDLE 2.197
81#define DISPERSION_K_MIDDLE 1.31e-04
82#define CENTRALLAMBDA_K_LONG 2.328
83#define DISPERSION_K_LONG 1.30e-04
84
85
86// FITS header keywords in reference linelist table extensions
87#define ERIS_IFU_REFTABLE_INSTR_HDR "INSTRUME"
88#define ERIS_IFU_REFTABLE_LAMPS_HDR "LAMPS"
89#define ERIS_IFU_REFTABLE_SPIFFI_VAL "SINFONI"
90#define ERIS_IFU_REFTABLE_SPIFFIER_VAL "ERIS"
91#define ERIS_IFU_REFTABLE_ARGON_VAL "Ar"
92#define ERIS_IFU_REFTABLE_NEON_VAL "Ne"
93#define ERIS_IFU_REFTABLE_KRYPTON_VAL "Kr"
94#define ERIS_IFU_REFTABLE_XEON_VAL "Xe"
95#define ERIS_IFU_REFTABLE_IGNORED_COLUMN "ignored"
96#define ERIS_IFU_REFTABLE_LAMBDA_COLUMN "wavelength"
97#define ERIS_IFU_REFTABLE_INTENSITY_COLUMN "intensity"
98
99// FITS table columns in firstFit table
100#define ERIS_IFU_FIRSTFIT_INSTRUMENT "instrument"
101#define ERIS_IFU_FIRSTFIT_BAND "band"
102#define ERIS_IFU_FIRSTFIT_LAMPS "lamps"
103#define ERIS_IFU_FIRSTFIT_BLOCK "block"
104#define ERIS_IFU_FIRSTFIT_POSITION "position"
105#define ERIS_IFU_FIRSTFIT_WAVELENGTH "wavelength"
106
107#define ERIS_IFU_ARCFRAMR_IDX "FRAMESET_IDX"
108#define ERIS_IFU_ARCFRAME_DIT "DIT"
109#define ERIS_IFU_ARCFRAME_LAMP "LAMP_STATUS"
110#define ERIS_IFU_ARCFRAME_FILE "FILENAME"
111
112#define ERIS_IFU_FITTABLE_SLITLET "slitlet"
113#define ERIS_IFU_FITTABLE_INDEX "index"
114#define ERIS_IFU_FITTABLE_POSITION "position"
115#define ERIS_IFU_FITTABLE_ERRORCODE "errorcode"
116#define ERIS_IFU_FITTABLE_WAVELENGTH "wavelength"
117
118
119struct waveSetupStruct {
120 double fwhm;
121 double sigma;
122 int s_range;
123 int c_range;
124 double ri_dispersion;
125 double ri_centralLambda;
126};
127struct waveTablesStruct {
128 cpl_table *slitletFitting;
129 cpl_table *columnFitting;
130 cpl_table *slitletCoeff;
131 cpl_table *columnCoeffRaw;
132 cpl_table *columnCoeffSmoothed;
133 cpl_table *smoothingCoeff;
134};
135
136/*-----------------------------------------------------------------------------
137 Functions prototypes
138 -----------------------------------------------------------------------------*/
139
140/*----------------------------------------------------------------------------*/
164/*----------------------------------------------------------------------------*/
165cpl_error_code eris_ifu_wave_get_arc_images (
166 cpl_frameset *arcFrames,
167 int exposureCorrectionMode,
168 int *arcImgCnt,
169 hdrl_imagelist **arcImages,
170 int **lampStates,
171 ifsBand *band,
172 ifsPreopticsScale *scale,
173 ifsInstrument *instrument,
174 double saturation_threshold,
175 cpl_table** qclog);
176
177/*----------------------------------------------------------------------------*/
203/*----------------------------------------------------------------------------*/
205 cpl_table *darkTable,
206 cpl_table *litTable,
207 int lampState,
208 float dit,
209 int exposureCorrectionMode,
210 double saturation_threshold,
211 cpl_table** qclog);
212
213/*----------------------------------------------------------------------------*/
231/*----------------------------------------------------------------------------*/
232cpl_image * eris_ifu_wave_get_calImg(int arcImagesCnt,
233 hdrl_imagelist *arcImages,
234 int *lampStates,
235 ifsBand band,
236 ifsInstrument instrument,
237 struct waveSetupStruct waveSetup,
238 const char* refLineTableFileName,
239 const char* firstFitTableFileName,
240 cpl_bivector *slitPos,
241 struct waveTablesStruct *tables,
242 int productDepth,
243 cpl_frameset *fs,
244 const cpl_parameterlist* parlist,
245 cpl_table* qclog);
246/*----------------------------------------------------------------------------*/
261/*----------------------------------------------------------------------------*/
262cpl_bivector *eris_ifu_wave_get_refLines(
263 const char * refLineTableFileName,
264 ifsInstrument instrument,
265 int lampState);
266
267/*----------------------------------------------------------------------------*/
279/*----------------------------------------------------------------------------*/
280cpl_vector * eris_ifu_wave_collapse_slitlet(const cpl_image *waveImg,
281 int center);
282
283/*----------------------------------------------------------------------------*/
299/*----------------------------------------------------------------------------*/
300void eris_ifu_wave_save_spectrum(cpl_image **collapsedSpectra,
301 int aIdx,
302 cpl_vector *collapsedSpectrum,
303 int sIdx,
304 cpl_size nRows,
305 int lampState,
306 ifsBand band,
307 ifsInstrument instrument,
308 cpl_bivector *refLines,
309 int productDepth);
310
311/*----------------------------------------------------------------------------*/
323/*----------------------------------------------------------------------------*/
324cpl_polynomial* eris_ifu_get_first_fit(
325 cpl_image **spectra,
326 int *lampStates,
327 int spectrumCnt,
328 int slitlet,
329 int ffOffsetIn,
330 int *ffOffsetOut,
331 struct waveSetupStruct waveSetup,
332 cpl_table *firstFitTable,
333 cpl_table *fittingDumpTable,
334 cpl_table *coeffDumpTable);
335
336/*----------------------------------------------------------------------------*/
348/*----------------------------------------------------------------------------*/
349cpl_error_code eris_ifu_fit_all_lines(const char *recipe_name,
350 int sIdx,
351 const double *slitletStart,
352 const double *slitletEnd,
353 int arcImgCnt,
354 const cpl_image **dataImg,
355 cpl_bivector **refLines,
356 struct waveSetupStruct waveSetup,
357 cpl_polynomial *firstFit,
358 cpl_polynomial *allFits[ERIS_IFU_DETECTOR_SIZE_Y],
359 cpl_table *dumpTable,
360 cpl_table *columnCoeffRawTable,
361 cpl_table *columnCoeffSmoothedTable,
362 cpl_table *smoothingCoeffTable);
363/*----------------------------------------------------------------------------*/
375/*----------------------------------------------------------------------------*/
377 const char* firstFitTableFileName,
378 ifsInstrument instrument,
379// int lampStatus,
380 ifsBand band);
381
383 const cpl_image *arcImg,
384 const cpl_image *waveCalImg,
385 ifsBand band,
386 double minLambda,
387 double maxLambda,
388 cpl_propertylist *plist,
389 int axisNumber);
390
392 int arcImgCnt,
393 const cpl_image **dataImg,
394 const cpl_image *waveCalImg,
395 ifsBand band,
396 int *lampStates,
397 cpl_frameset* frameset,
398 const cpl_parameterlist* parlist);
399
400cpl_error_code eris_ifu_wave_smooth_coeffs(
401 int sIdx,
402 int start,
403 int end,
404 int fitDegree,
405 cpl_polynomial *allFits[ERIS_IFU_DETECTOR_SIZE_Y],
406 cpl_table *columnCoeffSmoothedTable,
407 cpl_table *smoothingCoeffTable);
408
409cpl_error_code eris_ifu_wave_pos_err(
410 cpl_polynomial *allFits[ERIS_IFU_DETECTOR_SIZE_Y],
411 cpl_table *fitTable, ifsBand band);
412
413cpl_error_code eris_ifu_read_wave_setup(
414 const char* filename,
415 ifsBand band,
416 struct waveSetupStruct *waveSetup);
417
418cpl_table *eris_ifu_wave_create_fitting_table( void );
419
421 cpl_table *table,
422 int row,
423 int slitlet,
424 int index,
425 int arcImgIdx,
426 int position,
427 double wavelength,
428 struct gaussParStruct *gaussPar);
429
431 int size,
432 int polynomialDegree);
433
434cpl_error_code eris_ifu_wave_fill_coeff_table(
435 cpl_table *table,
436 int row,
437 int idx,
438 int nLines,
439 cpl_polynomial *polynomial);
440
442 struct waveTablesStruct *tables,
443 ifsInstrument instrument,
444 ifsBand band,
445 struct waveSetupStruct waveSetup,
446 cpl_frameset* frameset,
447 const cpl_parameterlist* parlist,
448 const char* recipe_name);
449
450cpl_error_code eris_ifu_wave_init_tables(
451 struct waveTablesStruct *tables);
452
454 struct waveTablesStruct *tables);
455
457 struct waveTablesStruct *tables);
458cpl_error_code
459eris_ifu_get_dispersion(ifsBand band, double* dispersion);
460
461cpl_error_code
462eris_ifu_get_central_lambda(ifsBand band, double* centralLambda);
463
464#endif
465
466
cpl_error_code eris_ifu_get_dispersion(ifsBand band, double *dispersion)
Get spectral dispersion for instrument band.
cpl_polynomial * eris_ifu_get_first_fit(cpl_image **spectra, int *lampStates, int spectrumCnt, int slitlet, int ffOffsetIn, int *ffOffsetOut, struct waveSetupStruct waveSetup, cpl_table *firstFitTable, cpl_table *fittingDumpTable, cpl_table *coeffDumpTable)
Generate initial wavelength fit for a slitlet.
cpl_error_code eris_ifu_wave_fill_fitting_table(cpl_table *table, int row, int slitlet, int index, int arcImgIdx, int position, double wavelength, struct gaussParStruct *gaussPar)
Fill fitting table row with Gaussian fit results.
cpl_table * eris_ifu_wave_create_coeff_table(int size, int polynomialDegree)
Create coefficient table for polynomial fits.
cpl_error_code eris_ifu_wave_get_arc_images(cpl_frameset *arcFrames, int exposureCorrectionMode, int *arcImgCnt, hdrl_imagelist **arcImages, int **lampStates, ifsBand *band, ifsPreopticsScale *scale, ifsInstrument *instrument, double saturation_threshold, cpl_table **qclog)
Load and preprocess arc lamp images for wavelength calibration.
void eris_ifu_wave_save_spectrum(cpl_image **collapsedSpectra, int aIdx, cpl_vector *collapsedSpectrum, int sIdx, cpl_size nRows, int lampStatus, ifsBand band, ifsInstrument instrument, cpl_bivector *refLines, int productDepth)
Save collapsed spectrum to product file.
cpl_bivector * eris_ifu_wave_get_refLines(const char *refLineTableFileName, ifsInstrument instrument, int lampState)
Load reference arc line wavelengths for specified lamp configuration.
cpl_image * eris_ifu_wave_get_calImg(int arcImagesCnt, hdrl_imagelist *arcImages, int *lampStates, ifsBand band, ifsInstrument instrument, struct waveSetupStruct waveSetup, const char *refLineTableFileName, const char *firstFitTableFileName, cpl_bivector *slitPos, struct waveTablesStruct *tables, int productDepth, cpl_frameset *fs, const cpl_parameterlist *parlist, cpl_table *qclog)
Generate wavelength calibration image from arc lamp data.
void eris_ifu_wave_free_tables(struct waveTablesStruct *tables)
Free all wavelength fitting tables.
hdrl_image * eris_ifu_wave_collapse_arc_images(cpl_table *darkTable, cpl_table *litTable, int lampState, float dit, int exposureCorrectionMode, double threshold, cpl_table **qclog)
Collapse multiple arc images with dark subtraction.
cpl_error_code eris_ifu_wave_smooth_coeffs(int sIdx, int start, int end, int fitDegree, cpl_polynomial *allFits[ERIS_IFU_DETECTOR_SIZE_Y], cpl_table *columnCoeffSmoothedTable, cpl_table *smoothingCoeffTable)
Smooth polynomial coefficients across detector columns.
cpl_error_code eris_ifu_save_resampled_arc_images(int arcImgCnt, const cpl_image **dataImg, const cpl_image *waveCalImg, ifsBand band, int *lampStates, cpl_frameset *frameset, const cpl_parameterlist *parlist)
Save resampled arc images as FITS product.
cpl_table * eris_ifu_wave_create_fitting_table(void)
Create fitting table for line fit results.
cpl_error_code eris_ifu_wave_pos_err(cpl_polynomial *allFits[ERIS_IFU_DETECTOR_SIZE_Y], cpl_table *fitTable, ifsBand band)
Compute wavelength errors and spectral resolution.
cpl_error_code eris_ifu_fit_all_lines(const char *recipe_name, int sIdx, const double *slitletStart, const double *slitletEnd, int arcImgCnt, const cpl_image **dataImg, cpl_bivector **refLines, struct waveSetupStruct waveSetup, cpl_polynomial *firstFit, cpl_polynomial *allFits[ERIS_IFU_DETECTOR_SIZE_Y], cpl_table *dumpTable, cpl_table *columnCoeffRawTable, cpl_table *columnCoeffSmoothedTable, cpl_table *smoothingCoeffTable)
Fit all reference lines in a slitlet across detector columns.
void eris_ifu_wave_clear_tables(struct waveTablesStruct *tables)
Clear wavelength table pointers without freeing.
cpl_image * eris_ifu_wave_resampled_arc_image(const cpl_image *arcImg, const cpl_image *waveCalImg, ifsBand band, double minLambda, double maxLambda, cpl_propertylist *plist, int axisNumber)
Resample arc image to uniform wavelength grid.
cpl_error_code eris_ifu_wave_init_tables(struct waveTablesStruct *tables)
Initialize wavelength fitting tables.
cpl_error_code eris_ifu_wave_save_fitting_tables(struct waveTablesStruct *tables, ifsInstrument instrument, ifsBand band, struct waveSetupStruct waveSetup, cpl_frameset *frameset, const cpl_parameterlist *parlist, const char *recipe_name)
Save all wavelength fitting tables to FITS file.
cpl_vector * eris_ifu_wave_collapse_slitlet(const cpl_image *dataImg, int center)
Collapse slitlet spatially to create 1D spectrum.
cpl_error_code eris_ifu_read_wave_setup(const char *filename, ifsBand band, struct waveSetupStruct *waveSetup)
Read wavelength setup parameters from configuration file.
cpl_table * eris_ifu_wave_get_firstFitTable(const char *firstFitTableFileName, ifsInstrument instrument, ifsBand band)
Load first fit table for instrument and band.
cpl_error_code eris_ifu_wave_fill_coeff_table(cpl_table *table, int row, int idx, int nLines, cpl_polynomial *polynomial)
Fill coefficient table row with polynomial data.