ERIS Pipeline Reference Manual 1.8.15
Functions
IFU Geometric Distortion Correction

Functions

cpl_vector * eris_ifu_dist_calc_centers_profile (const cpl_vector *profile, cpl_boolean lowerCutLevel)
 Detect peak positions from a collapsed profile.
 
cpl_vector * eris_ifu_dist_estimate_low_slitlet (const cpl_vector *est_centers)
 Estimate position of missing low slitlet.
 
cpl_vector * eris_ifu_dist_calc_centers_fit (const cpl_vector *profile, const cpl_vector *est_centers, cpl_boolean do_fix_cnt)
 Fit Gaussian profiles to refine center positions.
 
cpl_error_code eris_ifu_dist_calc_centers_copy (const cpl_vector *fit_centers, int y_index, double y_value, cpl_table **cen_array)
 Copy fitted centers to the output table array.
 
cpl_table ** eris_ifu_dist_calc_centers (const hdrl_image *fibre_div, const hdrl_image *fibre_on, int productDepth)
 Calculate slitlet centers across the detector.
 
int eris_ifu_distortion_get_narcs (int i, cpl_boolean triple_traces, cpl_boolean cut_off_left, cpl_boolean cut_off_right)
 Determine number of arc traces to process for a slitlet.
 
cpl_polynomial ** eris_ifu_dist_calc_distortion (cpl_table **slit_edges, cpl_table **centers, int productDepth, cpl_boolean cut_off_left, cpl_boolean cut_off_right, cpl_table **minmax_borders, cpl_propertylist ***qc, cpl_propertylist *pl, cpl_frameset *frameset, const cpl_parameterlist *parlist)
 Calculate distortion polynomials for all slitlets.
 
cpl_polynomial ** eris_ifu_dist_calc_distortion_full (cpl_table **slit_edges, cpl_table **centers, int productDepth, cpl_boolean cut_off_left, cpl_boolean cut_off_right)
 Calculate distortion polynomials (alternative method)
 
eris_ifu_vector * eris_ifu_dist_calc_distortion_fitedge (const cpl_table *edge, const char *col_name, const eris_ifu_vector *y, int n_calib, int n_size, int fit_order, int slitlet, cpl_table *dbg_tbl)
 Fit polynomial to single edge as function of Y.
 
cpl_error_code eris_ifu_dist_calc_distortion_fillgrid (cpl_bivector *grid, const eris_ifu_vector *data, cpl_vector *val_to_fit, double x_pos, int n_size, int arc_cnt)
 Fill grid with distortion mapping data.
 
cpl_polynomial * eris_ifu_dist_poly_fit_2d_create (cpl_bivector *xy_pos, const cpl_vector *values, double *msee)
 Create 2D polynomial fit from grid data.
 
cpl_error_code eris_ifu_dist_save_distortion (cpl_polynomial **poly2d, const cpl_table *minmax_borders, const char *fn, cpl_frameset *frameset, const cpl_parameterlist *parlist, cpl_propertylist **qc)
 Save distortion polynomials to FITS file.
 
hdrl_image * eris_ifu_dist_warp_image_full (const hdrl_image *hdrl_img_in, cpl_polynomial **poly_u, int productDepth)
 Warp full image using distortion polynomials (alternative method)
 
hdrl_image * eris_ifu_dist_warp_slitlet (const hdrl_image *imgIn, const cpl_polynomial *poly_u, const cpl_polynomial *poly_v, double l_min, double r_max, int slitletNr)
 Warp single slitlet.
 
hdrl_image * eris_ifu_dist_warp_image (const hdrl_image *imgIn, cpl_polynomial **poly_u, const cpl_table *borders)
 Warp full detector image by warping each slitlet.
 
hdrl_image * eris_ifu_dist_warp_bpm (const hdrl_image *bpmIn, cpl_polynomial **poly_u, const cpl_table *borders, productDepthType productDepth)
 Warp bad pixel mask using distortion polynomials.
 
hdrl_imagelist * eris_ifu_stack_warped (const hdrl_image *imgIn, const int *rowIx)
 Stack warped image into cube format.
 
cpl_error_code eris_ifu_dist_warp_stats (const hdrl_image *hdrlWarpedImg, cpl_propertylist *qc_list, cpl_propertylist *pl, cpl_frameset *frameset, const cpl_parameterlist *parlist)
 Compute QC statistics on warped image.
 
cpl_error_code eris_ifu_image_add_slit (hdrl_image *hdrlImgFull, const hdrl_image *hdrlImgSlit, int offset)
 Paste slitlet image into full detector image.
 
