CR2RE Pipeline Reference Manual 1.6.2
Functions
Spectrum 1D

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

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
 
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_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
 
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
 
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.
 
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.
 

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.

Function Documentation

◆ 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_ininput flux
msk_inbad pixels mask
wavelengthswavelengths of the spectrum
lengthlength of the flux and msl
half_windowhalf 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

Definition at line 160 of file hdrl_DER_SNR.c.

Referenced by hdrl_spectrum1D_create_error_DER_SNR().

◆ 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
fluxInput Flux
mskBad Pixel Mask
startFirst Pixel
stopLast Pixel
szLength 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).

Definition at line 89 of file hdrl_DER_SNR.c.

◆ 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
selfspectrum
scalar_operatorscalar factor
Returns
error code, for possible return codes see hdrl_image_add_scalar

Definition at line 710 of file hdrl_spectrum.c.

References hdrl_image_add_scalar().

Referenced by hdrl_spectrum1D_compute_shift_fit().

◆ 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
selfspectrum
scalar_operatorscalar 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

Definition at line 616 of file hdrl_spectrum.c.

References 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
selffirst factor, it is mutated to contain self+other
othersecond factor
Returns
error code, for possible return codes see hdrl_image_add_image

Definition at line 553 of file hdrl_spectrum.c.

References hdrl_image_add_image().

Referenced by cr2res_combine_extracted().

◆ 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
f1factor 1
f2factor 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

Definition at line 499 of file hdrl_spectrum.c.

References 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
selfspectrum
desttable
flux_col_namename of the column containing the flux
wavelength_col_namename of the column containing the wavelengths
flux_e_col_namename of the column containing the flux error
flux_bpm_col_namename 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.

Definition at line 1115 of file hdrl_spectrum.c.

References hdrl_spectrum1D_get_flux_value(), hdrl_spectrum1D_get_size(), and hdrl_spectrum1D_get_wavelength_value().

Referenced by hdrl_spectrum1D_convert_to_table().

◆ 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
s1first spectrum wavelength
s2second spectrum wavelength
Returns
CPL_TRUE if compatible, CPL_FALSE otherwise.

Definition at line 1294 of file hdrl_spectrum.c.

References hdrl_spectrum1D_are_wavelengths_compatible().

Referenced by hdrl_spectrum1D_compute_shift_xcorrelation(), and hdrl_spectrum1D_resample().

◆ 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
w1first wavelength array
w2first wavelength array
Returns
CPL_TRUE if compatible, CPL_FALSE otherwise.

Definition at line 1263 of file hdrl_spectrum.c.

Referenced by hdrl_spectrum1D_are_spectra_compatible(), and hdrl_spectrum1D_resample_on_array().

◆ 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
obsThe spectrum the shift has to be computed on
parThe shift parameter, see hdrl_spectrum1D_shift_fit_parameter_create
Returns
(wfound - wguess) / wguess.

Definition at line 198 of file hdrl_spectrum_shift.c.

References hdrl_spectrum1D_add_scalar(), hdrl_spectrum1D_delete(), hdrl_spectrum1D_div_spectrum(), and hdrl_spectrum1D_select_wavelengths().

Referenced by hdrl_response_compute().

◆ 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
s1first spectrum
s2second spectrum
half_winhalf window where the correlation will be calculated
normalizenormalize 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;

Definition at line 94 of file hdrl_spectrum_shift.c.

References hdrl_compute_offset_gaussian(), hdrl_spectrum1D_are_spectra_compatible(), hdrl_spectrum1D_get_wavelength(), and hdrl_spectrum1D_is_uniformly_sampled().

◆ 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
selftable
flux_col_namename of the column containing the flux
wavelength_col_namename of the column containing the wavelengths
flux_e_col_namename of the column containing the flux error
flux_bpm_col_namename of the column containing the flux bpm
scalescale 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

Definition at line 1200 of file hdrl_spectrum.c.

References hdrl_spectrum1D_create().

Referenced by cr2res_combine_extracted().

◆ 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
selfspectrum
flux_col_namename of the column containing the flux
wavelength_col_namename of the column containing the wavelengths
flux_e_col_namename of the column containing the flux error
flux_bpm_col_namename 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

Definition at line 1074 of file hdrl_spectrum.c.

References hdrl_spectrum1D_append_to_table(), and hdrl_spectrum1D_get_size().

