High-Level Data Reduction Library: Spectrum 1D

High-Level Data Reduction Library 1.6.0 High-Level data reduction routines for ESO pipelines

Loading...
Searching...
No Matches
Data Structures | Typedefs | Functions | Variables
Spectrum 1D

This module defines the hdrl_spectrum1D data structure, provides basic functionalities for it (constructors, destructor, operators). More...

## Data Structures
struct | hdrl_spectrum1D_shift_parameter

## Typedefs
typedef cpl_error_code(* | operate_image_mutable) (hdrl_image *self, const hdrl_image *other)
typedef cpl_error_code(* | operate_image_scalar_mutable) (hdrl_image *self, hdrl_value scalar)

## Functions
hdrl_error_t | estimate_noise_window (const hdrl_data_t *flux, const cpl_binary *msk, cpl_size start, cpl_size stop, const cpl_size sz)
| Estimate the noise in the pixels between [start, stop]. The noise calculation is done using the formula from: Stoehr, F. et al. DER SNR: A Simple & General Spectroscopic Signal-to-Noise Measurement Algorithm.
cpl_image * | estimate_noise_DER_SNR (const hdrl_data_t *flux_in, const cpl_binary *msk_in, const cpl_array *wavelengths, const cpl_size length, const cpl_size half_window)
| For every pixel in position i in img_arg, the function estimates the noise using the pixels in the window [i - half_window, i + half_window]. For details on the calculation inside the window, see estimate_noise_window()
hdrl_spectrum1D * | hdrl_spectrum1D_create (const cpl_image *arg_flux, const cpl_image *arg_flux_e, const cpl_array *wavelength, hdrl_spectrum1D_wave_scale wave_scale)
| hdrl_spectrum1D default constructor
hdrl_spectrum1D * | hdrl_spectrum1D_create_analytic (calculate_analytic_spectrum_point func, const cpl_array *wavelength, hdrl_spectrum1D_wave_scale scale)
| hdrl_spectrum1D constructor in the case of a spectrum defined by an analytical function
hdrl_spectrum1D * | hdrl_spectrum1D_create_error_free (const cpl_image *arg_flux, const cpl_array *wavelength, hdrl_spectrum1D_wave_scale scale)
| hdrl_spectrum1D constructor in the case of error-free spectrum (i.e. the error on the flux is zero for every wavelengths).
hdrl_spectrum1D * | hdrl_spectrum1D_create_error_DER_SNR (const cpl_image *arg_flux, cpl_size half_window, const cpl_array *wavelength, hdrl_spectrum1D_wave_scale scale)
| hdrl_spectrum1D constructor when no error information is available, in this case we use DER_SNR to esimate the error. Please refer to the documentation of the function estimate_noise_DER_SNR().
hdrl_spectrum1D * | hdrl_spectrum1D_duplicate (const hdrl_spectrum1D *self)
| hdrl_spectrum1D copy constructor
void | hdrl_spectrum1D_delete (hdrl_spectrum1D **p_self)
| hdrl_spectrum1D destructor
cpl_size | hdrl_spectrum1D_get_size (const hdrl_spectrum1D *self)
| hdrl_spectrum1D getter for size
const hdrl_image * | hdrl_spectrum1D_get_flux (const hdrl_spectrum1D *self)
| hdrl_spectrum1D getter flux
hdrl_spectrum1D_wavelength | hdrl_spectrum1D_get_wavelength (const hdrl_spectrum1D *self)
| hdrl_spectrum1D getter for wavelengths
hdrl_spectrum1D_wave_scale | hdrl_spectrum1D_get_scale (const hdrl_spectrum1D *self)
| hdrl_spectrum1D getter for scale
hdrl_value | hdrl_spectrum1D_get_flux_value (const hdrl_spectrum1D *self, int idx, int *rej)
| hdrl_spectrum1D getter for a flux value
hdrl_data_t | hdrl_spectrum1D_get_wavelength_value (const hdrl_spectrum1D *self, int idx, int *rej)
| hdrl_spectrum1D getter for a wavelength value
hdrl_spectrum1D * | hdrl_spectrum1D_div_spectrum_create (const hdrl_spectrum1D *num, const hdrl_spectrum1D *den)
| divide one spectrum by another spectrum
hdrl_spectrum1D * | hdrl_spectrum1D_mul_spectrum_create (const hdrl_spectrum1D *f1, const hdrl_spectrum1D *f2)
| multiply one spectrum by another spectrum
hdrl_spectrum1D * | hdrl_spectrum1D_add_spectrum_create (const hdrl_spectrum1D *f1, const hdrl_spectrum1D *f2)
| sum one spectrum to another spectrum
hdrl_spectrum1D * | hdrl_spectrum1D_sub_spectrum_create (const hdrl_spectrum1D *f1, const hdrl_spectrum1D *f2)
| subtract two spectra
cpl_error_code | hdrl_spectrum1D_div_spectrum (hdrl_spectrum1D *self, const hdrl_spectrum1D *other)
| divide one spectrum by another spectrum
cpl_error_code | hdrl_spectrum1D_mul_spectrum (hdrl_spectrum1D *self, const hdrl_spectrum1D *other)
| multiply one spectrum by another spectrum
cpl_error_code | hdrl_spectrum1D_add_spectrum (hdrl_spectrum1D *self, const hdrl_spectrum1D *other)
| sum two spectra
cpl_error_code | hdrl_spectrum1D_sub_spectrum (hdrl_spectrum1D *self, const hdrl_spectrum1D *other)
| subtract two spectra
hdrl_spectrum1D * | hdrl_spectrum1D_div_scalar_create (const hdrl_spectrum1D *self, hdrl_value scalar_operator)
| divide a spectrum by a scalar
hdrl_spectrum1D * | hdrl_spectrum1D_mul_scalar_create (const hdrl_spectrum1D *self, hdrl_value scalar_operator)
| multiply a spectrum by a scalar
hdrl_spectrum1D * | hdrl_spectrum1D_add_scalar_create (const hdrl_spectrum1D *self, hdrl_value scalar_operator)
| add a scalar to a spectrum
hdrl_spectrum1D * | hdrl_spectrum1D_sub_scalar_create (const hdrl_spectrum1D *self, hdrl_value scalar_operator)
| subtract a scalar from a spectrum
hdrl_spectrum1D * | hdrl_spectrum1D_pow_scalar_create (const hdrl_spectrum1D *self, hdrl_value scalar_operator)
| subtract a scalar from a spectrum
hdrl_spectrum1D * | hdrl_spectrum1D_exp_scalar_create (const hdrl_spectrum1D *self, hdrl_value scalar_operator)
| subtract a scalar from a spectrum
cpl_error_code | hdrl_spectrum1D_div_scalar (hdrl_spectrum1D *self, hdrl_value scalar_operator)
| computes the elementwise division of a spectrum by a scalar, the self parameter is modified
cpl_error_code | hdrl_spectrum1D_mul_scalar (hdrl_spectrum1D *self, hdrl_value scalar_operator)
| computes the elementwise multiplication of a spectrum by a scalar, the self parameter is modified
cpl_error_code | hdrl_spectrum1D_add_scalar (hdrl_spectrum1D *self, hdrl_value scalar_operator)
| computes the elementwise addition of a spectrum by a scalar, the self parameter is modified
cpl_error_code | hdrl_spectrum1D_sub_scalar (hdrl_spectrum1D *self, hdrl_value scalar_operator)
| computes the elementwise subtraction of a spectrum by a scalar, the self parameter is modified
cpl_error_code | hdrl_spectrum1D_pow_scalar (hdrl_spectrum1D *self, hdrl_value scalar_operator)
| computes the elementwise power of the flux to the scalar, the self parameter is modified
cpl_error_code | hdrl_spectrum1D_exp_scalar (hdrl_spectrum1D *self, hdrl_value scalar_operator)
| computes the elementwise power of the scalar to the flux, the self parameter is modified
cpl_error_code | hdrl_spectrum1D_wavelength_mult_scalar_linear (hdrl_spectrum1D *self, hdrl_data_t scale_linear)
| computes the elementwise multiplication of the scalar for the wavelength. The scalar is assumed to be expressed in linear units. the self parameter is modified
hdrl_spectrum1D * | hdrl_spectrum1D_wavelength_mult_scalar_linear_create (const hdrl_spectrum1D *self, hdrl_data_t scale_linear)
| computes the elementwise multiplication of the scalar for the wavelength. The scalar is assumed to be expressed in linear units. Self is unchanged and the function returns a newly allocated spectrum.
cpl_error_code | hdrl_spectrum1D_wavelength_shift (hdrl_spectrum1D *self, hdrl_data_t shift)
| computes the elementwise shift of the wavelength by the shift parameter. The self parameter is modified
hdrl_spectrum1D * | hdrl_spectrum1D_wavelength_shift_create (const hdrl_spectrum1D *self, hdrl_data_t shift)
| computes the elementwise shift of the wavelength by the shift parameter.
cpl_error_code | hdrl_spectrum1D_wavelength_convert_to_linear (hdrl_spectrum1D *self)
| converts the wavelength scale to linear.
hdrl_spectrum1D * | hdrl_spectrum1D_wavelength_convert_to_linear_create (const hdrl_spectrum1D *self)
| converts the wavelength scale to linear.
cpl_error_code | hdrl_spectrum1D_wavelength_convert_to_log (hdrl_spectrum1D *self)
| converts the wavelength scale to log. If the spectrum is already in log scale nothing is done.
hdrl_spectrum1D * | hdrl_spectrum1D_wavelength_convert_to_log_create (const hdrl_spectrum1D *self)
| converts the wavelength scale to log. It returns a modified version of self. self is not modified. If self is already in log, the function is equivalent to a duplication.
hdrl_spectrum1D * | hdrl_spectrum1D_select_wavelengths (const hdrl_spectrum1D *self, const cpl_bivector *windows, const cpl_boolean is_internal)
| the function selects or discards flux values according to whether the value of the corresponding wavelength belongs to the interval [min_lambda, max_lambda].
hdrl_spectrum1D * | hdrl_spectrum1D_reject_pixels (const hdrl_spectrum1D *self, const cpl_array *bad_samples)
| For every i-th element in bad_samples having value CPL_TRUE, the i-th pixel in the 1D spectrum is marked as bad.
cpl_table * | hdrl_spectrum1D_convert_to_table (const hdrl_spectrum1D *self, const char *flux_col_name, const char *wavelength_col_name, const char *flux_e_col_name, const char *flux_bpm_col_name)
| converts a spectrum in a table.
cpl_error_code | hdrl_spectrum1D_append_to_table (const hdrl_spectrum1D *self, cpl_table *dest, const char *flux_col_name, const char *wavelength_col_name, const char *flux_e_col_name, const char *flux_bpm_col_name)
| append a spectrum to a table.
hdrl_spectrum1D * | hdrl_spectrum1D_convert_from_table (const cpl_table *self, const char *flux_col_name, const char *wavelength_col_name, const char *flux_e_col_name, const char *flux_bpm_col_name, hdrl_spectrum1D_wave_scale scale)
| convert a table to a spectrum
void | hdrl_spectrum1D_save (const hdrl_spectrum1D *s, const char *fname)
cpl_boolean | hdrl_spectrum1D_are_wavelengths_compatible (const cpl_array *w1, const cpl_array *w2)
| checks if two wavelengths array are defined on the same wavelengths.
cpl_boolean | hdrl_spectrum1D_are_spectra_compatible (const hdrl_spectrum1D_wavelength *s1, const hdrl_spectrum1D_wavelength *s2)
| checks if two spectrum wavelengths are equal.
cpl_boolean | hdrl_spectrum1D_is_uniformly_sampled (const hdrl_spectrum1D *self, double *bin)
| checks if the spectrum is defined on uniformly sampled wavelengths.
hdrl_parameter * | hdrl_spectrum1D_resample_interpolate_parameter_create (const hdrl_spectrum1D_interpolation_method method)
| constructor for the hdrl_parameter in the case of interpolation
hdrl_parameter * | hdrl_spectrum1D_resample_integrate_parameter_create (void)
| constructor for the hdrl_parameter in the case of integration
hdrl_parameter * | hdrl_spectrum1D_resample_interpolate_parameter_parse_parlist (const cpl_parameterlist *parlist, const char *prefix)
cpl_parameterlist * | hdrl_spectrum1D_resample_interpolate_parameter_create_parlist (const char *base_context, const char *prefix, const char *method_def)
hdrl_parameter * | hdrl_spectrum1D_resample_fit_parameter_create (const int k, const int nCoeff)
| constructor for the hdrl_parameter in the case of interpolation
hdrl_parameter * | hdrl_spectrum1D_resample_fit_windowed_parameter_create (const int k, const int nCoeff, const long window, const double factor)
| constructor for the hdrl_parameter in the case of interpolation
cpl_error_code | hdrl_resample_parameter_verify (const hdrl_parameter *par)
hdrl_spectrum1D * | hdrl_spectrum1D_resample (const hdrl_spectrum1D *self, const hdrl_spectrum1D_wavelength *waves, const hdrl_parameter *par)
| resample a hdrl_spectrum1D on the wavelengths contained in waves
hdrl_spectrum1D * | hdrl_spectrum1D_resample_on_array (const hdrl_spectrum1D *self, const cpl_array *waves, const hdrl_parameter *par)
| resample a hdrl_spectrum1D on the wavelengths contained in waves
cpl_size | hdrl_spectrum1D_resample_filter_dups_and_substitute_with_median (double *x, double *y1, double *y2, cpl_size sample_len)
hdrl_xcorrelation_result * | hdrl_spectrum1D_compute_shift_xcorrelation (const hdrl_spectrum1D *s1, const hdrl_spectrum1D *s2, cpl_size half_win, const cpl_boolean normalize)
| The function computes the shift between the two spectra.
hdrl_parameter * | hdrl_spectrum1D_shift_fit_parameter_create (const hdrl_data_t wguess, const hdrl_data_t range_wmin, const hdrl_data_t range_wmax, const hdrl_data_t fit_wmin, const hdrl_data_t fit_wmax, const hdrl_data_t fit_half_win)
| The function create a hdrl_spectrum1D_shift_parameter to be used in hdrl_spectrum1D_compute_shift_fit.
hdrl_data_t | hdrl_spectrum1D_compute_shift_fit (const hdrl_spectrum1D *obs, const hdrl_parameter *par)
| The function compute the shift due to radial velocity. If wguess is the reference line and wfound is its position in the obs spectrum, the function returns (wfound - wguess) / wguess. The algorithm generate a smoothed fit of the spectrum, between [range_wmin, range_wmax] but the wavelengths between [fit_wim, fit_wmax] are ignored when fitting. obs is then divided by the fitted spectrum. The ratio is then smoothed again via fitting inside the window [wguess - fit_half_win, wguess + fit_half_win]. The wavelength corresponding to the minimum value is wfound.
cpl_size | convert_to_matrix_and_vector (cpl_matrix **x, cpl_vector **values, const hdrl_spectrum1D *s)
hdrl_spectrum1Dlist * | hdrl_spectrum1Dlist_new (void)
| hdrl_spectrum1Dlist default constructor
hdrl_spectrum1Dlist * | hdrl_spectrum1Dlist_duplicate (const hdrl_spectrum1Dlist *l)
| hdrl_spectrum1Dlist copy-constructor
hdrl_spectrum1Dlist * | hdrl_spectrum1Dlist_wrap (hdrl_spectrum1D **self, const cpl_size sz)
| hdrl_spectrum1Dlist wrapper
hdrl_spectrum1D * | hdrl_spectrum1Dlist_get (hdrl_spectrum1Dlist *self, const cpl_size idx)
| hdrl_spectrum1Dlist getter of the i-th element
const hdrl_spectrum1D * | hdrl_spectrum1Dlist_get_const (const hdrl_spectrum1Dlist *self, const cpl_size idx)
| hdrl_spectrum1Dlist getter of the i-th element
cpl_error_code | hdrl_spectrum1Dlist_set (hdrl_spectrum1Dlist *self, hdrl_spectrum1D *s, const cpl_size idx)
| hdrl_spectrum1Dlist setter of the i-th element
hdrl_spectrum1D * | hdrl_spectrum1Dlist_unset (hdrl_spectrum1Dlist *self, const cpl_size idx)
| hdrl_spectrum1Dlist remove of the i-th element
void | hdrl_spectrum1Dlist_delete (hdrl_spectrum1Dlist *l)
| hdrl_spectrum1Dlist destructor
cpl_size | hdrl_spectrum1Dlist_get_size (const hdrl_spectrum1Dlist *l)
| hdrl_spectrum1Dlist getter for size
cpl_error_code | hdrl_spectrum1Dlist_collapse (const hdrl_spectrum1Dlist *list, const hdrl_parameter *stacking_par, const cpl_array *wlengths, const hdrl_parameter *resample_par, const cpl_boolean mark_bpm_in_interpolation, hdrl_spectrum1D **result, cpl_image **contrib, hdrl_imagelist **resampled_and_aligned_fluxes)
| collapsing a hdrl_spectrum1Dlist. The spectra in list are first resampled on the wavelengths wlengths. The resampling method is regulated by the resample_par. For more information on samplig_par see hdrl_spectrum1D_resample_on_array. The resampled fluxes are collapsed as in hdrl_imagelist_collapse and the collapsing is regulated by the parameter stacking_par. For more information on stacking_par please see the documentation of hdrl_imagelist_collapse.