cpl_table ** eris_ifu_dist_calc_slitpos (cpl_image **arcImg, cpl_table **centers_array, cpl_table *valid_arc_lines, int productDepth, cpl_boolean *cut_off_left, cpl_boolean *cut_off_right, const cpl_frameset *frameset, const cpl_parameterlist *parlist)
 Calculate slitlet edge positions from arc lamp images.
 
cpl_error_code eris_ifu_fit_gauss (const cpl_vector *x, const cpl_vector *y, double *x0, double *sigma, double *area, double *offset)
 Fit Gaussian to find peak center and width.
 
cpl_vector * eris_ifu_polyfit_edge (const eris_ifu_vector *x, const eris_ifu_vector *y, int fit_order)
 Iterative polynomial fitting with outlier rejection.
 
cpl_error_code eris_ifu_wavecal_processSof_dist (cpl_frameset *frames, int exposureCorrectionMode, int *arcImgCnt, hdrl_imagelist **arcImages, int **lampStates, ifsBand *band, ifsPreopticsScale *scale, ifsInstrument *instrument, double saturation_threhold, cpl_table **qclog)
 Process arc lamp images for distortion calibration.
 
cpl_error_code eris_ifu_distortion_reduce_lines (cpl_table *tbl, ifsBand band, int nr_cols)
 Filter valid arc lines by intensity and fit quality.
 
cpl_error_code eris_ifu_distortion_reduce_identical_lines (cpl_table *tbl)
 Remove duplicate or overlapping arc lines.
 
cpl_table * eris_ifu_dist_wave (cpl_frameset *fs, cpl_table **centers_fitted, int productDepth, cpl_image ***arcImgs, int *imgCnt, const cpl_parameterlist *parlist, cpl_table **qclog)
 Perform wavelength calibration to identify valid arc lines.
 

Detailed Description

This module provides comprehensive functions for geometric distortion correction in IFU spectrograph data. The distortion correction process involves:

The main workflow includes:

  1. Calculate slitlet centers from fiber illumination frames
  2. Detect slit edges from arc lamp images
  3. Fit 2D polynomials to map distorted to rectified coordinates
  4. Warp science images using the distortion maps
  5. Transform bad pixel masks accordingly
  6. Compute QC statistics on warped images
Note
This module handles both single-fiber and triple-fiber slitlet configurations
Special handling is implemented for edge slitlets that may be cut off
Memory management: Caller is responsible for freeing returned objects

Function Documentation

◆ eris_ifu_dist_calc_centers()

cpl_table ** eris_ifu_dist_calc_centers ( const hdrl_image *  fibre_div,
const hdrl_image *  fibre_on,
int  productDepth 
)

Calculate slitlet centers across the detector.

Parameters
fibre_divDivided fiber flat field image
fibre_onFiber illumination image
productDepthDebug output level (bit flags)
Returns
Array of SLITLET_CNT tables containing fitted center positions, or NULL on error

This is the main function for determining slitlet center positions:

  1. Takes horizontal chunk in middle of detector
  2. Collapses in Y to get profile
  3. Estimates and fits centers to determine number of traces (32 or 96)
  4. Allocates output tables accordingly
  5. Processes full detector in chunks from center outward
  6. Stores results in per-slitlet tables with columns:
    • Single trace: "x", "y"
    • Triple trace: "x_l", "x", "x_r", "y"
Note
Each element of returned array must be freed with cpl_table_delete()
Array itself must be freed with cpl_free()
Debug files saved if productDepth & 4

Definition at line 785 of file eris_ifu_distortion_static.c.

References BRK_IF_ERROR, BRK_IF_NULL, CATCH, CATCH_MSGS, CHECK_ERROR_STATE, eris_ifu_calc_centers_collapse_chunk(), eris_ifu_dist_calc_centers_copy(), eris_ifu_dist_calc_centers_fit(), eris_ifu_dist_calc_centers_profile(), eris_ifu_free_propertylist(), eris_ifu_free_string(), eris_ifu_free_table(), eris_ifu_free_vector(), eris_ifu_save_vector_dbg(), hdrl_image_get_image_const(), and TRY.

◆ eris_ifu_dist_calc_centers_copy()

cpl_error_code eris_ifu_dist_calc_centers_copy ( const cpl_vector *  fit_centers,
int  y_index,
double  y_value,
cpl_table **  cen_array 
)

Copy fitted centers to the output table array.

Parameters
fit_centersVector of fitted center positions
y_indexRow index in output tables
y_valueY coordinate value to store
cen_arrayArray of output tables (one per slitlet)
Returns
CPL_ERROR_NONE on success, error code otherwise

This function distributes fitted centers into per-slitlet tables:

  • For 32 traces: stores center position in "x" column
  • For 96 traces: stores left, center, and right traces in "x_l", "x", "x_r" columns
  • Handles edge cases where traces run off detector by comparing with neighboring rows
