27#include "hdrl_spectrum.h"
29#include "hdrl_DER_SNR.h"
30#include "hdrl_utils.h"
48typedef cpl_error_code (* operate_image_mutable) (hdrl_image * self,
49 const hdrl_image * other);
51typedef cpl_error_code (* operate_image_scalar_mutable) (hdrl_image * self,
54static inline cpl_error_code
55operate_spectra_flux_mutate(hdrl_spectrum1D * self,
56 const hdrl_spectrum1D * other,
57 operate_image_mutable func);
59static inline hdrl_spectrum1D *
60operate_spectra_flux_create(
const hdrl_spectrum1D * self,
61 const hdrl_spectrum1D * other,
62 operate_image_mutable func);
64static inline cpl_error_code
65operate_spectra_scalar_flux_mutate(hdrl_spectrum1D * self,
67 operate_image_scalar_mutable func);
69static inline hdrl_spectrum1D *
70operate_spectra_scalar_flux_create(
const hdrl_spectrum1D * self,
72 operate_image_scalar_mutable func);
75hdrl_spectrum1D * hdrl_spectrum1D_wrap(hdrl_image * arg_flux,
76 cpl_array * wavelength,
77 hdrl_spectrum1D_wave_scale scale);
79static inline int compare_double(
const void * a,
const void * b);
81static inline cpl_boolean is_uniformly_sampled(
const double * v, cpl_size sz,
85static inline cpl_boolean
86is_wlen_selected(
const cpl_bivector * windows,
const cpl_boolean is_internal,
118 const cpl_image * arg_flux_e,
119 const cpl_array * wavelength,
120 hdrl_spectrum1D_wave_scale wave_scale){
122 cpl_ensure(arg_flux != NULL && wavelength != NULL && arg_flux_e != NULL,
123 CPL_ERROR_NULL_INPUT, NULL);
125 cpl_ensure(cpl_image_get_size_y(arg_flux) == 1
126 && cpl_image_get_size_y(arg_flux_e) == 1,
127 CPL_ERROR_INCOMPATIBLE_INPUT, NULL);
129 cpl_ensure(cpl_image_get_size_x(arg_flux) == cpl_array_get_size(wavelength)
130 && cpl_image_get_size_x(arg_flux_e) == cpl_array_get_size(wavelength),
131 CPL_ERROR_INCOMPATIBLE_INPUT, NULL);
133 cpl_image * flux_error = cpl_image_cast(arg_flux_e, HDRL_TYPE_ERROR);
134 cpl_image * flux = cpl_image_cast(arg_flux, HDRL_TYPE_DATA);
136 hdrl_image * flux_img = hdrl_image_wrap(flux, flux_error, NULL, CPL_TRUE);
137 cpl_array * lambda = cpl_array_cast(wavelength, HDRL_TYPE_DATA);
139 return hdrl_spectrum1D_wrap(flux_img, lambda, wave_scale);
161 calculate_analytic_spectrum_point func,
162 const cpl_array * wavelength,
163 hdrl_spectrum1D_wave_scale scale){
165 cpl_ensure(wavelength != NULL, CPL_ERROR_NULL_INPUT, NULL);
166 cpl_ensure(func != NULL, CPL_ERROR_NULL_INPUT, NULL);
168 cpl_size sx = cpl_array_get_size(wavelength);
169 cpl_image * flux = cpl_image_new(sx, 1, HDRL_TYPE_DATA);
170 cpl_image * flux_e = cpl_image_new(sx, 1, HDRL_TYPE_ERROR);
172 for(cpl_size i = 0; i < sx; ++i){
173 hdrl_data_t lambda = cpl_array_get(wavelength, i, NULL);
174 hdrl_value v = func(lambda);
175 cpl_image_set(flux, i + 1, 1, v.data);
176 cpl_image_set(flux_e, i + 1, 1, v.error);
179 hdrl_spectrum1D * to_ret =
182 cpl_image_delete(flux);
183 cpl_image_delete(flux_e);
205 (
const cpl_image * arg_flux,
206 const cpl_array * wavelength,
207 hdrl_spectrum1D_wave_scale scale){
209 cpl_ensure(arg_flux != NULL, CPL_ERROR_NULL_INPUT, NULL);
211 cpl_size sx = cpl_image_get_size_x(arg_flux);
212 cpl_size sy = cpl_image_get_size_y(arg_flux);
214 cpl_ensure(sy == 1 && sx > 0, CPL_ERROR_INCOMPATIBLE_INPUT, NULL);
216 cpl_image * zero_errors = cpl_image_new(sx, sy, HDRL_TYPE_ERROR);
217 cpl_image_fill_window(zero_errors, 1, 1, sx, sy, 0.0);
220 (arg_flux, zero_errors, wavelength, scale);
222 cpl_image_delete(zero_errors);
251 (
const cpl_image * arg_flux,
252 cpl_size half_window,
253 const cpl_array * wavelength,
254 hdrl_spectrum1D_wave_scale scale){
255 cpl_ensure(arg_flux != NULL, CPL_ERROR_NULL_INPUT, NULL);
256 cpl_ensure(wavelength != NULL, CPL_ERROR_NULL_INPUT, NULL);
258 cpl_size sx = cpl_image_get_size_x(arg_flux);
259 cpl_size sy = cpl_image_get_size_y(arg_flux);
261 cpl_ensure(sy == 1 && sx > 0, CPL_ERROR_INCOMPATIBLE_INPUT, NULL);
263 cpl_image * flux = cpl_image_cast(arg_flux, HDRL_TYPE_DATA);
265 const hdrl_data_t * flux_data =
266 (
const hdrl_data_t*)cpl_image_get_data_const(flux);
267 const cpl_mask * mask_in = cpl_image_get_bpm_const(flux);
268 const cpl_binary * msk_in =
269 mask_in == NULL ? NULL : cpl_mask_get_data_const(mask_in);
272 (flux_data, msk_in, wavelength, sx, half_window);
274 if(!DER_SNR_errors || cpl_error_get_code() != CPL_ERROR_NONE){
275 cpl_image_delete(flux);
276 cpl_image_delete(DER_SNR_errors);
283 cpl_mask * msk = cpl_image_unset_bpm(DER_SNR_errors);
284 cpl_mask_delete(cpl_image_set_bpm(flux, msk));
287 (flux , DER_SNR_errors, wavelength, scale);
289 cpl_image_delete(DER_SNR_errors);
290 cpl_image_delete(flux);
304 if(!self)
return NULL;
307 cpl_array * lambdas = cpl_array_duplicate(self->wavelength);
310 return hdrl_spectrum1D_wrap(flux, lambdas, self->wave_scale);
327 hdrl_spectrum1D * spectrum = *p_self;
329 if(!spectrum)
return;
331 cpl_array_delete(spectrum->wavelength);
348 return cpl_array_get_size(self->wavelength);
360 if(!self)
return NULL;
372hdrl_spectrum1D_wavelength
375 hdrl_spectrum1D_wavelength to_ret = {NULL, NULL,
376 hdrl_spectrum1D_wave_scale_linear};
378 cpl_ensure(self != NULL,
379 CPL_ERROR_NULL_INPUT, to_ret);
383 const cpl_array * lambdas = self->wavelength;
389 to_ret.wavelength = lambdas;
400hdrl_spectrum1D_wave_scale
402 cpl_ensure(self != NULL,
403 CPL_ERROR_NULL_INPUT, hdrl_spectrum1D_wave_scale_linear);
405 return self->wave_scale;
419 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, ((hdrl_value){0.0, 0.0}));
437 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0.0);
439 const hdrl_spectrum1D_wavelength lambdas =
442 const cpl_array * wlengs = lambdas.wavelength;
443 const hdrl_data_t to_ret = (hdrl_data_t) cpl_array_get(wlengs, idx, NULL);
446 const cpl_mask * msk = lambdas.bpm;
448 *rej = cpl_mask_get(msk, idx + 1, 1);
468 const hdrl_spectrum1D * den){
484 const hdrl_spectrum1D * f2){
500 const hdrl_spectrum1D * f2){
517 const hdrl_spectrum1D * f2){
530 const hdrl_spectrum1D * other){
542 const hdrl_spectrum1D * other){
554 const hdrl_spectrum1D * other){
567 const hdrl_spectrum1D * other){
583 hdrl_value scalar_operator){
600 hdrl_value scalar_operator){
617 hdrl_value scalar_operator){
634 hdrl_value scalar_operator){
651 hdrl_value scalar_operator){
668 hdrl_value scalar_operator){
682 hdrl_value scalar_operator){
697 hdrl_value scalar_operator){
711 hdrl_value scalar_operator){
725 hdrl_value scalar_operator){
739 hdrl_value scalar_operator){
753 hdrl_value scalar_operator){
769 hdrl_data_t scale_linear)
771 cpl_ensure_code(scale_linear > 0, CPL_ERROR_INCOMPATIBLE_INPUT);
773 if(self == NULL)
return CPL_ERROR_NONE;
775 if(self->wave_scale == hdrl_spectrum1D_wave_scale_linear)
776 return cpl_array_multiply_scalar(self->wavelength, scale_linear);
778 return cpl_array_add_scalar(self->wavelength, log(scale_linear));
795 hdrl_data_t scale_linear)
797 if(!self)
return NULL;
801 cpl_error_code fail =
820 if(!self)
return CPL_ERROR_NONE;
822 return cpl_array_add_scalar(self->wavelength, shift);
839 if(!self)
return NULL;
862 if(self == NULL || self->wave_scale == hdrl_spectrum1D_wave_scale_linear)
863 return CPL_ERROR_NONE;
865 cpl_error_code fail = cpl_array_exponential(self->wavelength, CPL_MATH_E);
866 self->wave_scale = hdrl_spectrum1D_wave_scale_linear;
901 if(self == NULL || self->wave_scale == hdrl_spectrum1D_wave_scale_log)
902 return CPL_ERROR_NONE;
904 cpl_error_code fail = cpl_array_logarithm(self->wavelength, CPL_MATH_E);
905 self->wave_scale = hdrl_spectrum1D_wave_scale_log;
956 const cpl_bivector * windows,
const cpl_boolean is_internal){
958 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
959 cpl_ensure(windows != NULL, CPL_ERROR_NULL_INPUT, NULL);
962 cpl_size num_selected = 0;
964 for(cpl_size i = 0; i < sz; ++i){
966 if(is_wlen_selected(windows, is_internal, w))
970 if(num_selected == sz)
973 cpl_ensure(num_selected > 0, CPL_ERROR_ILLEGAL_OUTPUT, NULL);
975 cpl_image * flux = cpl_image_new(num_selected, 1, HDRL_TYPE_DATA);
976 cpl_image * flux_e = cpl_image_new(num_selected, 1, HDRL_TYPE_ERROR);
977 cpl_array * wavs = cpl_array_new(num_selected, HDRL_TYPE_DATA);
979 cpl_size idx_this = 0;
980 for(cpl_size i = 0; i < sz; ++i){
984 if(!is_wlen_selected(windows, is_internal, w))
continue;
989 cpl_image_set(flux, idx_this + 1, 1, v.data);
990 cpl_image_set(flux_e, idx_this + 1, 1, v.error);
993 cpl_image_reject(flux, idx_this + 1, 1);
994 cpl_image_reject(flux_e, idx_this + 1, 1);
997 cpl_array_set(wavs, idx_this, w);
1005 cpl_image_delete(flux);
1006 cpl_image_delete(flux_e);
1007 cpl_array_delete(wavs);
1028 const cpl_array * bad_samples){
1030 const cpl_size sz = cpl_array_get_size(bad_samples);
1032 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
1033 cpl_ensure(bad_samples != NULL, CPL_ERROR_NULL_INPUT, NULL);
1038 for(cpl_size i = 0; i < sz; ++i){
1040 if(cpl_array_get_int(bad_samples, i, NULL))
1048 hdrl_spectrum1D * to_ret =
1050 wlen.wavelength, wlen.scale);
1075 const hdrl_spectrum1D * self,
const char * flux_col_name,
1076 const char* wavelength_col_name,
const char * flux_e_col_name,
1077 const char * flux_bpm_col_name){
1079 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
1080 cpl_ensure(flux_col_name != NULL || wavelength_col_name != NULL,
1081 CPL_ERROR_NULL_INPUT, NULL);
1085 cpl_table * tb = cpl_table_new(sz);
1086 cpl_ensure(tb != NULL, CPL_ERROR_NULL_INPUT, NULL);
1089 (self, tb, flux_col_name, wavelength_col_name, flux_e_col_name,
1093 cpl_table_delete(tb);
1116(
const hdrl_spectrum1D * self, cpl_table * dest,
1117const char * flux_col_name,
const char* wavelength_col_name,
1118const char * flux_e_col_name,
const char * flux_bpm_col_name){
1120 cpl_ensure_code(self != NULL && dest != NULL,CPL_ERROR_NULL_INPUT);
1121 cpl_ensure_code(flux_col_name != NULL || wavelength_col_name != NULL,
1122 CPL_ERROR_NULL_INPUT);
1124 cpl_size cl_sz = cpl_table_get_nrow(dest);
1127 cpl_ensure_code(sz == cl_sz, CPL_ERROR_INCOMPATIBLE_INPUT);
1129 if(wavelength_col_name){
1130 double * lambdas = cpl_calloc(sz ,
sizeof(
double));
1131 for(cpl_size i = 0; i < sz; i++){
1134 cpl_error_code fail =
1135 cpl_table_wrap_double(dest, lambdas, wavelength_col_name);
1144 double * flux = cpl_calloc(sz ,
sizeof(
double));
1145 for(cpl_size i = 0; i < sz; i++){
1149 cpl_error_code fail = cpl_table_wrap_double(dest, flux, flux_col_name);
1156 if(flux_e_col_name){
1157 double * e_flux = cpl_calloc(sz ,
sizeof(
double));
1158 for(cpl_size i = 0; i < sz; i++){
1161 cpl_error_code fail =
1162 cpl_table_wrap_double(dest, e_flux, flux_e_col_name);
1170 if(flux_bpm_col_name){
1171 int * bpm_flux = cpl_calloc(sz ,
sizeof(
int));
1172 for(cpl_size i = 0; i < sz; i++){
1175 cpl_error_code fail =
1176 cpl_table_wrap_int(dest, bpm_flux, flux_bpm_col_name);
1183 return CPL_ERROR_NONE;
1201(
const cpl_table * self,
const char * flux_col_name,
1202const char* wavelength_col_name,
const char * flux_e_col_name,
1203const char * flux_bpm_col_name, hdrl_spectrum1D_wave_scale scale){
1205 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
1206 cpl_ensure(flux_col_name != NULL, CPL_ERROR_NULL_INPUT, NULL);
1207 cpl_ensure(wavelength_col_name != NULL, CPL_ERROR_NULL_INPUT, NULL);
1209 cpl_size sz = cpl_table_get_nrow(self);
1211 cpl_ensure(sz > 1, CPL_ERROR_ILLEGAL_INPUT, NULL);
1213 cpl_image * flux = cpl_image_new(sz, 1, HDRL_TYPE_DATA);
1214 cpl_image * flux_e = cpl_image_new(sz, 1, HDRL_TYPE_ERROR);
1215 cpl_array * lambdas = cpl_array_new(sz, HDRL_TYPE_DATA);
1218 for(cpl_size i = 0; i < sz; ++i){
1219 const double fx = cpl_table_get(self, flux_col_name, i, NULL);
1220 const double l = cpl_table_get(self, wavelength_col_name, i, NULL);
1224 fx_e = cpl_table_get(self, flux_e_col_name, i, NULL);
1227 if(flux_bpm_col_name)
1228 rej = cpl_table_get_int(self, flux_bpm_col_name, i, NULL);
1230 cpl_image_set(flux, i + 1, 1, fx);
1233 cpl_image_reject(flux, i + 1, 1);
1235 cpl_image_set(flux_e, i + 1, 1, fx_e);
1236 cpl_array_set(lambdas, i, l);
1241 cpl_image_delete(flux);
1242 cpl_image_delete(flux_e);
1243 cpl_array_delete(lambdas);
1247void hdrl_spectrum1D_save(
const hdrl_spectrum1D * s,
const char * fname){
1248 if(s == NULL)
return;
1251 cpl_table_save(tb, NULL, NULL, fname, CPL_IO_CREATE);
1252 cpl_table_delete(tb);
1264 const cpl_array * w2){
1265 if(w1 == NULL && w2 == NULL)
return CPL_TRUE;
1267 if(w1 == NULL)
return CPL_FALSE;
1269 if(w2 == NULL)
return CPL_FALSE;
1271 cpl_size sz = cpl_array_get_size(w1);
1272 if(sz != cpl_array_get_size(w2))
return CPL_FALSE;
1273 for(cpl_size i = 0; i < sz; i++){
1274 const double wa = cpl_array_get(w1, i, NULL);
1275 const double wb = cpl_array_get(w2, i, NULL);
1277 const double d = wa - wb;
1278 if(fabs(d) > 1e-10 * CPL_MIN(wa, wb)){
1295 const hdrl_spectrum1D_wavelength* s2){
1297 if(s1 == NULL && s2 == NULL)
return CPL_TRUE;
1299 if(s1 == NULL)
return CPL_FALSE;
1301 if(s2 == NULL)
return CPL_FALSE;
1303 if(s1->scale != s2->scale)
return CPL_FALSE;
1323 if(self == NULL)
return CPL_FALSE;
1327 if(sz <= 2)
return CPL_TRUE;
1329 double * vd = cpl_calloc(sz,
sizeof(
double));
1331 for(cpl_size i = 0; i < sz; ++i){
1335 qsort(vd, sz,
sizeof(
double), compare_double);
1337 cpl_boolean to_ret = is_uniformly_sampled(vd, sz, bin);
1358static inline cpl_error_code operate_spectra_flux_mutate(hdrl_spectrum1D * self,
1359 const hdrl_spectrum1D * other,
1360 operate_image_mutable func){
1361 cpl_ensure_code(self != NULL && other != NULL,
1362 CPL_ERROR_NULL_INPUT);
1367 CPL_ERROR_INCOMPATIBLE_INPUT);
1369 hdrl_image * f1 = self->flux;
1370 const hdrl_image * f2 = other->flux;
1372 cpl_ensure_code(f1 != NULL && f2 != NULL,
1373 CPL_ERROR_NULL_INPUT);
1377 return CPL_ERROR_NONE;
1390static inline hdrl_spectrum1D *
1391operate_spectra_flux_create(
const hdrl_spectrum1D * self,
1392 const hdrl_spectrum1D * other,
1393 operate_image_mutable func){
1397 cpl_error_code fail = operate_spectra_flux_mutate(to_ret, other, func);
1415static inline cpl_error_code
1416operate_spectra_scalar_flux_mutate(hdrl_spectrum1D * self,
1418 operate_image_scalar_mutable func){
1420 if(!self)
return CPL_ERROR_NONE;
1422 hdrl_image * f1 = self->flux;
1424 cpl_ensure_code(f1 != NULL, CPL_ERROR_NULL_INPUT);
1428 return CPL_ERROR_NONE;
1441static inline hdrl_spectrum1D *
1442operate_spectra_scalar_flux_create(
const hdrl_spectrum1D * self,
1444 operate_image_scalar_mutable func){
1448 cpl_error_code fail =
1449 operate_spectra_scalar_flux_mutate(to_ret, scalar, func);
1459hdrl_spectrum1D * hdrl_spectrum1D_wrap(hdrl_image * arg_flux,
1460 cpl_array * wavelength,
1461 hdrl_spectrum1D_wave_scale scale){
1463 hdrl_spectrum1D * to_ret = cpl_calloc(1,
sizeof(*to_ret));
1465 to_ret->flux = arg_flux;
1466 to_ret->wavelength = wavelength;
1467 to_ret->wave_scale = scale;
1472int compare_double(
const void * a,
const void * b){
1473 const double ad = *((
const double *)a);
1474 const double bd = *((
const double *)b);
1475 const double delta = ad - bd;
1476 if(delta > 0.0)
return 1;
1477 if(delta < 0.0)
return -1;
1481#if HDRL_SIZEOF_DATA == 4
1482 const double wave_delta = 1.e-5;
1484 const double wave_delta = 1.e-6;
1488cpl_boolean is_uniformly_sampled(
const double * v, cpl_size sz,
double * bin){
1490 const double d = v[1] - v[0];
1492 for(cpl_size i = 1; i < sz - 1; ++i){
1493 const double d2 = (v[i + 1] - v[i]);
1494 const double eps = (fabs(d2 - d) / d);
1495 if(eps > wave_delta){
1504static inline cpl_boolean
1505is_contained_in_at_least_one_window(
const cpl_bivector * windows,
const hdrl_data_t w){
1506 const cpl_size sz = cpl_bivector_get_size(windows);
1508 for(cpl_size i = 0; i < sz; ++i){
1509 const double wmin = cpl_vector_get(cpl_bivector_get_x_const(windows), i);
1510 const double wmax = cpl_vector_get(cpl_bivector_get_y_const(windows), i);
1512 if(w >= wmin && w <= wmax)
return CPL_TRUE;
1518static inline cpl_boolean
1519is_wlen_selected(
const cpl_bivector * windows,
const cpl_boolean is_internal,
1520 const hdrl_data_t w){
1522 if(is_internal)
return is_contained_in_at_least_one_window(windows, w);
1524 return !is_contained_in_at_least_one_window(windows, w);
hdrl_value hdrl_image_get_pixel(const hdrl_image *self, cpl_size xpos, cpl_size ypos, int *pis_rejected)
get pixel values of hdrl_image
cpl_error_code hdrl_image_sub_image(hdrl_image *self, const hdrl_image *other)
Subtract two images, store the result in the first image.
cpl_error_code hdrl_image_div_scalar(hdrl_image *self, hdrl_value value)
Elementwise division of an image with a scalar.
cpl_error_code hdrl_image_pow_scalar(hdrl_image *self, const hdrl_value exponent)
computes the power of an image by a scalar
cpl_error_code hdrl_image_add_image(hdrl_image *self, const hdrl_image *other)
Add two images, store the result in the first image.
cpl_error_code hdrl_image_div_image(hdrl_image *self, const hdrl_image *other)
Divide two images, store the result in the first image.
cpl_error_code hdrl_image_mul_scalar(hdrl_image *self, hdrl_value value)
Elementwise multiplication of an image with a scalar.
hdrl_image * hdrl_image_duplicate(const hdrl_image *himg)
copy hdrl_image
cpl_error_code hdrl_image_add_scalar(hdrl_image *self, hdrl_value value)
Elementwise addition of a scalar to an image.
cpl_error_code hdrl_image_mul_image(hdrl_image *self, const hdrl_image *other)
Multiply two images, store the result in the first image.
cpl_error_code hdrl_image_exp_scalar(hdrl_image *self, const hdrl_value base)
computes the exponential of an image by a scalar
cpl_image * hdrl_image_get_error(hdrl_image *himg)
get error as cpl image
cpl_image * hdrl_image_get_image(hdrl_image *himg)
get data as cpl image
cpl_error_code hdrl_image_reject(hdrl_image *self, cpl_size xpos, cpl_size ypos)
mark pixel as bad
const cpl_image * hdrl_image_get_image_const(const hdrl_image *himg)
get data as cpl image
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image
cpl_error_code hdrl_image_sub_scalar(hdrl_image *self, hdrl_value value)
Elementwise subtraction of a scalar from an image.
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.
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_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 wi...
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