ERIS Pipeline Reference Manual 1.9.2
Functions
eris_ifu_wavecal_static.c File Reference

Wavelength Calibration Functions for ERIS IFU. More...

#include <stdbool.h>
#include <string.h>
#include <math.h>
#include <eris_utils.h>
#include "eris_ifu_error.h"
#include "eris_ifu_utils.h"
#include "eris_ifu_functions.h"
#include "eris_ifu_dfs.h"
#include "eris_ifu_wavecal_static.h"
#include "eris_ifu_debug.h"

Go to the source code of this file.

Functions

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.
 
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_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.
 
cpl_bivector * eris_ifu_wave_get_refLines (const char *refLineTableFileName, ifsInstrument instrument, int lampState)
 Load reference arc line wavelengths for specified lamp configuration.
 
cpl_vector * eris_ifu_wave_collapse_slitlet (const cpl_image *dataImg, int center)
 Collapse slitlet spatially to create 1D spectrum.
 
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_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.
 
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_wave_pos_err (cpl_polynomial *allFits[ERIS_IFU_DETECTOR_SIZE_Y], cpl_table *fitTable, ifsBand band)
 Compute wavelength errors and spectral resolution.
 
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_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_get_dispersion (ifsBand band, double *dispersion)
 Get spectral dispersion for instrument band.
 
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_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_error_code eris_ifu_read_wave_setup (const char *filename, ifsBand band, struct waveSetupStruct *waveSetup)
 Read wavelength setup parameters from configuration file.
 
cpl_error_code eris_ifu_wave_init_tables (struct waveTablesStruct *tables)
 Initialize wavelength fitting tables.
 
cpl_table * eris_ifu_wave_create_fitting_table (void)
 Create fitting table for line fit results.
 
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_fill_coeff_table (cpl_table *table, int row, int idx, int nLines, cpl_polynomial *polynomial)
 Fill coefficient table row with polynomial data.
 
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.
 
void eris_ifu_wave_free_tables (struct waveTablesStruct *tables)
 Free all wavelength fitting tables.
 
void eris_ifu_wave_clear_tables (struct waveTablesStruct *tables)
 Clear wavelength table pointers without freeing.
 

Detailed Description

Wavelength Calibration Functions for ERIS IFU.

This module provides comprehensive wavelength calibration functionality for the ERIS IFU pipeline. It implements the complete wavelength solution pipeline including:

The wavelength calibration uses arc lamp spectra (Ar, Ne, Kr, Xe) to establish the wavelength-pixel relationship across the detector. A polynomial fit is performed for each detector column, with coefficients smoothed spatially to reduce noise.

Definition in file eris_ifu_wavecal_static.c.

Function Documentation

◆ eris_ifu_fit_all_lines()

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.

This function processes a single slitlet, fitting all reference arc lines in each detector column within the slitlet. For each column:

  • Uses firstFit to predict line positions
  • Performs Gaussian fits to locate actual line centers
  • Applies quality filters (sigma, offset, position deviation)
  • Fits polynomial wavelength solution for the column
  • Stores fit results and coefficients in output tables

After all columns are processed, polynomial coefficients are smoothed spatially to reduce noise and improve wavelength solution stability.

Parameters
recipe_nameRecipe name (REC_NAME_WAVECAL or REC_NAME_DISTORTION)
sIdxSlitlet index to process
slitletStartArray of slitlet start positions
slitletEndArray of slitlet end positions
arcImgCntNumber of arc images
dataImgArray of arc lamp images
refLinesArray of reference line bivectors (per image)
waveSetupWavelength setup parameters
firstFitInitial wavelength fit polynomial
allFitsOutput: array of polynomial fits for all columns
dumpTableOutput: table of line fit results
columnCoeffRawTableOutput: raw polynomial coefficients
columnCoeffSmoothedTableOutput: smoothed polynomial coefficients
smoothingCoeffTableOutput: smoothing polynomial coefficients
Returns
CPL_ERROR_NONE on success, error code otherwise
Note
Column fit uses COLUMN_FIT_DEGREE polynomial order
Lines are rejected if: sigma >= waveSetup.sigma, |position deviation| > 5 pixels, or offset < -10 - peak/300