## Variables
const double | wave_delta = 1.e-6

## Detailed Description

This module defines the hdrl_spectrum1D data structure, provides basic functionalities for it (constructors, destructor, operators).

constructors

errors

error conditions

calculation

functions

interpolation

for interpolation

fitting. We first resample .2 forward and then resample .2 backward. We expect that the flux of this 2nd spectrum has very similar errors to the original one.

## Typedef Documentation

## ◆ operate_image_mutable

typedef cpl_error_code(* operate_image_mutable) (hdrl_image *self, const hdrl_image *other)

## ◆ operate_image_scalar_mutable

typedef cpl_error_code(* operate_image_scalar_mutable) (hdrl_image *self, hdrl_value scalar)

## Function Documentation

## ◆ convert_to_matrix_and_vector()

cpl_size convert_to_matrix_and_vector | ( | cpl_matrix ** | x,
|  | cpl_vector ** | values,
|  | const hdrl_spectrum1D * | s
| ) |  |

## ◆ estimate_noise_DER_SNR()

cpl_image * estimate_noise_DER_SNR | ( | const hdrl_data_t * | flux_in,
|  | const cpl_binary * | msk_in,
|  | const cpl_array * | wavelengths,
|  | const cpl_size | length,
|  | const cpl_size | half_window
| ) |  |

