CR2RE Pipeline Reference Manual 1.6.10
cr2res_detlin-test.c
1/*
2 * This file is part of the CR2RES Pipeline
3 * Copyright (C) 2002,2003 European Southern Observatory
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA
18 */
19
20#ifdef HAVE_CONFIG_H
21#include <config.h>
22#endif
23
24/*-----------------------------------------------------------------------------
25 Includes
26 -----------------------------------------------------------------------------*/
27
28#include <stdlib.h>
29#include <string.h>
30#include <math.h>
31#include <cpl.h>
32#include <hdrl.h>
33#include <cr2res_dfs.h>
34#include <cr2res_detlin.h>
35#include <cr2res_utils.h>
36
37#define CR2RES_DETECTOR_SIZE 2048
38
39/*-----------------------------------------------------------------------------
40 Functions prototypes
41 -----------------------------------------------------------------------------*/
42
43
44/*----------------------------------------------------------------------------*/
49/*----------------------------------------------------------------------------*/
52/*----------------------------------------------------------------------------*/
60/*----------------------------------------------------------------------------*/
61static void test_cr2res_detlin_compute(){
62 /*int cr2res_detlin_compute(
63 const cpl_vector * dits,
64 const cpl_vector * values,
65 cpl_size max_degree,
66 cpl_polynomial ** fitted,
67 cpl_vector ** error) */
68
69 int n = 100;
70 int i;
71 cpl_size pow;
72 double aduPsec = 666.6;
73 cpl_size max_degree=2;
74 cpl_vector * dits = cpl_vector_new(n);
75 cpl_vector * adus = cpl_vector_new(n);
76 cpl_polynomial * poly_fitted;
77 cpl_polynomial * poly_nonlin = cpl_polynomial_new(1);
78 cpl_vector * error;
79 cpl_vector * adus_corr;
80
81pow=0;
82cpl_polynomial_set_coeff(poly_nonlin,&pow,0.0);
83pow=1;
84cpl_polynomial_set_coeff(poly_nonlin,&pow,0.0);
85pow=2;
86cpl_polynomial_set_coeff(poly_nonlin,&pow,5E-5);
87
88/* Fill data */
89for (i=0; i<n; i++){
90 double adu;
91 cpl_vector_set(dits, i, i+1);
92 adu=(i+1)*aduPsec / (1+cpl_polynomial_eval_1d(poly_nonlin,i+1,NULL));
93 cpl_vector_set(adus, i, adu);
94}
95
96 cr2res_detlin_compute(dits, adus, max_degree, &poly_fitted, &error);
97 adus_corr = cr2res_polynomial_eval_vector(poly_fitted,adus);
98 cpl_vector_dump(adus_corr,stdout);
99 cpl_vector_multiply(adus_corr,adus);
100 cpl_polynomial_dump(poly_fitted, stdout);
101
102 /* Check if we are close to true aduPsec*/
103 cpl_vector_divide_scalar(adus_corr,aduPsec);
104 cpl_vector_dump(adus_corr,stdout);
105 cpl_test_vector_abs(adus_corr,dits,aduPsec*0.02);
106
107 cpl_vector_delete(dits);
108 cpl_vector_delete(adus);
109 cpl_vector_delete(adus_corr);
110 cpl_polynomial_delete(poly_nonlin);
111 if (error != NULL) cpl_vector_delete(error);
112 if (poly_fitted != NULL) cpl_polynomial_delete(poly_fitted);
113 return ;
114}
115
116/*----------------------------------------------------------------------------*/
120/*----------------------------------------------------------------------------*/
121int main(void)
122{
123 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_DEBUG);
124
125 test_cr2res_detlin_compute();
126
127 return cpl_test_end(0);
128}
129
int main(void)
Run the Unit tests.
int cr2res_detlin_compute(const cpl_vector *dits, const cpl_vector *adus, cpl_size max_degree, cpl_polynomial **fitted, cpl_vector **error)
Fits the response of a given pixel to the illumination increase.
cpl_vector * cr2res_polynomial_eval_vector(const cpl_polynomial *poly, const cpl_vector *vec)
Evaluate a polynomial on a vector.