Definition at line 1274 of file eris_ifu_wavecal_static.c.

References BRK_IF_ERROR, BRK_IF_NULL, CATCH, eris_ifu_1d_polynomial_fit(), eris_ifu_free_vector(), eris_ifu_wave_fill_coeff_table(), eris_ifu_wave_fill_fitting_table(), eris_ifu_wave_smooth_coeffs(), and TRY.

Referenced by eris_ifu_dist_wave(), and eris_ifu_wave_get_calImg().

◆ eris_ifu_get_dispersion()

cpl_error_code eris_ifu_get_dispersion ( ifsBand  band,
double *  dispersion 
)

Get spectral dispersion for instrument band.

Returns the spectral dispersion (micrometers per pixel) for the specified instrument band. Used for wavelength axis calibration and spectral resolution calculations.

Parameters
bandInstrument band identifier
dispersionOutput: dispersion in µm/pixel
Returns
CPL_ERROR_NONE on success, error code otherwise
Note
Dispersion values are hardcoded constants defined in header

Definition at line 1794 of file eris_ifu_wavecal_static.c.

Referenced by eris_ifu_wave_pos_err(), and eris_ifu_wave_resampled_arc_image().

◆ eris_ifu_get_first_fit()

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.

Generates the first polynomial fit relating wavelength to pixel position for a specific slitlet. This initial fit is used as a starting point for finding lines in all detector columns. The function:

  • Loads reference line positions from firstFitTable
  • Performs Gaussian fits to locate lines in collapsed spectra
  • Fits a polynomial (wavelength vs. position) to the found lines
  • Computes position offset between expected and found line centers
Parameters
spectraArray of collapsed spectra images (one per lamp state)
lampStatesArray of lamp state codes
spectrumCntNumber of spectra
slitletSlitlet number to process
ffOffsetInInput pixel offset from previous fit
ffOffsetOutOutput: computed pixel offset for this slitlet
waveSetupWavelength setup parameters
firstFitTableTable of reference line positions
fittingDumpTableTable to store fit results
coeffDumpTableTable to store polynomial coefficients
Returns
Polynomial fit (wavelength = f(pixel)), or NULL on error
Note
Uses FIRST_FIT_DEGREE polynomial order
Offset is computed as mean of (found - expected) positions

Definition at line 1099 of file eris_ifu_wavecal_static.c.

References BRK_IF_ERROR, BRK_IF_NULL, BRK_WITH_ERROR_MSG, CATCH, CHECK_ERROR_STATE, eris_ifu_1d_polynomial_fit(), eris_ifu_free_table(), eris_ifu_free_vector(), eris_ifu_get_lampString(), eris_ifu_wave_fill_coeff_table(), eris_ifu_wave_fill_fitting_table(), and TRY.

Referenced by eris_ifu_dist_wave(), and eris_ifu_wave_get_calImg().

◆ eris_ifu_read_wave_setup()

cpl_error_code eris_ifu_read_wave_setup ( const char *  filename,
ifsBand  band,
struct waveSetupStruct *  waveSetup 
)

Read wavelength setup parameters from configuration file.

Loads band-specific wavelength calibration parameters from a FITS table, including search ranges for line fitting and expected line width (FWHM). These parameters control the wavelength calibration algorithm behavior.

Parameters
filenamePath to wavelength setup FITS table
bandInstrument band to load parameters for
waveSetupOutput: structure filled with setup parameters
Returns
CPL_ERROR_NONE on success, error code otherwise
Note
Parameters include: fwhm, s_range, c_range, ri_dispersion, ri_centrallambda
Sigma is computed from FWHM as: sigma = fwhm / (2 × sqrt(2 ln 2))
Table must contain exactly one row matching the band name