Note
Requires cen_array to be pre-allocated with SLITLET_CNT tables
Special logic handles partial traces at detector edges

Definition at line 586 of file eris_ifu_distortion_static.c.

References BRK_IF_ERROR, BRK_IF_NULL, BRK_WITH_ERROR_MSG, CATCH, CATCH_MSGS, and TRY.

Referenced by eris_ifu_dist_calc_centers().

◆ eris_ifu_dist_calc_centers_fit()

cpl_vector * eris_ifu_dist_calc_centers_fit ( const cpl_vector *  profile,
const cpl_vector *  est_centers,
cpl_boolean  do_fix_cnt 
)

Fit Gaussian profiles to refine center positions.

Parameters
profileThe profile in X across the detector
est_centersEstimated center positions from peak detection
do_fix_cntIf TRUE, correct the count to exactly 32 or 96 traces
Returns
Vector with exactly 32 or 96 fitted center values, or NULL on error

This function performs Gaussian fitting to refine center estimates:

  • First call (do_fix_cnt=TRUE): Determines correct number of traces (32 or 96)
  • Fits Gaussian to each estimated center to get sub-pixel precision
  • If more traces detected than expected, uses statistical outlier rejection
  • Subsequent calls (do_fix_cnt=FALSE): Handles edge cases where traces run off detector

Outlier rejection strategy:

  • Check leftmost and rightmost slitlets separately using median and stddev
  • Reject peaks differing by more than thresh*stddev from local median
  • Apply stricter global rejection if needed
Note
Returned vector must be freed by caller using cpl_vector_delete()
Function exits with error if less than 32 or 96 valid traces found

Definition at line 371 of file eris_ifu_distortion_static.c.

References BRK_IF_ERROR, BRK_IF_NULL, CATCH, CATCH_MSGS, eris_ifu_dist_estimate_low_slitlet(), eris_ifu_free_ifu_vector(), eris_ifu_free_vector(), eris_ifu_vector_count_non_rejected(), eris_ifu_vector_create(), eris_ifu_vector_extract(), eris_ifu_vector_get(), eris_ifu_vector_get_median(), eris_ifu_vector_get_stdev_median(), eris_ifu_vector_is_rejected(), eris_ifu_vector_reject(), SET_ERROR, and TRY.

Referenced by eris_ifu_dist_calc_centers().

◆ eris_ifu_dist_calc_centers_profile()

cpl_vector * eris_ifu_dist_calc_centers_profile ( const cpl_vector *  profile,
cpl_boolean  lowerCutLevel 
)

Detect peak positions from a collapsed profile.

Parameters
profileInput profile vector (collapsed in Y direction)
lowerCutLevelIf TRUE, use lower threshold for peak detection
Returns
Vector containing detected peak center positions, or NULL on error

This function analyzes a horizontal profile and detects peaks by:

  • Computing a dynamic cut level based on profile mean
  • Finding left and right edges of peaks above the threshold
  • Calculating center positions as (left+right)/2
  • Iterating with decreasing thresholds if expected peak count not found
  • Sorting peaks by height to remove low-amplitude spurious detections
Note
The function expects to find either SLITLET_CNT (32) or 3*SLITLET_CNT (96) peaks
Returned vector must be freed by caller using cpl_vector_delete()
Border pixels (ERIS_IFU_DETECTOR_BP_BORDER) are ignored in the detection

Definition at line 73 of file eris_ifu_distortion_static.c.

References BRK_IF_ERROR, BRK_IF_NULL, CATCH, CATCH_MSGS, eris_ifu_free_ifu_vector(), eris_ifu_free_vector(), eris_ifu_vector_create(), eris_ifu_vector_get_mean(), and TRY.

Referenced by eris_ifu_dist_calc_centers().

◆ eris_ifu_dist_calc_distortion()

cpl_polynomial ** eris_ifu_dist_calc_distortion ( cpl_table **  slit_edges,
cpl_table **  centers,
int  productDepth,
cpl_boolean  cut_off_left,
cpl_boolean  cut_off_right,
cpl_table **  minmax_borders,
cpl_propertylist ***  qc,
cpl_propertylist *  pl,
cpl_frameset *  frameset,
const cpl_parameterlist *  parlist 
)

Calculate distortion polynomials for all slitlets.

Parameters
slit_edgesArray of tables with detected slit edge positions
centersArray of tables with fitted slitlet centers
productDepthDebug output level
cut_off_leftIndicates if leftmost slitlet is cut off
cut_off_rightIndicates if rightmost slitlet is cut off
minmax_bordersOutput: table with min/max border positions per slitlet
qcOutput: array of QC property lists (one per slitlet)
plProperty list for FITS headers
framesetInput frameset
parlistParameter list
Returns
Array of SLITLET_CNT distortion polynomials, or NULL on error