◆ 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_fluxflux with bpm
arg_flux_eerror for the flux
wavelengthwavelengths
wave_scalethe 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.

Definition at line 117 of file hdrl_spectrum.c.

Referenced by hdrl_spectrum1D_convert_from_table(), hdrl_spectrum1D_create_analytic(), hdrl_spectrum1D_create_error_DER_SNR(), hdrl_spectrum1D_create_error_free(), hdrl_spectrum1D_reject_pixels(), hdrl_spectrum1D_select_wavelengths(), and hdrl_spectrum1Dlist_collapse().

◆ 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
funcanalytical function defining the spectrum
wavelengthfrequencies the flux is calculated on
scalethe 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.

Definition at line 160 of file hdrl_spectrum.c.

References hdrl_spectrum1D_create().

Referenced by hdrl_efficiency_compute().

◆ 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_fluxflux with bpm
half_windowhalf window the DER_SNR is calculated on
wavelengthfrequencies
scalethe 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()

Definition at line 250 of file hdrl_spectrum.c.

References estimate_noise_DER_SNR(), and 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_fluxflux with bpm
wavelengthfrequencies
scalethe 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()

Definition at line 204 of file hdrl_spectrum.c.

References hdrl_spectrum1D_create().

◆ hdrl_spectrum1D_delete()

void hdrl_spectrum1D_delete ( hdrl_spectrum1D **  p_self)

◆ 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
selfspectrum
scalar_operatorscalar factor
Returns
error code, for possible return codes see hdrl_image_div_scalar

Definition at line 681 of file hdrl_spectrum.c.

References hdrl_image_div_scalar().

Referenced by hdrl_efficiency_compute().

◆ 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
selfspectrum
scalar_operatorscalar 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

Definition at line 582 of file hdrl_spectrum.c.

References 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
selfnumerator, it is mutated to contain self/other
otherdenumerator
Returns
error code, for possible return codes see hdrl_image_div_image

Definition at line 529 of file hdrl_spectrum.c.

References hdrl_image_div_image().

Referenced by hdrl_efficiency_compute(), hdrl_response_core_compute(), and hdrl_spectrum1D_compute_shift_fit().

◆ 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
numnumerator
dendenumerator
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

Definition at line 467 of file hdrl_spectrum.c.

References hdrl_image_div_image().

◆ hdrl_spectrum1D_duplicate()

hdrl_spectrum1D * hdrl_spectrum1D_duplicate ( const hdrl_spectrum1D *  self)

◆ 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
selfspectrum
scalar_operatorscalar factor
Returns
error code, for possible return codes see hdrl_image_exp_scalar

Definition at line 752 of file hdrl_spectrum.c.

References hdrl_image_exp_scalar().

Referenced by hdrl_efficiency_compute(), and hdrl_response_core_compute().

◆ 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
selfspectrum
scalar_operatorscalar 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

Definition at line 667 of file hdrl_spectrum.c.

References hdrl_image_exp_scalar().

◆ hdrl_spectrum1D_get_flux()

const hdrl_image * hdrl_spectrum1D_get_flux ( const hdrl_spectrum1D *  self)

hdrl_spectrum1D getter flux

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

Definition at line 358 of file hdrl_spectrum.c.

Referenced by hdrl_spectrum1D_get_flux_value(), hdrl_spectrum1D_get_wavelength(), and hdrl_spectrum1D_reject_pixels().

◆ 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
selfthe spectrum
idxposition of the sample. The samples are a 0-indexed sequence.
rejoutput, set to 0 if the value is not a valid pixel.
Returns
the i-th pixel value.

Definition at line 417 of file hdrl_spectrum.c.

References hdrl_image_get_pixel(), and hdrl_spectrum1D_get_flux().

Referenced by cr2res_combine_extracted(), hdrl_spectrum1D_append_to_table(), and hdrl_spectrum1D_select_wavelengths().

◆ hdrl_spectrum1D_get_scale()

hdrl_spectrum1D_wave_scale hdrl_spectrum1D_get_scale ( const hdrl_spectrum1D *  self)

hdrl_spectrum1D getter for scale

Parameters
selfthe spectrum
Returns
the scale.

Definition at line 401 of file hdrl_spectrum.c.

Referenced by hdrl_spectrum1D_get_wavelength(), hdrl_spectrum1D_select_wavelengths(), and hdrl_spectrum1Dlist_collapse().