Definition at line 2200 of file eris_ifu_wavecal_static.c.

References BRK_IF_NULL, BRK_WITH_ERROR_MSG, CATCH, CHECK_ERROR_STATE, eris_ifu_free_table(), eris_ifu_get_bandString(), and TRY.

Referenced by eris_ifu_dist_wave().

◆ eris_ifu_save_resampled_arc_images()

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.

Resamples all arc lamp images to wavelength coordinates and saves them as a multi-extension FITS file. Each extension contains one resampled arc image with complete WCS information. This product is useful for verifying wavelength calibration quality and identifying problematic spectral regions.

Parameters
arcImgCntNumber of arc images
dataImgArray of arc lamp images
waveCalImgWavelength calibration image
bandInstrument band
lampStatesArray of lamp state codes
framesetFrameset for product header
parlistParameter list for product header
Returns
CPL_ERROR_NONE on success, error code otherwise
Note
Saved to ERIS_IFU_PRO_WAVE_LAMP_RESAMPLED_FN
Each extension includes lamp state in LAMPS keyword

Definition at line 2105 of file eris_ifu_wavecal_static.c.

References BRK_IF_ERROR, BRK_IF_NULL, CATCH, CATCH_MSG, CATCH_MSGS, eris_ifu_free_image(), eris_ifu_free_propertylist(), eris_ifu_get_lampString(), eris_ifu_save_image_dbg(), eris_ifu_wave_resampled_arc_image(), RECOVER, and TRY.

Referenced by eris_ifu_wave_get_calImg().

◆ eris_ifu_wave_clear_tables()

void eris_ifu_wave_clear_tables ( struct waveTablesStruct *  tables)

Clear wavelength table pointers without freeing.

Sets all table pointers in the structure to NULL without freeing the tables. Use when tables have been transferred elsewhere or when re-initializing the structure.

Parameters
tablesStructure to clear

Definition at line 2736 of file eris_ifu_wavecal_static.c.

Referenced by eris_ifu_dist_wave().

◆ eris_ifu_wave_collapse_arc_images()

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.

This function processes arc lamp frames with a specific lamp state and DIT. It collapses multiple frames using median (>=3 frames) or mean (1-2 frames) combination. Dark frames with matching DIT are collapsed and subtracted. QC parameters are computed for all frames and the final difference image.

Parameters
darkTableTable of dark frame information
litTableTable of illuminated arc frame information
lampStateLamp state code to process
ditDIT (detector integration time) to match
exposureCorrectionModeExposure correction method
thresholdSaturation threshold for pixel flagging
qclogOutput: QC log table with frame statistics
Returns
Collapsed and dark-subtracted arc image, or NULL on error
Note
Uses median combination for 3+ frames, mean for 1-2 frames
QC parameters: mean flux, median flux, max flux, saturated pixel count

Definition at line 288 of file eris_ifu_wavecal_static.c.

References ASSURE, BRK_IF_ERROR, BRK_IF_NULL, CATCH, CHECK_ERROR_STATE, eris_ifu_free_hdrl_image(), eris_ifu_free_hdrl_imagelist(), eris_ifu_load_exposure_file(), eris_qclog_add_double(), eris_qclog_add_int(), eris_qclog_init(), hdrl_image_delete(), hdrl_image_duplicate(), hdrl_image_get_image(), hdrl_image_get_mean(), hdrl_image_get_median(), hdrl_image_sub_image(), hdrl_imagelist_collapse_mean(), hdrl_imagelist_collapse_median(), hdrl_imagelist_get(), hdrl_imagelist_get_size(), hdrl_imagelist_new(), hdrl_imagelist_set(), and TRY.

Referenced by eris_ifu_wave_get_arc_images().

◆ eris_ifu_wave_collapse_slitlet()

