ERIS Pipeline Reference Manual 1.9.2
Functions
Lambda Correction for IFU Spectra

Functions

cpl_polynomial * eris_ifu_lcorr_get (cpl_imagelist *cube, hdrl_imagelist *hdrlCube, const cpl_propertylist *header, cpl_vector *peaks, const int pfit_order)
 Create wavelength correction polynomial from IFU cube using OH lines.
 
cpl_bivector * eris_ifu_lcorr_extract_spectrum (const cpl_imagelist *cube, const cpl_propertylist *header, const double min_frac, const cpl_vector *range)
 Extract integrated spectrum from IFU cube for brightest spaxels.
 
cpl_image * eris_ifu_lcorr_create_object_mask (const cpl_imagelist *cube, double min_frac, const cpl_vector *lambda, const cpl_vector *range)
 Create spaxel selection mask for spectrum extraction.
 
cpl_vector * eris_ifu_lcorr_create_lambda_vector (const cpl_propertylist *header)
 Create wavelength vector from FITS header WCS keywords.
 
cpl_bivector * eris_ifu_lcorr_read_OH_reference_spectrum (const char *filename, cpl_size ext_number)
 Read OH reference spectrum from FITS file.
 
cpl_array * eris_ifu_lcorr_get_peak_positions (const cpl_bivector *spectrum, double min_frac, cpl_vector *range)
 Detect emission line peak positions in a spectrum.
 
cpl_vector * eris_ifu_lcorr_get_peak_lambdas (const cpl_bivector *spectrum, double min_frac, cpl_vector *range)
 Detect and refine emission line peak wavelengths using Gaussian fitting.
 
int gauss1d_fnc (const double x[], const double a[], double *result)
 define a Gaussian profile
 
int gauss1d_fncd (const double x[], const double a[], double result[])
 define a Gaussian profile
 
double fit_peak (const cpl_bivector *spectrum, const cpl_size size, double lambda_in, int half_width, double *sigma_par)
 fit a peak
 
cpl_polynomial * eris_ifu_lcorr_crosscorrelate_spectra (cpl_bivector *object, cpl_vector *peaks, ifsBand bandId, const int pfit_order)
 cross-correlate two input spectra
 
void eris_ifu_lcorr_open_debug_file (const char *filename)
 open ASCII file to hold debug results
 
void eris_ifu_lcorr_close_debug_file (void)
 close ASCII file that hold debug results
 

Detailed Description

This module provides functions for wavelength (lambda) correction of IFU spectra using OH sky line emission features. The correction compensates for flexure-induced wavelength shifts by cross-correlating observed OH lines with reference positions.

The typical workflow is:

  1. Extract an integrated spectrum from the IFU cube
  2. Detect OH emission line peaks in the extracted spectrum
  3. Cross-correlate observed peaks with reference OH line positions
  4. Fit a polynomial correction that maps observed wavelengths to true wavelengths
  5. Apply the correction to the entire wavelength solution

The correction polynomial can be of varying degree (typically 0-3), with higher degrees allowing for non-linear wavelength distortions but requiring more detected lines.

Function Documentation

◆ eris_ifu_lcorr_close_debug_file()

void eris_ifu_lcorr_close_debug_file ( void  )

close ASCII file that hold debug results

Definition at line 1433 of file eris_ifu_lambda_corr.c.

◆ eris_ifu_lcorr_create_lambda_vector()

cpl_vector * eris_ifu_lcorr_create_lambda_vector ( const cpl_propertylist *  header)

Create wavelength vector from FITS header WCS keywords.

Constructs a wavelength vector using the WCS (World Coordinate System) properties of the spectral axis (axis 3) from a data cube's FITS header. Uses the standard FITS keywords NAXIS3, CRVAL3, CDELT3, and CRPIX3.

Parameters
headerProperty list (FITS header) containing WCS keywords
Returns
Vector of wavelengths in microns, or NULL on error
Note
The returned vector must be deallocated with cpl_vector_delete()
Required FITS keywords: NAXIS3, CRVAL3, CDELT3, CRPIX3
Wavelength for plane i is: lambda[i] = (i+1 - CRPIX3) * CDELT3 + CRVAL3