For every pixel in position i in img_arg, the function estimates the noise using the pixels in the window [i - half_window, i + half_window]. For details on the calculation inside the window, see estimate_noise_window()

Parameters

  flux_in | input flux
  msk_in | bad pixels mask
  wavelengths | wavelengths of the spectrum
  length | length of the flux and msl
  half_window | half window used to calculate the noise for each pixel.

Returns
  the estimate standard deviation for each pixel or NULL in case of error.

Possible cpl-error-code set in this function (which also implies that NULL is returned):

- CPL_ERROR_NULL_INPUT: if any among flux_in, msk_in or wavelengths are NULL
- CPL_ERROR_INCOMPATIBLE_INPUT: if half_window < 2 or length > 4

## ◆ estimate_noise_window()

hdrl_error_t estimate_noise_window | ( | const hdrl_data_t * | flux,
|  | const cpl_binary * | msk,
|  | cpl_size | start,
|  | cpl_size | stop,
|  | const cpl_size | sz
| ) |  |

Estimate the noise in the pixels between [start, stop]. The noise calculation is done using the formula from: Stoehr, F. et al. DER SNR: A Simple & General Spectroscopic Signal-to-Noise Measurement Algorithm.

Parameters

  flux | Input Flux
  msk | Bad Pixel Mask
  start | First Pixel
  stop | Last Pixel
  sz | Length of the flux (must be the same for msk)

Returns
  estimated noise for the given window, NAN is returned in case of error or if there are not enough non bad pixels to execute the calculation.

Possible cpl-error-code set in this function (which also implies that NAN is returned):

- CPL_ERROR_NULL_INPUT: if flux or msk are NULL
- CPL_ERROR_INCOMPATIBLE_INPUT: if start, stop and size are either not compatible with each other or if the resulting window is too small to calculate the noise (there must be at least 4 pixels between start and stop).

## ◆ hdrl_resample_parameter_verify()

cpl_error_code hdrl_resample_parameter_verify | ( | const hdrl_parameter * | par | ) |

## ◆ hdrl_spectrum1D_add_scalar()

cpl_error_code hdrl_spectrum1D_add_scalar | ( | hdrl_spectrum1D * | self,
|  | hdrl_value | scalar_operator
| ) |  |

computes the elementwise addition of a spectrum by a scalar, the self parameter is modified

Parameters

  self | spectrum
  scalar_operator | scalar factor

Returns
  error code, for possible return codes see hdrl_image_add_scalar

## ◆ hdrl_spectrum1D_add_scalar_create()

hdrl_spectrum1D * hdrl_spectrum1D_add_scalar_create | ( | const hdrl_spectrum1D * | self,
|  | hdrl_value | scalar_operator
| ) |  |

add a scalar to a spectrum

Parameters

  self | spectrum
  scalar_operator | scalar factor

Returns
  a newly created spectrum, whose flux is calculated adding every sample of self to scalar_operator. Returns NULL in case of error.

Possible cpl-error-code set in this function: hdrl_image_add_scalar

## ◆ hdrl_spectrum1D_add_spectrum()

cpl_error_code hdrl_spectrum1D_add_spectrum | ( | hdrl_spectrum1D * | self,
|  | const hdrl_spectrum1D * | other
| ) |  |

sum two spectra

Parameters

  self | first factor, it is mutated to contain self+other
  other | second factor

Returns
  error code, for possible return codes see hdrl_image_add_image

## ◆ hdrl_spectrum1D_add_spectrum_create()

hdrl_spectrum1D * hdrl_spectrum1D_add_spectrum_create | ( | const hdrl_spectrum1D * | f1,
|  | const hdrl_spectrum1D * | f2
| ) |  |

sum one spectrum to another spectrum

void

Parameters

  f1 | factor 1
  f2 | factor 2

Returns
  a newly allocated spectrum whose flux values are f1+f2, with error propagation.

Possible cpl-error-code set in this function: hdrl_image_add_image

## ◆ hdrl_spectrum1D_append_to_table()

cpl_error_code hdrl_spectrum1D_append_to_table | ( | const hdrl_spectrum1D * | self,
|  | cpl_table * | dest,
|  | const char * | flux_col_name,
|  | const char * | wavelength_col_name,
|  | const char * | flux_e_col_name,
|  | const char * | flux_bpm_col_name
| ) |  |

append a spectrum to a table.

Parameters

  self | spectrum
  dest | table
  flux_col_name | name of the column containing the flux
  wavelength_col_name | name of the column containing the wavelengths
  flux_e_col_name | name of the column containing the flux error
  flux_bpm_col_name | name of the column containing the flux bpm

Returns
  cpl_error_code, for error codes see cpl_table_wrap_double

If NULL is provided instead of a name, the corresponding column is not inserted in the table. At least one between wavelength_col_name and flux_col_name must be not NULL.

## ◆ hdrl_spectrum1D_are_spectra_compatible()

cpl_boolean hdrl_spectrum1D_are_spectra_compatible | ( | const hdrl_spectrum1D_wavelength * | s1,
|  | const hdrl_spectrum1D_wavelength * | s2
| ) |  |

checks if two spectrum wavelengths are equal.