cpl_vector * eris_ifu_wave_collapse_slitlet ( const cpl_image *  dataImg,
int  center 
)

Collapse slitlet spatially to create 1D spectrum.

Return a CPL vector which is an collapsed spectrum of a slitlet.

Extracts a 1D spectrum from an arc image by collapsing a slitlet in the spatial direction. Uses a median of pixels within ±10 pixels of the specified center column to reduce noise while preserving line shapes.

Parameters
dataImgInput arc lamp image
centerCenter column of slitlet to collapse
Returns
1D spectrum vector (length = image height), or NULL on error
Note
Uses 21-pixel wide window (center ± 10 pixels)
Invalid pixels are replaced with zero before median calculation

Definition at line 1023 of file eris_ifu_wavecal_static.c.

References BRK_IF_ERROR, BRK_IF_NULL, CATCH, CHECK_ERROR_STATE, eris_ifu_free_vector(), and TRY.

Referenced by eris_ifu_dist_wave(), and eris_ifu_wave_get_calImg().

◆ eris_ifu_wave_create_coeff_table()

cpl_table * eris_ifu_wave_create_coeff_table ( int  size,
int  polynomialDegree 
)

Create coefficient table for polynomial fits.

Creates a table to store polynomial coefficients with columns for:

  • slitlet: Slitlet or column identifier
  • nlines: Number of lines used in fit
  • degree: Polynomial degree
  • coeffs: Array of polynomial coefficients
Parameters
sizeNumber of rows to create
polynomialDegreeMaximum polynomial degree (determines array size)
Returns
New coefficient table, or NULL on error

Definition at line 2468 of file eris_ifu_wavecal_static.c.

References BRK_IF_NULL, CATCH, CHECK_ERROR_STATE, and TRY.

Referenced by eris_ifu_wave_init_tables().

◆ eris_ifu_wave_create_fitting_table()

cpl_table * eris_ifu_wave_create_fitting_table ( void  )

Create fitting table for line fit results.

Creates a table structure to store Gaussian fit results for arc lines. The table includes columns for:

  • Position information (slitlet, index/column, arc image index, position)
  • Reference wavelength
  • Fit results (x0, sigma, area, offset, mse, error code)
  • Derived quantities (wavelength fit, wavelength error, resolution)
  • Fit data (xdata, ydata arrays for plotting/debugging)
Returns
New fitting table, or NULL on error
Note
Table is created with 0 rows; rows are added as needed
Array columns (xdata, ydata) have size GAUSS_PAR_RANGE_MAX

Definition at line 2345 of file eris_ifu_wavecal_static.c.

References BRK_IF_NULL, CATCH, CHECK_ERROR_STATE, and TRY.

Referenced by eris_ifu_wave_init_tables().

◆ eris_ifu_wave_fill_coeff_table()

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.

Extracts polynomial coefficients and stores them in a table row along with metadata (index, number of lines used, polynomial degree).

Parameters
tableCoefficient table to update
rowRow index to fill
idxSlitlet or column identifier
nLinesNumber of lines used in polynomial fit
polynomialPolynomial to extract coefficients from
Returns
CPL_ERROR_NONE on success, error code otherwise

Definition at line 2508 of file eris_ifu_wavecal_static.c.

References CATCH, CATCH_MSGS, CHECK_ERROR_STATE, and TRY.

Referenced by eris_ifu_fit_all_lines(), eris_ifu_get_first_fit(), and eris_ifu_wave_smooth_coeffs().

◆ eris_ifu_wave_fill_fitting_table()

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.

Populates a single row of the fitting table with line fit information including position, wavelength, Gaussian parameters, and fit data.

Parameters
tableFitting table to update
rowRow index to fill
slitletSlitlet number
indexColumn or block index
arcImgIdxArc image index
positionExpected line position (pixels)
wavelengthReference wavelength (µm)
gaussParGaussian fit parameters structure
Returns
CPL_ERROR_NONE on success, error code otherwise
Note
Array data beyond gaussPar->range is zeroed for reproducible output