◆ hdrl_spectrum1D_get_size()

cpl_size hdrl_spectrum1D_get_size ( const hdrl_spectrum1D *  self)

hdrl_spectrum1D getter for size

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

Definition at line 344 of file hdrl_spectrum.c.

Referenced by cr2res_combine_extracted(), hdrl_spectrum1D_append_to_table(), hdrl_spectrum1D_convert_to_table(), hdrl_spectrum1D_is_uniformly_sampled(), hdrl_spectrum1D_reject_pixels(), and hdrl_spectrum1D_select_wavelengths().

◆ hdrl_spectrum1D_get_wavelength()

hdrl_spectrum1D_wavelength hdrl_spectrum1D_get_wavelength ( const hdrl_spectrum1D *  self)

◆ 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
selfthe spectrum
idxposition of the sample. The samples are a 0-indexed sequence.
rejoutput, set to 0 if the value is not a valid pixel.
Returns
the i-th wavelength value.

Definition at line 435 of file hdrl_spectrum.c.

References hdrl_spectrum1D_get_wavelength().

Referenced by cr2res_combine_extracted(), hdrl_spectrum1D_append_to_table(), hdrl_spectrum1D_is_uniformly_sampled(), and hdrl_spectrum1D_select_wavelengths().

◆ 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
selfthe input spectrum
binbin width - output parameter
Returns
CPL_TRUE if if the spectrum is defined on uniformly sampled wavelengths, false otherwise.

Definition at line 1318 of file hdrl_spectrum.c.

References hdrl_spectrum1D_get_size(), and hdrl_spectrum1D_get_wavelength_value().

Referenced by hdrl_spectrum1D_compute_shift_xcorrelation().

◆ 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
selfspectrum
scalar_operatorscalar factor
Returns
error code, for possible return codes see hdrl_image_mul_scalar

Definition at line 696 of file hdrl_spectrum.c.

References hdrl_image_mul_scalar().

Referenced by hdrl_efficiency_compute(), and hdrl_response_core_compute().

◆ 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
selfspectrum
scalar_operatorscalar 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

Definition at line 599 of file hdrl_spectrum.c.

References 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
selffirst factor, it is mutated to contain self*other
othersecond factor
Returns
error code, for possible return codes see hdrl_image_mul_image

Definition at line 541 of file hdrl_spectrum.c.

References hdrl_image_mul_image().

Referenced by hdrl_efficiency_compute(), and hdrl_response_core_compute().

◆ 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
f1factor 1
f2factor 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

Definition at line 483 of file hdrl_spectrum.c.

References 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
selfspectrum
scalar_operatorscalar factor
Returns
error code, for possible return codes see hdrl_image_pow_scalar

Definition at line 738 of file hdrl_spectrum.c.

References 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
selfspectrum
scalar_operatorscalar 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

Definition at line 650 of file hdrl_spectrum.c.

References 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
selfspectrum
bad_samplesflags 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.

Definition at line 1027 of file hdrl_spectrum.c.

References hdrl_image_delete(), hdrl_image_duplicate(), hdrl_image_get_error(), hdrl_image_get_image(), hdrl_image_reject(), hdrl_spectrum1D_create(), hdrl_spectrum1D_get_flux(), hdrl_spectrum1D_get_size(), and hdrl_spectrum1D_get_wavelength().

◆ 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
selfthe spectrum to be resampled
wavesthe waves the spectrum has to be resampled on
parhdrl_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)

Definition at line 429 of file hdrl_spectrum_resample.c.

References hdrl_spectrum1D_are_spectra_compatible(), hdrl_spectrum1D_duplicate(), and hdrl_spectrum1D_get_wavelength().

Referenced by cr2res_combine_extracted(), hdrl_efficiency_compute(), and hdrl_response_core_compute().

◆ 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
korder of the B-spline
nCoeffnumber of coefficients used for the fit
Returns
the constructed parameter

Definition at line 338 of file hdrl_spectrum_resample.c.

◆ 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
korder of the B-spline
nCoeffnumber of coefficients used for the fit
windownumber of destination wavelengths whose flux values are computed using the same model
factorGiven 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

Definition at line 366 of file hdrl_spectrum_resample.c.

◆ 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

Definition at line 255 of file hdrl_spectrum_resample.c.