Parameters

  s1 | first spectrum wavelength
  s2 | second spectrum wavelength

Returns
  CPL_TRUE if compatible, CPL_FALSE otherwise.

## ◆ hdrl_spectrum1D_are_wavelengths_compatible()

cpl_boolean hdrl_spectrum1D_are_wavelengths_compatible | ( | const cpl_array * | w1,
|  | const cpl_array * | w2
| ) |  |

checks if two wavelengths array are defined on the same wavelengths.

Parameters

  w1 | first wavelength array
  w2 | first wavelength array

Returns
  CPL_TRUE if compatible, CPL_FALSE otherwise.

## ◆ hdrl_spectrum1D_compute_shift_fit()

hdrl_data_t hdrl_spectrum1D_compute_shift_fit | ( | const hdrl_spectrum1D * | obs,
|  | const hdrl_parameter * | par
| ) |  |

The function compute the shift due to radial velocity. If wguess is the reference line and wfound is its position in the obs spectrum, the function returns (wfound - wguess) / wguess. The algorithm generate a smoothed fit of the spectrum, between [range_wmin, range_wmax] but the wavelengths between [fit_wim, fit_wmax] are ignored when fitting. obs is then divided by the fitted spectrum. The ratio is then smoothed again via fitting inside the window [wguess - fit_half_win, wguess + fit_half_win]. The wavelength corresponding to the minimum value is wfound.

Parameters

  obs | The spectrum the shift has to be computed on
  par | The shift parameter, see hdrl_spectrum1D_shift_fit_parameter_create

Returns
  (wfound - wguess) / wguess.

## ◆ hdrl_spectrum1D_compute_shift_xcorrelation()

hdrl_xcorrelation_result * hdrl_spectrum1D_compute_shift_xcorrelation | ( | const hdrl_spectrum1D * | s1,
|  | const hdrl_spectrum1D * | s2,
|  | cpl_size | half_win,
|  | const cpl_boolean | normalize
| ) |  |

The function computes the shift between the two spectra.

Parameters

  s1 | first spectrum
  s2 | second spectrum
  half_win | half window where the correlation will be calculated
  normalize | normalize mean and stdev in cross-correlation calculation

Returns
  estimation of the shift after gaussian fit.

Possible cpl-error-code set in this function:

- CPL_ERROR_NULL_INPUT: s1 or s2 is NULL;
- CPL_ERROR_INCOMPATIBLE_INPUT: if wavelengths are not uniformly sampled, or if the two spectra are not compatible;

## ◆ hdrl_spectrum1D_convert_from_table()

hdrl_spectrum1D * hdrl_spectrum1D_convert_from_table | ( | const cpl_table * | self,
|  | const char * | flux_col_name,
|  | const char * | wavelength_col_name,
|  | const char * | flux_e_col_name,
|  | const char * | flux_bpm_col_name,
|  | hdrl_spectrum1D_wave_scale | scale
| ) |  |

convert a table to a spectrum

Parameters

  self | table
  flux_col_name | name of the column containing the flux
  wavelength_col_name | name of the column containing the wavelengths
  flux_e_col_name | name of the column containing the flux error
  flux_bpm_col_name | name of the column containing the flux bpm
  scale | scale of the spectrum

Returns
  the newly allocated spectrum. NULL if error occurs. If NULL is provided instead of flux_e_col_name, the spectrum is assumed error free.

Possible cpl-error-code set in this function: see error free spectrum ctor

## ◆ hdrl_spectrum1D_convert_to_table()

cpl_table * hdrl_spectrum1D_convert_to_table | ( | const hdrl_spectrum1D * | self,
|  | const char * | flux_col_name,
|  | const char * | wavelength_col_name,
|  | const char * | flux_e_col_name,
|  | const char * | flux_bpm_col_name
| ) |  |

converts a spectrum in a table.

Parameters

  self | spectrum
  flux_col_name | name of the column containing the flux
  wavelength_col_name | name of the column containing the wavelengths
  flux_e_col_name | name of the column containing the flux error
  flux_bpm_col_name | name of the column containing the flux bpm

Returns
  the newly allocated table. NULL if error occurs.

If NULL is provided instead of a name, the corresponding column is not inserted in the table. At least one between wavelength_col_name and flux_col_name must be not NULL.

Possible cpl-error-code set in this function: see cpl_table_wrap_double

## ◆ hdrl_spectrum1D_create()

hdrl_spectrum1D * hdrl_spectrum1D_create | ( | const cpl_image * | arg_flux,
|  | const cpl_image * | arg_flux_e,
|  | const cpl_array * | wavelength,
|  | hdrl_spectrum1D_wave_scale | wave_scale
| ) |  |

hdrl_spectrum1D default constructor

Parameters

  arg_flux | flux with bpm
  arg_flux_e | error for the flux
  wavelength | wavelengths
  wave_scale | the scale of the wavelengths of the spectrum (logarithmic or linear)

Returns
  hdrl_spectrum1D or NULL on error

The constructor allocates memory of a hdrl_spectrum1D structure. The cpl_image(s) and the cpl_array are copied inside the newly allocated data structure. The bpm of arg_flux becomes the bpm of the spectrum.

Note
  providing a sorted, strictly monotonic increasing wavelength array will improve performance of DER_SNR calculation and resampling since no sorting will be required.

Possible cpl-error-code set in this function:

- CPL_ERROR_NULL_INPUT: if any of the images or array are NULL
- CPL_ERROR_INCOMPATIBLE_INPUT: if the sizes of images and array do not match, or if the height of the image is not 1.

## ◆ hdrl_spectrum1D_create_analytic()

hdrl_spectrum1D * hdrl_spectrum1D_create_analytic | ( | calculate_analytic_spectrum_point | func,
|  | const cpl_array * | wavelength,
|  | hdrl_spectrum1D_wave_scale | scale
| ) |  |

hdrl_spectrum1D constructor in the case of a spectrum defined by an analytical function

Parameters

  func | analytical function defining the spectrum
  wavelength | frequencies the flux is calculated on
  scale | the scale of the spectrum (logarithmic or linear)

Returns
  hdrl_spectrum1D or NULL on error

The constructor allocates memory of a hdrl_spectrum1D structure. The cpl_array is copied inside the newly allocated data structure. For every wavelength inside the CPL array flux and error are calculated using func.

Possible cpl-error-code set in this function:

- CPL_ERROR_NULL_INPUT: if any among the func or the array are NULL.

## ◆ hdrl_spectrum1D_create_error_DER_SNR()

hdrl_spectrum1D * hdrl_spectrum1D_create_error_DER_SNR | ( | const cpl_image * | arg_flux,
|  | cpl_size | half_window,
|  | const cpl_array * | wavelength,
|  | hdrl_spectrum1D_wave_scale | scale
| ) |  |

hdrl_spectrum1D constructor when no error information is available, in this case we use DER_SNR to esimate the error. Please refer to the documentation of the function estimate_noise_DER_SNR().

Parameters

  arg_flux | flux with bpm
  half_window | half window the DER_SNR is calculated on
  wavelength | frequencies
  scale | the scale of the spectrum (logarithmic or linear)

Returns
  hdrl_spectrum1D or NULL on error

The constructor allocates memory of a hdrl_spectrum1D structure. The cpl_array and the cpl_image are copied inside the newly allocated data structure. The flux error is calculated creating a window of 2 * half_window + 1 pixels around each flux pixel and then using the noise estimation used for DER_SNR calculation. The use of DER_SNR can increase the number of bad pixels, in the case of a good pixel surrounded by bad pixels. See estimate_noise_DER_SNR() for more details.

Possible cpl-error-code set in this function: see hdrl_spectrum1D_create()

## ◆ hdrl_spectrum1D_create_error_free()

hdrl_spectrum1D * hdrl_spectrum1D_create_error_free | ( | const cpl_image * | arg_flux,
|  | const cpl_array * | wavelength,
|  | hdrl_spectrum1D_wave_scale | scale
| ) |  |

hdrl_spectrum1D constructor in the case of error-free spectrum (i.e. the error on the flux is zero for every wavelengths).