Definition at line 2401 of file eris_ifu_wavecal_static.c.

References BRK_IF_NULL, CATCH, CHECK_ERROR_STATE, and TRY.

Referenced by eris_ifu_fit_all_lines(), and eris_ifu_get_first_fit().

◆ eris_ifu_wave_free_tables()

void eris_ifu_wave_free_tables ( struct waveTablesStruct *  tables)

Free all wavelength fitting tables.

Deletes all tables in the waveTablesStruct and sets pointers to NULL. Safe to call even if some tables are already NULL.

Parameters
tablesStructure containing table pointers to free

Definition at line 2715 of file eris_ifu_wavecal_static.c.

References eris_ifu_free_table().

◆ eris_ifu_wave_get_arc_images()

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.

Extract and preprocess arc images from frameset.

This function loads raw arc lamp frames, identifies lamp states and DITs, sorts frames by lamp configuration, and collapses multiple frames with the same lamp state. Dark frames are automatically identified and subtracted. Returns a list of preprocessed arc images ready for wavelength calibration.

Parameters
arcFramesInput frameset containing arc and dark frames
exposureCorrectionModeExposure correction method (CDS, UTR, etc.)
arcImgCntOutput: number of arc images produced
arcImagesOutput: collapsed arc images (one per lamp state)
lampStatesOutput: array of lamp state codes for each image
bandOutput: instrument band (must be consistent across frames)
scaleOutput: pre-optics scale (must be consistent)
instrumentOutput: instrument identifier (SPIFFI/SPIFFIER)
saturation_thresholdThreshold for pixel saturation detection
qclogOutput: QC log table with frame statistics
Returns
CPL_ERROR_NONE on success, error code otherwise
Note
Frames with different lamp states and DITs are processed separately
Dark frames (lamp state = 0) are used for dark subtraction
QC parameters include mean/median/max flux and number of saturated pixels

Definition at line 84 of file eris_ifu_wavecal_static.c.

References ASSURE, BRK_IF_ERROR, BRK_IF_NULL, BRK_WITH_ERROR_MSG, CATCH, CHECK_ERROR_STATE, eris_ifu_free_propertylist(), eris_ifu_free_string(), eris_ifu_free_table(), eris_ifu_get_band(), eris_ifu_get_callamp_status(), eris_ifu_get_dit(), eris_ifu_get_instrument(), eris_ifu_get_lampString(), eris_ifu_get_preopticsScale(), eris_ifu_wave_collapse_arc_images(), eris_qclog_init(), hdrl_imagelist_delete(), hdrl_imagelist_get_size(), hdrl_imagelist_new(), hdrl_imagelist_set(), SET_ERROR_MSG, and TRY.

◆ eris_ifu_wave_get_calImg()

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.

Return the wavelength calibration image.

This is the main wavelength calibration function. It processes arc lamp images to create a 2D wavelength calibration image where each pixel value represents the wavelength at that detector position. The processing includes:

  • Loading reference arc line wavelengths
  • Collapsing spectra for each slitlet
  • Computing initial wavelength fit (first fit)
  • Fitting all reference lines in each detector column
  • Smoothing polynomial coefficients spatially
  • Computing wavelength errors and spectral resolution
  • Saving resampled arc images and fitting tables
Parameters
arcImagesCntNumber of arc images to process
arcImagesList of preprocessed arc images
lampStatesArray of lamp state codes for each image
bandInstrument band
instrumentInstrument identifier (SPIFFI/SPIFFIER)
waveSetupWavelength setup parameters (ranges, sigma)
refLineTableFileNamePath to reference line table
firstFitTableFileNamePath to first fit table
slitPosSlitlet positions (if NULL, uses default)
tablesStructure containing fitting tables
productDepthBitmask for intermediate product saving
fsFrameset for product headers
parlistParameter list for product headers
qclogQC log table
Returns
2D wavelength calibration image, or NULL on error
Note
The output image has dimensions ERIS_IFU_DETECTOR_SIZE_X × ERIS_IFU_DETECTOR_SIZE_Y
Each pixel value is the wavelength in micrometers at that position
QC parameters include central wavelength and its error