◆ 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
methodinterpolation methods, see the enum hdrl_spectrum1D_interpolation_method
Returns
the constructed parameter

Definition at line 239 of file hdrl_spectrum_resample.c.

Referenced by cr2res_combine_extracted(), hdrl_barycorr_compute(), hdrl_efficiency_compute(), hdrl_response_compute(), and hdrl_response_core_compute().

◆ 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
selfthe spectrum to be resampled
wavesthe waves the spectrum has to be resampled on
parhdrl_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)

Definition at line 484 of file hdrl_spectrum_resample.c.

References hdrl_spectrum1D_are_wavelengths_compatible(), hdrl_spectrum1D_duplicate(), and hdrl_spectrum1D_get_wavelength().

Referenced by hdrl_response_compute(), and hdrl_spectrum1Dlist_collapse().

◆ 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
selfspectrum
windowsthe intervals required for selection
is_internalparallel 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

Definition at line 955 of file hdrl_spectrum.c.

References hdrl_spectrum1D_create(), hdrl_spectrum1D_duplicate(), hdrl_spectrum1D_get_flux_value(), hdrl_spectrum1D_get_scale(), hdrl_spectrum1D_get_size(), and hdrl_spectrum1D_get_wavelength_value().

Referenced by hdrl_spectrum1D_compute_shift_fit().

◆ 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
wguessReference line wavelength position
range_wminMinimum of wavelength box for line fit
range_wmaxMaximum of wavelength box for line fit
fit_wminMinimum wavelength value used to fit line slope
fit_wmaxMaximum wavelength value used to fit line slope
fit_half_winHalf box where polynomial fit is performed
Returns
the constructed hdrl_parameter.

Definition at line 162 of file hdrl_spectrum_shift.c.

◆ 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
selfspectrum
scalar_operatorscalar factor
Returns
error code, for possible return codes see hdrl_image_sub_scalar

Definition at line 724 of file hdrl_spectrum.c.

References 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
selfspectrum
scalar_operatorscalar 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

Definition at line 633 of file hdrl_spectrum.c.

References 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
selffirst factor, it is mutated to contain self-other
othersecond factor
Returns
error code, for possible return codes see hdrl_image_sub_image

Definition at line 566 of file hdrl_spectrum.c.

References hdrl_image_sub_image().

Referenced by hdrl_efficiency_compute(), and hdrl_response_core_compute().

◆ hdrl_spectrum1D_sub_spectrum_create()

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

subtract two spectra

Parameters
f1factor 1
f2factor 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

Definition at line 516 of file hdrl_spectrum.c.

References 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
selfspectrum
Returns
error code, for error codes see cpl_array_exponential

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

Definition at line 860 of file hdrl_spectrum.c.

Referenced by hdrl_spectrum1D_wavelength_convert_to_linear_create().

◆ 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
selfspectrum
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

Definition at line 881 of file hdrl_spectrum.c.

References hdrl_spectrum1D_delete(), hdrl_spectrum1D_duplicate(), and hdrl_spectrum1D_wavelength_convert_to_linear().

◆ 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
selfspectrum
Returns
error code, for error codes see cpl_array_logarithm

Definition at line 899 of file hdrl_spectrum.c.

Referenced by hdrl_spectrum1D_wavelength_convert_to_log_create().

◆ 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
selfspectrum
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

Definition at line 922 of file hdrl_spectrum.c.

References hdrl_spectrum1D_delete(), hdrl_spectrum1D_duplicate(), and hdrl_spectrum1D_wavelength_convert_to_log().

◆ 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
selfspectrum
scale_linearscalar factor
Returns
error code, for possible return codes see cpl_array_multiply_scalar and cpl_array_add_scalar.

Definition at line 768 of file hdrl_spectrum.c.

Referenced by hdrl_spectrum1D_wavelength_mult_scalar_linear_create().

◆ 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
selfspectrum
scale_linearscalar factor
Returns
the modified spectrum

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

Definition at line 794 of file hdrl_spectrum.c.

References hdrl_spectrum1D_delete(), hdrl_spectrum1D_duplicate(), and hdrl_spectrum1D_wavelength_mult_scalar_linear().

◆ 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
selfspectrum
shiftscalar factor
Returns
error code, for error codes see cpl_array_add_scalar

Definition at line 817 of file hdrl_spectrum.c.

Referenced by hdrl_spectrum1D_wavelength_shift_create().

