36#include "hdrl_utils.h"
37#include "hdrl_collapse.h"
38#include "hdrl_bpm_utils.h"
48#define ARRAY_LEN(a) sizeof((a))/sizeof((a)[0])
57static cpl_error_code hdrl_image_to_vector_test(
void)
61 cpl_vector * v = hdrl_image_to_vector(NULL, NULL);
62 cpl_test_error(CPL_ERROR_NULL_INPUT);
64 v = hdrl_image_to_vector(NULL, (
void*)1);
65 cpl_test_error(CPL_ERROR_NULL_INPUT);
69 cpl_image * img = cpl_image_new(5, 6, CPL_TYPE_INT);
70 cpl_vector * v = hdrl_image_to_vector(img, NULL);
71 cpl_test_error(CPL_ERROR_NONE);
72 cpl_test_eq(cpl_vector_get_size(v), 5 * 6);
73 cpl_image_delete(img);
78 cpl_image * img = cpl_image_new(1, 1, CPL_TYPE_INT);
79 cpl_image_reject(img, 1, 1);
80 cpl_vector * v = hdrl_image_to_vector(img, NULL);
81 cpl_test_error(CPL_ERROR_NONE);
83 cpl_image_delete(img);
87 cpl_image * img = cpl_image_new(5, 6, CPL_TYPE_INT);
88 cpl_image_set(img, 3, 5, 100);
89 cpl_image_reject(img, 3, 5);
90 cpl_vector * v = hdrl_image_to_vector(img, NULL);
91 cpl_test_error(CPL_ERROR_NONE);
92 cpl_test_eq(cpl_vector_get_size(v), 5 * 6 - 1);
93 cpl_test_eq(cpl_vector_get_sum(v), 0);
94 cpl_image_delete(img);
99 cpl_image * img = cpl_image_new(5, 6, CPL_TYPE_INT);
100 cpl_mask * m = cpl_mask_new(5, 6);
101 cpl_image_set(img, 2, 5, 100);
102 cpl_image_set(img, 3, 5, 100);
103 cpl_mask_set(m, 3, 5, CPL_BINARY_1);
104 cpl_vector * v = hdrl_image_to_vector(img, m);
105 cpl_test_error(CPL_ERROR_NONE);
106 cpl_test_eq(cpl_vector_get_size(v), 5 * 6 - 1);
107 cpl_test_eq(cpl_vector_get_sum(v), 100);
108 cpl_image_delete(img);
110 cpl_vector_delete(v);
114 cpl_image * img = cpl_image_new(5, 6, CPL_TYPE_DOUBLE);
115 cpl_mask * m = cpl_mask_new(5, 6);
116 cpl_image_set(img, 2, 5, 100.);
117 cpl_image_set(img, 3, 5, 100.);
118 cpl_mask_set(m, 3, 5, CPL_BINARY_1);
119 cpl_vector * v = hdrl_image_to_vector(img, m);
120 cpl_test_error(CPL_ERROR_NONE);
121 cpl_test_eq(cpl_vector_get_size(v), 5 * 6 - 1);
122 cpl_test_eq(cpl_vector_get_sum(v), 100);
123 cpl_image_delete(img);
125 cpl_vector_delete(v);
127 return cpl_error_get_code();
131static cpl_error_code hdrl_imagelist_to_vector_test(
void)
134 cpl_imagelist * list = cpl_imagelist_new();
135 cpl_vector * v = hdrl_imagelist_to_vector(NULL, 1, 1);
136 cpl_test_error(CPL_ERROR_NULL_INPUT);
138 v = hdrl_imagelist_to_vector(list, 1, 1);
139 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
141 cpl_imagelist_set(list, cpl_image_new(5, 5, CPL_TYPE_INT), 0);
142 v = hdrl_imagelist_to_vector(list, 0, 0);
143 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
145 v = hdrl_imagelist_to_vector(list, 0, 1);
146 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
148 v = hdrl_imagelist_to_vector(list, 1, 0);
149 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
151 v = hdrl_imagelist_to_vector(list, 10, 3);
152 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
154 v = hdrl_imagelist_to_vector(list, 3, 10);
155 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
157 v = hdrl_imagelist_to_vector(list, 10, 10);
158 cpl_test_error(CPL_ERROR_ACCESS_OUT_OF_RANGE);
160 cpl_imagelist_delete(list);
163 cpl_imagelist * list = cpl_imagelist_new();
164 cpl_imagelist_set(list, cpl_image_new(5, 6, CPL_TYPE_INT), 0);
165 cpl_vector * v = hdrl_imagelist_to_vector(list, 1, 1);
166 cpl_test_error(CPL_ERROR_NONE);
167 cpl_test_eq(cpl_vector_get_size(v), 1);
168 cpl_vector_delete(v);
169 cpl_imagelist_set(list, cpl_image_new(5, 6, CPL_TYPE_INT), 1);
170 v = hdrl_imagelist_to_vector(list, 1, 1);
171 cpl_test_error(CPL_ERROR_NONE);
172 cpl_test_eq(cpl_vector_get_size(v), 2);
173 cpl_imagelist_delete(list);
174 cpl_vector_delete(v);
178 cpl_imagelist * list = cpl_imagelist_new();
179 cpl_image * img = cpl_image_new(5, 6, CPL_TYPE_INT);
180 cpl_image_reject(img, 2, 1);
181 cpl_imagelist_set(list, img, 0);
182 cpl_imagelist_set(list, cpl_image_duplicate(img), 1);
183 cpl_vector * v = hdrl_imagelist_to_vector(list, 2, 1);
184 cpl_test_error(CPL_ERROR_NONE);
186 cpl_imagelist_delete(list);
187 cpl_vector_delete(v);
191 cpl_imagelist * list = cpl_imagelist_new();
192 cpl_image * img = cpl_image_new(5, 6, CPL_TYPE_INT);
193 cpl_image_set(img, 2, 1, 100);
194 cpl_imagelist_set(list, cpl_image_duplicate(img), 0);
195 cpl_imagelist_set(list, cpl_image_duplicate(img), 1);
196 cpl_image_reject(img, 2, 1);
197 cpl_imagelist_set(list, img, 2);
199 cpl_imagelist_set(list, cpl_image_new(5, 6, CPL_TYPE_INT), 3);
200 cpl_vector * v = hdrl_imagelist_to_vector(list, 2, 1);
201 cpl_test_error(CPL_ERROR_NONE);
202 cpl_test_eq(cpl_vector_get_size(v), 3);
203 cpl_test_eq(cpl_vector_get_sum(v), 200);
204 cpl_imagelist_delete(list);
205 cpl_vector_delete(v);
209 cpl_imagelist * list = cpl_imagelist_new();
210 cpl_image * img = cpl_image_new(5, 6, CPL_TYPE_DOUBLE);
211 cpl_image_add_scalar(img, 37);
212 cpl_image_set(img, 5, 6, 100);
213 cpl_imagelist_set(list, cpl_image_duplicate(img), 0);
214 cpl_imagelist_set(list, cpl_image_duplicate(img), 1);
215 cpl_image_reject(img, 5, 6);
216 cpl_imagelist_set(list, img, 2);
218 cpl_imagelist_set(list, cpl_image_new(5, 6, CPL_TYPE_DOUBLE), 3);
219 cpl_vector * v = hdrl_imagelist_to_vector(list, 5, 6);
220 cpl_test_error(CPL_ERROR_NONE);
221 cpl_test_eq(cpl_vector_get_size(v), 3);
222 cpl_test_eq(cpl_vector_get_sum(v), 200);
223 cpl_imagelist_delete(list);
224 cpl_vector_delete(v);
228 cpl_imagelist * list = cpl_imagelist_new();
229 cpl_image * img = cpl_image_new(5, 6, CPL_TYPE_DOUBLE);
230 cpl_image_add_scalar(img, 37);
231 cpl_image_set(img, 5, 6, 100);
232 cpl_imagelist_set(list, cpl_image_duplicate(img), 0);
233 cpl_imagelist_set(list, cpl_image_duplicate(img), 1);
234 cpl_image_reject(img, 5, 6);
235 cpl_imagelist_set(list, img, 2);
237 cpl_imagelist_set(list, cpl_image_new(5, 6, CPL_TYPE_DOUBLE), 3);
239 hdrl_imagelist_to_vector_row(list, 6, o, NULL);
240 cpl_test_error(CPL_ERROR_NONE);
241 cpl_test_eq(cpl_vector_get_size(o[4]), 3);
242 cpl_test_eq(cpl_vector_get_sum(o[4]), 200);
243 cpl_imagelist_delete(list);
244 for (
size_t i = 0; i < 5; i++) {
245 cpl_vector_delete(o[i]);
250 cpl_imagelist * list = cpl_imagelist_new();
251 cpl_image * img = cpl_image_new(5, 6, CPL_TYPE_INT);
252 cpl_image_add_scalar(img, 37);
253 cpl_image_set(img, 5, 6, 100);
254 cpl_imagelist_set(list, cpl_image_duplicate(img), 0);
255 cpl_imagelist_set(list, cpl_image_duplicate(img), 1);
256 cpl_image_reject(img, 5, 6);
257 cpl_imagelist_set(list, img, 2);
259 cpl_imagelist_set(list, cpl_image_new(5, 6, CPL_TYPE_INT), 3);
261 hdrl_imagelist_to_vector_row(list, 6, o, NULL);
262 cpl_test_error(CPL_ERROR_NONE);
263 cpl_test_eq(cpl_vector_get_size(o[4]), 3);
264 cpl_test_eq(cpl_vector_get_sum(o[4]), 200);
265 cpl_imagelist_delete(list);
266 for (
size_t i = 0; i < 5; i++) {
267 cpl_vector_delete(o[i]);
270 return cpl_error_get_code();
273static cpl_error_code hdrl_imagelist_cplwrap(
void)
275 hdrl_imagelist *list = NULL;
276 cpl_imagelist *data = NULL;
277 cpl_imagelist *errs = NULL;
280 hdrl_imagelist_to_cplwrap(list, &data, &errs);
281 cpl_test_error(CPL_ERROR_NULL_INPUT);
285 hdrl_imagelist_to_cplwrap(list, &data, &errs);
286 cpl_test_error(CPL_ERROR_NONE);
287 cpl_imagelist_unwrap(data);
288 cpl_imagelist_unwrap(errs);
291 hdrl_imagelist_to_cplwrap(list, &data, &errs);
292 cpl_test_error(CPL_ERROR_NONE);
293 cpl_imagelist_unwrap(data);
294 cpl_imagelist_unwrap(errs);
299 return cpl_error_get_code();
302static cpl_error_code hdrl_normalize_test(
void)
304 cpl_imagelist * data = cpl_imagelist_new();
305 cpl_imagelist * errs = cpl_imagelist_new();
306 cpl_vector * vnorm_d, * vnorm_e;
307 cpl_array * acontrib;
309 const size_t nz = 23;
310 const size_t nx = 41;
311 const size_t ny = 17;
312 for (
size_t i = 0; i < nz; i++) {
313 cpl_image * img = cpl_image_new(nx, ny, HDRL_TYPE_DATA);
314 cpl_image_add_scalar(img, i + 1);
315 cpl_image * err = cpl_image_new(nx, ny, HDRL_TYPE_ERROR);
316 cpl_image_add_scalar(err, i + 1);
317 cpl_image_divide_scalar(err, 3.);
318 cpl_imagelist_set(data, img, i);
319 cpl_imagelist_set(errs, err, i);
323 hdrl_collapse_imagelist_to_vector_t * vmethod =
324 hdrl_collapse_imagelist_to_vector_mean();
325 hdrl_collapse_imagelist_to_vector_call(vmethod, data, errs,
326 &vnorm_d, &vnorm_e, &acontrib,
328 cpl_array_delete(acontrib);
332 cpl_imagelist * ndata = cpl_imagelist_duplicate(data);
333 cpl_imagelist * nerrs = cpl_imagelist_duplicate(errs);
334 hdrl_normalize_imagelist_by_vector(vnorm_d, vnorm_e,
336 cpl_test_error(CPL_ERROR_UNSUPPORTED_MODE);
337 cpl_imagelist_delete(ndata);
338 cpl_imagelist_delete(nerrs);
343 cpl_imagelist * ndata = cpl_imagelist_duplicate(data);
344 cpl_imagelist * nerrs = cpl_imagelist_duplicate(errs);
345 hdrl_normalize_imagelist_by_vector(vnorm_d, vnorm_e,
348 cpl_test_error(CPL_ERROR_NONE);
350 cpl_test_image_abs(cpl_imagelist_get_const(data, 0),
351 cpl_imagelist_get_const(ndata, 0), HDRL_EPS_DATA);
352 cpl_test_image_abs(cpl_imagelist_get_const(errs, 0),
353 cpl_imagelist_get_const(nerrs, 0), HDRL_EPS_ERROR);
354 for (
size_t i = 1; i < nz; i++) {
355 cpl_image * expect_d = cpl_image_new(nx, ny, HDRL_TYPE_DATA);
356 cpl_image * expect_e = cpl_image_new(nx, ny, HDRL_TYPE_ERROR);
357 double escale = hypot(((i + 1) / 3.) / sqrt(nx * ny),
358 (1. / 3.) / sqrt(nx * ny));
359 cpl_image_add_scalar(expect_e, hypot(escale, (i + 1) / 3.));
360 cpl_image_add_scalar(expect_d, 1);
361 cpl_test_image_abs(expect_d, cpl_imagelist_get_const(ndata, i),
363 cpl_test_image_abs(expect_e, cpl_imagelist_get_const(nerrs, i),
365 cpl_image_delete(expect_d);
366 cpl_image_delete(expect_e);
368 cpl_imagelist_delete(ndata);
369 cpl_imagelist_delete(nerrs);
374 cpl_imagelist *ndata = cpl_imagelist_duplicate(data);
375 cpl_imagelist *nerrs = cpl_imagelist_duplicate(errs);
379 cpl_vector *fake1 = cpl_vector_duplicate(vnorm_d);
380 cpl_vector *fake2 = cpl_vector_duplicate(vnorm_e);
381 cpl_imagelist *fake3 = cpl_imagelist_duplicate(ndata);
382 cpl_imagelist *fake4 = cpl_imagelist_duplicate(nerrs);
383 cpl_vector_set(fake1, 1, 0.);
384 cpl_vector_set(fake2, 1, 0.);
385 hdrl_normalize_imagelist_by_vector(fake1, fake2,
386 HDRL_SCALE_MULTIPLICATIVE, fake3, fake4);
387 cpl_vector_delete(fake1);
388 cpl_vector_delete(fake2);
389 cpl_imagelist_delete(fake3);
390 cpl_imagelist_delete(fake4);
394 hdrl_normalize_imagelist_by_vector(vnorm_d, vnorm_e,
395 HDRL_SCALE_MULTIPLICATIVE,
397 cpl_test_error(CPL_ERROR_NONE);
399 cpl_test_image_abs(cpl_imagelist_get_const(data, 0),
400 cpl_imagelist_get_const(ndata, 0), HDRL_EPS_DATA);
401 cpl_test_image_abs(cpl_imagelist_get_const(errs, 0),
402 cpl_imagelist_get_const(nerrs, 0), HDRL_EPS_ERROR);
403 for (
size_t i = 1; i < nz; i++) {
404 cpl_image * expect_d = cpl_image_new(nx, ny, HDRL_TYPE_DATA);
405 cpl_image * expect_e = cpl_image_new(nx, ny, HDRL_TYPE_ERROR);
407 cpl_image_add_scalar(expect_e, 0.3338112308308246);
408 cpl_image_add_scalar(expect_d, 1.);
409 cpl_test_image_abs(expect_d, cpl_imagelist_get_const(ndata, i),
411 cpl_test_image_abs(expect_e, cpl_imagelist_get_const(nerrs, i),
413 cpl_image_delete(expect_d);
414 cpl_image_delete(expect_e);
416 cpl_imagelist_delete(ndata);
417 cpl_imagelist_delete(nerrs);
420 cpl_imagelist_delete(data);
421 cpl_imagelist_delete(errs);
422 cpl_vector_delete(vnorm_d);
423 cpl_vector_delete(vnorm_e);
424 hdrl_collapse_imagelist_to_vector_delete(vmethod);
426 return cpl_error_get_code();
430static cpl_error_code hdrl_normalize_image_test(
void)
432 cpl_imagelist * data = cpl_imagelist_new();
433 cpl_imagelist * errs = cpl_imagelist_new();
434 cpl_imagelist * vnorm_d = cpl_imagelist_new();
435 cpl_imagelist * vnorm_e = cpl_imagelist_new();
436 cpl_vector * vnorm_d_, * vnorm_e_;
437 cpl_array * acontrib;
439 const size_t nz = 23;
440 const size_t nx = 41;
441 const size_t ny = 17;
442 for (
size_t i = 0; i < nz; i++) {
443 cpl_image * img = cpl_image_new(nx, ny, HDRL_TYPE_DATA);
444 cpl_image_add_scalar(img, i + 1);
445 cpl_image * err = cpl_image_new(nx, ny, HDRL_TYPE_ERROR);
446 cpl_image_add_scalar(err, i + 1);
447 cpl_image_divide_scalar(err, 3.);
448 cpl_imagelist_set(data, img, i);
449 cpl_imagelist_set(errs, err, i);
453 hdrl_collapse_imagelist_to_vector_t * vmethod =
454 hdrl_collapse_imagelist_to_vector_mean();
455 hdrl_collapse_imagelist_to_vector_call(vmethod, data, errs,
456 &vnorm_d_, &vnorm_e_, &acontrib,
458 cpl_array_delete(acontrib);
459 for (cpl_size i = 0; i < cpl_vector_get_size(vnorm_d_); i++) {
460 cpl_image * dimg = cpl_image_new(nx, ny, HDRL_TYPE_DATA);
461 cpl_image * eimg = cpl_image_new(nx, ny, HDRL_TYPE_ERROR);
462 cpl_image_add_scalar(dimg, cpl_vector_get(vnorm_d_, i));
463 cpl_image_add_scalar(eimg, cpl_vector_get(vnorm_e_, i));
464 cpl_imagelist_set(vnorm_d, dimg, i);
465 cpl_imagelist_set(vnorm_e, eimg, i);
467 cpl_vector_delete(vnorm_d_);
468 cpl_vector_delete(vnorm_e_);
473 cpl_imagelist * ndata = cpl_imagelist_duplicate(data);
474 cpl_imagelist * nerrs = cpl_imagelist_duplicate(errs);
475 hdrl_normalize_imagelist_by_imagelist(vnorm_d, vnorm_e,
477 cpl_test_error(CPL_ERROR_UNSUPPORTED_MODE);
478 cpl_imagelist_delete(ndata);
479 cpl_imagelist_delete(nerrs);
484 cpl_imagelist * ndata = cpl_imagelist_duplicate(data);
485 cpl_imagelist * nerrs = cpl_imagelist_duplicate(errs);
486 hdrl_normalize_imagelist_by_imagelist(vnorm_d, vnorm_e,
489 cpl_test_error(CPL_ERROR_NONE);
491 cpl_test_image_abs(cpl_imagelist_get_const(data, 0),
492 cpl_imagelist_get_const(ndata, 0), HDRL_EPS_DATA);
493 cpl_test_image_abs(cpl_imagelist_get_const(errs, 0),
494 cpl_imagelist_get_const(nerrs, 0), HDRL_EPS_ERROR);
495 for (
size_t i = 1; i < nz; i++) {
496 cpl_image * expect_d = cpl_image_new(nx, ny, HDRL_TYPE_DATA);
497 cpl_image * expect_e = cpl_image_new(nx, ny, HDRL_TYPE_ERROR);
498 double escale = hypot(((i + 1) / 3.) / sqrt(nx * ny),
499 (1. / 3.) / sqrt(nx * ny));
500 cpl_image_add_scalar(expect_e, hypot(escale, (i + 1) / 3.));
501 cpl_image_add_scalar(expect_d, 1);
502 cpl_test_image_abs(expect_d, cpl_imagelist_get_const(ndata, i),
504 cpl_test_image_abs(expect_e, cpl_imagelist_get_const(nerrs, i),
506 cpl_image_delete(expect_d);
507 cpl_image_delete(expect_e);
509 cpl_imagelist_delete(ndata);
510 cpl_imagelist_delete(nerrs);
515 cpl_imagelist * ndata = cpl_imagelist_duplicate(data);
516 cpl_imagelist * nerrs = cpl_imagelist_duplicate(errs);
517 hdrl_normalize_imagelist_by_imagelist(vnorm_d, vnorm_e,
518 HDRL_SCALE_MULTIPLICATIVE,
520 cpl_test_error(CPL_ERROR_NONE);
522 cpl_test_image_abs(cpl_imagelist_get_const(data, 0),
523 cpl_imagelist_get_const(ndata, 0), HDRL_EPS_DATA);
524 cpl_test_image_abs(cpl_imagelist_get_const(errs, 0),
525 cpl_imagelist_get_const(nerrs, 0), HDRL_EPS_ERROR);
526 for (
size_t i = 1; i < nz; i++) {
527 cpl_image * expect_d = cpl_image_new(nx, ny, HDRL_TYPE_DATA);
528 cpl_image * expect_e = cpl_image_new(nx, ny, HDRL_TYPE_ERROR);
530 cpl_image_add_scalar(expect_e, 0.3338112308308246);
531 cpl_image_add_scalar(expect_d, 1.);
532 cpl_test_image_abs(expect_d, cpl_imagelist_get_const(ndata, i),
534 cpl_test_image_abs(expect_e, cpl_imagelist_get_const(nerrs, i),
536 cpl_image_delete(expect_d);
537 cpl_image_delete(expect_e);
539 cpl_imagelist_delete(ndata);
540 cpl_imagelist_delete(nerrs);
543 cpl_imagelist_delete(data);
544 cpl_imagelist_delete(errs);
545 cpl_imagelist_delete(vnorm_d);
546 cpl_imagelist_delete(vnorm_e);
547 hdrl_collapse_imagelist_to_vector_delete(vmethod);
549 return cpl_error_get_code();
555void hdrl_path_test(
void)
560 cwd = hdrl_get_cwd();
561 cpl_test_nonnull(cwd);
563 fd = hdrl_get_tempfile(NULL, CPL_TRUE);
572 fd = hdrl_get_tempfile(cwd, CPL_TRUE);
583void hdrl_string_test(
void)
591 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
594 result = strcmp(s,
"test");
595 cpl_test_zero(result);
599 result = strcmp(s,
"testbla");
600 cpl_test_zero(result);
604 result = strcmp(s,
"test");
605 cpl_test_zero(result);
609 result = strcmp(s,
"test.bla");
610 cpl_test_zero(result);
614 result = strcmp(s,
"test--bla--val");
615 cpl_test_zero(result);
619 result = strcmp(s,
"bla--val");
620 cpl_test_zero(result);
624 result = strcmp(s,
"test--val");
625 cpl_test_zero(result);
629 result = strcmp(s,
"test,val");
630 cpl_test_zero(result);
634 result = strcmp(s,
"val--test");
635 cpl_test_zero(result);
639 result = strcmp(s,
"bla--val");
640 cpl_test_zero(result);
644 result = strcmp(s,
"test--bla");
645 cpl_test_zero(result);
649 result = strcmp(s,
"test--bla");
650 cpl_test_zero(result);
655void hdrl_pfilter_test(
void)
657 cpl_imagelist * list1 = cpl_imagelist_new();
658 cpl_imagelist_set(list1, cpl_image_new(5, 5, CPL_TYPE_INT), 0);
659 cpl_imagelist_set(list1, cpl_image_new(5, 5, CPL_TYPE_INT), 1);
661 cpl_imagelist *list2;
664 cpl_test_error(CPL_ERROR_NULL_INPUT);
665 cpl_test_null(list2);
668 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
669 cpl_test_null(list2);
671 cpl_imagelist_delete(list2);
672 cpl_imagelist_delete(list1);
675 size_t any[] = {13, 22, 47, 100, 103, 104, 202, 203, 204,
677 size_t amx[] = {1, 1, 3, 3, 5, 7, 13};
678 size_t amy[] = {1, 3, 1, 3, 5, 7, 13};
679 for (
size_t j = 0; j < ARRAY_LEN(amx); j++) {
680 cpl_mask * m = cpl_mask_new(amx[j], amy[j]);
681 cpl_matrix * k = cpl_matrix_new(amx[j], amy[j]);
683 cpl_matrix_add_scalar(k, 1);
684 for (
size_t i = 0; i < ARRAY_LEN(any); i++) {
686 cpl_msg_info(cpl_func,
"Testing ny %zu mask %zu,%zu", ny,
688 cpl_image * img = cpl_image_new(nx, ny, CPL_TYPE_DOUBLE);
689 double * d = cpl_image_get_data_double(img);
690 for (
size_t kindex = 0; kindex < nx * ny; kindex++) {
691 d[kindex] = kindex + rand() % 100;
692 if (i % 2 == 0 && ((
int)d[kindex] % 20) == 0) {
693 cpl_image_reject(img, (rand() % nx) + 1, (rand() % ny) + 1);
696 cpl_image * orig_inp = cpl_image_duplicate(img);
697 cpl_image * ro = cpl_image_duplicate(img);
700 cpl_image_filter_mask(ro, img, m, CPL_FILTER_MEDIAN, CPL_BORDER_FILTER);
701 rp = hdrl_parallel_filter_image(img, NULL, m, CPL_FILTER_MEDIAN);
702 cpl_test_image_abs(rp, ro, 0);
704 cpl_test_image_abs(img, orig_inp, 0);
705 cpl_image_delete(rp);
707 cpl_image_filter(ro, img, k, CPL_FILTER_LINEAR, CPL_BORDER_FILTER);
708 rp = hdrl_parallel_filter_image(img, k, NULL, CPL_FILTER_LINEAR);
709 cpl_test_image_abs(rp, ro, 0);
711 cpl_test_image_abs(img, orig_inp, 0);
712 cpl_image_delete(rp);
714 cpl_image_delete(ro);
715 cpl_image_delete(img);
716 cpl_image_delete(orig_inp);
719 cpl_matrix_delete(k);
723void hdrl_pconvert_test(
void)
727 cpl_propertylist * plist = cpl_propertylist_new();
728 cpl_propertylist_update_int(plist,
"NAXIS", 2);
729 cpl_propertylist_update_int(plist,
"NAXIS1", nx);
730 cpl_propertylist_update_int(plist,
"NAXIS2", ny);
731 cpl_propertylist_update_string(plist,
"CTYPE1",
"RA---ZPN");
732 cpl_propertylist_update_string(plist,
"CTYPE2",
"DEC--ZPN");
733 cpl_propertylist_update_double(plist,
"CRVAL1", 149.947);
734 cpl_propertylist_update_double(plist,
"CRVAL2", 2.205);
735 cpl_propertylist_update_double(plist,
"CRPIX1", 5401.42);
736 cpl_propertylist_update_double(plist,
"CRPIX2", 6834.89);
737 cpl_propertylist_update_double(plist,
"CD1_1", 1.8072e-07);
738 cpl_propertylist_update_double(plist,
"CD1_2", 9.4796e-05);
739 cpl_propertylist_update_double(plist,
"CD2_1", -9.4820e-05);
740 cpl_propertylist_update_double(plist,
"CD2_2", 2.0167e-07);
741 cpl_propertylist_update_double(plist,
"PV2_1", 1.);
742 cpl_propertylist_update_double(plist,
"PV2_2", 0.);
743 cpl_propertylist_update_double(plist,
"PV2_3", 44.);
744 cpl_propertylist_update_double(plist,
"PV2_4", 0.);
745 cpl_propertylist_update_double(plist,
"PV2_5", -10300.);
746 cpl_propertylist_update_string(plist,
"CUNIT1",
"deg");
747 cpl_propertylist_update_string(plist,
"CUNIT2",
"deg");
749 cpl_wcs * wcs = cpl_wcs_new_from_propertylist(plist);
750 cpl_matrix * from = cpl_matrix_new(nx * ny, 2);
751 for (cpl_size y = 0; y < ny; y++) {
752 for (cpl_size x = 0; x < nx; x++) {
753 cpl_matrix_set(from, (y * nx) + x, 0, x);
754 cpl_matrix_set(from, (y * nx) + x, 1, y);
757 cpl_matrix * to, *to2, *toc, *toc2;
758 cpl_array * status, *statusc;
759 hdrl_wcs_convert(wcs, from, &to, &status, CPL_WCS_PHYS2WORLD);
760 cpl_test_error(CPL_ERROR_NONE);
761 cpl_wcs_convert(wcs, from, &toc, &statusc, CPL_WCS_PHYS2WORLD);
763 cpl_test_matrix_abs(to, toc, 0.);
764 cpl_test_array_abs(status, statusc, 0.);
765 cpl_array_delete(status);
766 cpl_array_delete(statusc);
768 hdrl_wcs_convert(wcs, to, &to2, &status, CPL_WCS_WORLD2PHYS);
769 cpl_test_error(CPL_ERROR_NONE);
770 cpl_wcs_convert(wcs, to, &toc2, &statusc, CPL_WCS_WORLD2PHYS);
772 cpl_test_matrix_abs(to2, toc2, 0.);
773 cpl_test_array_abs(status, statusc, 0.);
775 cpl_matrix_delete(to);
776 cpl_matrix_delete(toc);
777 cpl_matrix_delete(to2);
778 cpl_matrix_delete(toc2);
779 cpl_array_delete(status);
780 cpl_array_delete(statusc);
783 hdrl_wcs_convert(wcs, from, &to, &status, CPL_WCS_WORLD2PHYS);
784 cpl_test_error(CPL_ERROR_UNSPECIFIED);
785 cpl_wcs_convert(wcs, from, &toc, &statusc, CPL_WCS_WORLD2PHYS);
786 cpl_test_array_abs(status, statusc, 0.);
788 cpl_matrix_delete(to);
789 cpl_matrix_delete(toc);
790 cpl_array_delete(status);
791 cpl_array_delete(statusc);
794 hdrl_wcs_convert(NULL, NULL, NULL, NULL, CPL_WCS_PHYS2WORLD);
795 cpl_test_error(CPL_ERROR_NULL_INPUT);
797 hdrl_wcs_convert(wcs, from, &to, &status, (cpl_wcs_trans_mode)1421);
798 cpl_test_error(CPL_ERROR_UNSUPPORTED_MODE);
800 cpl_propertylist_erase(plist,
"NAXIS2");
802 wcs = cpl_wcs_new_from_propertylist(plist);
803 hdrl_wcs_convert(wcs, from, &to, &status, CPL_WCS_PHYS2WORLD);
804 cpl_test_error(CPL_ERROR_UNSPECIFIED);
805 cpl_matrix_delete(to);
806 cpl_array_delete(status);
808 cpl_propertylist_delete(plist);
810 cpl_matrix_delete(from);
813static cpl_error_code hdrl_airmass_test(
void){
815 cpl_errorstate prestate = cpl_errorstate_get();
818 hdrl_value airmass, airmass1, airmass2, airmass3;
821 hdrl_airmass_approx typeAirmassAprox1 = HDRL_AIRMASS_APPROX_HARDIE;
822 hdrl_airmass_approx typeAirmassAprox2 = HDRL_AIRMASS_APPROX_YOUNG_IRVINE;
823 hdrl_airmass_approx typeAirmassAprox3 = HDRL_AIRMASS_APPROX_YOUNG;
828 hdrl_value ra1 = { 122.994945, 0.};
829 hdrl_value dec1 = {74.95304, 0.};
830 hdrl_value lst1 = {25407.072748, 0.};
831 hdrl_value exptime1 = {120., 0.};
832 hdrl_value geolat1 = {37.2236, 0.};
834 hdrl_value ra2 = {238.071555, 0.};
835 hdrl_value dec2 = {32.92533, 0.};
836 hdrl_value lst2 = {60515.584209, 0.};
837 hdrl_value exptime2 = {300., 0.};
838 hdrl_value geolat2 = {37.2236, 0.};
840 hdrl_value ra3 = {0.125, 0.};
841 hdrl_value dec3 = {-30., 0.};
842 hdrl_value lst3 = {69446.2765265328, 0.};
843 hdrl_value exptime3 = {3600., 0.};
844 hdrl_value geolat3 = {-24.625278, 0.};
850 airmass =
hdrl_utils_airmass((hdrl_value){-1.,0.}, dec1, lst1, exptime1, geolat1, typeAirmassAprox1);
851 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
852 cpl_test(airmass.data == -1.);
855 airmass =
hdrl_utils_airmass(ra1, (hdrl_value){180.,0.}, lst1, exptime1, geolat1, typeAirmassAprox1);
856 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
857 cpl_test(airmass.data == -1.);
860 airmass =
hdrl_utils_airmass(ra1, dec1, (hdrl_value){-1.,0.}, exptime1, geolat1, typeAirmassAprox1);
861 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
862 cpl_test(airmass.data == -1.);
865 airmass =
hdrl_utils_airmass(ra1, dec1, lst1, (hdrl_value){-1.,0.}, geolat1, typeAirmassAprox1);
866 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
867 cpl_test(airmass.data == -1.);
870 airmass =
hdrl_utils_airmass(ra1, dec1, lst1, exptime1, (hdrl_value){180.,0.}, typeAirmassAprox1);
871 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
872 cpl_test(airmass.data == -1.);
876 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
877 cpl_test(airmass.data == -1.);
883 cpl_test(cpl_errorstate_is_equal(prestate) == CPL_TRUE);
886 cpl_test(cpl_errorstate_is_equal(prestate) == CPL_TRUE);
889 cpl_test(cpl_errorstate_is_equal(prestate) == CPL_TRUE);
893 cpl_test(airmass1.data > 1.27803 - 0.001);
894 cpl_test(airmass1.data < 1.27803 + 0.001);
896 cpl_test(airmass2.data > 1.02529 - 0.001);
897 cpl_test(airmass2.data < 1.02529 + 0.001);
899 cpl_test(airmass3.data > 1.79364 - 0.001);
900 cpl_test(airmass3.data < 1.79364 + 0.001);
906 double deltaRa = delta;
907 double deltaDec = delta;
908 double deltaLst = delta;
909 double deltaExptime = delta;
910 double deltaGeolat = delta;
912 ra1.error = deltaRa * fabs(ra1.data);
913 dec1.error = deltaDec * fabs(dec1.data);
914 lst1.error = deltaLst * fabs(lst1.data);
915 exptime1.error = deltaExptime * fabs(exptime1.data);
916 geolat1.error = deltaGeolat * fabs(geolat1.data);
918 ra2.error = deltaRa * fabs(ra2.data);
919 dec2.error = deltaDec * fabs(dec2.data);
920 lst2.error = deltaLst * fabs(lst2.data);
921 exptime2.error = deltaExptime * fabs(exptime2.data);
922 geolat2.error = deltaGeolat * fabs(geolat2.data);
924 ra3.error = deltaRa * fabs(ra3.data);
925 dec3.error = deltaDec * fabs(dec3.data);
926 lst3.error = deltaLst * fabs(lst3.data);
927 exptime3.error = deltaExptime * fabs(exptime3.data);
928 geolat3.error = deltaGeolat * fabs(geolat3.data);
931 cpl_test(cpl_errorstate_is_equal(prestate) == CPL_TRUE);
934 cpl_test(cpl_errorstate_is_equal(prestate) == CPL_TRUE);
937 cpl_test(cpl_errorstate_is_equal(prestate) == CPL_TRUE);
941 cpl_test(airmass1.data > 1.27803 - 0.001 );
942 cpl_test(airmass1.data < 1.27803 + 0.001 );
943 cpl_test(airmass1.error > 0.0136602 - 0.0001);
944 cpl_test(airmass1.error < 0.0136602 + 0.0001);
946 cpl_test(airmass2.data > 1.02529 - 0.001 );
947 cpl_test(airmass2.data < 1.02529 + 0.001 );
948 cpl_test(airmass2.error > 0.0216347 - 0.0001);
949 cpl_test(airmass2.error < 0.0216347 + 0.0001);
951 cpl_test(airmass3.data > 1.79364 - 0.001 );
952 cpl_test(airmass3.data < 1.79364 + 0.001 );
953 cpl_test(airmass3.error > 0.128632 - 0.0001);
954 cpl_test(airmass3.error < 0.128631 + 0.0001);
960 cpl_test(cpl_errorstate_is_equal(prestate) == CPL_TRUE);
963 cpl_test(cpl_errorstate_is_equal(prestate) == CPL_TRUE);
966 cpl_test(cpl_errorstate_is_equal(prestate) == CPL_TRUE);
971 cpl_test(airmass1.data > 1.27803 - 0.001 );
972 cpl_test(airmass1.data < 1.27803 + 0.001 );
973 cpl_test(airmass1.error > 0.0136602 - 0.0001);
974 cpl_test(airmass1.error < 0.0136602 + 0.0001);
976 cpl_test(airmass2.data > 1.2778 - 0.001 );
977 cpl_test(airmass2.data < 1.2778 + 0.001 );
978 cpl_test(airmass2.error > 0.0135473 - 0.0001);
979 cpl_test(airmass2.error < 0.0135473 + 0.0001);
981 cpl_test(airmass3.data > 1.27755 - 0.001 );
982 cpl_test(airmass3.data < 1.27755 + 0.001 );
983 cpl_test(airmass3.error > 0.0135339 - 0.0001);
984 cpl_test(airmass3.error < 0.0135339 + 0.0001);
987 return cpl_error_get_code();
990static cpl_error_code hdrl_license_test(
void)
993 cpl_test_nonnull(str);
995 return cpl_error_get_code();
998static cpl_error_code hdrl_region_test(
void)
1003 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1012 cpl_test_error(CPL_ERROR_NONE);
1015 cpl_test_error(CPL_ERROR_NULL_INPUT);
1018 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1021 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1024 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1027 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1030 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1033 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1038 cpl_test_error(CPL_ERROR_NONE);
1039 cpl_test_nonnull(p);
1042 cpl_test_error(CPL_ERROR_NONE);
1045 cpl_test_error(CPL_ERROR_NONE);
1048 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1051 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1054 cpl_test_error(CPL_ERROR_NULL_INPUT);
1056 cpl_test_eq(llx, 1);
1059 cpl_test_error(CPL_ERROR_NULL_INPUT);
1061 cpl_test_eq(lly, 1);
1064 cpl_test_error(CPL_ERROR_NULL_INPUT);
1066 cpl_test_eq(urx, 20);
1069 cpl_test_error(CPL_ERROR_NULL_INPUT);
1071 cpl_test_eq(ury, 20);
1078 NULL,
"test",
"region-", p);
1079 cpl_test_error(CPL_ERROR_NULL_INPUT);
1080 cpl_test_null(plist);
1083 "RECIPE", NULL,
"region-", p);
1084 cpl_test_error(CPL_ERROR_NULL_INPUT);
1085 cpl_test_null(plist);
1088 "RECIPE",
"test", NULL, p);
1089 cpl_test_error(CPL_ERROR_NULL_INPUT);
1090 cpl_test_null(plist);
1093 "RECIPE",
"test",
"region-", NULL);
1094 cpl_test_error(CPL_ERROR_NULL_INPUT);
1095 cpl_test_null(plist);
1100 "RECIPE",
"test",
"region-", pFake);
1101 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
1102 cpl_test_null(plFake);
1107 "RECIPE",
"test",
"region-", p);
1108 cpl_test_error(CPL_ERROR_NONE);
1109 cpl_test_nonnull(plist1);
1112 NULL,
"test",
"region-");
1113 cpl_test_error(CPL_ERROR_NULL_INPUT);
1114 cpl_test_null(out1);
1117 plist1, NULL,
"region-");
1118 cpl_test_error(CPL_ERROR_NULL_INPUT);
1119 cpl_test_null(out1);
1122 plist1,
"test", NULL);
1123 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
1124 cpl_test_null(out1);
1127 plist1,
"test",
"region-");
1128 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
1129 cpl_test_null(out1);
1134 "test",
"",
"region-", p);
1135 cpl_test_error(CPL_ERROR_NONE);
1136 cpl_test_nonnull(plist2);
1139 plist2,
"test",
"region-");
1140 cpl_test_error(CPL_ERROR_NONE);
1141 cpl_test_nonnull(out2);
1147 cpl_test_error(CPL_ERROR_NULL_INPUT);
1151 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1155 cpl_test_error(CPL_ERROR_NONE);
1160 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1163 cpl_test_error(CPL_ERROR_NONE);
1167 cpl_parameterlist_delete(plist1);
1168 cpl_parameterlist_delete(plist2);
1182 return cpl_error_get_code();
1192 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
1194 hdrl_image_to_vector_test();
1195 hdrl_imagelist_to_vector_test();
1196 hdrl_imagelist_cplwrap();
1197 hdrl_normalize_test();
1198 hdrl_normalize_image_test();
1201 hdrl_pfilter_test();
1202 hdrl_pconvert_test();
1203 hdrl_airmass_test();
1204 hdrl_license_test();
1207 return cpl_test_end(0);
cpl_imagelist * hdrl_bpm_filter_list(const cpl_imagelist *inlist, cpl_size kernel_nx, cpl_size kernel_ny, cpl_filter_mode filter)
Wrapper around hdrl_bpm_filter() to filter list of images.
hdrl_parameter * hdrl_collapse_mean_parameter_create(void)
create a parameter object for mean
void hdrl_imagelist_delete(hdrl_imagelist *himlist)
Free all memory used by a hdrl_imagelist object including the images.
hdrl_imagelist * hdrl_imagelist_new(void)
Create an empty imagelist.
void hdrl_parameter_delete(hdrl_parameter *obj)
shallow delete of a parameter
const char * hdrl_get_license(void)
Get the pipeline copyright and license.
hdrl_value hdrl_utils_airmass(hdrl_value aRA, hdrl_value aDEC, hdrl_value aLST, hdrl_value aExptime, hdrl_value aLatitude, hdrl_airmass_approx type)
Compute the effective airmass of an observation. Takes in count the error propagation if you enter th...
cpl_error_code hdrl_rect_region_parameter_verify(const hdrl_parameter *param, const cpl_size max_x, const cpl_size max_y)
Verify basic correctness of the parameters.
cpl_error_code hdrl_rect_region_parameter_update(hdrl_parameter *rect_region, cpl_size llx, cpl_size lly, cpl_size urx, cpl_size ury)
Update Rect Region Parameters object.
cpl_parameterlist * hdrl_rect_region_parameter_create_parlist(const char *base_context, const char *prefix, const char *name_prefix, const hdrl_parameter *defaults)
Create parameter list for hdrl_rect_region.
cpl_error_code hdrl_rect_region_fix_negatives(hdrl_parameter *rect_region, const cpl_size nx, const cpl_size ny)
wrap negative or zero coordinates around full image size
hdrl_parameter * hdrl_rect_region_parameter_create(cpl_size llx, cpl_size lly, cpl_size urx, cpl_size ury)
Creates Rect Region Parameters object.
cpl_size hdrl_rect_region_get_llx(const hdrl_parameter *p)
get lower left x coordinate of rectangual region
cpl_size hdrl_rect_region_get_urx(const hdrl_parameter *p)
get upper right x coordinate of rectangular region
cpl_size hdrl_rect_region_get_lly(const hdrl_parameter *p)
get lower left y coordinate of rectangual region
char * hdrl_join_string(const char *sep_, int n,...)
join strings together
cpl_size hdrl_rect_region_get_ury(const hdrl_parameter *p)
get upper right y coordinate of rectangual region
hdrl_parameter * hdrl_rect_region_parameter_parse_parlist(const cpl_parameterlist *parlist, const char *base_context, const char *name_prefix)
parse parameterlist for rectangle parameters
cpl_boolean hdrl_rect_region_parameter_check(const hdrl_parameter *self)
Check that the parameter is hdrl_rect_region parameter.