Definition at line 593 of file eris_ifu_wavecal_static.c.

References BRK_IF_ERROR, BRK_IF_NULL, CATCH, eris_ifu_fit_all_lines(), eris_ifu_free_bivector(), eris_ifu_free_image(), eris_ifu_free_polynomial(), eris_ifu_free_table(), eris_ifu_free_vector(), eris_ifu_get_first_fit(), eris_ifu_save_image_dbg(), eris_ifu_save_resampled_arc_images(), eris_ifu_wave_collapse_slitlet(), eris_ifu_wave_get_firstFitTable(), eris_ifu_wave_get_refLines(), eris_ifu_wave_pos_err(), eris_ifu_wave_save_spectrum(), eris_pfits_put_qc(), eris_qclog_add_double(), hdrl_image_add_image(), hdrl_image_get_image(), hdrl_image_get_image_const(), hdrl_imagelist_get(), hdrl_imagelist_get_const(), and TRY.

◆ eris_ifu_wave_get_firstFitTable()

cpl_table * eris_ifu_wave_get_firstFitTable ( const char *  firstFitTableFileName,
ifsInstrument  instrument,
ifsBand  band 
)

Load first fit table for instrument and band.

Loads the table of initial fit parameters (reference line positions) for the specified instrument and spectral band. The table contains expected pixel positions of strong arc lines used to bootstrap the wavelength calibration.

Parameters
firstFitTableFileNamePath to first fit FITS table
instrumentInstrument identifier (SPIFFI/SPIFFIER)
bandInstrument band
Returns
Extracted table for specified instrument/band, or NULL on error
Note
Returns only rows matching instrument and band
Table must contain ERIS_IFU_FIRSTFIT_INSTRUMENT and _BAND columns

Definition at line 1726 of file eris_ifu_wavecal_static.c.

References BRK_IF_NULL, BRK_WITH_ERROR_MSG, CATCH, CHECK_ERROR_STATE, eris_ifu_free_string(), eris_ifu_free_table(), eris_ifu_get_bandString(), and TRY.

Referenced by eris_ifu_dist_wave(), and eris_ifu_wave_get_calImg().

◆ eris_ifu_wave_get_refLines()

cpl_bivector * eris_ifu_wave_get_refLines ( const char *  refLineTableFileName,
ifsInstrument  instrument,
int  lampState 
)

Load reference arc line wavelengths for specified lamp configuration.

Return a bivector (lambda, intensitry) holding the arc lamp reference lines.

Loads reference arc line wavelengths and intensities from a FITS table for the specified instrument and lamp state. The table contains multiple extensions, one for each instrument/lamp combination. Lines marked as ignored are skipped. Wavelengths in nanometers are automatically converted to micrometers.

Parameters
refLineTableFileNamePath to reference line FITS table
instrumentInstrument identifier (SPIFFI/SPIFFIER)
lampStateLamp state code (combination of AR, NE, KR, XE lamps)
Returns
Bivector containing wavelengths (x) and intensities (y), or NULL on error
Note
Wavelengths > 100 are assumed to be in nm and converted to µm
Lines with ignored flag = 1 are excluded

Definition at line 879 of file eris_ifu_wavecal_static.c.

References BRK_IF_ERROR, BRK_IF_NULL, BRK_WITH_ERROR_MSG, CATCH, CHECK_ERROR_STATE, eris_ifu_free_propertylist(), eris_ifu_free_table(), eris_ifu_free_vector(), and TRY.

Referenced by eris_ifu_dist_wave(), and eris_ifu_wave_get_calImg().

