28#include <hdrl_efficiency.h>
30#include "hdrl_spectrum.h"
31#include "hdrl_spectrum_resample.h"
32#include "hdrl_parameter.h"
47} hdrl_efficiency_parameters;
49static hdrl_parameter_typeobj
50hdrl_efficiency_parameters_type = {
51 HDRL_PARAMETER_EFFICIENCY,
52 (hdrl_alloc *)&cpl_malloc,
53 (hdrl_free *)&cpl_free,
55 sizeof(hdrl_efficiency_parameters),
58static inline cpl_error_code
59hdrl_efficiency_parameter_check(
const hdrl_parameter * pars);
61static inline hdrl_value
62hdrl_efficiency_parameter_get_Am(
const hdrl_parameter * pars);
63static inline hdrl_value
64hdrl_efficiency_parameter_get_Ap(
const hdrl_parameter * pars);
65static inline hdrl_value
66hdrl_efficiency_parameter_get_G(
const hdrl_parameter * pars);
67static inline hdrl_value
68hdrl_efficiency_parameter_get_Tex(
const hdrl_parameter * pars);
69static inline hdrl_value
70hdrl_efficiency_parameter_get_Atel(
const hdrl_parameter * pars);
72static inline hdrl_spectrum1D *
73select_obs_spectrum(
const hdrl_spectrum1D * I_std,
74 const hdrl_spectrum1D * I_std_ref,
75 const hdrl_spectrum1D * E_x);
77static inline hdrl_data_t
78lowest_w_max(
const cpl_array * a1,
const cpl_array * a2);
80static inline hdrl_data_t
81highest_w_min(
const cpl_array * a1,
const cpl_array * a2);
104 const hdrl_value Ap,
const hdrl_value Am,
const hdrl_value G,
105 const hdrl_value Tex){
107 hdrl_efficiency_parameters * p
108 = (hdrl_efficiency_parameters *)
109 hdrl_parameter_new(&hdrl_efficiency_parameters_type);
115 p->Atel = (hdrl_value){0.0, 0.0};
116 return (hdrl_parameter*) p;
134 const hdrl_value Ap,
const hdrl_value Am,
const hdrl_value G,
135 const hdrl_value Tex,
const hdrl_value Atel){
137 hdrl_efficiency_parameters * p
138 = (hdrl_efficiency_parameters *)
139 hdrl_parameter_new(&hdrl_efficiency_parameters_type);
146 return (hdrl_parameter*) p;
182const hdrl_spectrum1D * I_std_arg,
183const hdrl_spectrum1D * I_std_ref,
184const hdrl_spectrum1D * E_x,
185const hdrl_parameter * pars){
187 cpl_ensure(I_std_arg != NULL, CPL_ERROR_NULL_INPUT, NULL);
188 cpl_ensure(I_std_ref != NULL, CPL_ERROR_NULL_INPUT, NULL);
189 cpl_ensure(E_x != NULL, CPL_ERROR_NULL_INPUT, NULL);
190 cpl_ensure(pars != NULL, CPL_ERROR_NULL_INPUT, NULL);
192 const hdrl_value Ap = hdrl_efficiency_parameter_get_Ap(pars);
193 const hdrl_value Am = hdrl_efficiency_parameter_get_Am(pars);
194 const hdrl_value G = hdrl_efficiency_parameter_get_G(pars);
195 const hdrl_value Tex = hdrl_efficiency_parameter_get_Tex(pars);
197 cpl_ensure(cpl_error_get_code() == CPL_ERROR_NONE,
198 CPL_ERROR_ILLEGAL_OUTPUT, NULL);
200 hdrl_spectrum1D * I_std = select_obs_spectrum(I_std_arg, I_std_ref, E_x);
202 cpl_ensure(I_std != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL);
204 const hdrl_spectrum1D_wavelength spec_wav =
208 hdrl_spectrum1D_interp_akima);
211 cpl_ensure(exponential != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL);
214 hdrl_spectrum1D_interp_akima);
218 cpl_ensure(I_std_ref_resampled != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL);
284 const hdrl_spectrum1D * I_std_arg,
285 const hdrl_spectrum1D * I_std_ref,
286 const hdrl_spectrum1D * E_x,
287 const hdrl_parameter * pars)
290 cpl_ensure(I_std_arg != NULL, CPL_ERROR_NULL_INPUT, NULL);
291 cpl_ensure(I_std_ref != NULL, CPL_ERROR_NULL_INPUT, NULL);
292 cpl_ensure(E_x != NULL, CPL_ERROR_NULL_INPUT, NULL);
293 cpl_ensure(pars != NULL, CPL_ERROR_NULL_INPUT, NULL);
295 const hdrl_value Ap = hdrl_efficiency_parameter_get_Ap(pars);
296 const hdrl_value Am = hdrl_efficiency_parameter_get_Am(pars);
297 const hdrl_value G = hdrl_efficiency_parameter_get_G(pars);
298 const hdrl_value Tex = hdrl_efficiency_parameter_get_Tex(pars);
299 const hdrl_value Atel = hdrl_efficiency_parameter_get_Atel(pars);
301 cpl_ensure(cpl_error_get_code() == CPL_ERROR_NONE, CPL_ERROR_ILLEGAL_OUTPUT, NULL);
303 hdrl_spectrum1D * I_std = select_obs_spectrum(I_std_arg, I_std_ref, E_x);
304 cpl_ensure(I_std != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL);
309 hdrl_spectrum1D_interp_akima);
313 cpl_ensure(exponential != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL);
316 hdrl_spectrum1D_interp_akima);
320 cpl_ensure(I_std_ref_resampled != NULL, CPL_ERROR_ILLEGAL_OUTPUT, NULL);
340 E_ph, spec_wav.wavelength, spec_wav.scale);
364hdrl_value
E_ph(hdrl_data_t lambda){
365 const double nm2um = 0.001;
366 const double hc = 1.e7*1.986e-19 / nm2um;
368 return (hdrl_value){ hc / lambda, 0.0};
376static inline cpl_error_code
377hdrl_efficiency_parameter_check(
const hdrl_parameter * pars){
380 cpl_ensure_code(pars != NULL, CPL_ERROR_NULL_INPUT);
382 cpl_boolean is_compatible = hdrl_parameter_get_parameter_enum(pars) ==
383 HDRL_PARAMETER_EFFICIENCY;
384 cpl_ensure_code(is_compatible , CPL_ERROR_INCOMPATIBLE_INPUT);
386 return CPL_ERROR_NONE;
389static inline hdrl_value
390hdrl_efficiency_parameter_get_Am(
const hdrl_parameter * pars){
392 if(hdrl_efficiency_parameter_check(pars))
393 return (hdrl_value){0.0,0.0};
395 const hdrl_efficiency_parameters * p
396 = (
const hdrl_efficiency_parameters*)pars;
401static inline hdrl_value
402hdrl_efficiency_parameter_get_Ap(
const hdrl_parameter * pars){
404 if(hdrl_efficiency_parameter_check(pars))
405 return (hdrl_value){0.0,0.0};
407 const hdrl_efficiency_parameters * p
408 = (
const hdrl_efficiency_parameters*)pars;
413static inline hdrl_value
414hdrl_efficiency_parameter_get_G(
const hdrl_parameter * pars){
416 if(hdrl_efficiency_parameter_check(pars))
417 return (hdrl_value){0.0,0.0};
419 const hdrl_efficiency_parameters * p
420 = (
const hdrl_efficiency_parameters*)pars;
425static inline hdrl_value
426hdrl_efficiency_parameter_get_Tex(
const hdrl_parameter * pars){
428 if(hdrl_efficiency_parameter_check(pars))
429 return (hdrl_value){0.0,0.0};
431 const hdrl_efficiency_parameters * p
432 = (
const hdrl_efficiency_parameters*)pars;
437static inline hdrl_value
438hdrl_efficiency_parameter_get_Atel(
const hdrl_parameter * pars){
440 if(hdrl_efficiency_parameter_check(pars))
441 return (hdrl_value){0.0,0.0};
443 const hdrl_efficiency_parameters * p
444 = (
const hdrl_efficiency_parameters*)pars;
449static inline hdrl_data_t
450highest_w_min(
const cpl_array * a1,
const cpl_array * a2){
451 const hdrl_data_t w1 = cpl_array_get_min(a1);
452 const hdrl_data_t w2 = cpl_array_get_min(a2);
454 return CPL_MAX(w2, w1);
458static inline hdrl_data_t
459lowest_w_max(
const cpl_array * a1,
const cpl_array * a2){
460 const hdrl_data_t w1 = cpl_array_get_max(a1);
461 const hdrl_data_t w2 = cpl_array_get_max(a2);
463 return CPL_MIN(w2, w1);
468static inline hdrl_spectrum1D *
469select_obs_spectrum(
const hdrl_spectrum1D * I_std,
470 const hdrl_spectrum1D * I_std_ref,
471 const hdrl_spectrum1D * E_x){
473 const cpl_array * w_std_ref =
476 const cpl_array * E_x_ref =
479 const hdrl_data_t w_min = highest_w_min(w_std_ref, E_x_ref);
480 const hdrl_data_t w_max = lowest_w_max(w_std_ref, E_x_ref);
482 cpl_ensure(w_min < w_max, CPL_ERROR_ILLEGAL_INPUT, NULL);
484 cpl_bivector * wavs = cpl_bivector_new(1);
485 cpl_vector_set(cpl_bivector_get_x(wavs), 0, w_min);
486 cpl_vector_set(cpl_bivector_get_y(wavs), 0, w_max);
491 cpl_bivector_delete(wavs);
hdrl_spectrum1D * hdrl_response_core_compute(const hdrl_spectrum1D *I_std_arg, const hdrl_spectrum1D *I_std_ref, const hdrl_spectrum1D *E_x, const hdrl_parameter *pars)
core response calculation
hdrl_parameter * hdrl_response_parameter_create(const hdrl_value Ap, const hdrl_value Am, const hdrl_value G, const hdrl_value Tex)
ctor for the hdrl_parameter for response
hdrl_parameter * hdrl_efficiency_parameter_create(const hdrl_value Ap, const hdrl_value Am, const hdrl_value G, const hdrl_value Tex, const hdrl_value Atel)
ctor for the hdrl_parameter for efficiency
hdrl_value E_ph(hdrl_data_t lambda)
energy of the photon calculation
hdrl_spectrum1D * hdrl_efficiency_compute(const hdrl_spectrum1D *I_std_arg, const hdrl_spectrum1D *I_std_ref, const hdrl_spectrum1D *E_x, const hdrl_parameter *pars)
efficiency calculation
void hdrl_parameter_delete(hdrl_parameter *obj)
shallow delete of a parameter
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
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
cpl_error_code hdrl_spectrum1D_div_spectrum(hdrl_spectrum1D *self, const hdrl_spectrum1D *other)
divide one spectrum by another spectrum
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_spectrum1D * hdrl_spectrum1D_duplicate(const hdrl_spectrum1D *self)
hdrl_spectrum1D copy constructor
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_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_sub_spectrum(hdrl_spectrum1D *self, const hdrl_spectrum1D *other)
subtract two spectra
hdrl_spectrum1D_wavelength hdrl_spectrum1D_get_wavelength(const hdrl_spectrum1D *self)
hdrl_spectrum1D getter for wavelengths
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_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...
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