This function computes 2D polynomial distortion maps:

  1. Fits polynomials to edge positions as function of Y
  2. Estimates cut-off edges using neighboring slitlet widths
  3. Defines target positions in rectified coordinate system
  4. Builds 2D grid of (target_x, target_y) -> measured_x
  5. Fits 2D polynomial to this mapping
  6. Computes QC statistics (slitlet widths, center positions, etc.)
Note
Polynomial degree is 2 in X and 3 in Y
Each polynomial must be freed with cpl_polynomial_delete()
Array must be freed with cpl_free()
QC property lists contain statistics on fitted edges

Definition at line 1136 of file eris_ifu_distortion_static.c.

References ASSURE, BRK_IF_ERROR, BRK_IF_NULL, CHECK_ERROR_STATE, eris_ifu_dist_calc_distortion(), eris_ifu_dist_calc_distortion_fitedge(), eris_ifu_distortion_get_narcs(), eris_ifu_free_ifu_vector(), eris_ifu_vector_add(), eris_ifu_vector_duplicate(), eris_ifu_vector_get_mean(), eris_ifu_vector_new_wrap(), eris_ifu_vector_subtract(), and TRY.

Referenced by eris_ifu_dist_calc_distortion().

◆ eris_ifu_dist_calc_distortion_fillgrid()

cpl_error_code eris_ifu_dist_calc_distortion_fillgrid ( cpl_bivector *  grid,
const eris_ifu_vector *  data,
cpl_vector *  val_to_fit,
double  x_pos,
int  n_size,
int  arc_cnt 
)

Fill grid with distortion mapping data.

Parameters
gridOutput: 2D grid of target coordinates (x, y)
dataInput: fitted edge positions
val_to_fitOutput: measured X positions to fit
x_posTarget X position for this arc
n_sizeNumber of data points
arc_cntArc index (for offset in grid)
Returns
CPL_ERROR_NONE on success, error code otherwise

Populates grid and value arrays for 2D polynomial fitting:

  • Grid X: all set to x_pos (target coordinate)
  • Grid Y: distributed Y coordinates
  • Values: measured X positions from fitted data
Note
Rejected values in data are set to NAN in val_to_fit

Definition at line 2449 of file eris_ifu_distortion_static.c.

◆ eris_ifu_dist_calc_distortion_fitedge()

eris_ifu_vector * eris_ifu_dist_calc_distortion_fitedge ( const cpl_table *  edge,
const char *  col_name,
const eris_ifu_vector *  y,
int  n_calib,
int  n_size,
int  fit_order,
int  slitlet,
cpl_table *  dbg_tbl 
)

Fit polynomial to single edge as function of Y.

Parameters
edgeTable with edge positions
col_nameColumn name containing X positions
yY coordinate vector
n_calibNumber of calibration points
n_sizeOutput vector size (number of Y positions)
fit_orderPolynomial order (typically 2 or 3)
slitletSlitlet index for debugging
dbg_tblDebug table to store polynomial coefficients
Returns
Vector with fitted edge positions at n_size Y coordinates, or NULL on error

Fits polynomial of form: x(y) = a0 + a1*y + a2*y^2 + ... Returns evaluated positions at regular Y intervals.

Note
Returned vector must be freed with eris_ifu_vector_delete()

Definition at line 2363 of file eris_ifu_distortion_static.c.

Referenced by eris_ifu_dist_calc_distortion().

◆ eris_ifu_dist_calc_distortion_full()

cpl_polynomial ** eris_ifu_dist_calc_distortion_full ( cpl_table **  slit_edges,
cpl_table **  centers,
int  productDepth,
cpl_boolean  cut_off_left,
cpl_boolean  cut_off_right 
)

Calculate distortion polynomials (alternative method)

Parameters
slit_edgesArray of tables with detected slit edge positions
centersArray of tables with fitted slitlet centers
productDepthDebug output level
cut_off_leftIndicates if leftmost slitlet is cut off
cut_off_rightIndicates if rightmost slitlet is cut off
Returns
Array of SLITLET_CNT distortion polynomials, or NULL on error

Alternative distortion calculation with different polynomial fitting approach. Uses same input data but different target coordinate calculation.

Note
Polynomial degree is 3 in both X and Y
Each polynomial must be freed with cpl_polynomial_delete()
Array must be freed with cpl_free()

Definition at line 1844 of file eris_ifu_distortion_static.c.

◆ eris_ifu_dist_calc_slitpos()

cpl_table ** eris_ifu_dist_calc_slitpos ( cpl_image **  arcImg,
cpl_table **  centers_array,
cpl_table *  valid_arc_lines,
int  productDepth,
cpl_boolean *  cut_off_left,
cpl_boolean *  cut_off_right,
const cpl_frameset *  frameset,
const cpl_parameterlist *  parlist 
)