◆ eris_ifu_wave_init_tables()

cpl_error_code eris_ifu_wave_init_tables ( struct waveTablesStruct *  tables)

Initialize wavelength fitting tables.

Creates all tables needed to store wavelength calibration results:

  • slitletFitting: Gaussian fit results for first fit lines
  • columnFitting: Gaussian fit results for all column fits
  • slitletCoeff: Polynomial coefficients for first fits
  • columnCoeffRaw: Raw polynomial coefficients per column
  • columnCoeffSmoothed: Smoothed polynomial coefficients
  • smoothingCoeff: Coefficients of smoothing polynomials
Parameters
tablesOutput: structure with pointers to created tables
Returns
CPL_ERROR_NONE on success, error code otherwise
Note
All table pointers are initialized even on error (may be NULL)
Tables must be freed with eris_ifu_wave_free_tables()

Definition at line 2295 of file eris_ifu_wavecal_static.c.

References CATCH, CHECK_ERROR_STATE, eris_ifu_wave_create_coeff_table(), eris_ifu_wave_create_fitting_table(), and TRY.

Referenced by eris_ifu_dist_wave().

◆ eris_ifu_wave_pos_err()

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.

For each successfully fitted reference line, this function:

  • Evaluates the wavelength polynomial at the fitted line position
  • Computes wavelength error (reference - fitted wavelength)
  • Calculates spectral resolution R = λ/(FWHM × dispersion)
  • Updates the fitting table with these derived quantities

The spectral resolution uses the Gaussian sigma from line fits converted to FWHM (2.355σ) and multiplied by the band dispersion.

Parameters
allFitsArray of wavelength polynomials for all columns
fitTableFitting table to update (modified in place)
bandInstrument band (for dispersion lookup)
Returns
CPL_ERROR_NONE on success, error code otherwise
Note
Only processes rows with errorCode == 0 (successful fits)
Resolution = wavelength / (sigma × dispersion × 2.355)

Definition at line 1543 of file eris_ifu_wavecal_static.c.

References CATCH, CHECK_ERROR_STATE, eris_ifu_get_dispersion(), and TRY.

Referenced by eris_ifu_wave_get_calImg().

◆ eris_ifu_wave_resampled_arc_image()

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.

Resamples an arc lamp image from detector coordinates (pixel, row) to wavelength coordinates (pixel, wavelength) using the wavelength calibration image. Each detector column is interpolated from its non-uniform wavelength sampling to a uniform grid with constant dispersion. This enables direct visualization of arc line positions and wavelength coverage.

The wavelength axis is constructed with:

  • Constant dispersion from band parameters
  • Center at central wavelength
  • Range covering [minLambda, maxLambda] from wavecal image
Parameters
arcImgInput arc lamp image (detector coordinates)
waveCalImgWavelength calibration image
bandInstrument band (for dispersion)
minLambdaMinimum wavelength in output grid (µm)
maxLambdaMaximum wavelength in output grid (µm)
plistProperty list to update with WCS keywords
axisNumberFITS axis number for wavelength (usually 2)
Returns
Resampled arc image in wavelength coordinates, or NULL on error
Note
Output image has same width as input, height determined by wavelength range
Uses 1D interpolation (degree -5) for resampling
Updates FITS WCS keywords (CTYPE, CUNIT, CRPIX, CRVAL, CDELT, CD matrix)
Columns that fail to resample are flagged but processing continues

Definition at line 1945 of file eris_ifu_wavecal_static.c.

References ASSURE, BRK_IF_NULL, CATCH, CHECK_ERROR_STATE, eris_ifu_1d_interpolation(), eris_ifu_free_double_array(), eris_ifu_free_string(), eris_ifu_free_vector(), eris_ifu_get_dispersion(), and TRY.

Referenced by eris_ifu_jitter_build_cube(), and eris_ifu_save_resampled_arc_images().

◆ eris_ifu_wave_save_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.