Parameters

  arg_flux | flux with bpm
  wavelength | frequencies
  scale | the scale of the spectrum (logarithmic or linear)

Returns
  hdrl_spectrum1D or NULL on error

The constructor allocates memory of a hdrl_spectrum1D structure. The cpl_array and the cpl_image are copied inside the newly allocated data structure. The flux error is considered to be zero.

Possible cpl-error-code set in this function: see hdrl_spectrum1D_create()

## ◆ hdrl_spectrum1D_delete()

void hdrl_spectrum1D_delete | ( | hdrl_spectrum1D ** | p_self | ) |

hdrl_spectrum1D destructor

Parameters

  p_self | spectrum to delete.

If p_self is NULL or *p_self is NULL nothing is done.

## ◆ hdrl_spectrum1D_div_scalar()

cpl_error_code hdrl_spectrum1D_div_scalar | ( | hdrl_spectrum1D * | self,
|  | hdrl_value | scalar_operator
| ) |  |

computes the elementwise division of a spectrum by a scalar, the self parameter is modified

Parameters

  self | spectrum
  scalar_operator | scalar factor

Returns
  error code, for possible return codes see hdrl_image_div_scalar

## ◆ hdrl_spectrum1D_div_scalar_create()

hdrl_spectrum1D * hdrl_spectrum1D_div_scalar_create | ( | const hdrl_spectrum1D * | self,
|  | hdrl_value | scalar_operator
| ) |  |

divide a spectrum by a scalar

Parameters

  self | spectrum
  scalar_operator | scalar factor

Returns
  a newly created spectrum, whose flux is calculated dividing every sample of self by scalar_operator. Returns NULL in case of error.

Possible cpl-error-code set in this function: hdrl_image_div_scalar

## ◆ hdrl_spectrum1D_div_spectrum()

cpl_error_code hdrl_spectrum1D_div_spectrum | ( | hdrl_spectrum1D * | self,
|  | const hdrl_spectrum1D * | other
| ) |  |

divide one spectrum by another spectrum

Parameters

  self | numerator, it is mutated to contain self/other
  other | denumerator

Returns
  error code, for possible return codes see hdrl_image_div_image

## ◆ hdrl_spectrum1D_div_spectrum_create()

hdrl_spectrum1D * hdrl_spectrum1D_div_spectrum_create | ( | const hdrl_spectrum1D * | num,
|  | const hdrl_spectrum1D * | den
| ) |  |

divide one spectrum by another spectrum

Parameters

  num | numerator
  den | denumerator

Returns
  a newly allocated spectrum whose flux values are num/den, with error propagation.

Possible cpl-error-code set in this function: hdrl_image_div_image

## ◆ hdrl_spectrum1D_duplicate()

hdrl_spectrum1D * hdrl_spectrum1D_duplicate | ( | const hdrl_spectrum1D * | self | ) |

hdrl_spectrum1D copy constructor

Parameters

  self | spectrum that has to be duplicated

Returns
  a copy of self, return NULL if self was NULL

## ◆ hdrl_spectrum1D_exp_scalar()

cpl_error_code hdrl_spectrum1D_exp_scalar | ( | hdrl_spectrum1D * | self,
|  | hdrl_value | scalar_operator
| ) |  |

computes the elementwise power of the scalar to the flux, the self parameter is modified

Parameters

  self | spectrum
  scalar_operator | scalar factor

Returns
  error code, for possible return codes see hdrl_image_exp_scalar

## ◆ hdrl_spectrum1D_exp_scalar_create()

hdrl_spectrum1D * hdrl_spectrum1D_exp_scalar_create | ( | const hdrl_spectrum1D * | self,
|  | hdrl_value | scalar_operator
| ) |  |

subtract a scalar from a spectrum

Parameters

  self | spectrum
  scalar_operator | scalar factor

Returns
  a newly created spectrum, whose flux is calculated elevating the value of scalar_operator to the samples. Returns NULL in case of error.

Possible cpl-error-code set in this function: hdrl_image_exp_scalar

## ◆ hdrl_spectrum1D_get_flux()

const hdrl_image * hdrl_spectrum1D_get_flux | ( | const hdrl_spectrum1D * | self | ) |

hdrl_spectrum1D getter flux

Parameters

  self | the spectrum

Returns
  hdrl image containing flux information (bpm, flux and error)

## ◆ hdrl_spectrum1D_get_flux_value()

hdrl_value hdrl_spectrum1D_get_flux_value | ( | const hdrl_spectrum1D * | self,
|  | int | idx,
|  | int * | rej
| ) |  |

hdrl_spectrum1D getter for a flux value

Parameters

  self | the spectrum
  idx | position of the sample. The samples are a 0-indexed sequence.
  rej | output, set to 0 if the value is not a valid pixel.

Returns
  the i-th pixel value.

## ◆ hdrl_spectrum1D_get_scale()

hdrl_spectrum1D_wave_scale hdrl_spectrum1D_get_scale | ( | const hdrl_spectrum1D * | self | ) |

hdrl_spectrum1D getter for scale

Parameters

  self | the spectrum

Returns
  the scale.

## ◆ hdrl_spectrum1D_get_size()

cpl_size hdrl_spectrum1D_get_size | ( | const hdrl_spectrum1D * | self | ) |

hdrl_spectrum1D getter for size

Parameters

  self | the spectrum

Returns
  the number of samples the 1D spectrum is made of

## ◆ hdrl_spectrum1D_get_wavelength()

hdrl_spectrum1D_wavelength hdrl_spectrum1D_get_wavelength | ( | const hdrl_spectrum1D * | self | ) |

hdrl_spectrum1D getter for wavelengths

Parameters

  self | the spectrum

Returns
  the wavelengths the spectrum is defined on. It returns also its scale and its bpm.

## ◆ hdrl_spectrum1D_get_wavelength_value()

hdrl_data_t hdrl_spectrum1D_get_wavelength_value | ( | const hdrl_spectrum1D * | self,
|  | int | idx,
|  | int * | rej
| ) |  |

hdrl_spectrum1D getter for a wavelength value

Parameters

  self | the spectrum
  idx | position of the sample. The samples are a 0-indexed sequence.
  rej | output, set to 0 if the value is not a valid pixel.

Returns
  the i-th wavelength value.

## ◆ hdrl_spectrum1D_is_uniformly_sampled()

cpl_boolean hdrl_spectrum1D_is_uniformly_sampled | ( | const hdrl_spectrum1D * | self,
|  | double * | bin
| ) |  |

checks if the spectrum is defined on uniformly sampled wavelengths.

Parameters

  self | the input spectrum
  bin | bin width - output parameter

Returns
  CPL_TRUE if if the spectrum is defined on uniformly sampled wavelengths, false otherwise.

## ◆ hdrl_spectrum1D_mul_scalar()

cpl_error_code hdrl_spectrum1D_mul_scalar | ( | hdrl_spectrum1D * | self,
|  | hdrl_value | scalar_operator
| ) |  |

computes the elementwise multiplication of a spectrum by a scalar, the self parameter is modified

Parameters

  self | spectrum
  scalar_operator | scalar factor

Returns
  error code, for possible return codes see hdrl_image_mul_scalar

## ◆ hdrl_spectrum1D_mul_scalar_create()

hdrl_spectrum1D * hdrl_spectrum1D_mul_scalar_create | ( | const hdrl_spectrum1D * | self,
|  | hdrl_value | scalar_operator
| ) |  |

multiply a spectrum by a scalar

Parameters

  self | spectrum
  scalar_operator | scalar factor

Returns
  a newly created spectrum, whose flux is calculated multiplying every sample of self by scalar_operator. Returns NULL in case of error.

Possible cpl-error-code set in this function: hdrl_image_mul_scalar

## ◆ hdrl_spectrum1D_mul_spectrum()

cpl_error_code hdrl_spectrum1D_mul_spectrum | ( | hdrl_spectrum1D * | self,
|  | const hdrl_spectrum1D * | other
| ) |  |

multiply one spectrum by another spectrum