Definition at line 436 of file eris_ifu_lambda_corr.c.

References ASSURE, BRK_IF_NULL, CATCH, CATCH_MSG, and TRY.

Referenced by eris_ifu_dar_correction(), eris_ifu_lcorr_extract_spectrum(), and eris_ifu_sky_tweak().

◆ eris_ifu_lcorr_create_object_mask()

cpl_image * eris_ifu_lcorr_create_object_mask ( const cpl_imagelist *  cube,
double  min_frac,
const cpl_vector *  lambda,
const cpl_vector *  range 
)

Create spaxel selection mask for spectrum extraction.

For every spaxel, calculates median flux (optionally restricted to specific wavelength ranges) and creates a binary mask selecting the brightest fraction of spaxels. This mask is used to extract an integrated spectrum from the brightest regions of the field.

Parameters
cubeInput data cube (imagelist)
min_fracFraction of brightest spaxels to select (0.0-1.0, e.g., 0.8 for top 80%)
lambdaWavelength vector corresponding to cube's spectral axis, or NULL
rangeWavelength ranges for flux calculation (NULL for all wavelengths) Format: [min1, max1, min2, max2, ...] pairs in microns
Returns
Binary mask image (1.0=selected, 0.0=rejected), or NULL on error
Note
Either both lambda and range must be provided, or both must be NULL
The range vector must have an even number of elements (lower/upper pairs)
Each lambda entry corresponds to one plane in the cube's z-axis
The returned image must be deallocated with cpl_image_delete()
When range is specified, only wavelengths within the specified range(s) contribute to the median flux calculation for spaxel selection

Definition at line 283 of file eris_ifu_lambda_corr.c.

References ASSURE, BRK_IF_ERROR, BRK_IF_NULL, CATCH, CATCH_MSG, eris_ifu_mask_nans_in_cube(), and TRY.

Referenced by eris_ifu_lcorr_extract_spectrum(), eris_ifu_plot_cube_background(), and eris_ifu_sky_tweak().

◆ eris_ifu_lcorr_crosscorrelate_spectra()

cpl_polynomial * eris_ifu_lcorr_crosscorrelate_spectra ( cpl_bivector *  object,
cpl_vector *  peaks,
ifsBand  bandId,
const int  pfit_order 
)

cross-correlate two input spectra

Parameters
objectinput spectrum
peakspeaks
bandIdband setup
pfit_order
Returns
polynomial with solution in case of success, NULL otherwise.

Definition at line 1139 of file eris_ifu_lambda_corr.c.

References ASSURE, BRK_IF_ERROR, BRK_IF_NULL, CATCH, CATCH_MSG, CHECK_ERROR_STATE, eris_ifu_get_band_resolution(), fit_peak(), and TRY.

Referenced by eris_ifu_lcorr_get().

◆ eris_ifu_lcorr_extract_spectrum()

cpl_bivector * eris_ifu_lcorr_extract_spectrum ( const cpl_imagelist *  cube,
const cpl_propertylist *  header,
const double  min_frac,
const cpl_vector *  range 
)

Extract integrated spectrum from IFU cube for brightest spaxels.

Creates an integrated spectrum by selecting the brightest spaxels in the cube (based on median flux) and summing their spectral contributions. This produces a high signal-to-noise spectrum suitable for OH line detection and wavelength calibration.

Parameters
cubeInput data cube (imagelist with spectral axis)
headerFITS header containing WCS keywords (NAXIS3, CRVAL3, CDELT3, CRPIX3)
min_fracFraction of brightest spaxels to include (e.g., 0.8 = brightest 80%)
rangeOptional wavelength ranges to consider for spaxel selection (NULL for all) Format: [min1, max1, min2, max2, ...] in microns
Returns
Bivector with X=wavelengths (microns) and Y=integrated flux, or NULL on error
Note
The returned bivector must be deallocated with cpl_bivector_delete()
Spaxel selection is based on median flux across the specified wavelength range(s)
The wavelength vector is computed from WCS keywords in the header

Definition at line 213 of file eris_ifu_lambda_corr.c.

