CR2RE Pipeline Reference Manual 1.6.8
hdrl_spectrum.h
1/* $Id: hdrl_spectrum.h,v 0.1 2017-02-28 16:20:00 msalmist Exp $
2 *
3 * This file is part of the HDRL
4 * Copyright (C) 2017 European Southern Observatory
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21/*
22 * $Author: msalmist $
23 * $Date: 2017-02-28 16:20:00 $
24 * $Revision: 0.1 $
25 * $Name: not supported by cvs2svn $
26 */
27
28#ifndef HDRL_SPECTRUM_H
29#define HDRL_SPECTRUM_H
30
31/*-----------------------------------------------------------------------------
32 Includes
33 -----------------------------------------------------------------------------*/
34
35#include "hdrl_image.h"
36#include "hdrl_correlation.h"
37#include "hdrl_spectrum_defs.h"
38
39#include <cpl.h>
40
41CPL_BEGIN_DECLS
42
43#if defined HDRL_USE_EXPERIMENTAL || defined HDRL_USE_PRIVATE
44
45cpl_boolean
46hdrl_spectrum1D_is_uniformly_sampled(const hdrl_spectrum1D * self, double * bin);
47
48void hdrl_spectrum1D_save(const hdrl_spectrum1D * s, const char * fname);
49
50#endif
51
52/*-----------------------------------------------------------------------------
53 Functions - Constructors
54 -----------------------------------------------------------------------------*/
55hdrl_spectrum1D * hdrl_spectrum1D_create(const cpl_image * arg_flux,
56 const cpl_image * arg_flux_e,
57 const cpl_array * wavelength,
58 hdrl_spectrum1D_wave_scale wave_scale);
59
61 (const cpl_image * arg_flux,
62 const cpl_array * wavelength,
63 hdrl_spectrum1D_wave_scale scale);
64
66 (const cpl_image * arg_flux,
67 cpl_size half_window,
68 const cpl_array * wavelength,
69 hdrl_spectrum1D_wave_scale scale);
70
71typedef hdrl_value (* calculate_analytic_spectrum_point) (hdrl_data_t lambda);
72
73hdrl_spectrum1D * hdrl_spectrum1D_create_analytic(
74 calculate_analytic_spectrum_point func,
75 const cpl_array * wavelength,
76 hdrl_spectrum1D_wave_scale scale);
77
78hdrl_spectrum1D * hdrl_spectrum1D_duplicate(const hdrl_spectrum1D* self);
79
80void hdrl_spectrum1D_delete(hdrl_spectrum1D ** p_self);
81
82
83/*-----------------------------------------------------------------------------
84 Functions - Getter operations
85 -----------------------------------------------------------------------------*/
86
87cpl_size hdrl_spectrum1D_get_size(const hdrl_spectrum1D * self);
88
89const hdrl_image*
90hdrl_spectrum1D_get_flux(const hdrl_spectrum1D * self);
91
92
93typedef struct{
94 const cpl_array * wavelength;
95 const cpl_mask * bpm;
96 hdrl_spectrum1D_wave_scale scale;
97}hdrl_spectrum1D_wavelength;
98
99hdrl_spectrum1D_wavelength
100hdrl_spectrum1D_get_wavelength(const hdrl_spectrum1D * self);
101
102hdrl_spectrum1D_wave_scale
103hdrl_spectrum1D_get_scale(const hdrl_spectrum1D * self);
104
105
106hdrl_value
107hdrl_spectrum1D_get_flux_value(const hdrl_spectrum1D * self, int idx, int* rej);
108
109hdrl_data_t
110hdrl_spectrum1D_get_wavelength_value(const hdrl_spectrum1D * self, int idx, int* rej);
111
112
113/*-----------------------------------------------------------------------------
114 Functions - Vectorial flux operations
115 -----------------------------------------------------------------------------*/
116
117cpl_boolean
118hdrl_spectrum1D_are_spectra_compatible(const hdrl_spectrum1D_wavelength* s1,
119 const hdrl_spectrum1D_wavelength* s2);
120cpl_boolean
122 const cpl_array* w2);
123hdrl_spectrum1D *
124hdrl_spectrum1D_div_spectrum_create(const hdrl_spectrum1D * num,
125 const hdrl_spectrum1D * den);
126
127hdrl_spectrum1D *
128hdrl_spectrum1D_mul_spectrum_create(const hdrl_spectrum1D * f1,
129 const hdrl_spectrum1D * f2);
130
131hdrl_spectrum1D *
132hdrl_spectrum1D_add_spectrum_create(const hdrl_spectrum1D * f1,
133 const hdrl_spectrum1D * f2);
134
135hdrl_spectrum1D *
136hdrl_spectrum1D_sub_spectrum_create(const hdrl_spectrum1D * f1,
137 const hdrl_spectrum1D * f2);
138
139
140cpl_error_code hdrl_spectrum1D_div_spectrum( hdrl_spectrum1D * self,
141 const hdrl_spectrum1D * other);
142
143cpl_error_code hdrl_spectrum1D_mul_spectrum( hdrl_spectrum1D * self,
144 const hdrl_spectrum1D * other);
145
146cpl_error_code hdrl_spectrum1D_add_spectrum( hdrl_spectrum1D * self,
147 const hdrl_spectrum1D * other);
148
149cpl_error_code hdrl_spectrum1D_sub_spectrum( hdrl_spectrum1D * self,
150 const hdrl_spectrum1D * other);
151
152/*-----------------------------------------------------------------------------
153 Functions - Scalar flux operations
154 -----------------------------------------------------------------------------*/
155
156hdrl_spectrum1D *
157hdrl_spectrum1D_div_scalar_create(const hdrl_spectrum1D * self,
158 hdrl_value scalar_operator);
159
160hdrl_spectrum1D *
161hdrl_spectrum1D_mul_scalar_create(const hdrl_spectrum1D * self,
162 hdrl_value scalar_operator);
163
164hdrl_spectrum1D *
165hdrl_spectrum1D_add_scalar_create(const hdrl_spectrum1D * self,
166 hdrl_value scalar_operator);
167
168hdrl_spectrum1D *
169hdrl_spectrum1D_sub_scalar_create(const hdrl_spectrum1D * self,
170 hdrl_value scalar_operator);
171
172hdrl_spectrum1D *
173hdrl_spectrum1D_pow_scalar_create(const hdrl_spectrum1D * self,
174 hdrl_value scalar_operator);
175
176hdrl_spectrum1D *
177hdrl_spectrum1D_exp_scalar_create(const hdrl_spectrum1D * self,
178 hdrl_value scalar_operator);
179
180cpl_error_code hdrl_spectrum1D_div_scalar(hdrl_spectrum1D * self,
181 hdrl_value scalar_operator);
182
183cpl_error_code hdrl_spectrum1D_mul_scalar(hdrl_spectrum1D * self,
184 hdrl_value scalar_operator);
185
186cpl_error_code hdrl_spectrum1D_add_scalar(hdrl_spectrum1D * self,
187 hdrl_value scalar_operator);
188
189cpl_error_code hdrl_spectrum1D_sub_scalar(hdrl_spectrum1D * self,
190 hdrl_value scalar_operator);
191
192cpl_error_code hdrl_spectrum1D_pow_scalar(hdrl_spectrum1D * self,
193 hdrl_value scalar_operator);
194
195cpl_error_code hdrl_spectrum1D_exp_scalar(hdrl_spectrum1D * self,
196 hdrl_value scalar_operator);
197
198/*-----------------------------------------------------------------------------
199 Functions - Wavelength operations
200 -----------------------------------------------------------------------------*/
201
202cpl_error_code hdrl_spectrum1D_wavelength_mult_scalar_linear(hdrl_spectrum1D * self,
203 hdrl_data_t scale_linear);
204
205hdrl_spectrum1D *
207 hdrl_data_t scale_linear);
208
209
210cpl_error_code hdrl_spectrum1D_wavelength_shift(hdrl_spectrum1D * self,
211 hdrl_data_t shift);
212
213hdrl_spectrum1D *
214hdrl_spectrum1D_wavelength_shift_create(const hdrl_spectrum1D * self,
215 hdrl_data_t shift);
216
217
218cpl_error_code hdrl_spectrum1D_wavelength_convert_to_linear(hdrl_spectrum1D * self);
219
220hdrl_spectrum1D *
221hdrl_spectrum1D_wavelength_convert_to_linear_create(const hdrl_spectrum1D * self);
222
223cpl_error_code hdrl_spectrum1D_wavelength_convert_to_log(hdrl_spectrum1D * self);
224
225
226hdrl_spectrum1D *
227hdrl_spectrum1D_wavelength_convert_to_log_create(const hdrl_spectrum1D * self);
228
229/*-----------------------------------------------------------------------------
230 Functions - Selectors
231 -----------------------------------------------------------------------------*/
232
233hdrl_spectrum1D *
234hdrl_spectrum1D_select_wavelengths(const hdrl_spectrum1D * self,
235 const cpl_bivector * windows, const cpl_boolean is_internal);
236
237hdrl_spectrum1D *
238hdrl_spectrum1D_reject_pixels(const hdrl_spectrum1D * self,
239 const cpl_array * bad_samples);
240
241
242/*-----------------------------------------------------------------------------
243 Functions - Table conversions
244 -----------------------------------------------------------------------------*/
245
247(const hdrl_spectrum1D * self, const char * flux_col_name,
248const char* wavelength_col_name, const char * flux_e_col_name,
249const char * flux_bpm_col_name);
250
252(const cpl_table * self, const char * flux_col_name,
253const char* wavelength_col_name, const char * flux_e_col_name,
254const char * flux_bpm_col_name, hdrl_spectrum1D_wave_scale scale);
255
257(const hdrl_spectrum1D * self, cpl_table * dest,
258const char * flux_col_name, const char* wavelength_col_name,
259const char * flux_e_col_name, const char * flux_bpm_col_name);
260
261
262CPL_END_DECLS
263
264#endif
hdrl_spectrum1D * hdrl_spectrum1D_pow_scalar_create(const hdrl_spectrum1D *self, hdrl_value scalar_operator)
subtract a scalar from a spectrum
const hdrl_image * hdrl_spectrum1D_get_flux(const hdrl_spectrum1D *self)
hdrl_spectrum1D getter flux
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_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...
cpl_error_code hdrl_spectrum1D_wavelength_convert_to_linear(hdrl_spectrum1D *self)
converts the wavelength scale to linear.
hdrl_spectrum1D * hdrl_spectrum1D_sub_spectrum_create(const hdrl_spectrum1D *f1, const hdrl_spectrum1D *f2)
subtract two spectra
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 modifi...
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_pow_scalar(hdrl_spectrum1D *self, hdrl_value scalar_operator)
computes the elementwise power of the flux to the scalar, the self parameter is modified
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_duplicate(const hdrl_spectrum1D *self)
hdrl_spectrum1D copy constructor
cpl_size hdrl_spectrum1D_get_size(const hdrl_spectrum1D *self)
hdrl_spectrum1D getter for size
void hdrl_spectrum1D_delete(hdrl_spectrum1D **p_self)
hdrl_spectrum1D destructor
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_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_div_spectrum_create(const hdrl_spectrum1D *num, const hdrl_spectrum1D *den)
divide one spectrum by another spectrum
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
hdrl_spectrum1D * hdrl_spectrum1D_mul_scalar_create(const hdrl_spectrum1D *self, hdrl_value scalar_operator)
multiply a spectrum by a scalar
cpl_error_code hdrl_spectrum1D_sub_spectrum(hdrl_spectrum1D *self, const hdrl_spectrum1D *other)
subtract two spectra
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.
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_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 es...
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
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....
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_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_boolean hdrl_spectrum1D_is_uniformly_sampled(const hdrl_spectrum1D *self, double *bin)
checks if the spectrum is defined on uniformly sampled wavelengths.
CPL_BEGIN_DECLS 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
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_add_spectrum(hdrl_spectrum1D *self, const hdrl_spectrum1D *other)
sum two spectra
hdrl_spectrum1D * hdrl_spectrum1D_exp_scalar_create(const hdrl_spectrum1D *self, hdrl_value scalar_operator)
subtract a scalar from 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_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...
hdrl_spectrum1D_wave_scale hdrl_spectrum1D_get_scale(const hdrl_spectrum1D *self)
hdrl_spectrum1D getter for scale
hdrl_spectrum1D_wavelength hdrl_spectrum1D_get_wavelength(const hdrl_spectrum1D *self)
hdrl_spectrum1D getter for wavelengths
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 fo...
hdrl_spectrum1D * hdrl_spectrum1D_add_scalar_create(const hdrl_spectrum1D *self, hdrl_value scalar_operator)
add a scalar to a spectrum
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_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
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_wavelength_convert_to_linear_create(const hdrl_spectrum1D *self)
converts the wavelength scale to linear.
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.
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 wave...
hdrl_spectrum1D * hdrl_spectrum1D_add_spectrum_create(const hdrl_spectrum1D *f1, const hdrl_spectrum1D *f2)
sum one spectrum to another 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_boolean hdrl_spectrum1D_are_spectra_compatible(const hdrl_spectrum1D_wavelength *s1, const hdrl_spectrum1D_wavelength *s2)
checks if two spectrum wavelengths are equal.
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 mar...
hdrl_value hdrl_spectrum1D_get_flux_value(const hdrl_spectrum1D *self, int idx, int *rej)
hdrl_spectrum1D getter for a flux value