Parameters

  self | first factor, it is mutated to contain self*other
  other | second factor

Returns
  error code, for possible return codes see hdrl_image_mul_image

## ◆ hdrl_spectrum1D_mul_spectrum_create()

hdrl_spectrum1D * hdrl_spectrum1D_mul_spectrum_create | ( | const hdrl_spectrum1D * | f1,
|  | const hdrl_spectrum1D * | f2
| ) |  |

multiply one spectrum by another spectrum

Parameters

  f1 | factor 1
  f2 | factor 2

Returns
  a newly allocated spectrum whose flux values are f1*f2, with error propagation.

Possible cpl-error-code set in this function: hdrl_image_mul_image

## ◆ hdrl_spectrum1D_pow_scalar()

cpl_error_code hdrl_spectrum1D_pow_scalar | ( | hdrl_spectrum1D * | self,
|  | hdrl_value | scalar_operator
| ) |  |

computes the elementwise power of the flux to the scalar, the self parameter is modified

Parameters

  self | spectrum
  scalar_operator | scalar factor

Returns
  error code, for possible return codes see hdrl_image_pow_scalar

## ◆ hdrl_spectrum1D_pow_scalar_create()

hdrl_spectrum1D * hdrl_spectrum1D_pow_scalar_create | ( | const hdrl_spectrum1D * | self,
|  | hdrl_value | scalar_operator
| ) |  |

subtract a scalar from a spectrum

Parameters

  self | spectrum
  scalar_operator | scalar factor

Returns
  a newly created spectrum, whose flux is calculated elevating every sample to the value of scalar_operator. Returns NULL in case of error.

Possible cpl-error-code set in this function: hdrl_image_pow_scalar

## ◆ hdrl_spectrum1D_reject_pixels()

hdrl_spectrum1D * hdrl_spectrum1D_reject_pixels | ( | const hdrl_spectrum1D * | self,
|  | const cpl_array * | bad_samples
| ) |  |

For every i-th element in bad_samples having value CPL_TRUE, the i-th pixel in the 1D spectrum is marked as bad.

Parameters

  self | spectrum
  bad_samples | flags indicating whether the pixel is bad

Returns
  the spectrum having the appropriate bad pixels selected.

It returns a modified version of self. self is not modified. Possible cpl-error-code set in this function:

- CPL_ERROR_ILLEGAL_INPUT: if min_lambda < max_lambda;
- CPL_ERROR_ILLEGAL_OUTPUT: if the length of bad_samples and the length of self are different.

## ◆ hdrl_spectrum1D_resample()

hdrl_spectrum1D * hdrl_spectrum1D_resample | ( | const hdrl_spectrum1D * | self,
|  | const hdrl_spectrum1D_wavelength * | waves,
|  | const hdrl_parameter * | par
| ) |  |

resample a hdrl_spectrum1D on the wavelengths contained in waves

Parameters

  self | the spectrum to be resampled
  waves | the waves the spectrum has to be resampled on
  par | hdrl_parameter, see hdrl_spectrum1D_resample_fit_parameter_create(), hdrl_spectrum1D_resample_interpolate_parameter_create() or hdrl_spectrum1D_resample_integrate_parameter_create().

Returns
  the resampled spectrum, NULL in case of error (see below).

Note
  providing a spectrum with sorted, strictly monotonic increasing wavelength values will provide the best performance. If the spectrum is not sorted, the routine will create a copy of it and sort the copy. In case of duplicated wavelengths they are collapsed in a single wavelength and the corresponding flux is calculated as the median of the fluxes. Error propagation is performed through linear interpolation of the variance (error^2) of the spectrum in case of fit or interpolation. In case of integration we integrate the variance using the same weights used for the flux. The integration is done assuming that the flux is constant inside the bin and that the bin is centered on the sample. The only exceptions are the first bin (it starts at the sample) and the last bin (it ends at the sample).

Possible cpl-error-code set in this function:

- CPL_ERROR_NULL_INPUT: if any of the pointers are NULL
- CPL_ERROR_INCOMPATIBLE_INPUT: if the scale of self and waves are different or if par cannot be casted to any of the resample parameters (fit, interpolation, integration)

## ◆ hdrl_spectrum1D_resample_filter_dups_and_substitute_with_median()

cpl_size hdrl_spectrum1D_resample_filter_dups_and_substitute_with_median | ( | double * | x,
|  | double * | y1,
|  | double * | y2,
|  | cpl_size | sample_len
| ) |  |

## ◆ hdrl_spectrum1D_resample_fit_parameter_create()

hdrl_parameter * hdrl_spectrum1D_resample_fit_parameter_create | ( | const int | k,
|  | const int | nCoeff
| ) |  |

constructor for the hdrl_parameter in the case of interpolation

Parameters

  k | order of the B-spline
  nCoeff | number of coefficients used for the fit

Returns
  the constructed parameter

## ◆ hdrl_spectrum1D_resample_fit_windowed_parameter_create()

hdrl_parameter * hdrl_spectrum1D_resample_fit_windowed_parameter_create | ( | const int | k,
|  | const int | nCoeff,
|  | const long | window,
|  | const double | factor
| ) |  |

constructor for the hdrl_parameter in the case of interpolation

Parameters

  k | order of the B-spline
  nCoeff | number of coefficients used for the fit
  window | number of destination wavelengths whose flux values are computed using the same model
  factor | Given window2 = window * factor. window2 is the number of source wavelengths used to compute the fit model

Returns
  the constructed parameter, NULL in case of error

Note
  window must be greater than 0 and factor greater or equal than 1.0

## ◆ hdrl_spectrum1D_resample_integrate_parameter_create()

hdrl_parameter * hdrl_spectrum1D_resample_integrate_parameter_create | ( | void |  | ) |

constructor for the hdrl_parameter in the case of integration

Returns
  the constructed parameter

## ◆ hdrl_spectrum1D_resample_interpolate_parameter_create()

hdrl_parameter * hdrl_spectrum1D_resample_interpolate_parameter_create | ( | const hdrl_spectrum1D_interpolation_method | method | ) |

constructor for the hdrl_parameter in the case of interpolation

Parameters

  method | interpolation methods, see the enum hdrl_spectrum1D_interpolation_method

Returns
  the constructed parameter

## ◆ hdrl_spectrum1D_resample_interpolate_parameter_create_parlist()

cpl_parameterlist * hdrl_spectrum1D_resample_interpolate_parameter_create_parlist | ( | const char * | base_context,
|  | const char * | prefix,
|  | const char * | method_def
| ) |  |

## ◆ hdrl_spectrum1D_resample_interpolate_parameter_parse_parlist()

hdrl_parameter * hdrl_spectrum1D_resample_interpolate_parameter_parse_parlist | ( | const cpl_parameterlist * | parlist,
|  | const char * | prefix
| ) |  |

## ◆ hdrl_spectrum1D_resample_on_array()

hdrl_spectrum1D * hdrl_spectrum1D_resample_on_array | ( | const hdrl_spectrum1D * | self,
|  | const cpl_array * | waves,
|  | const hdrl_parameter * | par
| ) |  |

resample a hdrl_spectrum1D on the wavelengths contained in waves

Parameters

  self | the spectrum to be resampled
  waves | the waves the spectrum has to be resampled on
  par | hdrl_parameter, see hdrl_spectrum1D_resample_fit_parameter_create(), hdrl_spectrum1D_resample_interpolate_parameter_create() or hdrl_spectrum1D_resample_integrate_parameter_create().

Returns
  the resampled spectrum, NULL in case of error (see below).

Note
  providing a spectrum with sorted, strictly monotonic increasing wavelength values will provide the best performance. If the spectrum is not sorted, the routine will create a copy of it and sort the copy. In case of duplicated wavelengths they are collapsed in a single wavelength and the corresponding flux is calculated as the median of the fluxes. Error propagation is performed through linear interpolation of the variance (error^2) of the spectrum in case of fit or interpolation. In case of integration we integrate the variance using the same weights used for the flux. The integration is done assuming that the flux is constant inside the bin and that the bin is centered on the sample. The only exceptions are the first bin (it starts at the sample) and the last bin (it ends at the sample).

