21#ifndef ERISP_ERIS_ERIS_IFU_WAVE_H_
22#define ERISP_ERIS_ERIS_IFU_WAVE_H_
36#include "eris_ifu_functions.h"
45#define FIRST_FIT_DEGREE 2
46#define COLUMN_FIT_DEGREE 3
47#define SMOOTH_FIT_DEGREE 2
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
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
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"
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"
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"
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"
119struct waveSetupStruct {
124 double ri_dispersion;
125 double ri_centralLambda;
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;
166 cpl_frameset *arcFrames,
167 int exposureCorrectionMode,
169 hdrl_imagelist **arcImages,
172 ifsPreopticsScale *scale,
173 ifsInstrument *instrument,
174 double saturation_threshold,
205 cpl_table *darkTable,
209 int exposureCorrectionMode,
210 double saturation_threshold,
233 hdrl_imagelist *arcImages,
236 ifsInstrument instrument,
237 struct waveSetupStruct waveSetup,
238 const char* refLineTableFileName,
239 const char* firstFitTableFileName,
240 cpl_bivector *slitPos,
241 struct waveTablesStruct *tables,
244 const cpl_parameterlist* parlist,
263 const char * refLineTableFileName,
264 ifsInstrument instrument,
302 cpl_vector *collapsedSpectrum,
307 ifsInstrument instrument,
308 cpl_bivector *refLines,
331 struct waveSetupStruct waveSetup,
332 cpl_table *firstFitTable,
333 cpl_table *fittingDumpTable,
334 cpl_table *coeffDumpTable);
351 const double *slitletStart,
352 const double *slitletEnd,
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);
377 const char* firstFitTableFileName,
378 ifsInstrument instrument,
383 const cpl_image *arcImg,
384 const cpl_image *waveCalImg,
388 cpl_propertylist *plist,
393 const cpl_image **dataImg,
394 const cpl_image *waveCalImg,
397 cpl_frameset* frameset,
398 const cpl_parameterlist* parlist);
405 cpl_polynomial *allFits[ERIS_IFU_DETECTOR_SIZE_Y],
406 cpl_table *columnCoeffSmoothedTable,
407 cpl_table *smoothingCoeffTable);
410 cpl_polynomial *allFits[ERIS_IFU_DETECTOR_SIZE_Y],
411 cpl_table *fitTable, ifsBand band);
414 const char* filename,
416 struct waveSetupStruct *waveSetup);
428 struct gaussParStruct *gaussPar);
432 int polynomialDegree);
439 cpl_polynomial *polynomial);
442 struct waveTablesStruct *tables,
443 ifsInstrument instrument,
445 struct waveSetupStruct waveSetup,
446 cpl_frameset* frameset,
447 const cpl_parameterlist* parlist,
448 const char* recipe_name);
451 struct waveTablesStruct *tables);
454 struct waveTablesStruct *tables);
457 struct waveTablesStruct *tables);
462eris_ifu_get_central_lambda(ifsBand band,
double* centralLambda);
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.