Saves all wavelength calibration fitting tables as extensions in a single FITS file. The primary header contains metadata (instrument, band, setup parameters), and each table is saved as a separate extension with descriptive EXTNAME keywords.

Tables saved (if not NULL):

  • slitletFittingTable: First fit line results
  • columnFittingTable: Column fit line results
  • slitletCoeff: First fit polynomial coefficients
  • columnCoeffRaw: Raw column polynomial coefficients
  • columnCoeffSmoothed: Smoothed column coefficients
  • smoothingCoeff: Smoothing polynomial coefficients
Parameters
tablesStructure containing all fitting tables
instrumentInstrument identifier
bandInstrument band
waveSetupWavelength setup parameters
framesetFrameset for product header
parlistParameter list for product header
recipe_nameRecipe name for product header
Returns
CPL_ERROR_NONE on success, error code otherwise
Note
Saved to ERIS_IFU_PRO_WAVE_FIT_TABLES_FN
Creates empty FITS file if no tables are provided

Definition at line 2572 of file eris_ifu_wavecal_static.c.

References BRK_IF_ERROR, BRK_IF_NULL, CATCH, eris_ifu_free_propertylist(), eris_ifu_get_bandString(), and TRY.

Referenced by eris_ifu_dist_wave().

◆ eris_ifu_wave_save_spectrum()

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.

Internal helper function to collect and save collapsed spectra.

Organizes collapsed slitlet spectra into an image for saving. Spectra are arranged by slitlet block to match the detector geometry. On first call (sIdx=0), initializes the output image. On last call (sIdx=SLITLET_CNT-1), saves the complete image to FITS with appropriate headers including lamp state, band, and instrument information.

Parameters
collapsedSpectraArray of spectrum images (one per arc image)
aIdxArc image index
collapsedSpectrumCurrent collapsed spectrum to add
sIdxSlitlet index
nRowsNumber of rows in spectrum
lampStatusLamp state code
bandInstrument band
instrumentInstrument identifier
refLinesReference line bivector
productDepthBitmask controlling product saving (bit 0)
Note
Product saved only if productDepth & 1 is true
Reference line wavelengths and intensities saved as extensions

Definition at line 1607 of file eris_ifu_wavecal_static.c.

References BRK_IF_ERROR, BRK_IF_NULL, CATCH, eris_ifu_free_propertylist(), eris_ifu_get_bandString(), eris_ifu_get_lampString(), and TRY.

Referenced by eris_ifu_dist_wave(), and eris_ifu_wave_get_calImg().

◆ eris_ifu_wave_smooth_coeffs()

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.

Smooths wavelength polynomial coefficients spatially across columns within a slitlet to reduce noise and improve wavelength solution stability. For each polynomial coefficient:

  • Sorts columns by central wavelength to handle edge cases
  • Fits a smoothing polynomial through coefficient values
  • Rejects 2 outliers from each end before fitting
  • Replaces original coefficients with smoothed values

This spatial smoothing assumes wavelength solutions vary slowly across neighboring columns, which is generally valid for well-aligned spectrographs.

Parameters
sIdxSlitlet index
startFirst column in slitlet
endLast column in slitlet
fitDegreeDegree of wavelength polynomial (per column)
allFitsArray of polynomial fits (modified in place)
columnCoeffSmoothedTableOutput: smoothed polynomial coefficients
smoothingCoeffTableOutput: smoothing polynomial coefficients
Returns
CPL_ERROR_NONE on success, error code otherwise
Note
Uses SMOOTH_FIT_DEGREE polynomial for smoothing
Removes 4 outliers total (2 from each end) before fitting

Definition at line 1455 of file eris_ifu_wavecal_static.c.

References CATCH, eris_ifu_1d_polynomial_fit(), eris_ifu_free_polynomial(), eris_ifu_wave_fill_coeff_table(), and TRY.

Referenced by eris_ifu_fit_all_lines().