Possible cpl-error-code set in this function:

- CPL_ERROR_NULL_INPUT: if any of the pointers are NULL
- CPL_ERROR_INCOMPATIBLE_INPUT: if par cannot be casted to any of the resample parameters (fit, interpolation, integration)

## ◆ hdrl_spectrum1D_save()

void hdrl_spectrum1D_save | ( | const hdrl_spectrum1D * | s,
|  | const char * | fname
| ) |  |

## ◆ hdrl_spectrum1D_select_wavelengths()

hdrl_spectrum1D * hdrl_spectrum1D_select_wavelengths | ( | const hdrl_spectrum1D * | self,
|  | const cpl_bivector * | windows,
|  | const cpl_boolean | is_internal
| ) |  |

the function selects or discards flux values according to whether the value of the corresponding wavelength belongs to the interval [min_lambda, max_lambda].

Parameters

  self | spectrum
  windows | the intervals required for selection
  is_internal | parallel array to windows, specifies if selection is internal to the interval or external to the interval.

Returns
  the selected subset of self or NULL in case of error

Note
  : the complexity is O(kn) where k is the number of windows and n is the number of samples in the spectrum. The assumption is that k << n, making the complexity O(n).

Possible cpl-error-code set in this function:

- CPL_ERROR_ILLEGAL_OUTPUT: if no samples falls in the selected interval
- CPL_ERROR_ILLEGAL_INPUT: if windows and is_internal have different lengths, or if is_internal is not of type CPL_TYPE_INT
- CPL_ERROR_NULL_INPUT: if any of the pointers is NULL

## ◆ hdrl_spectrum1D_shift_fit_parameter_create()

hdrl_parameter * hdrl_spectrum1D_shift_fit_parameter_create | ( | const hdrl_data_t | wguess,
|  | const hdrl_data_t | range_wmin,
|  | const hdrl_data_t | range_wmax,
|  | const hdrl_data_t | fit_wmin,
|  | const hdrl_data_t | fit_wmax,
|  | const hdrl_data_t | fit_half_win
| ) |  |

The function create a hdrl_spectrum1D_shift_parameter to be used in hdrl_spectrum1D_compute_shift_fit.

Parameters

  wguess | Reference line wavelength position
  range_wmin | Minimum of wavelength box for line fit
  range_wmax | Maximum of wavelength box for line fit
  fit_wmin | Minimum wavelength value used to fit line slope
  fit_wmax | Maximum wavelength value used to fit line slope
  fit_half_win | Half box where polynomial fit is performed

Returns
  the constructed hdrl_parameter.

## ◆ hdrl_spectrum1D_sub_scalar()

cpl_error_code hdrl_spectrum1D_sub_scalar | ( | hdrl_spectrum1D * | self,
|  | hdrl_value | scalar_operator
| ) |  |

computes the elementwise subtraction of a spectrum by a scalar, the self parameter is modified

Parameters

  self | spectrum
  scalar_operator | scalar factor

Returns
  error code, for possible return codes see hdrl_image_sub_scalar

## ◆ hdrl_spectrum1D_sub_scalar_create()

hdrl_spectrum1D * hdrl_spectrum1D_sub_scalar_create | ( | const hdrl_spectrum1D * | self,
|  | hdrl_value | scalar_operator
| ) |  |

subtract a scalar from a spectrum

Parameters

  self | spectrum
  scalar_operator | scalar factor

Returns
  a newly created spectrum, whose flux is calculated subtracting from every sample of self the value of scalar_operator. Returns NULL in case of error.

Possible cpl-error-code set in this function: hdrl_image_sub_scalar

## ◆ hdrl_spectrum1D_sub_spectrum()

cpl_error_code hdrl_spectrum1D_sub_spectrum | ( | hdrl_spectrum1D * | self,
|  | const hdrl_spectrum1D * | other
| ) |  |

subtract two spectra

Parameters

  self | first factor, it is mutated to contain self-other
  other | second factor

Returns
  error code, for possible return codes see hdrl_image_sub_image

## ◆ hdrl_spectrum1D_sub_spectrum_create()

hdrl_spectrum1D * hdrl_spectrum1D_sub_spectrum_create | ( | const hdrl_spectrum1D * | f1,
|  | const hdrl_spectrum1D * | f2
| ) |  |

subtract two spectra

Parameters

  f1 | factor 1
  f2 | factor 2

Returns
  a newly allocated spectrum whose flux values are f1-f2, with error propagation.

Possible cpl-error-code set in this function: hdrl_image_sub_image

## ◆ hdrl_spectrum1D_wavelength_convert_to_linear()

cpl_error_code hdrl_spectrum1D_wavelength_convert_to_linear | ( | hdrl_spectrum1D * | self | ) |

converts the wavelength scale to linear.

Parameters

  self | spectrum

Returns
  error code, for error codes see cpl_array_exponential

If the spectrum is already in linear scale nothing is done.

## ◆ hdrl_spectrum1D_wavelength_convert_to_linear_create()

hdrl_spectrum1D * hdrl_spectrum1D_wavelength_convert_to_linear_create | ( | const hdrl_spectrum1D * | self | ) |

converts the wavelength scale to linear.

Parameters

  self | spectrum

Returns
  the modified spectrum

It returns a modified version of self. self is not modified. If self is already in linear, the function is equivalent to a duplication. Possible cpl-error-code set in this function: see cpl_array_exponential

## ◆ hdrl_spectrum1D_wavelength_convert_to_log()

cpl_error_code hdrl_spectrum1D_wavelength_convert_to_log | ( | hdrl_spectrum1D * | self | ) |

converts the wavelength scale to log. If the spectrum is already in log scale nothing is done.

Parameters

  self | spectrum

Returns
  error code, for error codes see cpl_array_logarithm

## ◆ hdrl_spectrum1D_wavelength_convert_to_log_create()

hdrl_spectrum1D * hdrl_spectrum1D_wavelength_convert_to_log_create | ( | const hdrl_spectrum1D * | self | ) |

converts the wavelength scale to log. It returns a modified version of self. self is not modified. If self is already in log, the function is equivalent to a duplication.

Parameters

  self | spectrum

Returns
  the modified spectrum

It returns a modified version of self. self is not modified. If self is already in log, the function is equivalent to a duplication. Possible cpl-error-code set in this function: see cpl_array_logarithm

## ◆ hdrl_spectrum1D_wavelength_mult_scalar_linear()

cpl_error_code hdrl_spectrum1D_wavelength_mult_scalar_linear | ( | hdrl_spectrum1D * | self,
|  | hdrl_data_t | scale_linear
| ) |  |

computes the elementwise multiplication of the scalar for the wavelength. The scalar is assumed to be expressed in linear units. the self parameter is modified

Parameters

  self | spectrum
  scale_linear | scalar factor

Returns
  error code, for possible return codes see cpl_array_multiply_scalar and cpl_array_add_scalar.

## ◆ hdrl_spectrum1D_wavelength_mult_scalar_linear_create()

hdrl_spectrum1D * hdrl_spectrum1D_wavelength_mult_scalar_linear_create | ( | const hdrl_spectrum1D * | self,
|  | hdrl_data_t | scale_linear
| ) |  |

computes the elementwise multiplication of the scalar for the wavelength. The scalar is assumed to be expressed in linear units. Self is unchanged and the function returns a newly allocated spectrum.

Parameters

  self | spectrum
  scale_linear | scalar factor

Returns
  the modified spectrum

Possible cpl-error-code set in this function: see cpl_array_multiply_scalar and cpl_array_add_scalar.

## ◆ hdrl_spectrum1D_wavelength_shift()

cpl_error_code hdrl_spectrum1D_wavelength_shift | ( | hdrl_spectrum1D * | self,
|  | hdrl_data_t | shift
| ) |  |

computes the elementwise shift of the wavelength by the shift parameter. The self parameter is modified

Parameters

  self | spectrum
  shift | scalar factor