References ASSURE, BRK_IF_ERROR, BRK_IF_NULL, CATCH, CATCH_MSG, eris_ifu_extract_spec(), eris_ifu_lcorr_create_lambda_vector(), eris_ifu_lcorr_create_object_mask(), and TRY.

Referenced by eris_ifu_lcorr_get().

◆ eris_ifu_lcorr_get()

cpl_polynomial * eris_ifu_lcorr_get ( cpl_imagelist *  cube,
hdrl_imagelist *  hdrlCube,
const cpl_propertylist *  header,
cpl_vector *  peaks,
const int  pfit_order 
)

Create wavelength correction polynomial from IFU cube using OH lines.

This is the main entry point for lambda correction. It extracts an integrated spectrum from the input cube, detects OH emission line peaks, and cross-correlates them with reference line positions to derive a wavelength correction polynomial.

Parameters
cubeInput data cube (CPL imagelist format), set to NULL if hdrlCube is provided
hdrlCubeInput data cube (HDRL imagelist format), set to NULL if cube is provided
headerFITS header containing WCS and instrument information
peaksVector containing reference OH line wavelengths (in microns)
pfit_orderOrder of polynomial fit (0=constant shift, 1=linear, 2=quadratic, etc.)
Returns
Polynomial representing the wavelength correction, or NULL on error
Note
Exactly one of cube or hdrlCube must be non-NULL
The returned polynomial must be deallocated with cpl_polynomial_delete()
The correction polynomial maps observed wavelengths to corrected wavelengths: lambda_corrected = lambda_observed + polynomial(lambda_observed)
A polynomial order of 0 is recommended for K-band to avoid extrapolation errors
Higher orders (1-3) may improve accuracy in H and J bands with many detected lines

Definition at line 84 of file eris_ifu_lambda_corr.c.

References ASSURE, BRK_IF_ERROR, BRK_IF_NULL, CATCH, CHECK_ERROR_STATE, eris_ifu_get_band(), eris_ifu_lcorr_crosscorrelate_spectra(), eris_ifu_lcorr_extract_spectrum(), eris_ifu_mask_nans_in_cube(), hdrl_image_get_image(), hdrl_imagelist_get(), hdrl_imagelist_get_size(), and TRY.

Referenced by eris_ifu_jitter_process_exposures().

◆ eris_ifu_lcorr_get_peak_lambdas()

cpl_vector * eris_ifu_lcorr_get_peak_lambdas ( const cpl_bivector *  spectrum,
double  min_frac,
cpl_vector *  range 
)

Detect and refine emission line peak wavelengths using Gaussian fitting.

Identifies emission line peaks in the input spectrum and refines their positions by fitting Gaussian profiles. Outlier peaks are rejected based on statistical analysis of fitted wavelength shifts and line widths (sigma). This produces a clean set of well-measured line wavelengths suitable for wavelength calibration.

Parameters
spectrumInput spectrum as bivector (X=wavelength in microns, Y=flux)
min_fracMinimum flux threshold as fraction of maximum flux (0.0-1.0)
rangeOptional wavelength ranges to search (NULL for all wavelengths) Format: [min1, max1, min2, max2, ...] pairs in microns
Returns
Vector of refined peak wavelengths in microns, or NULL on error
Note
The returned vector must be deallocated with cpl_vector_delete()
Peaks too close together (< 2 * spectral resolution) are rejected
Outliers are identified using 3-sigma clipping on wavelength shift and line width
Gaussian fitting uses a window of ±5 pixels around each initial peak position
Failed Gaussian fits result in peak rejection

Definition at line 729 of file eris_ifu_lambda_corr.c.

References ASSURE, BRK_IF_ERROR, BRK_IF_NULL, BRK_WITH_ERROR, CATCH, CHECK_ERROR_STATE, eris_ifu_free_int_array(), eris_ifu_free_vector(), eris_ifu_lcorr_get_peak_positions(), fit_peak(), and TRY.

Referenced by eris_ifu_jitter_processSof().

◆ eris_ifu_lcorr_get_peak_positions()

cpl_array * eris_ifu_lcorr_get_peak_positions ( const cpl_bivector *  spectrum,
double  min_frac,
cpl_vector *  range 
)