Calculate slitlet edge positions from arc lamp images.

Parameters
arcImgArray of arc lamp images
centers_arrayArray of tables with fitted slitlet centers
valid_arc_linesTable of valid arc lines (from wavelength calibration)
productDepthDebug output level
cut_off_leftOutput: TRUE if leftmost slitlet is cut off
cut_off_rightOutput: TRUE if rightmost slitlet is cut off
framesetInput frameset
parlistParameter list
Returns
Array of SLITLET_CNT tables with detected edge positions, or NULL on error

Detects slit edges for each arc line:

  1. For each slitlet, extracts center position
  2. For each valid arc line, creates horizontal profile
  3. Fits Gaussian to find left and right edges
  4. Applies statistical outlier rejection based on slit width
  5. Handles edge cases where first/last slitlet extends beyond detector

Output tables contain columns:

  • edge_left: X coordinate of left edge
  • edge_right: X coordinate of right edge
  • slit_width: Distance between edges
  • y_pos: Y coordinate of arc line
Note
Each table must be freed with cpl_table_delete()
Array must be freed with cpl_free()
Cut-off flags help subsequent processing handle edge slitlets correctly

Definition at line 3818 of file eris_ifu_distortion_static.c.

◆ eris_ifu_dist_estimate_low_slitlet()

cpl_vector * eris_ifu_dist_estimate_low_slitlet ( const cpl_vector *  est_centers)

Estimate position of missing low slitlet.

Parameters
est_centersInput vector with estimated center positions
Returns
New vector with corrected center positions including estimated missing slitlet, or NULL on error