◆ 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
selfspectrum
shiftscalar 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

Definition at line 836 of file hdrl_spectrum.c.

References hdrl_spectrum1D_delete(), hdrl_spectrum1D_duplicate(), and hdrl_spectrum1D_wavelength_shift().

◆ 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
listhdrl_spectrum1D list
stacking_parparameter regulating the stacking
wlengthswavelengths the resulting spectrum is defined on
resample_parparameter regulating the resampling
mark_bpm_in_interpolationif true interpolated pixels whose neighbors (in the original spectrum) are rejected, are not considered during collapsing
resultthe resulting spectrum
contriboutput contribution mask
resampled_and_aligned_fluxesresampled 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.

Definition at line 350 of file hdrl_spectrumlist.c.

References hdrl_image_delete(), hdrl_image_get_error(), hdrl_image_get_image(), hdrl_imagelist_collapse(), hdrl_spectrum1D_create(), hdrl_spectrum1D_get_scale(), hdrl_spectrum1D_resample_on_array(), hdrl_spectrum1Dlist_get_const(), and hdrl_spectrum1Dlist_get_size().

◆ hdrl_spectrum1Dlist_delete()

void hdrl_spectrum1Dlist_delete ( hdrl_spectrum1Dlist *  l)

hdrl_spectrum1Dlist destructor

Parameters
lhdrl_spectrum1Dlist

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

Definition at line 286 of file hdrl_spectrumlist.c.

References hdrl_spectrum1D_delete(), and hdrl_spectrum1Dlist_get_size().

◆ hdrl_spectrum1Dlist_duplicate()

hdrl_spectrum1Dlist * hdrl_spectrum1Dlist_duplicate ( const hdrl_spectrum1Dlist *  l)

hdrl_spectrum1Dlist copy-constructor

Parameters
linput 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.

Definition at line 122 of file hdrl_spectrumlist.c.

References hdrl_spectrum1D_duplicate(), hdrl_spectrum1Dlist_get_const(), hdrl_spectrum1Dlist_get_size(), hdrl_spectrum1Dlist_new(), and hdrl_spectrum1Dlist_set().

Referenced by hdrl_response_telluric_evaluation_parameter_create().

◆ hdrl_spectrum1Dlist_get()

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

hdrl_spectrum1Dlist getter of the i-th element

Parameters
selfhdrl_spectrum1Dlist
idxindex 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

Definition at line 168 of file hdrl_spectrumlist.c.

◆ 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
selfhdrl_spectrum1Dlist
idxindex 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

Definition at line 189 of file hdrl_spectrumlist.c.

Referenced by hdrl_spectrum1Dlist_collapse(), and hdrl_spectrum1Dlist_duplicate().

◆ hdrl_spectrum1Dlist_get_size()

cpl_size hdrl_spectrum1Dlist_get_size ( const hdrl_spectrum1Dlist *  l)

hdrl_spectrum1Dlist getter for size

Parameters
lhdrl_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

Definition at line 309 of file hdrl_spectrumlist.c.

Referenced by hdrl_spectrum1Dlist_collapse(), hdrl_spectrum1Dlist_delete(), hdrl_spectrum1Dlist_duplicate(), and hdrl_spectrum1Dlist_unset().

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

Definition at line 102 of file hdrl_spectrumlist.c.

Referenced by hdrl_spectrum1Dlist_duplicate(), and hdrl_spectrum1Dlist_wrap().

◆ 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
selfhdrl_spectrum1Dlist
shdrl_spectrum1D we want to insert
idxposition 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

Definition at line 216 of file hdrl_spectrumlist.c.

References hdrl_spectrum1D_delete().

Referenced by hdrl_spectrum1Dlist_duplicate().

◆ hdrl_spectrum1Dlist_unset()

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

hdrl_spectrum1Dlist remove of the i-th element

Parameters
selfhdrl_spectrum1Dlist
idxposition 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

Definition at line 254 of file hdrl_spectrumlist.c.

References hdrl_spectrum1Dlist_get_size().

◆ hdrl_spectrum1Dlist_wrap()

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

hdrl_spectrum1Dlist wrapper

Parameters
selfarray of pointers to hdrl_spectrum1D
sznumber 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.

Definition at line 149 of file hdrl_spectrumlist.c.

References hdrl_spectrum1Dlist_new().