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);
326 hdrl_spectrum1D * spectrum = *p_self;
328 if(!spectrum)
return;
330 cpl_array_delete(spectrum->wavelength);
347 return cpl_array_get_size(self->wavelength);
359 if(!self)
return NULL;
371hdrl_spectrum1D_wavelength
374 hdrl_spectrum1D_wavelength to_ret = {NULL, NULL,
375 hdrl_spectrum1D_wave_scale_linear};
377 cpl_ensure(self != NULL,
378 CPL_ERROR_NULL_INPUT, to_ret);
382 const cpl_array * lambdas = self->wavelength;
388 to_ret.wavelength = lambdas;
399hdrl_spectrum1D_wave_scale
401 cpl_ensure(self != NULL,
402 CPL_ERROR_NULL_INPUT, hdrl_spectrum1D_wave_scale_linear);
404 return self->wave_scale;
418 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, ((hdrl_value){0.0, 0.0}));
436 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, 0.0);
438 const hdrl_spectrum1D_wavelength lambdas =
441 const cpl_array * wlengs = lambdas.wavelength;
442 const hdrl_data_t to_ret = (hdrl_data_t) cpl_array_get(wlengs, idx, NULL);
445 const cpl_mask * msk = lambdas.bpm;
447 *rej = cpl_mask_get(msk, idx + 1, 1);
467 const hdrl_spectrum1D * den){
483 const hdrl_spectrum1D * f2){
499 const hdrl_spectrum1D * f2){
516 const hdrl_spectrum1D * f2){
529 const hdrl_spectrum1D * other){
541 const hdrl_spectrum1D * other){
553 const hdrl_spectrum1D * other){
566 const hdrl_spectrum1D * other){
582 hdrl_value scalar_operator){
599 hdrl_value scalar_operator){
616 hdrl_value scalar_operator){
633 hdrl_value scalar_operator){
650 hdrl_value scalar_operator){
667 hdrl_value scalar_operator){
681 hdrl_value scalar_operator){
696 hdrl_value scalar_operator){
710 hdrl_value scalar_operator){
724 hdrl_value scalar_operator){
738 hdrl_value scalar_operator){
752 hdrl_value scalar_operator){
768 hdrl_data_t scale_linear)
770 cpl_ensure_code(scale_linear > 0, CPL_ERROR_INCOMPATIBLE_INPUT);
772 if(self == NULL)
return CPL_ERROR_NONE;
774 if(self->wave_scale == hdrl_spectrum1D_wave_scale_linear)
775 return cpl_array_multiply_scalar(self->wavelength, scale_linear);
777 return cpl_array_add_scalar(self->wavelength, log(scale_linear));
794 hdrl_data_t scale_linear)
796 if(!self)
return NULL;
800 cpl_error_code fail =
819 if(!self)
return CPL_ERROR_NONE;
821 return cpl_array_add_scalar(self->wavelength, shift);
838 if(!self)
return NULL;
861 if(self == NULL || self->wave_scale == hdrl_spectrum1D_wave_scale_linear)
862 return CPL_ERROR_NONE;
864 cpl_error_code fail = cpl_array_exponential(self->wavelength, CPL_MATH_E);
865 self->wave_scale = hdrl_spectrum1D_wave_scale_linear;
900 if(self == NULL || self->wave_scale == hdrl_spectrum1D_wave_scale_log)
901 return CPL_ERROR_NONE;
903 cpl_error_code fail = cpl_array_logarithm(self->wavelength, CPL_MATH_E);
904 self->wave_scale = hdrl_spectrum1D_wave_scale_log;
955 const cpl_bivector * windows,
const cpl_boolean is_internal){
957 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
958 cpl_ensure(windows != NULL, CPL_ERROR_NULL_INPUT, NULL);
961 cpl_size num_selected = 0;
963 for(cpl_size i = 0; i < sz; ++i){
965 if(is_wlen_selected(windows, is_internal, w))
969 if(num_selected == sz)
972 cpl_ensure(num_selected > 0, CPL_ERROR_ILLEGAL_OUTPUT, NULL);
974 cpl_image * flux = cpl_image_new(num_selected, 1, HDRL_TYPE_DATA);
975 cpl_image * flux_e = cpl_image_new(num_selected, 1, HDRL_TYPE_ERROR);
976 cpl_array * wavs = cpl_array_new(num_selected, HDRL_TYPE_DATA);
978 cpl_size idx_this = 0;
979 for(cpl_size i = 0; i < sz; ++i){
983 if(!is_wlen_selected(windows, is_internal, w))
continue;
988 cpl_image_set(flux, idx_this + 1, 1, v.data);
989 cpl_image_set(flux_e, idx_this + 1, 1, v.error);
992 cpl_image_reject(flux, idx_this + 1, 1);
993 cpl_image_reject(flux_e, idx_this + 1, 1);
996 cpl_array_set(wavs, idx_this, w);
1004 cpl_image_delete(flux);
1005 cpl_image_delete(flux_e);
1006 cpl_array_delete(wavs);
1027 const cpl_array * bad_samples){
1029 const cpl_size sz = cpl_array_get_size(bad_samples);
1031 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
1032 cpl_ensure(bad_samples != NULL, CPL_ERROR_NULL_INPUT, NULL);
1037 for(cpl_size i = 0; i < sz; ++i){
1039 if(cpl_array_get_int(bad_samples, i, NULL))
1047 hdrl_spectrum1D * to_ret =
1049 wlen.wavelength, wlen.scale);
1074 const hdrl_spectrum1D * self,
const char * flux_col_name,
1075 const char* wavelength_col_name,
const char * flux_e_col_name,
1076 const char * flux_bpm_col_name){
1078 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
1079 cpl_ensure(flux_col_name != NULL || wavelength_col_name != NULL,
1080 CPL_ERROR_NULL_INPUT, NULL);
1084 cpl_table * tb = cpl_table_new(sz);
1085 cpl_ensure(tb != NULL, CPL_ERROR_NULL_INPUT, NULL);
1088 (self, tb, flux_col_name, wavelength_col_name, flux_e_col_name,
1092 cpl_table_delete(tb);
1115(
const hdrl_spectrum1D * self, cpl_table * dest,
1116const char * flux_col_name,
const char* wavelength_col_name,
1117const char * flux_e_col_name,
const char * flux_bpm_col_name){
1119 cpl_ensure_code(self != NULL && dest != NULL,CPL_ERROR_NULL_INPUT);
1120 cpl_ensure_code(flux_col_name != NULL || wavelength_col_name != NULL,
1121 CPL_ERROR_NULL_INPUT);
1123 cpl_size cl_sz = cpl_table_get_nrow(dest);
1126 cpl_ensure_code(sz == cl_sz, CPL_ERROR_INCOMPATIBLE_INPUT);
1128 if(wavelength_col_name){
1129 double * lambdas = cpl_calloc(sz ,
sizeof(
double));
1130 for(cpl_size i = 0; i < sz; i++){
1133 cpl_error_code fail =
1134 cpl_table_wrap_double(dest, lambdas, wavelength_col_name);
1143 double * flux = cpl_calloc(sz ,
sizeof(
double));
1144 for(cpl_size i = 0; i < sz; i++){
1148 cpl_error_code fail = cpl_table_wrap_double(dest, flux, flux_col_name);
1155 if(flux_e_col_name){
1156 double * e_flux = cpl_calloc(sz ,
sizeof(
double));
1157 for(cpl_size i = 0; i < sz; i++){
1160 cpl_error_code fail =
1161 cpl_table_wrap_double(dest, e_flux, flux_e_col_name);
1169 if(flux_bpm_col_name){
1170 int * bpm_flux = cpl_calloc(sz ,
sizeof(
int));
1171 for(cpl_size i = 0; i < sz; i++){
1174 cpl_error_code fail =
1175 cpl_table_wrap_int(dest, bpm_flux, flux_bpm_col_name);
1182 return CPL_ERROR_NONE;
1200(
const cpl_table * self,
const char * flux_col_name,
1201const char* wavelength_col_name,
const char * flux_e_col_name,
1202const char * flux_bpm_col_name, hdrl_spectrum1D_wave_scale scale){
1204 cpl_ensure(self != NULL, CPL_ERROR_NULL_INPUT, NULL);
1205 cpl_ensure(flux_col_name != NULL, CPL_ERROR_NULL_INPUT, NULL);
1206 cpl_ensure(wavelength_col_name != NULL, CPL_ERROR_NULL_INPUT, NULL);
1208 cpl_size sz = cpl_table_get_nrow(self);
1210 cpl_ensure(sz > 1, CPL_ERROR_ILLEGAL_INPUT, NULL);
1212 cpl_image * flux = cpl_image_new(sz, 1, HDRL_TYPE_DATA);
1213 cpl_image * flux_e = cpl_image_new(sz, 1, HDRL_TYPE_ERROR);
1214 cpl_array * lambdas = cpl_array_new(sz, HDRL_TYPE_DATA);
1217 for(cpl_size i = 0; i < sz; ++i){
1218 const double fx = cpl_table_get(self, flux_col_name, i, NULL);
1219 const double l = cpl_table_get(self, wavelength_col_name, i, NULL);
1223 fx_e = cpl_table_get(self, flux_e_col_name, i, NULL);
1226 if(flux_bpm_col_name)
1227 rej = cpl_table_get_int(self, flux_bpm_col_name, i, NULL);
1229 cpl_image_set(flux, i + 1, 1, fx);
1232 cpl_image_reject(flux, i + 1, 1);
1234 cpl_image_set(flux_e, i + 1, 1, fx_e);
1235 cpl_array_set(lambdas, i, l);
1240 cpl_image_delete(flux);
1241 cpl_image_delete(flux_e);
1242 cpl_array_delete(lambdas);
1246void hdrl_spectrum1D_save(
const hdrl_spectrum1D * s,
const char * fname){
1247 if(s == NULL)
return;
1250 cpl_table_save(tb, NULL, NULL, fname, CPL_IO_CREATE);
1251 cpl_table_delete(tb);
1263 const cpl_array * w2){
1264 if(w1 == NULL && w2 == NULL)
return CPL_TRUE;
1266 if(w1 == NULL)
return CPL_FALSE;
1268 if(w2 == NULL)
return CPL_FALSE;
1270 cpl_size sz = cpl_array_get_size(w1);
1271 if(sz != cpl_array_get_size(w2))
return CPL_FALSE;
1272 for(cpl_size i = 0; i < sz; i++){
1273 const double wa = cpl_array_get(w1, i, NULL);
1274 const double wb = cpl_array_get(w2, i, NULL);
1276 const double d = wa - wb;
1277 if(fabs(d) > 1e-10 * CPL_MIN(wa, wb)){
1294 const hdrl_spectrum1D_wavelength* s2){
1296 if(s1 == NULL && s2 == NULL)
return CPL_TRUE;
1298 if(s1 == NULL)
return CPL_FALSE;
1300 if(s2 == NULL)
return CPL_FALSE;
1302 if(s1->scale != s2->scale)
return CPL_FALSE;
1322 if(self == NULL)
return CPL_FALSE;
1326 if(sz <= 2)
return CPL_TRUE;
1328 double * vd = cpl_calloc(sz,
sizeof(
double));
1330 for(cpl_size i = 0; i < sz; ++i){
1334 qsort(vd, sz,
sizeof(
double), compare_double);
1336 cpl_boolean to_ret = is_uniformly_sampled(vd, sz, bin);
1357static inline cpl_error_code operate_spectra_flux_mutate(hdrl_spectrum1D * self,
1358 const hdrl_spectrum1D * other,
1359 operate_image_mutable func){
1360 cpl_ensure_code(self != NULL && other != NULL,
1361 CPL_ERROR_NULL_INPUT);
1366 CPL_ERROR_INCOMPATIBLE_INPUT);
1368 hdrl_image * f1 = self->flux;
1369 const hdrl_image * f2 = other->flux;
1371 cpl_ensure_code(f1 != NULL && f2 != NULL,
1372 CPL_ERROR_NULL_INPUT);
1376 return CPL_ERROR_NONE;
1389static inline hdrl_spectrum1D *
1390operate_spectra_flux_create(
const hdrl_spectrum1D * self,
1391 const hdrl_spectrum1D * other,
1392 operate_image_mutable func){
1396 cpl_error_code fail = operate_spectra_flux_mutate(to_ret, other, func);
1414static inline cpl_error_code
1415operate_spectra_scalar_flux_mutate(hdrl_spectrum1D * self,
1417 operate_image_scalar_mutable func){
1419 if(!self)
return CPL_ERROR_NONE;
1421 hdrl_image * f1 = self->flux;
1423 cpl_ensure_code(f1 != NULL, CPL_ERROR_NULL_INPUT);
1427 return CPL_ERROR_NONE;
1440static inline hdrl_spectrum1D *
1441operate_spectra_scalar_flux_create(
const hdrl_spectrum1D * self,
1443 operate_image_scalar_mutable func){
1447 cpl_error_code fail =
1448 operate_spectra_scalar_flux_mutate(to_ret, scalar, func);
1458hdrl_spectrum1D * hdrl_spectrum1D_wrap(hdrl_image * arg_flux,
1459 cpl_array * wavelength,
1460 hdrl_spectrum1D_wave_scale scale){
1462 hdrl_spectrum1D * to_ret = cpl_calloc(1,
sizeof(*to_ret));
1464 to_ret->flux = arg_flux;
1465 to_ret->wavelength = wavelength;
1466 to_ret->wave_scale = scale;
1471int compare_double(
const void * a,
const void * b){
1472 const double ad = *((
const double *)a);
1473 const double bd = *((
const double *)b);
1474 const double delta = ad - bd;
1475 if(delta > 0.0)
return 1;
1476 if(delta < 0.0)
return -1;
1480#if HDRL_SIZEOF_DATA == 4
1481 const double wave_delta = 1.e-5;
1483 const double wave_delta = 1.e-6;
1487cpl_boolean is_uniformly_sampled(
const double * v, cpl_size sz,
double * bin){
1489 const double d = v[1] - v[0];
1491 for(cpl_size i = 1; i < sz - 1; ++i){
1492 const double d2 = (v[i + 1] - v[i]);
1493 const double eps = (fabs(d2 - d) / d);
1494 if(eps > wave_delta){
1503static inline cpl_boolean
1504is_contained_in_at_least_one_window(
const cpl_bivector * windows,
const hdrl_data_t w){
1505 const cpl_size sz = cpl_bivector_get_size(windows);
1507 for(cpl_size i = 0; i < sz; ++i){
1508 const double wmin = cpl_vector_get(cpl_bivector_get_x_const(windows), i);
1509 const double wmax = cpl_vector_get(cpl_bivector_get_y_const(windows), i);
1511 if(w >= wmin && w <= wmax)
return CPL_TRUE;
1517static inline cpl_boolean
1518is_wlen_selected(
const cpl_bivector * windows,
const cpl_boolean is_internal,
1519 const hdrl_data_t w){
1521 if(is_internal)
return is_contained_in_at_least_one_window(windows, w);
1523 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