Returns
  error code, for error codes see cpl_array_add_scalar

## ◆ hdrl_spectrum1D_wavelength_shift_create()

hdrl_spectrum1D * hdrl_spectrum1D_wavelength_shift_create | ( | const hdrl_spectrum1D * | self,
|  | hdrl_data_t | shift
| ) |  |

computes the elementwise shift of the wavelength by the shift parameter.

Parameters

  self | spectrum
  shift | scalar factor

Returns
  spectrum

The self parameter is not modified, and a modified copy of self is returned. Possible cpl-error-code set in this function: see cpl_array_add_scalar

## ◆ hdrl_spectrum1Dlist_collapse()

cpl_error_code hdrl_spectrum1Dlist_collapse | ( | const hdrl_spectrum1Dlist * | list,
|  | const hdrl_parameter * | stacking_par,
|  | const cpl_array * | wlengths,
|  | const hdrl_parameter * | resample_par,
|  | const cpl_boolean | mark_bpm_in_interpolation,
|  | hdrl_spectrum1D ** | result,
|  | cpl_image ** | contrib,
|  | hdrl_imagelist ** | resampled_and_aligned_fluxes
| ) |  |

collapsing a hdrl_spectrum1Dlist. The spectra in list are first resampled on the wavelengths wlengths. The resampling method is regulated by the resample_par. For more information on samplig_par see hdrl_spectrum1D_resample_on_array. The resampled fluxes are collapsed as in hdrl_imagelist_collapse and the collapsing is regulated by the parameter stacking_par. For more information on stacking_par please see the documentation of hdrl_imagelist_collapse.

Parameters

  list | hdrl_spectrum1D list
  stacking_par | parameter regulating the stacking
  wlengths | wavelengths the resulting spectrum is defined on
  resample_par | parameter regulating the resampling
  mark_bpm_in_interpolation | if true interpolated pixels whose neighbors (in the original spectrum) are rejected, are not considered during collapsing
  result | the resulting spectrum
  contrib | output contribution mask
  resampled_and_aligned_fluxes | resampled and aligned fluxes to be collapsed

Returns
  cpl_error_code

Possible cpl-error-code set in this function:

- CPL_ERROR_NULL_INPUT: if any among input pointers in NULL of if any of the spectra inside the list are NULL.
  - CPL_ERROR_ILLEGAL_INPUT: if all the elements inside list are not defined on the same scale.

## ◆ hdrl_spectrum1Dlist_delete()

void hdrl_spectrum1Dlist_delete | ( | hdrl_spectrum1Dlist * | l | ) |

hdrl_spectrum1Dlist destructor

Parameters

  l | hdrl_spectrum1Dlist

The function deallocates the list and all the spectra it was containing. If l is NULL no operation is performed.

## ◆ hdrl_spectrum1Dlist_duplicate()

hdrl_spectrum1Dlist * hdrl_spectrum1Dlist_duplicate | ( | const hdrl_spectrum1Dlist * | l | ) |

hdrl_spectrum1Dlist copy-constructor

Parameters

  l | input list

Returns
  a copy of the input list

The constructor allocates memory of a new hdrl_spectrum1Dlist structure. Each element of the new list is a copy of the corresponding element in the source list.

## ◆ hdrl_spectrum1Dlist_get()

hdrl_spectrum1D * hdrl_spectrum1Dlist_get | ( | hdrl_spectrum1Dlist * | self,
|  | const cpl_size | idx
| ) |  |

hdrl_spectrum1Dlist getter of the i-th element

Parameters

  self | hdrl_spectrum1Dlist
  idx | index of the element we want. 0 <= index < size

Returns
  a pointer to the i-th element. NULL in case of error.

Possible cpl-error-code set in this function:

- CPL_ERROR_NULL_INPUT: if self is NULL
- CPL_ERROR_ACCESS_OUT_OF_RANGE: index is less than 0 or index >= size

## ◆ hdrl_spectrum1Dlist_get_const()

const hdrl_spectrum1D * hdrl_spectrum1Dlist_get_const | ( | const hdrl_spectrum1Dlist * | self,
|  | const cpl_size | idx
| ) |  |

hdrl_spectrum1Dlist getter of the i-th element

Parameters

  self | hdrl_spectrum1Dlist
  idx | index of the element we want. 0 <= index < size

Returns
  a const pointer to the i-th element. NULL in case of error.

Possible cpl-error-code set in this function:

- CPL_ERROR_NULL_INPUT: if self is NULL
- CPL_ERROR_ACCESS_OUT_OF_RANGE: index is less than 0 or index >= size

## ◆ hdrl_spectrum1Dlist_get_size()

cpl_size hdrl_spectrum1Dlist_get_size | ( | const hdrl_spectrum1Dlist * | l | ) |

hdrl_spectrum1Dlist getter for size

Parameters

  l | hdrl_spectrum1Dlist

Returns
  the size of the list. The size can be less or equal than the capacity of the list. The size refers to the number of valid elements in the list.

Possible cpl-error-code set in this function:

- CPL_ERROR_NULL_INPUT: if l is NULL

## ◆ hdrl_spectrum1Dlist_new()

hdrl_spectrum1Dlist * hdrl_spectrum1Dlist_new | ( | void |  | ) |

hdrl_spectrum1Dlist default constructor

Returns
  a newly allocated hdrl_spectrum1Dlist

The constructor allocates memory of a hdrl_spectrum1Dlist structure. The struct has zero capacity when allocated.

## ◆ hdrl_spectrum1Dlist_set()

cpl_error_code hdrl_spectrum1Dlist_set | ( | hdrl_spectrum1Dlist * | self,
|  | hdrl_spectrum1D * | s,
|  | const cpl_size | idx
| ) |  |

hdrl_spectrum1Dlist setter of the i-th element

Parameters

  self | hdrl_spectrum1Dlist
  s | hdrl_spectrum1D we want to insert
  idx | position the spectrum is inserted in. 0 <= index <= size

Returns
  a cpl_error_code.

The function insert s inside self. if index == size, the capacity of the list is increased to accommodate the new element. If a spectrum was already contained in the i-th position, it is de-allocated. The list becomes responsible for the memory management of s.

Possible cpl-error-code set in this function:

- CPL_ERROR_NULL_INPUT: if self is NULL
- CPL_ERROR_ACCESS_OUT_OF_RANGE: index < 0 or index > size
- CPL_ERROR_ILLEGAL_INPUT: if s is already contained inside self

## ◆ hdrl_spectrum1Dlist_unset()

hdrl_spectrum1D * hdrl_spectrum1Dlist_unset | ( | hdrl_spectrum1Dlist * | self,
|  | const cpl_size | idx
| ) |  |

hdrl_spectrum1Dlist remove of the i-th element

Parameters

  self | hdrl_spectrum1Dlist
  idx | position of element we want to remove from the list. 0 <= index < size

Returns
  the removed element. NULL in case of error of if the idx-th element was NULL

The function extract the idx-th element from the list. It shifts all the elements from idx + 1 to size - 1 down of one position. If the new size is less than half the capacity, the capacity is reduced.

Possible cpl-error-code set in this function:

- CPL_ERROR_NULL_INPUT: if self is NULL
- CPL_ERROR_ACCESS_OUT_OF_RANGE: index < 0 or index >= size

## ◆ hdrl_spectrum1Dlist_wrap()

hdrl_spectrum1Dlist * hdrl_spectrum1Dlist_wrap | ( | hdrl_spectrum1D ** | self,
|  | const cpl_size | sz
| ) |  |

hdrl_spectrum1Dlist wrapper

Parameters

  self | array of pointers to hdrl_spectrum1D
  sz | number of elements in self

Returns
  self wrapped in a hdrl_spectrum1Dlist. The returned structure takes ownership of the self pointer.

The constructor allocates memory of a new hdrl_spectrum1Dlist structure. The structure takes ownership of self, and therefore it is responsible for its de-allocation. Self must not contain duplicate or NULL pointers.

## Variable Documentation

## ◆ wave_delta

const double wave_delta = 1.e-6