Detect emission line peak positions in a spectrum.

Identifies local maxima (peaks) in the input spectrum that exceed a minimum flux threshold. Peaks can be restricted to specified wavelength ranges. The algorithm finds peaks by detecting sign changes in the first derivative (positive to negative transition).

Parameters
spectrumInput spectrum as bivector (X=wavelength, Y=flux)
min_fracMinimum flux threshold as fraction of maximum flux (0.0-1.0)
rangeOptional wavelength ranges to search (NULL for all wavelengths) Format: [min1, max1, min2, max2, ...] pairs in microns
Returns
Array of peak indices (positions in the spectrum vector), or NULL on error
Note
The returned array must be deallocated with cpl_array_delete()
Only flux values above (max_flux * min_frac) are considered
A peak is identified where derivative changes from positive to negative
If range is specified, peaks outside all ranges are ignored
The range vector must have an even number of elements

Definition at line 602 of file eris_ifu_lambda_corr.c.

References ASSURE, BRK_IF_ERROR, BRK_IF_NULL, CATCH, CATCH_MSG, and TRY.

Referenced by eris_ifu_lcorr_get_peak_lambdas().

◆ eris_ifu_lcorr_open_debug_file()

void eris_ifu_lcorr_open_debug_file ( const char *  filename)

open ASCII file to hold debug results

Parameters
filenameinput filename

Definition at line 1423 of file eris_ifu_lambda_corr.c.

◆ eris_ifu_lcorr_read_OH_reference_spectrum()

cpl_bivector * eris_ifu_lcorr_read_OH_reference_spectrum ( const char *  filename,
cpl_size  ext_number 
)

Read OH reference spectrum from FITS file.

Loads a reference OH sky emission spectrum from a FITS file and constructs a bivector with wavelength and flux values. The wavelength scale is derived from WCS keywords in the file's header.

Parameters
filenamePath to FITS file containing the reference spectrum
ext_numberFITS extension number to read (0 for primary HDU)
Returns
Bivector with X=wavelengths (microns) and Y=flux, or NULL on error
Note
The returned bivector must be deallocated with cpl_bivector_delete()
The file must contain FITS keywords: NAXIS1, CRVAL1, CDELT1, CRPIX1
CRPIX1 can be integer, float, or double type
Wavelength for pixel i is: lambda[i] = CRVAL1 + (i + 1 - CRPIX1) * CDELT1

Definition at line 499 of file eris_ifu_lambda_corr.c.

References ASSURE, BRK_IF_NULL, BRK_WITH_ERROR_MSG, CATCH, CATCH_MSG, CHECK_ERROR_STATE, and TRY.

Referenced by eris_ifu_jitter_processSof().

◆ fit_peak()

double fit_peak ( const cpl_bivector *  spectrum,
const cpl_size  size,
double  lambda_in,
int  half_width,
double *  sigma_par 
)

fit a peak

Parameters
spectruminput spectrum
sizesize of input spectrum
lambda_ininput lambda near which peak is found
half_widthinput half_with of range where fit is done
sigma_paroutput sigma
Returns
position of peak maximum, 0 in case of failure.

Definition at line 1012 of file eris_ifu_lambda_corr.c.

References gauss1d_fnc(), and gauss1d_fncd().

Referenced by eris_ifu_lcorr_crosscorrelate_spectra(), and eris_ifu_lcorr_get_peak_lambdas().

◆ gauss1d_fnc()

int gauss1d_fnc ( const double  x[],
const double  a[],
double *  result 
)

define a Gaussian profile

Parameters
xFile name of input FITS file holding the reference spectrum
aminimum fraction
resultGaussian profile
Returns
1 in case of success, 0 otherwise.

Definition at line 940 of file eris_ifu_lambda_corr.c.

Referenced by fit_peak().

◆ gauss1d_fncd()

int gauss1d_fncd ( const double  x[],
const double  a[],
double  result[] 
)

define a Gaussian profile

Parameters
xFile name of input FITS file holding the reference spectrum
aminimum fraction
resultGaussian profile
Returns
1 in case of success, 0 otherwise.

Definition at line 969 of file eris_ifu_lambda_corr.c.

Referenced by fit_peak().