This function handles cases where peak detection misses a slitlet by:

  • Checking if the correct number of slitlets is detected (32 or 96)
  • If missing, estimating the position based on neighboring slitlets
  • Special handling for the known bad slitlet (#15 in 25mas mode)
  • Removing trailing zeros caused by detector edge cutoff
Note
For 25mas scale: looks for missing slitlet around position 15
For 100mas/250mas scales: checks distances between consecutive traces
Returned vector must be freed by caller using cpl_vector_delete()

Definition at line 218 of file eris_ifu_distortion_static.c.

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

Referenced by eris_ifu_dist_calc_centers_fit().

◆ eris_ifu_dist_poly_fit_2d_create()

cpl_polynomial * eris_ifu_dist_poly_fit_2d_create ( cpl_bivector *  xy_pos,
const cpl_vector *  values,
double *  msee 
)

Create 2D polynomial fit from grid data.

Parameters
xy_pos2D grid of (x,y) positions
valuesMeasured values to fit
mseeOutput: mean squared error estimate (optional, can be NULL)
Returns
Fitted 2D polynomial, or NULL on error

Performs 2D polynomial fit with maximum degrees:

  • X dimension: degree 2
  • Y dimension: degree 3

The polynomial can be evaluated at any (x,y) to get the fitted value.

Note
Returned polynomial must be freed with cpl_polynomial_delete()
NaN values in input are handled by CPL fitting routine

Definition at line 2526 of file eris_ifu_distortion_static.c.

◆ eris_ifu_dist_save_distortion()

cpl_error_code eris_ifu_dist_save_distortion ( cpl_polynomial **  poly2d,
const cpl_table *  minmax_borders,
const char *  fn,
cpl_frameset *  frameset,
const cpl_parameterlist *  parlist,
cpl_propertylist **  qc 
)

Save distortion polynomials to FITS file.

Parameters
poly2dArray of 2D polynomials (one per slitlet)
minmax_bordersTable with min/max border positions
fnOutput filename
framesetInput frameset for provenance
parlistParameter list for provenance
qcArray of QC property lists
Returns
CPL_ERROR_NONE on success, error code otherwise

Saves polynomials in FITS table format with:

  • One extension per slitlet
  • Columns: degx, degy, coeff
  • QC parameters in extension headers
  • Final extension contains minmax_borders table
Note
Output file can be loaded by eris_ifu_load_distortion_polynomials()

Definition at line 2611 of file eris_ifu_distortion_static.c.

◆ eris_ifu_dist_warp_bpm()

hdrl_image * eris_ifu_dist_warp_bpm ( const hdrl_image *  bpmIn,
cpl_polynomial **  poly_u,
const cpl_table *  borders,
productDepthType  productDepth 
)

Warp bad pixel mask using distortion polynomials.

Parameters
bpmInInput bad pixel mask as HDRL image
poly_uArray of X-distortion polynomials
bordersTable with slitlet boundaries
productDepthDebug output level
Returns
Warped bad pixel mask, or NULL on error

Warps bad pixel mask with special handling:

  1. Creates column contribution map (each pixel stores its original column number)
  2. Warps the contribution map
  3. Interpolates BPM values based on fractional contributions
  4. Marks border regions as bad where data comes from outside valid detector area

This ensures bad pixels are correctly propagated through geometric transformation.

Note
Returned image must be freed with hdrl_image_delete()
Algorithm accounts for fractional pixel contributions at boundaries

Definition at line 3119 of file eris_ifu_distortion_static.c.

Referenced by eris_ifu_jitter_build_cube().

◆ eris_ifu_dist_warp_image()

hdrl_image * eris_ifu_dist_warp_image ( const hdrl_image *  imgIn,
cpl_polynomial **  poly_u,
const cpl_table *  borders 
)

Warp full detector image by warping each slitlet.

Parameters
imgInInput HDRL image
poly_uArray of X-distortion polynomials (one per slitlet)
bordersTable with l_min/r_max for each slitlet
Returns
Warped full detector image, or NULL on error

Main warping function that:

  1. Creates output image of same size as input
  2. Warps each slitlet independently
  3. Pastes warped slitlets into output at standard positions

This approach is more accurate than full-image warping as it handles discontinuities between slitlets properly.

Note
Returned image must be freed with hdrl_image_delete()
Can be parallelized (warping of different slitlets is independent)

Definition at line 3034 of file eris_ifu_distortion_static.c.

Referenced by eris_ifu_jitter_build_cube().

◆ eris_ifu_dist_warp_image_full()

hdrl_image * eris_ifu_dist_warp_image_full ( const hdrl_image *  hdrl_img_in,
cpl_polynomial **  poly_u,
int  productDepth 
)

Warp full image using distortion polynomials (alternative method)

Parameters
hdrl_img_inInput HDRL image to warp
poly_uArray of X-distortion polynomials
productDepthDebug output level
Returns
Warped HDRL image, or NULL on error

Alternative warping method that processes entire image at once. Uses polynomial_warp with identity Y polynomial.

Note
Returned image must be freed with hdrl_image_delete()
Less efficient than slitlet-wise warping

Definition at line 2805 of file eris_ifu_distortion_static.c.

◆ eris_ifu_dist_warp_slitlet()

hdrl_image * eris_ifu_dist_warp_slitlet ( const hdrl_image *  imgIn,
const cpl_polynomial *  poly_u,
const cpl_polynomial *  poly_v,
double  l_min,
double  r_max,
int  slitletNr 
)

Warp single slitlet.

Parameters
imgInInput HDRL image
poly_uX-distortion polynomial
poly_vY-distortion polynomial (typically identity)
l_minMinimum X coordinate of slitlet
r_maxMaximum X coordinate of slitlet
slitletNrSlitlet index for diagnostics
Returns
Warped slitlet image (SLITLET_WIDTH x ERIS_IFU_DETECTOR_SIZE_Y), or NULL on error

Extracts and warps a single slitlet:

  1. Extracts region from l_min to r_max
  2. Applies polynomial warping
  3. Trims or pads result to standard SLITLET_WIDTH (64 pixels)

Special handling for slitlets extending beyond detector boundaries.

Note
Returned image must be freed with hdrl_image_delete()
Output width is always SLITLET_WIDTH regardless of input

Definition at line 2923 of file eris_ifu_distortion_static.c.

◆ eris_ifu_dist_warp_stats()

cpl_error_code eris_ifu_dist_warp_stats ( const hdrl_image *  hdrlWarpedImg,
cpl_propertylist *  qc_list,
cpl_propertylist *  pl,
cpl_frameset *  frameset,
const cpl_parameterlist *  parlist 
)

Compute QC statistics on warped image.

Parameters
hdrlWarpedImgWarped image to analyze
qc_listOutput: QC parameters to add to product
plProperty list for output file
framesetInput frameset
parlistParameter list
Returns
CPL_ERROR_NONE on success, error code otherwise

Computes quality control parameters on warped image:

  • Re-detects slitlet centers to verify distortion correction
  • Calculates center position statistics (stdev, median)
  • Measures slitlet widths
  • Saves fitted centers to QC file

QC parameters added per slitlet:

  • C STDEV: standard deviation of center position
  • C MEDIAN: median center position
  • R-L STDEV/MEDIAN: slitlet width statistics
  • For triple traces: additional center-left, center-right statistics
Note
Creates intermediate QC file with fitted centers

Definition at line 3356 of file eris_ifu_distortion_static.c.

◆ eris_ifu_dist_wave()

cpl_table * eris_ifu_dist_wave ( cpl_frameset *  fs,
cpl_table **  centers_fitted,
int  productDepth,
cpl_image ***  arcImgs,
int *  imgCnt,
const cpl_parameterlist *  parlist,
cpl_table **  qclog 
)

Perform wavelength calibration to identify valid arc lines.

Parameters
fsFrameset with arc images and reference data
centers_fittedArray of tables with fitted slitlet centers
productDepthDebug output level
arcImgsOutput: array of arc lamp images
imgCntOutput: number of images
parlistParameter list
qclogOutput: QC log table
Returns
Table of valid arc lines with positions, or NULL on error

Performs simplified wavelength calibration to identify good arc lines:

  1. Loads arc lamp images and reference line lists
  2. Collapses spectra at slitlet centers
  3. Performs first-fit wavelength calibration
  4. Fits all lines and computes quality metrics
  5. Filters lines by intensity and fit quality
  6. Returns table with columns: slitlet, position, wavelength, fit parameters

This provides the list of valid arc lines needed for distortion calibration.

Note
Returned table must be freed with cpl_table_delete()
Uses wavelength calibration to ensure only real arc lines are used

Definition at line 5083 of file eris_ifu_distortion_static.c.

References BRK_IF_ERROR, BRK_IF_NULL, BRK_WITH_ERROR_MSG, CATCH, CHECK_ERROR_STATE, eris_ifu_fit_all_lines(), eris_ifu_free_bivector(), eris_ifu_free_hdrl_imagelist(), eris_ifu_free_image(), eris_ifu_free_polynomial(), eris_ifu_free_propertylist(), eris_ifu_free_table(), eris_ifu_free_vector(), eris_ifu_get_first_fit(), eris_ifu_read_wave_setup(), eris_ifu_wave_clear_tables(), eris_ifu_wave_collapse_slitlet(), eris_ifu_wave_get_firstFitTable(), eris_ifu_wave_get_refLines(), eris_ifu_wave_init_tables(), eris_ifu_wave_save_fitting_tables(), eris_ifu_wave_save_spectrum(), eris_ifu_wavecal_processSof_dist(), hdrl_image_get_image_const(), hdrl_imagelist_get_const(), and TRY.

◆ eris_ifu_distortion_get_narcs()

int eris_ifu_distortion_get_narcs ( int  i,
cpl_boolean  triple_traces,
cpl_boolean  cut_off_left,
cpl_boolean  cut_off_right 
)

Determine number of arc traces to process for a slitlet.

Parameters
iSlitlet index
triple_tracesTRUE if 3 traces per slitlet, FALSE if 1
cut_off_leftTRUE if leftmost slitlet is cut off
cut_off_rightTRUE if rightmost slitlet is cut off
Returns
Number of arc traces (3 or 5 for single-fiber, 5 or 7 for triple-fiber)

Counts: left edge + right edge + center line(s) Decrements count if edge slitlet is cut off at detector boundary.

Definition at line 1087 of file eris_ifu_distortion_static.c.

Referenced by eris_ifu_dist_calc_distortion().

◆ eris_ifu_distortion_reduce_identical_lines()

cpl_error_code eris_ifu_distortion_reduce_identical_lines ( cpl_table *  tbl)

Remove duplicate or overlapping arc lines.

Parameters
tblTable of arc lines (modified in place)
Returns
CPL_ERROR_NONE on success, error code otherwise

Removes lines with identical or very similar wavelengths (< 0.001 difference). When duplicates found, removes both entries to avoid ambiguity.

Note
Processes each slitlet separately
Modifies table in place by erasing rows

Definition at line 5005 of file eris_ifu_distortion_static.c.

References BRK_IF_NULL, CATCH, CATCH_MSGS, CHECK_ERROR_STATE, eris_ifu_free_table(), and TRY.

◆ eris_ifu_distortion_reduce_lines()

cpl_error_code eris_ifu_distortion_reduce_lines ( cpl_table *  tbl,
ifsBand  band,
int  nr_cols 
)

Filter valid arc lines by intensity and fit quality.

Parameters
tblTable of fitted arc lines (modified in place)
bandSpectral band (affects thresholds)
nr_colsNumber of columns per slitlet
Returns
CPL_ERROR_NONE on success, error code otherwise

Applies multiple filtering criteria:

  1. Removes lines with area below band- and slitlet-specific threshold
  2. Removes lines with intensity below threshold
  3. Removes lines that failed fitting in >50% of columns
  4. Removes lines that appear only once (likely spurious)
  5. Keeps only center column for multi-column fits
  6. Removes lines with non-zero error codes
Note
Modifies table in place by erasing rows
Thresholds vary by band and slitlet (slitlet #16 has lower thresholds)

Definition at line 4767 of file eris_ifu_distortion_static.c.

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

◆ eris_ifu_fit_gauss()

cpl_error_code eris_ifu_fit_gauss ( const cpl_vector *  x,
const cpl_vector *  y,
double *  x0,
double *  sigma,
double *  area,
double *  offset 
)

Fit Gaussian to find peak center and width.

Parameters
xX coordinates
yY values (intensities)
x0Output: center position
sigmaOutput: Gaussian width (positive on success)
areaOutput: Gaussian area (positive on success)
offsetOutput: background offset level
Returns
CPL_ERROR_NONE on success, error code otherwise

Performs iterative Gaussian fitting:

  1. First attempt: fit all 4 parameters (x0, sigma, area, offset)
  2. If first fit doesn't converge, fix sigma and area, refit x0 and offset
  3. Returns best-fit parameters even if convergence not achieved

Gaussian model: y = offset + (area / sqrt(2*pi*sigma^2)) * exp(-(x-x0)^2 / (2*sigma^2))

Note
Returns -1 for all parameters if fitting completely fails
Convergence issues are handled gracefully; partial results may be returned

Definition at line 4417 of file eris_ifu_distortion_static.c.

Referenced by eris_ifu_slitpos_gauss().

◆ eris_ifu_image_add_slit()

cpl_error_code eris_ifu_image_add_slit ( hdrl_image *  hdrlImgFull,
const hdrl_image *  hdrlImgSlit,
int  offset 
)

Paste slitlet image into full detector image.

Parameters
hdrlImgFullFull detector image (modified in place)
hdrlImgSlitSlitlet image to paste
offsetX offset for paste position
Returns
CPL_ERROR_NONE on success, error code otherwise

Copies data, error, and mask from slitlet image into full image at specified offset. Useful for assembling warped image from individual slitlets.

Note
Can be parallelized if different offsets ensure non-overlapping regions
Both images must have same Y dimension (ERIS_IFU_DETECTOR_SIZE_Y)

Definition at line 3715 of file eris_ifu_distortion_static.c.

◆ eris_ifu_polyfit_edge()

cpl_vector * eris_ifu_polyfit_edge ( const eris_ifu_vector *  x,
const eris_ifu_vector *  y,
int  fit_order 
)

Iterative polynomial fitting with outlier rejection.

Parameters
xX coordinates
yY values to fit
fit_orderPolynomial order (1, 2, or 3)
Returns
Vector of polynomial coefficients [a0, a1, a2, ...], or NULL on error

Performs robust polynomial fitting:

  1. Fit polynomial to all data
  2. Calculate residuals
  3. Reject points with residuals > median + 5*stddev
  4. Repeat 3 times total

Polynomial form: y(x) = a0 + a1*x + a2*x^2 + a3*x^3

Note
Handles rejected values in input eris_ifu_vector structures
Returned vector must be freed with cpl_vector_delete()
Rejection mask in x and y is synchronized

Definition at line 4522 of file eris_ifu_distortion_static.c.

◆ eris_ifu_stack_warped()

hdrl_imagelist * eris_ifu_stack_warped ( const hdrl_image *  imgIn,
const int *  rowIx 
)

Stack warped image into cube format.

Parameters
imgInInput warped full-detector image
rowIxLUT for slitlet ordering
Returns
Image list representing cube (z-axis is spectral), or NULL on error

Transforms 2D warped image into 3D cube by stacking slitlets:

  • Each plane in Z corresponds to one wavelength (detector Y coordinate)
  • Each plane contains all 32 slitlets side-by-side
  • Slitlet order is determined by rowIx mapping
Note
Returned imagelist must be freed with hdrl_imagelist_delete()
No wavelength calibration applied; still in pixel coordinates

Definition at line 3280 of file eris_ifu_distortion_static.c.

◆ eris_ifu_wavecal_processSof_dist()

cpl_error_code eris_ifu_wavecal_processSof_dist ( cpl_frameset *  frames,
int  exposureCorrectionMode,
int *  arcImgCnt,
hdrl_imagelist **  arcImages,
int **  lampStates,
ifsBand *  band,
ifsPreopticsScale *  scale,
ifsInstrument *  instrument,
double  saturation_threhold,
cpl_table **  qclog 
)

Process arc lamp images for distortion calibration.

Parameters
framesInput frameset
exposureCorrectionModeExposure correction flags
arcImgCntOutput: number of arc images
arcImagesOutput: HDRL imagelist of arc images
lampStatesOutput: array of lamp state flags
bandOutput: spectral band
scaleOutput: preoptics scale
instrumentOutput: instrument identifier
saturation_threholdSaturation threshold for QC
qclogOutput: QC log table
Returns
CPL_ERROR_NONE on success, error code otherwise

Loads and processes arc lamp frames:

  • Identifies ON and OFF frames
  • Performs exposure corrections
  • Combines multiple lamp images if needed
  • Extracts instrument configuration
Note
Similar to eris_ifu_wave_get_arc_images() but tailored for distortion
Caller must free arcImages, lampStates

Definition at line 4677 of file eris_ifu_distortion_static.c.

Referenced by eris_ifu_dist_wave().