CR2RE Pipeline Reference Manual 1.6.8
hdrl_resample-test.c
1/*
2 * This file is part of the HDRL
3 * Copyright (C) 2016 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 02110-1301 USA
18 */
19
20
21#ifdef HAVE_CONFIG_H
22#include <config.h>
23#endif
24
25/*-----------------------------------------------------------------------------
26 Includes
27 -----------------------------------------------------------------------------*/
28#include <cpl.h>
29#include <stdint.h>
30#include <math.h>
31#include <assert.h>
32#include <hdrl_utils.h>
33#include <hdrl_resample.h>
34#include <hdrl_resample.c>
35#include <hdrl_random.h>
36#ifndef _OPENMP
37#define omp_get_max_threads() 1
38#else
39#include <omp.h>
40#endif
41
42/* The following code contains several unit tests to cover the hdrl_resample.c
43 * library. As we would like that any function has its own unit test for easy
44 * we used a naming convention as follow:
45 *
46 * 'test_function()' tests the function 'function()';
47 *
48 * There are a few exceptions: "in a few cases it was more convenient to have
49 * a single function testing several library functions
50 * Moreover we have some additional unit tests, testing special functionality
51 * which follows a different naming convention.
52 *
53 */
54/* -------------------------------- DEFINES --------------------------------- */
55#define RECIPE_NAME "hdrldemo_resample"
56
57/*Fine-grained accuracies*/
58#define HDRL_DELTA_COMPARE_VALUE_ABS CPL_MAX(HDRL_EPS_DATA, HDRL_EPS_ERROR) * 4.
59
60#define HDRL_EPS_TEST HDRL_EPS_DATA
61/* For resampling method definition */
62#define DRIZZLE_DOWN_SCALING_FACTOR_X 0.8
63#define DRIZZLE_DOWN_SCALING_FACTOR_Y 0.8
64#define DRIZZLE_DOWN_SCALING_FACTOR_Z 0.8
65#define RENKA_CRITICAL_RADIUS 1.25
66#define LANCZOS_KERNEL_SIZE 2
67#define LOOP_DISTANCE 1.0
68/* Image value */
69#define HDRL_FLUX_ADU 100
70/* For WCS definition From SINFONI cube example 1:
71 * SINFO.2005-08-22T07:47:54.305.fits */
72#define HDRL_SCALE_Z 500
73#define HDRL_CD11 -3.47222e-05
74#define HDRL_CD12 0.0
75#define HDRL_CD21 0.0
76#define HDRL_CD22 3.47222e-05
77#define HDRL_CD13 0.0
78#define HDRL_CD31 0.0
79#define HDRL_CD23 0.0
80#define HDRL_CD32 0.0
81#define HDRL_CD33 2.45e-10*HDRL_SCALE_Z
82
83#define HDRL_CDELT1 fabs(HDRL_CD11)
84#define HDRL_CDELT2 fabs(HDRL_CD22)
85#define HDRL_CDELT3 fabs(HDRL_CD33)
86
87#define HDRL_CRPIX1 33.5
88#define HDRL_CRPIX2 33.5
89#define HDRL_CRPIX3 1.
90
91#define HDRL_CRVAL1 48.0706
92#define HDRL_CRVAL2 -20.6219
93#define HDRL_CRVAL3 1.9283e-06
94
95#define HDRL_RA 48.070
96#define HDRL_DEC -20.621
97#define HDRL_RA_MIN 48.069416667
98#define HDRL_RA_MAX 48.0718125
99#define HDRL_DEC_MIN -20.6229925
100#define HDRL_DEC_MAX -20.620708611
101
102#define HDRL_LAMBDA_MIN 1.9283e-06
103#define HDRL_LAMBDA_MAX 2.47146e-06
104
105/* Image sizes */
106#define HDRL_SIZE_X 50
107#define HDRL_SIZE_Y 50
108#define HDRL_SIZE_Z 3
109
110
111/*----------------------------------------------------------------------------*/
116/*----------------------------------------------------------------------------*/
117static hdrl_image*
118hdrl_resample_util_hdrl_image_create(cpl_image* data, cpl_image* error,
119 cpl_image* bpm){
120 if(bpm != NULL) {
121 cpl_mask* mask = cpl_mask_threshold_image_create(bpm, 0, INT_MAX);
122 cpl_image_reject_from_mask(data, mask);
123 cpl_mask_delete(mask);
124 }
125 hdrl_image* hima = hdrl_image_create(data, error);
126
127 return hima;
128}
129
130/*----------------------------------------------------------------------------*/
135/*----------------------------------------------------------------------------*/
136static cpl_error_code test_hdrl_resample_compute2D_multiple(void)
137{
138
139 /* Data background always 1 and inner 9 pixel 49 - for error tracing*/
140
141 cpl_image * img_data = cpl_image_new(9, 9, CPL_TYPE_DOUBLE);
142 cpl_image * img_bpm = cpl_image_new(9, 9, CPL_TYPE_INT);
143
144 /* Set all data invalid */
145 cpl_image_add_scalar(img_bpm, 1.);
146
147 /* Set data in the center of the image */
148 cpl_image_set(img_data, 4, 4, 48.);
149 cpl_image_set(img_data, 5, 4, 48.);
150 cpl_image_set(img_data, 6, 4, 48.);
151 cpl_image_set(img_data, 4, 5, 48.);
152 cpl_image_set(img_data, 5, 5, 48.);
153 cpl_image_set(img_data, 6, 5, 48.);
154 cpl_image_set(img_data, 4, 6, 48.);
155 cpl_image_set(img_data, 5, 6, 48.);
156 cpl_image_set(img_data, 6, 6, 48.);
157 /* Adding 1 and creating the errors */
158 cpl_image_add_scalar(img_data, 1.0);
159 cpl_image * img_error=cpl_image_power_create(img_data, 0.5);
160
161 /* Set data in the center as valid */
162 cpl_image_set(img_bpm, 4, 4, 0);
163 cpl_image_set(img_bpm, 5, 4, 0);
164 cpl_image_set(img_bpm, 6, 4, 0);
165 cpl_image_set(img_bpm, 4, 5, 0);
166 cpl_image_set(img_bpm, 5, 5, 0);
167 cpl_image_set(img_bpm, 6, 5, 0);
168 cpl_image_set(img_bpm, 4, 6, 0);
169 cpl_image_set(img_bpm, 5, 6, 0);
170 cpl_image_set(img_bpm, 6, 6, 0);
171
172 /*Build the header for the wcs */
173 cpl_propertylist* plist = cpl_propertylist_new();
174
175 cpl_propertylist_append_int(plist, "NAXIS" , 2);
176 cpl_propertylist_append_int(plist, "NAXIS1" , 9);
177 cpl_propertylist_append_int(plist, "NAXIS2" , 9);
178 cpl_propertylist_append_double(plist, "CD1_1" , -0.01 );
179 cpl_propertylist_append_double(plist, "CD1_2" , 0. );
180 cpl_propertylist_append_double(plist, "CD2_1" , 0. );
181 cpl_propertylist_append_double(plist, "CD2_2" , 0.01 );
182 cpl_propertylist_append_double(plist, "CRPIX1" , 4.5 );
183 cpl_propertylist_append_double(plist, "CRPIX2" , 4.5 );
184 cpl_propertylist_append_double(plist, "CRVAL1" , 359.8 );
185 cpl_propertylist_append_double(plist, "CRVAL2" , 10.0 );
186 cpl_propertylist_append_string(plist, "CTYPE1" , "RA---TAN");
187 cpl_propertylist_append_string(plist, "CTYPE2" , "DEC--TAN");
188 cpl_propertylist_append_string(plist, "CUNIT1" , "deg" );
189 cpl_propertylist_append_string(plist, "CUNIT2" , "deg" );
190
191 hdrl_random_state * rastate = hdrl_random_state_new(1, NULL);
192 hdrl_random_state * decstate = hdrl_random_state_new(1, NULL);
193
194 /* Please be aware on the different accuracies set for the errors for the
195 * different methods */
196
197 /* generate hdrl image */
198 hdrl_image*
199 hima = hdrl_resample_util_hdrl_image_create(img_data, img_error, img_bpm);
200 const cpl_size iterations = 500;
201 for (cpl_size i = 0; i < iterations; i++) {
202 double rarandom = hdrl_random_uniform_double(rastate, 0., 360.);
203 double decrandom = hdrl_random_uniform_double(decstate, -89., 89.);
204 cpl_msg_info(cpl_func,"ra-random: %g, dec-random: %g ", rarandom,
205 decrandom);
206 cpl_propertylist_update_double(plist, "CRVAL1" , rarandom);
207 cpl_propertylist_update_double(plist, "CRVAL2" , decrandom);
208 cpl_wcs * wcs = cpl_wcs_new_from_propertylist(plist);
209
210 /* Construct the table */
211 cpl_table * table = hdrl_resample_image_to_table(hima, wcs);
212
213 hdrl_parameter *aParams_outputgrid = NULL;
214
215 /* Define the output grid */
216 aParams_outputgrid = hdrl_resample_parameter_create_outgrid2D(0.01, 0.01);
217 hdrl_resample_result *result = NULL;
218 hdrl_parameter *aParams_method = NULL;
219 int rej;
220
221 /* ---------------------------lanczos------------------------------- */
222
223 /* Define the method */
224 aParams_method = hdrl_resample_parameter_create_lanczos(1, CPL_FALSE, 2);
225 /* Do the resampling */
226 result = hdrl_resample_compute(table, aParams_method, aParams_outputgrid, wcs);
227 cpl_test_error(CPL_ERROR_NONE);
228 cpl_test_rel(cpl_image_get(hdrl_image_get_image_const(hdrl_imagelist_get_const(result->himlist, 0)),
229 5, 5, &rej), 49., 1e-6);
230 cpl_test_rel(cpl_image_get(hdrl_image_get_error_const(hdrl_imagelist_get_const(result->himlist, 0)),
231 5, 5, &rej), 7., 0.05);
232 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 0)),
233 5, 5), 0);
234 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 0)),
235 1, 1), 1);
236 hdrl_parameter_delete(aParams_method);
238
239 /* -----------------------------drizzle----------------------------- */
240
241 /* Define the method */
242 aParams_method = hdrl_resample_parameter_create_drizzle(1, CPL_FALSE,
243 0.8, 0.8, 0.8);
244 /* Do the resampling */
245
246 result = hdrl_resample_compute(table, aParams_method, aParams_outputgrid, wcs);
247 cpl_test_error(CPL_ERROR_NONE);
248 cpl_test_rel(cpl_image_get(hdrl_image_get_image_const(hdrl_imagelist_get_const(result->himlist, 0)),
249 5, 5, &rej), 49., 1e-6);
250 cpl_test_rel(cpl_image_get(hdrl_image_get_error_const(hdrl_imagelist_get_const(result->himlist, 0)),
251 5, 5, &rej), 7., 0.001);
252 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 0)),
253 5, 5), 0);
254 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 0)),
255 1, 1), 1);
256
257 hdrl_parameter_delete(aParams_method);
259
260 /* -----------------------------linear------------------------------ */
261
262 /* Define the method */
263 aParams_method = hdrl_resample_parameter_create_linear(1, CPL_FALSE);
264 /* Do the resampling */
265
266 result = hdrl_resample_compute(table, aParams_method, aParams_outputgrid, wcs);
267 cpl_test_error(CPL_ERROR_NONE);
268 cpl_test_rel(cpl_image_get(hdrl_image_get_image_const(hdrl_imagelist_get_const(result->himlist, 0)),
269 5, 5, &rej), 49., 1e-6);
270 cpl_test_rel(cpl_image_get(hdrl_image_get_error_const(hdrl_imagelist_get_const(result->himlist, 0)),
271 5, 5, &rej), 7., 0.3);
272 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 0)),
273 5, 5), 0);
274 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 0)),
275 1, 1), 1);
276
277 hdrl_parameter_delete(aParams_method);
279
280 /* -----------------------------quadratic--------------------------- */
281
282 /* Define the method */
283 aParams_method = hdrl_resample_parameter_create_quadratic(1, CPL_FALSE);
284 /* Do the resampling */
285
286 result = hdrl_resample_compute(table, aParams_method, aParams_outputgrid, wcs);
287 cpl_test_error(CPL_ERROR_NONE);
288 cpl_test_rel(cpl_image_get(hdrl_image_get_image_const(hdrl_imagelist_get_const(result->himlist, 0)),
289 5, 5, &rej), 49., 1e-6);
290 cpl_test_rel(cpl_image_get(hdrl_image_get_error_const(hdrl_imagelist_get_const(result->himlist, 0)),
291 5, 5, &rej), 7., 0.02);
292 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 0)),
293 5, 5), 0);
294 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 0)),
295 1, 1), 1);
296
297 hdrl_parameter_delete(aParams_method);
299
300 /* -----------------------------renka------------------------------- */
301
302 /* Define the method */
303 aParams_method = hdrl_resample_parameter_create_renka(1, CPL_FALSE,
304 1.25);
305 /* Do the resampling */
306
307 result = hdrl_resample_compute(table, aParams_method, aParams_outputgrid, wcs);
308 cpl_test_error(CPL_ERROR_NONE);
309 cpl_test_rel(cpl_image_get(hdrl_image_get_image_const(hdrl_imagelist_get_const(result->himlist, 0)),
310 5, 5, &rej), 49., 1e-6);
311 cpl_test_rel(cpl_image_get(hdrl_image_get_error_const(hdrl_imagelist_get_const(result->himlist, 0)),
312 5, 5, &rej), 7., 0.01);
313 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 0)),
314 5, 5), 0);
315 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 0)),
316 1, 1), 1);
317
318 hdrl_parameter_delete(aParams_method);
320
321 /* -----------------------------nearest----------------------------- */
322
323 /* Define the method */
325 /* Do the resampling */
326 result = hdrl_resample_compute(table, aParams_method, aParams_outputgrid, wcs);
327 cpl_test_error(CPL_ERROR_NONE);
328 cpl_test_rel(cpl_image_get(hdrl_image_get_image_const(hdrl_imagelist_get_const(result->himlist, 0)),
329 5, 5, &rej), 49., 1e-6);
330 cpl_test_rel(cpl_image_get(hdrl_image_get_error_const(hdrl_imagelist_get_const(result->himlist, 0)),
331 5, 5, &rej), 7., 0.00001);
332 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 0)),
333 5, 5), 0);
334 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 0)),
335 1, 1), 1);
336
337 hdrl_parameter_delete(aParams_method);
339
340 /* ----------------------------------------------------------------- */
341
342 hdrl_parameter_delete(aParams_outputgrid);
343 cpl_table_delete(table);
344 cpl_wcs_delete(wcs);
345 } /* Loop ends here */
346 hdrl_image_delete(hima);
347
348 /* ---------------- For manual updates and tests ----------------------- */
349
350 /* Test image spanning over ra 360 degree */
351 cpl_propertylist_update_double(plist, "CRVAL1" , 0.01);
352 cpl_propertylist_update_double(plist, "CRVAL2" , 20.1);
353
354 /* Test image rotated by 45 degree */
355 cpl_propertylist_update_double(plist, "CD1_1" , cos(45) );
356 cpl_propertylist_update_double(plist, "CD1_2" , -sin(45) );
357 cpl_propertylist_update_double(plist, "CD2_1" , sin(45) );
358 cpl_propertylist_update_double(plist, "CD2_2" , cos(45) );
359
360
361 cpl_wcs * wcs = cpl_wcs_new_from_propertylist(plist);
362
363 /* Construct the table */
364 hima = hdrl_resample_util_hdrl_image_create(img_data, img_error, img_bpm);
365
366 cpl_table * table = hdrl_resample_image_to_table(hima, wcs);
367
368 hdrl_image_delete(hima);
369 hdrl_parameter *aParams_outputgrid = NULL;
370
371 /* Define the output grid */
372 aParams_outputgrid = hdrl_resample_parameter_create_outgrid2D(cos(45) * 3., cos(45) * 3.);
373
374 hdrl_resample_result *result = NULL;
375
376 hdrl_parameter *aParams_method = NULL;
377 int rej;
378
379 /* Define the method */
380 aParams_method = hdrl_resample_parameter_create_lanczos(2, CPL_FALSE, 2);
381 /* Do the resampling */
382 result = hdrl_resample_compute(table, aParams_method, aParams_outputgrid, wcs);
383 cpl_test_error(CPL_ERROR_NONE);
384 cpl_test_rel(cpl_image_get(hdrl_image_get_image_const(hdrl_imagelist_get_const(result->himlist, 0)),
385 5, 5, &rej), 49., 1e-6);
386 cpl_test_rel(cpl_image_get(hdrl_image_get_error_const(hdrl_imagelist_get_const(result->himlist, 0)),
387 5, 5, &rej), 7., 0.3);
388 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 0)),
389 5, 5), 0);
390 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 0)),
391 1, 1), 1);
392
393 /*Save the original and resampled image/error/bpm*/
394 cpl_image_save(img_data, "image_orig.fits", CPL_TYPE_FLOAT, plist,
395 CPL_IO_CREATE);
396
397 cpl_image_save(img_error, "image_orig.fits", CPL_TYPE_FLOAT, plist,
398 CPL_IO_EXTEND);
399
400 cpl_image_save(img_bpm, "image_orig.fits", CPL_TYPE_INT, plist,
401 CPL_IO_EXTEND);
402
403 cpl_image_save(hdrl_image_get_image(hdrl_imagelist_get(result->himlist, 0)), "image_resampled.fits",
404 CPL_TYPE_FLOAT, result->header, CPL_IO_CREATE);
405 cpl_image_save(hdrl_image_get_error(hdrl_imagelist_get(result->himlist, 0)), "image_resampled.fits",
406 CPL_TYPE_FLOAT, result->header, CPL_IO_EXTEND);
407 cpl_mask_save(hdrl_image_get_mask(hdrl_imagelist_get(result->himlist, 0)), "image_resampled.fits",
408 result->header, CPL_IO_EXTEND);
409
410 /*Print the wcs from the original and resampled cube*/
411 hdrl_resample_wcs_print(wcs);
412
413 cpl_wcs_delete(wcs);
414 wcs = cpl_wcs_new_from_propertylist(result->header);
415 hdrl_resample_wcs_print(wcs);
416
417 hdrl_parameter_delete(aParams_method);
419 hdrl_parameter_delete(aParams_outputgrid);
420 cpl_table_delete(table);
421 cpl_wcs_delete(wcs);
422
423 /* --------------------------------------------------------------------- */
424
425 /* free the remaining memory */
426 cpl_propertylist_delete(plist);
427 cpl_image_delete(img_data);
428 cpl_image_delete(img_error);
429 cpl_image_delete(img_bpm);
430 hdrl_random_state_delete(rastate);
431 hdrl_random_state_delete(decstate);
432
433 cpl_test_error(CPL_ERROR_NONE);
434 return cpl_error_get_code();
435}
436
437static hdrl_imagelist*
438hdrl_resample_util_hdrl_imagelist_create(cpl_imagelist* dlist,
439 cpl_imagelist* elist, cpl_imagelist* qlist) {
440
441 cpl_ensure(dlist != NULL, CPL_ERROR_NULL_INPUT, NULL);
442 cpl_size size = cpl_imagelist_get_size(dlist);
443 if(qlist != NULL) {
444 for(cpl_size k = 0; k < size; k++) {
445 cpl_image* data = cpl_imagelist_get(dlist, k);
446
447 cpl_image* qual = cpl_imagelist_get(qlist, k);
448
449 /*we use INT_MAX instead of 1.1 as some pipeline
450 * may use pixel codes as qualifier */
451 cpl_mask* mask = cpl_mask_threshold_image_create(qual, 0, INT_MAX);
452
453 cpl_image_reject_from_mask(data, mask);
454 cpl_mask_delete(mask);
455 cpl_imagelist_set(dlist, data, k);
456 }
457 }
458 hdrl_imagelist* hlist = hdrl_imagelist_create(dlist, elist);
459
460 return hlist;
461
462}
463/*----------------------------------------------------------------------------*/
468/*----------------------------------------------------------------------------*/
469static cpl_error_code test_hdrl_resample_compute3D_multiple(void)
470{
471 cpl_test_error(CPL_ERROR_NONE);
472 cpl_imagelist * imglist_data = cpl_imagelist_new();
473 cpl_imagelist * imglist_error = cpl_imagelist_new();
474 cpl_imagelist * imglist_bpm = cpl_imagelist_new();
475 cpl_test_error(CPL_ERROR_NONE);
476
477 /* Data background always 0 and inner 9 pixel ramp up from 1 to 50 and then
478 * back to 1 */
479 cpl_test_error(CPL_ERROR_NONE);
480 for (cpl_size var = 0; var <99 ; ++var) {
481 cpl_image * data = cpl_image_new(9, 9, CPL_TYPE_DOUBLE);
482 cpl_image * bpm = cpl_image_new(9, 9, CPL_TYPE_INT);
483 /* Set all data invalid */
484 cpl_image_add_scalar(bpm, 1.);
485
486 if(var < 50) {
487 cpl_image_set(data, 4, 4, var + 1.);
488 cpl_image_set(data, 5, 4, var + 1.);
489 cpl_image_set(data, 6, 4, var + 1.);
490 cpl_image_set(data, 4, 5, var + 1.);
491 cpl_image_set(data, 5, 5, var + 1.);
492 cpl_image_set(data, 6, 5, var + 1.);
493 cpl_image_set(data, 4, 6, var + 1.);
494 cpl_image_set(data, 5, 6, var + 1.);
495 cpl_image_set(data, 6, 6, var + 1.);
496 cpl_image * errors=cpl_image_power_create(data, 0.5);
497
498 /* Set data in the center as valid */
499 cpl_image_set(bpm, 4, 4, 0);
500 cpl_image_set(bpm, 5, 4, 0);
501 cpl_image_set(bpm, 6, 4, 0);
502 cpl_image_set(bpm, 4, 5, 0);
503 cpl_image_set(bpm, 5, 5, 0);
504 cpl_image_set(bpm, 6, 5, 0);
505 cpl_image_set(bpm, 4, 6, 0);
506 cpl_image_set(bpm, 5, 6, 0);
507 cpl_image_set(bpm, 6, 6, 0);
508
509 cpl_imagelist_set(imglist_data, data, var);
510 cpl_imagelist_set(imglist_error, errors, var);
511 cpl_imagelist_set(imglist_bpm, bpm, var);
512 }
513 if(var >= 50) {
514 cpl_image_set(data, 4, 4, 99. - var);
515 cpl_image_set(data, 5, 4, 99. - var);
516 cpl_image_set(data, 6, 4, 99. - var);
517 cpl_image_set(data, 4, 5, 99. - var);
518 cpl_image_set(data, 5, 5, 99. - var);
519 cpl_image_set(data, 6, 5, 99. - var);
520 cpl_image_set(data, 4, 6, 99. - var);
521 cpl_image_set(data, 5, 6, 99. - var);
522 cpl_image_set(data, 6, 6, 99. - var);
523 cpl_image * errors=cpl_image_power_create(data, 0.5);
524
525 /* Set data in the center as valid */
526 cpl_image_set(bpm, 4, 4, 0);
527 cpl_image_set(bpm, 5, 4, 0);
528 cpl_image_set(bpm, 6, 4, 0);
529 cpl_image_set(bpm, 4, 5, 0);
530 cpl_image_set(bpm, 5, 5, 0);
531 cpl_image_set(bpm, 6, 5, 0);
532 cpl_image_set(bpm, 4, 6, 0);
533 cpl_image_set(bpm, 5, 6, 0);
534 cpl_image_set(bpm, 6, 6, 0);
535
536 cpl_imagelist_set(imglist_data, data, var);
537 cpl_imagelist_set(imglist_error, errors, var);
538 cpl_imagelist_set(imglist_bpm, bpm, var);
539 }
540 }
541 cpl_test_error(CPL_ERROR_NONE);
542 /*Build the header for the wcs */
543
544 cpl_propertylist* plist = cpl_propertylist_new();
545
546 cpl_propertylist_append_int(plist, "NAXIS" , 3 );
547 cpl_propertylist_append_int(plist, "NAXIS1" , 9 );
548 cpl_propertylist_append_int(plist, "NAXIS2" , 9 );
549 cpl_propertylist_append_int(plist, "NAXIS3" , 99 );
550 cpl_propertylist_append_double(plist, "CD1_1" , -0.01 );
551 cpl_propertylist_append_double(plist, "CD1_2" , 0. );
552 cpl_propertylist_append_double(plist, "CD2_1" , 0. );
553 cpl_propertylist_append_double(plist, "CD2_2" , 0.01 );
554 cpl_propertylist_append_double(plist, "CRPIX1" , 4.5 );
555 cpl_propertylist_append_double(plist, "CRPIX2" , 4.5 );
556 cpl_propertylist_append_double(plist, "CRVAL1" , 48.0 );
557 cpl_propertylist_append_double(plist, "CRVAL2" , -20.0 );
558 cpl_propertylist_append_string(plist, "CTYPE1" , "RA---TAN");
559 cpl_propertylist_append_string(plist, "CTYPE2" , "DEC--TAN");
560 cpl_propertylist_append_string(plist, "CUNIT1" , "deg" );
561 cpl_propertylist_append_string(plist, "CUNIT2" , "deg" );
562 cpl_propertylist_append_double(plist, "CD1_3" , 0. );
563 cpl_propertylist_append_double(plist, "CD2_3" , 0. );
564 cpl_propertylist_append_double(plist, "CD3_1" , 0. );
565 cpl_propertylist_append_double(plist, "CD3_2" , 0. );
566 cpl_propertylist_append_double(plist, "CD3_3" , 1.0 );
567 cpl_propertylist_append_double(plist, "CRPIX3" , 1.0 );
568 cpl_propertylist_append_double(plist, "CRVAL3" , 1.0 );
569 cpl_propertylist_append_string(plist, "CTYPE3" , "WAVE" );
570 cpl_propertylist_append_string(plist, "CUNIT3" , "m" );
571 cpl_test_error(CPL_ERROR_NONE);
572
573 hdrl_random_state * rastate = hdrl_random_state_new(1, NULL);
574 hdrl_random_state * decstate = hdrl_random_state_new(1, NULL);
575
576 /* Please be aware on the different accuracies set for the errors for the
577 * different methods */
578 hdrl_imagelist* hlist =
579 hdrl_resample_util_hdrl_imagelist_create(imglist_data,
580 imglist_error, imglist_bpm);
581 const cpl_size iterations = 20;
582 for (cpl_size i = 0; i < iterations; i++) {
583 double rarandom = hdrl_random_uniform_double(rastate, 0., 360.);
584 double decrandom = hdrl_random_uniform_double(decstate, -89., 89.);
585 cpl_msg_info(cpl_func,"ra-random: %g, dec-random: %g ", rarandom,
586 decrandom);
587 cpl_propertylist_update_double(plist, "CRVAL1" , rarandom);
588 cpl_propertylist_update_double(plist, "CRVAL2" , decrandom);
589 cpl_wcs * wcs = cpl_wcs_new_from_propertylist(plist);
590 cpl_test_error(CPL_ERROR_NONE);
591 /* Construct the table */
592 cpl_table * table = hdrl_resample_imagelist_to_table(hlist, wcs);
593
594 cpl_test_error(CPL_ERROR_NONE);
595 hdrl_parameter *aParams_outputgrid = NULL;
596 /* Define the output grid */
597 aParams_outputgrid =
599 cpl_test_nonnull(aParams_outputgrid);
600 cpl_test_error(CPL_ERROR_NONE);
601
602 hdrl_resample_result *result = NULL;
603 hdrl_parameter *aParams_method = NULL;
604 int rej;
605
606 /* ---------------------------lanczos------------------------------- */
607
608 /* Define the method */
609 aParams_method = hdrl_resample_parameter_create_lanczos(1, CPL_FALSE, 2);
610 /* Do the resampling */
611 result = hdrl_resample_compute(table, aParams_method, aParams_outputgrid, wcs);
612 cpl_test_error(CPL_ERROR_NONE);
613 cpl_test_rel(cpl_image_get(hdrl_image_get_image_const(hdrl_imagelist_get_const(result->himlist, 48)),
614 5, 5, &rej), 49., 1e-6);
615 cpl_test_rel(cpl_image_get(hdrl_image_get_error_const(hdrl_imagelist_get_const(result->himlist, 48)),
616 5, 5, &rej), 7., 0.05);
617 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 48)),
618 5, 5), 0);
619 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 48)),
620 1, 1), 1);
621 hdrl_parameter_delete(aParams_method);
623
624
625 /* -----------------------------drizzle----------------------------- */
626
627 /* Define the method */
628 aParams_method = hdrl_resample_parameter_create_drizzle(1, CPL_FALSE,
629 0.8, 0.8, 0.8);
630 /* Do the resampling */
631
632 result = hdrl_resample_compute(table, aParams_method, aParams_outputgrid, wcs);
633 cpl_test_error(CPL_ERROR_NONE);
634 cpl_test_rel(cpl_image_get(hdrl_image_get_image_const(hdrl_imagelist_get_const(result->himlist, 48)),
635 5, 5, &rej), 49., 1e-6);
636 cpl_test_rel(cpl_image_get(hdrl_image_get_error_const(hdrl_imagelist_get_const(result->himlist, 48)),
637 5, 5, &rej), 7., 0.001);
638 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 48)),
639 5, 5), 0);
640 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 48)),
641 1, 1), 1);
642
643 hdrl_parameter_delete(aParams_method);
645
646 /* -----------------------------linear------------------------------ */
647
648 /* Define the method */
649 aParams_method = hdrl_resample_parameter_create_linear(1, CPL_FALSE);
650 /* Do the resampling */
651
652 result = hdrl_resample_compute(table, aParams_method, aParams_outputgrid, wcs);
653 cpl_test_error(CPL_ERROR_NONE);
654 cpl_test_rel(cpl_image_get(hdrl_image_get_image_const(hdrl_imagelist_get_const(result->himlist, 48)),
655 5, 5, &rej), 49., 1e-6);
656 cpl_test_rel(cpl_image_get(hdrl_image_get_error_const(hdrl_imagelist_get_const(result->himlist, 48)),
657 5, 5, &rej), 7., 0.3);
658 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 48)),
659 5, 5), 0);
660 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 48)),
661 1, 1), 1);
662
663 hdrl_parameter_delete(aParams_method);
665
666 /* -----------------------------quadratic--------------------------- */
667
668 /* Define the method */
669 aParams_method = hdrl_resample_parameter_create_quadratic(1, CPL_FALSE);
670 /* Do the resampling */
671
672 result = hdrl_resample_compute(table, aParams_method, aParams_outputgrid, wcs);
673 cpl_test_error(CPL_ERROR_NONE);
674 cpl_test_rel(cpl_image_get(hdrl_image_get_image_const(hdrl_imagelist_get_const(result->himlist, 48)),
675 5, 5, &rej), 49., 1e-6);
676 cpl_test_rel(cpl_image_get(hdrl_image_get_error_const(hdrl_imagelist_get_const(result->himlist, 48)),
677 5, 5, &rej), 7., 0.02);
678 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 48)),
679 5, 5), 0);
680 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 48)),
681 1, 1), 1);
682
683 hdrl_parameter_delete(aParams_method);
685
686 /* -----------------------------renka------------------------------- */
687
688 /* Define the method */
689 aParams_method = hdrl_resample_parameter_create_renka(1, CPL_FALSE,
690 1.25);
691 /* Do the resampling */
692
693 result = hdrl_resample_compute(table, aParams_method, aParams_outputgrid, wcs);
694 cpl_test_error(CPL_ERROR_NONE);
695 cpl_test_rel(cpl_image_get(hdrl_image_get_image_const(hdrl_imagelist_get_const(result->himlist, 48)),
696 5, 5, &rej), 49., 1e-6);
697 cpl_test_rel(cpl_image_get(hdrl_image_get_error_const(hdrl_imagelist_get_const(result->himlist, 48)),
698 5, 5, &rej), 7., 0.01);
699 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 48)),
700 5, 5), 0);
701 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 48)),
702 1, 1), 1);
703
704 hdrl_parameter_delete(aParams_method);
706
707 /* -----------------------------nearest----------------------------- */
708
709 /* Define the method */
711 /* Do the resampling */
712 result = hdrl_resample_compute(table, aParams_method, aParams_outputgrid, wcs);
713 cpl_test_error(CPL_ERROR_NONE);
714 cpl_test_rel(cpl_image_get(hdrl_image_get_image_const(hdrl_imagelist_get_const(result->himlist, 48)),
715 5, 5, &rej), 49., 1e-6);
716 cpl_test_rel(cpl_image_get(hdrl_image_get_error_const(hdrl_imagelist_get_const(result->himlist, 48)),
717 5, 5, &rej), 7., 0.00001);
718 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 48)),
719 5, 5), 0);
720 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 48)),
721 1, 1), 1);
722
723 hdrl_parameter_delete(aParams_method);
725
726 /* ----------------------------------------------------------------- */
727
728 hdrl_parameter_delete(aParams_outputgrid);
729 cpl_table_delete(table);
730 cpl_wcs_delete(wcs);
731 } /* Loop ends here */
732
733
734 /* ---------------- For manual updates and tests ----------------------- */
735
736 /* Test image spanning over ra 360 degree */
737 cpl_propertylist_update_double(plist, "CRVAL1" , 0.03);
738 cpl_propertylist_update_double(plist, "CRVAL2" , 0.1);
739 cpl_wcs * wcs = cpl_wcs_new_from_propertylist(plist);
740
741 /* Construct the table */
742 cpl_table * table = hdrl_resample_imagelist_to_table(hlist, wcs);
744 hdrl_parameter *aParams_outputgrid = NULL;
745 /* Define the output grid */
746 aParams_outputgrid =
748 cpl_test_nonnull(aParams_outputgrid);
749 cpl_test_error(CPL_ERROR_NONE);
750
751 hdrl_resample_result *result = NULL;
752 hdrl_parameter *aParams_method = NULL;
753 int rej;
754
755 /* Define the method */
756 aParams_method = hdrl_resample_parameter_create_lanczos(1, CPL_FALSE, 2);
757 /* Do the resampling */
758 result = hdrl_resample_compute(table, aParams_method, aParams_outputgrid, wcs);
759 cpl_test_error(CPL_ERROR_NONE);
760 cpl_test_rel(cpl_image_get(hdrl_image_get_image_const(hdrl_imagelist_get_const(result->himlist, 48)),
761 5, 5, &rej), 49., 1e-6);
762 cpl_test_rel(cpl_image_get(hdrl_image_get_error_const(hdrl_imagelist_get_const(result->himlist, 48)),
763 5, 5, &rej), 7., 0.05);
764 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 48)),
765 5, 5), 0);
766 cpl_test_eq(cpl_mask_get(hdrl_image_get_mask_const(hdrl_imagelist_get_const(result->himlist, 48)),
767 1, 1), 1);
768
769 cpl_test_error(CPL_ERROR_NONE);
770 /*Save the original cube*/
771 cpl_propertylist_save(plist, "cube_orig.fits", CPL_IO_CREATE);
772 cpl_imagelist_save(imglist_data, "cube_orig.fits", CPL_TYPE_FLOAT, plist,
773 CPL_IO_EXTEND);
774 cpl_imagelist_save(imglist_bpm, "cube_orig.fits", CPL_TYPE_INT, plist,
775 CPL_IO_EXTEND);
776 cpl_imagelist_save(imglist_error, "cube_orig.fits", CPL_TYPE_FLOAT,
777 plist, CPL_IO_EXTEND);
778
779 /*Save the resampled cube */
780
781 cpl_propertylist_save(plist, "cube_resampled.fits", CPL_IO_CREATE);
782 cpl_test_error(CPL_ERROR_NONE);
783
784 cpl_imagelist * ilistdata = cpl_imagelist_new();
785 cpl_imagelist * ilisterrors = cpl_imagelist_new();
786 cpl_imagelist * ilistbpm = cpl_imagelist_new();
787
788 cpl_size planes = hdrl_imagelist_get_size(result->himlist);
789 for (cpl_size i = 0; i < planes; i++) {
790 /* The images are duplicated to avoid errors reported by cppcheck */
791 cpl_imagelist_set(ilistdata, cpl_image_duplicate(hdrl_image_get_image(hdrl_imagelist_get(result->himlist, i))), i);
792 cpl_imagelist_set(ilisterrors, cpl_image_duplicate(hdrl_image_get_error(hdrl_imagelist_get(result->himlist, i))), i);
793 cpl_image * bpm = cpl_image_new_from_mask(hdrl_image_get_mask(hdrl_imagelist_get(result->himlist, i)));
794 cpl_imagelist_set(ilistbpm, bpm, i);
795 }
796
797 /* Save the data/bpm/errors in the right extension as a cube */
798 cpl_imagelist_save(ilistdata, "cube_resampled.fits", CPL_TYPE_FLOAT,
799 result->header, CPL_IO_EXTEND);
800 cpl_imagelist_save(ilistbpm, "cube_resampled.fits", CPL_TYPE_INT,
801 result->header, CPL_IO_EXTEND);
802 cpl_imagelist_save(ilisterrors, "cube_resampled.fits", CPL_TYPE_FLOAT,
803 result->header, CPL_IO_EXTEND);
804
805
806 cpl_imagelist_delete(ilistdata);
807 cpl_imagelist_delete(ilisterrors);
808 cpl_imagelist_delete(ilistbpm);
809
810 /*Print the wcs from the original and resampled cube*/
811 hdrl_resample_wcs_print(wcs);
812 cpl_wcs_delete(wcs);
813 wcs = cpl_wcs_new_from_propertylist(result->header);
814 hdrl_resample_wcs_print(wcs);
815
816 /* free the memory */
817 cpl_propertylist_delete(plist);
818 cpl_imagelist_delete(imglist_data);
819 cpl_imagelist_delete(imglist_error);
820 cpl_imagelist_delete(imglist_bpm);
821 hdrl_random_state_delete(rastate);
822 hdrl_random_state_delete(decstate);
823
824 hdrl_parameter_delete(aParams_method);
825 hdrl_parameter_delete(aParams_outputgrid);
827 cpl_table_delete(table);
828 cpl_wcs_delete(wcs);
829
830 return cpl_error_get_code();
831}
832/* -------------------------------------------------------------------------- */
833
834
835/* -------------------------------------------------------------------------- */
862/*----------------------------------------------------------------------------*/
863/* unit tests utility */
864static cpl_propertylist*
865hdrl_resample_util_crea_header_image(const int naxis, const int sx, const int sy,
866 const double ra, const double dec,
867 const double cd11, const double cd12,
868 const double cd21, const double cd22,
869 const double crpix1, const double crpix2,
870 const double crval1, const double crval2,
871 const double cdelt1, const double cdelt2,
872 const char* ctype1, const char* ctype2,
873 const char* cunit1, const char* cunit2)
874{
875 cpl_propertylist* plist = cpl_propertylist_new();
876 cpl_propertylist_append_int(plist, "NAXIS", naxis);
877
878 cpl_propertylist_append_int(plist, "NAXIS1", sx);
879 cpl_propertylist_append_int(plist, "NAXIS2", sy);
880
881 cpl_propertylist_append_double(plist, "RA", ra);
882 cpl_propertylist_append_double(plist, "DEC", dec);
883
884 cpl_propertylist_append_double(plist, "CRPIX1", crpix1);
885 cpl_propertylist_append_double(plist, "CRPIX2", crpix2);
886
887 cpl_propertylist_append_double(plist, "CRVAL1", crval1);
888 cpl_propertylist_append_double(plist, "CRVAL2", crval2);
889
890 cpl_propertylist_append_double(plist, "CDELT1", cdelt1);
891 cpl_propertylist_append_double(plist, "CDELT2", cdelt2);
892
893 cpl_propertylist_append_string(plist, "CTYPE1", ctype1);
894 cpl_propertylist_append_string(plist, "CTYPE2", ctype2);
895
896 cpl_propertylist_append_string(plist, "CUNIT1", cunit1);
897 cpl_propertylist_append_string(plist, "CUNIT2", cunit2);
898
899 cpl_propertylist_append_double(plist, "CD1_1", cd11);
900 cpl_propertylist_append_double(plist, "CD1_2", cd12);
901 cpl_propertylist_append_double(plist, "CD2_1", cd21);
902 cpl_propertylist_append_double(plist, "CD2_2", cd22);
903
904 /* To be sure to have a standard FITS header we save and reload the image */
905 cpl_image* ima = cpl_image_new(sx, sy, CPL_TYPE_INT);
906 cpl_image_add_scalar(ima, 1);
907
908 cpl_image_save(ima, "ima.fits", CPL_TYPE_INT, plist, CPL_IO_DEFAULT);
909 cpl_image_delete(ima);
910 cpl_propertylist_delete(plist);
911 plist = cpl_propertylist_load("ima.fits", 0);
912 cpl_test_error(CPL_ERROR_NONE);
913 return plist;
914}
915
916
961/* unit tests utility */
962static cpl_propertylist*
963hdrl_resample_crea_header_cube(const int naxis,
964 const int sx, const int sy, const int sz,
965 const double ra, const double dec,
966 const double cd11, const double cd12,
967 const double cd21, const double cd22,
968 const double cd13, const double cd31,
969 const double cd23, const double cd32,
970 const double cd33,
971 const double crpix1, const double crpix2, const double crpix3,
972 const double crval1, const double crval2, const double crval3,
973 const double cdelt1, const double cdelt2, const double cdelt3,
974 const char* ctype1, const char* ctype2, const char* ctype3,
975 const char* cunit1, const char* cunit2, const char* cunit3)
976{
977 /* crea first the FITS header for a 2D example */
978 cpl_propertylist* plist =
979 hdrl_resample_util_crea_header_image(naxis, sx, sy, ra, dec,
980 cd11, cd12, cd21, cd22, crpix1, crpix2,
981 crval1, crval2, cdelt1, cdelt2, ctype1,
982 ctype2, cunit1, cunit2);
983
984 /* then add information for a 3D example */
985 cpl_propertylist_update_int(plist, "NAXIS", naxis);
986
987 cpl_propertylist_append_int(plist, "NAXIS3", sz);
988
989 cpl_propertylist_append_double(plist, "CRVAL3", crval3);
990 cpl_propertylist_append_double(plist, "CRPIX3", crpix3);
991 cpl_propertylist_append_double(plist, "CDELT3", cdelt3);
992 cpl_propertylist_append_string(plist, "CTYPE3", ctype3);
993 cpl_propertylist_append_string(plist, "CUNIT3", cunit3);
994
995 cpl_propertylist_append_double(plist, "CD1_3", cd13);
996 cpl_propertylist_append_double(plist, "CD3_1", cd31);
997 cpl_propertylist_append_double(plist, "CD2_3", cd23);
998 cpl_propertylist_append_double(plist, "CD3_2", cd32);
999 cpl_propertylist_append_double(plist, "CD3_3", cd33);
1000
1001
1002 /* To be sure to have a standard FITS header we save & reload the imagelist */
1003 cpl_image* ima = cpl_image_new(sx, sy, CPL_TYPE_INT);
1004 cpl_image_add_scalar(ima, 1);
1005 cpl_imagelist* iml = cpl_imagelist_new();
1006 for(int i = 0; i< sz;i++) {
1007 cpl_imagelist_set(iml, ima, i);
1008 }
1009
1010 cpl_imagelist_save(iml, "iml.fits", CPL_TYPE_INT, plist, CPL_IO_DEFAULT);
1011 cpl_imagelist_delete(iml);
1012 cpl_propertylist_delete(plist);
1013 plist = cpl_propertylist_load("iml.fits", 0);
1014 cpl_test_error(CPL_ERROR_NONE);
1015 return plist;
1016}
1017
1021static cpl_error_code
1022test_invalid_input_hdrl_resample_weight_function_renka(void){
1023 double r;
1024 double r_c;
1025
1026 /* test invalid input */
1027 /* case r = 0 */
1028 r = 0;
1029 r_c = 1;
1030 cpl_test_abs(hdrl_resample_weight_function_renka(r, r_c), FLT_MAX, HDRL_EPS_TEST);
1031 cpl_test_error(CPL_ERROR_NONE);
1032
1033 /* case r > r_c */
1034 r = 2;
1035 r_c = 1;
1036 cpl_test_abs(hdrl_resample_weight_function_renka(r, r_c), DBL_MIN, HDRL_EPS_TEST);
1037 cpl_test_error(CPL_ERROR_NONE);
1038
1039 /* case r == r_c */
1040 r = 2;
1041 r_c = 2;
1042 cpl_test_abs(hdrl_resample_weight_function_renka(r, r_c), DBL_MIN, HDRL_EPS_TEST);
1043 cpl_test_error(CPL_ERROR_NONE);
1044 return cpl_error_get_code();
1045}
1046static cpl_error_code
1047test_hdrl_resample_weight_function_renka(void)
1048{
1049 double r;
1050 double r_c;
1051 double res;
1052
1053 /* test invalid input */
1054 test_invalid_input_hdrl_resample_weight_function_renka();
1055
1056 /* test valid input */
1057 /* case r < r_c */
1058 r = 2.;
1059 r_c = 3.;
1060
1061 res = 0.0277777777777777762; /* value from print out on fc32 (laptop)*/
1062 cpl_test_abs(hdrl_resample_weight_function_renka(r, r_c), res, HDRL_EPS_TEST);
1063
1064 cpl_test_error(CPL_ERROR_NONE);
1065
1066 return cpl_error_get_code();
1067}
1068
1073static cpl_error_code
1074test_hdrl_resample_weight_function_drizzle(void)
1075{
1076 double x_in, y_in, z_in;
1077 double x_out, y_out, z_out;
1078 double dx, dy, dz;
1079
1080 /* 1st test case */
1081 x_in = 2, y_in = 2, z_in = 2;
1082 dx = 1, dy = 1, dz = 1;
1083 x_out = 1, y_out = 1, z_out = 1;
1084 double res = 0.015625;/* value from computation in code */
1085 hdrl_resample_weight_function_drizzle(x_in, y_in, z_in, x_out, y_out, z_out,
1086 dx, dy, dz);
1087 cpl_test_error(CPL_ERROR_NONE);
1088
1089 cpl_test_abs(hdrl_resample_weight_function_drizzle(x_in, y_in, z_in,
1090 x_out, y_out, z_out, dx, dy, dz),res,HDRL_EPS_TEST);
1091
1092 /* 2nd test case */
1093 x_in = 3, y_in = 3, z_in = 3;
1094 dx = 1, dy = 1, dz = 1;
1095 x_out = 2, y_out = 2, z_out = 2;
1096 res = 0.125;/* value from computation in code */
1097 hdrl_resample_weight_function_drizzle(x_in, y_in, z_in, x_out, y_out, z_out,
1098 dx, dy, dz);
1099 cpl_test_error(CPL_ERROR_NONE);
1100 cpl_test_abs(hdrl_resample_weight_function_drizzle(x_in, y_in, z_in,
1101 x_out, y_out, z_out, dx, dy, dz),res,HDRL_EPS_TEST);
1102
1103 /* 3rd test case */
1104 x_in = 2, y_in = 2, z_in = 2;
1105 dx = 10, dy = 10, dz = 10;
1106 x_out = 1, y_out = 1, z_out = 1;
1107 res = 0; /* value from computation in code */
1108 cpl_test_abs(hdrl_resample_weight_function_drizzle(x_in, y_in, z_in,
1109 x_out, y_out, z_out, dx, dy, dz),res,HDRL_EPS_TEST);
1110
1111 cpl_test_error(CPL_ERROR_NONE);
1112
1113 return cpl_error_get_code();
1114}
1115
1119static cpl_error_code
1120test_hdrl_resample_weight_function_linear(void)
1121{
1122 /* test invalid input */
1123 /* r = 0 */
1124 cpl_test_abs(hdrl_resample_weight_function_linear(0), FLT_MAX, HDRL_EPS_TEST);
1125 cpl_test_error(CPL_ERROR_NONE);
1126
1127 /* test valid input */
1128 /* r = 2 */
1129 cpl_test_abs(hdrl_resample_weight_function_linear(2), 0.5, HDRL_EPS_TEST);
1130 cpl_test_error(CPL_ERROR_NONE);
1131
1132
1133 return cpl_error_get_code();
1134}
1135
1139static cpl_error_code
1140test_hdrl_resample_weight_function_quadratic(void)
1141{
1142 /* test invalid input */
1143 /* r = 0 */
1144 cpl_test_abs(hdrl_resample_weight_function_quadratic(0), FLT_MAX, HDRL_EPS_TEST);
1145 cpl_test_error(CPL_ERROR_NONE);
1146
1147 /* test valid input */
1148 /* r = 4 */
1149 cpl_test_abs(hdrl_resample_weight_function_quadratic(4), 0.25, HDRL_EPS_TEST);
1150 cpl_test_error(CPL_ERROR_NONE);
1151
1152
1153 return cpl_error_get_code();
1154}
1155
1159static cpl_error_code
1160test_hdrl_resample_weight_function_sinc(void)
1161{
1162
1163 double r;
1164 double res;
1165 /* test invalid input */
1166 /* r = 0 */
1167 cpl_test_abs(hdrl_resample_weight_function_sinc(DBL_EPSILON), 1., HDRL_EPS_TEST);
1168 cpl_test_error(CPL_ERROR_NONE);
1169
1170 /* test valid input */
1171 r = 0.25;
1172
1173 res = 0.900316316157106056;/* value from computation in code */
1174 cpl_test_abs(hdrl_resample_weight_function_sinc(r), res, HDRL_EPS_TEST);
1175 cpl_test_error(CPL_ERROR_NONE);
1176
1177 return cpl_error_get_code();
1178}
1179
1183static cpl_error_code
1184test_hdrl_resample_weight_function_lanczos(void)
1185{
1186
1187 double dx = 1.;
1188 double dy = 1.;
1189 double dz = 1.;
1190 unsigned int ld = 4; /* loop distance */
1191 unsigned int lks = 2; /* lanczos kernel size */
1192
1193 /* test invalid input */
1194 /* dx = 0 || dy =0 || dz = 0 */
1195 cpl_test_abs(hdrl_resample_weight_function_lanczos(5., dy, dz, ld, lks), 0., HDRL_EPS_TEST);
1196 cpl_test_abs(hdrl_resample_weight_function_lanczos(dx, 5., dz, ld, lks), 0., HDRL_EPS_TEST);
1197 cpl_test_abs(hdrl_resample_weight_function_lanczos(dx, dy, 5., ld, lks), 0., HDRL_EPS_TEST);
1198 cpl_test_error(CPL_ERROR_NONE);
1199
1200 /* test valid input */
1201 double res = 4.32283142061004719e-50;/* value from computation in code */
1202 cpl_test_abs(hdrl_resample_weight_function_lanczos(dx, dy, dz, ld, lks), res, HDRL_EPS_TEST);
1203 cpl_test_error(CPL_ERROR_NONE);
1204
1205 return cpl_error_get_code();
1206}
1207
1211static cpl_image*
1212hdrl_resample_util_crea_image_dice_5(const cpl_size sx, const cpl_size sy,
1213 const double value)
1214{
1215 assert(value > 0);
1216 cpl_image * image = cpl_image_new(sx, sy, CPL_TYPE_DOUBLE);
1217 cpl_image * dice = cpl_image_new(sx, sy, CPL_TYPE_DOUBLE);
1218 cpl_image_add_scalar(image,value);
1219
1220 cpl_size xc = 0.5 * sx;
1221 cpl_size yc = 0.5 * sy;
1222 cpl_size dx = 2;
1223 cpl_size dy = 2;
1224 cpl_size xl = 0.25 * sx;
1225 cpl_size yl = 0.25 * sy;
1226 cpl_size xh = 0.75 * sx;
1227 cpl_size yh = 0.75 * sy;
1228 double flux_point=2.*value;
1229 cpl_image_fill_window(dice, xc - dx, yc - dy, xc + dx, yc + dy, flux_point);
1230 cpl_image_fill_window(dice, xl - dx, yl - dy, xl + dx, yl + dy, flux_point);
1231 cpl_image_fill_window(dice, xl - dx, yh - dy, xl + dx, yh + dy, flux_point);
1232 cpl_image_fill_window(dice, xh - dx, yh - dy, xh + dx, yh + dy, flux_point);
1233 cpl_image_fill_window(dice, xh - dx, yl - dy, xh + dx, yl + dy, flux_point);
1234 cpl_image_add(image,dice);
1235
1236 cpl_image_delete(dice);
1237 cpl_test_error(CPL_ERROR_NONE);
1238 return image;
1239}
1240
1241
1242/*----------------------------------------------------------------------------*/
1254/*----------------------------------------------------------------------------*/
1255static hdrl_parameter *
1256hdrl_resample_util_methodparam_create (
1257 const int loop_distance,
1258 const double critical_radius_renka,
1259 const int kernel_size_lanczos,
1260 const double pix_frac_drizzle_x,
1261 const double pix_frac_drizzle_y,
1262 const double pix_frac_drizzle_l,
1263 const int resample_method,
1264 const cpl_boolean use_errorweights
1265)
1266{
1267 hdrl_parameter *aParams_method = NULL;
1268
1269 /* Create the right re-sampling parameter */
1270 switch(resample_method) {
1271 case HDRL_RESAMPLE_METHOD_NEAREST:
1272 aParams_method =
1274 break;
1275 case HDRL_RESAMPLE_METHOD_RENKA:
1276 aParams_method =
1277 hdrl_resample_parameter_create_renka(loop_distance, use_errorweights,
1278 critical_radius_renka);
1279 break;
1280 case HDRL_RESAMPLE_METHOD_LINEAR:
1281 aParams_method =
1282 hdrl_resample_parameter_create_linear(loop_distance, use_errorweights);
1283 break;
1284 case HDRL_RESAMPLE_METHOD_QUADRATIC:
1285 aParams_method =
1286 hdrl_resample_parameter_create_quadratic(loop_distance, use_errorweights);
1287 break;
1288 case HDRL_RESAMPLE_METHOD_DRIZZLE:
1289 aParams_method =
1290 hdrl_resample_parameter_create_drizzle(loop_distance, use_errorweights,
1291 pix_frac_drizzle_x,
1292 pix_frac_drizzle_y,
1293 pix_frac_drizzle_l);
1294 break;
1295 case HDRL_RESAMPLE_METHOD_LANCZOS:
1296 aParams_method =
1297 hdrl_resample_parameter_create_lanczos(loop_distance, use_errorweights,
1298 kernel_size_lanczos);
1299 break;
1300 default:
1301 aParams_method =
1302 hdrl_resample_parameter_create_lanczos(loop_distance, use_errorweights,
1303 kernel_size_lanczos);
1304 cpl_msg_warning (cpl_func,
1305 "You set an unsupported method! Default to LANCZOS");
1306 break;
1307 }
1308
1309 cpl_test_error(CPL_ERROR_NONE);
1310 return aParams_method;
1311}
1312
1313
1314/*----------------------------------------------------------------------------*/
1321/*----------------------------------------------------------------------------*/
1322static cpl_wcs *
1323hdrl_resample_util_wcs_create_example_params(void)
1324{
1325
1326 cpl_propertylist* p = cpl_propertylist_new();
1327 /* leave out the velocity and stokes axes */
1328 cpl_propertylist_append_int(p, "NAXIS", 2);
1329 cpl_propertylist_append_int(p, "NAXIS1", 512);
1330 cpl_propertylist_append_int(p, "NAXIS2", 512);
1331 cpl_propertylist_append_double(p, "CRPIX1", 256.);
1332
1333 /* use the CDi_j matrix instead of CDELT */
1334 cpl_propertylist_append_double(p, "CD1_1", -0.003);
1335 cpl_propertylist_append_string(p, "CTYPE1", "RA---TAN");
1336 cpl_propertylist_append_double(p, "CRVAL1", 45.83);
1337 cpl_propertylist_append_string(p, "CUNIT1", "deg");
1338
1339 cpl_propertylist_append_double(p, "CRPIX2", 257.);
1340 cpl_propertylist_append_double(p, "CD2_2", 0.003);
1341 cpl_propertylist_append_string(p, "CTYPE2", "DEC--TAN");
1342 cpl_propertylist_append_double(p, "CRVAL2", 63.57);
1343 cpl_propertylist_append_string(p, "CUNIT2", "deg");
1344
1345 /* no cross terms */
1346 cpl_propertylist_append_double(p, "CD1_2", 0.);
1347 cpl_propertylist_append_double(p, "CD2_1", 0.);
1348
1349 /* XXX RA,DEC identical to the CRVALi for our functions */
1350 cpl_propertylist_append_double(p, "RA", 45.83);
1351 cpl_propertylist_append_double(p, "DEC", 63.57);
1352
1353 cpl_wcs* wcs = cpl_wcs_new_from_propertylist(p);
1354 cpl_propertylist_delete(p);
1355 cpl_test_error(CPL_ERROR_NONE);
1356 return wcs;
1357} /* hdrl_resample_util_wcs_create_example_params() */
1358
1359/*----------------------------------------------------------------------------*/
1364/*----------------------------------------------------------------------------*/
1365static cpl_wcs*
1366hdrl_resample_util_crea_wcs_2d(void)
1367{
1368 cpl_propertylist* plist = NULL;
1369 /* test valid input */
1370 int sx = HDRL_SIZE_X;
1371 int sy = HDRL_SIZE_Y;
1372
1373 int naxis = 2;
1374 double ra = 10.;
1375 double dec = 20.;
1376 double cd11 = HDRL_CD11;
1377 double cd22 = HDRL_CD22;
1378 double cd12 = HDRL_CD12;
1379 double cd21 = HDRL_CD21;
1380 const double crpix1 = HDRL_CRPIX1;
1381 const double crpix2 = HDRL_CRPIX2;
1382 const double crval1 = HDRL_CRVAL1;
1383 const double crval2 = HDRL_CRVAL2;
1384 const double cdelt1 = HDRL_CDELT1;
1385 const double cdelt2 = HDRL_CDELT2;
1386 const char* cunit1 = "";
1387 const char* cunit2 = "";
1388 const char* ctype1 = "pix";
1389 const char* ctype2 = "pix";
1390
1391 plist = hdrl_resample_util_crea_header_image(naxis, sx, sy, ra, dec,
1392 cd11, cd12, cd21, cd22, crpix1,
1393 crpix2, crval1, crval2,
1394 cdelt1, cdelt2, ctype1, ctype2,
1395 cunit1, cunit2);
1396 cpl_test_error(CPL_ERROR_NONE);
1397
1398 cpl_wcs* wcs = cpl_wcs_new_from_propertylist(plist);
1399 cpl_test_nonnull(wcs);
1400 cpl_test_error(CPL_ERROR_NONE);
1401 cpl_propertylist_delete(plist);
1402 return wcs;
1403
1404}
1405/*----------------------------------------------------------------------------*/
1410/*----------------------------------------------------------------------------*/
1411static cpl_wcs*
1412hdrl_resample_util_crea_wcs_3d(void)
1413{
1414 /* test 3D case */
1415 cpl_propertylist* plist = NULL;
1416 int sx = HDRL_SIZE_X;
1417 int sy = HDRL_SIZE_Y;
1418
1419 int naxis = 2;
1420 double ra = 10.;
1421 double dec = 20.;
1422 double cd11 = HDRL_CD11;
1423 double cd22 = HDRL_CD22;
1424 double cd12 = HDRL_CD12;
1425 double cd21 = HDRL_CD21;
1426 const double crpix1 = HDRL_CRPIX1;
1427 const double crpix2 = HDRL_CRPIX2;
1428 const double crval1 = HDRL_CRVAL1;
1429 const double crval2 = HDRL_CRVAL2;
1430 const double cdelt1 = HDRL_CDELT1;
1431 const double cdelt2 = HDRL_CDELT2;
1432 const char* cunit1 = "deg";
1433 const char* cunit2 = "deg";
1434 const char* ctype1 = "RA---TAN";
1435 const char* ctype2 = "DEC--TAN";
1436
1437 int sz = HDRL_SIZE_Z;
1438 double cd13 = HDRL_CD13;
1439 double cd31 = HDRL_CD31;
1440 double cd23 = HDRL_CD23;
1441 double cd32 = HDRL_CD32;
1442 double cd33 = HDRL_CD33;
1443 const double crpix3 = HDRL_CRPIX3;
1444 const double crval3 = HDRL_CRVAL3;
1445 const double cdelt3 = HDRL_CDELT3;
1446 const char* cunit3 = "m";
1447 const char* ctype3 = "WAV";
1448 naxis = 3;
1449 cpl_test_error(CPL_ERROR_NONE);
1450 cpl_propertylist_delete(plist);
1451 cpl_test_error(CPL_ERROR_NONE);
1452 plist = hdrl_resample_crea_header_cube(naxis, sx, sy, sz, ra, dec,
1453 cd11, cd12, cd21, cd22, cd13, cd31,
1454 cd23, cd32, cd33,
1455 crpix1, crpix2, crpix3,
1456 crval1, crval2, crval3,
1457 cdelt1, cdelt2, cdelt3,
1458 ctype1, ctype2, ctype3,
1459 cunit1, cunit2, cunit3);
1460 cpl_test_error(CPL_ERROR_NONE);
1461
1462 cpl_wcs* wcs = cpl_wcs_new_from_propertylist(plist);
1463 cpl_test_nonnull(wcs);
1464 cpl_test_error(CPL_ERROR_NONE);
1465 cpl_propertylist_delete(plist);
1466 return wcs;
1467
1468}
1469
1470CPL_DIAG_PRAGMA_PUSH_IGN(-Wunused-function);
1471/*----------------------------------------------------------------------------*/
1476/*----------------------------------------------------------------------------*/
1477static cpl_error_code
1478test_resample_wcs_as_muse(void)
1479{
1480
1481 // const double kLimitPos = 0.05; /* [pix] object position detection accuracy */
1482 /* accuracy limits for coordinate transformation tests */
1483 // const double kLimitDeg = DBL_EPSILON * 115; /* ~10 nano-arcsec for trafo to deg */
1484 // const double kLimitDegF = FLT_EPSILON * 13.51; /* ~5.8 milli-arcsec for trafo to *
1485 // * deg, with value stored in float */
1486 // const double kLimitPix = FLT_EPSILON * 205; /* ~1/40000th pixel for trafo to pix */
1487 // const double kLimitRot = FLT_EPSILON * 10; /* ~4.3 milli-arcsec for rotations */
1488 // const double kLimitSca = DBL_EPSILON * 7461; /* pixel scales to ~5.5 nano-arcsec */
1489
1490 const double kLimitPPl = FLT_EPSILON * 2.88; /* ~1.24 milli-arcsec in proj. plane */
1491
1492
1493 double v1, v2;
1494 /***************************************************************************
1495 * test transformations between projection plane and celestial coordinates *
1496 ***************************************************************************/
1497 /* use values from WCS Paper II, example 1 as references */
1498
1499 cpl_test_error(CPL_ERROR_NONE);
1500 cpl_wcs* wcs = hdrl_resample_util_wcs_create_example_params();
1501 cpl_test_nonnull(wcs);
1502 /* NB: for the following we just want to test the WCS==> other coordinates
1503 * are casual.
1504 */
1505 hdrl_parameter* hpar =
1507 10.1, 5.);
1508 cpl_test_nonnull(hpar);
1509 hdrl_resample_outgrid_parameter * par = (hdrl_resample_outgrid_parameter *) hpar;
1510 cpl_test_nonnull(par);
1511 par->wcs = wcs;
1512 double x, y;
1513 cpl_errorstate state = cpl_errorstate_get();
1514 cpl_test_error(CPL_ERROR_NONE);
1515
1516 cpl_test(hdrl_resample_wcs_projplane_from_celestial(par, 47.503264, 62.795111,
1517 &x, &y) == CPL_ERROR_NONE);
1518 cpl_test_error(CPL_ERROR_NONE);
1519 cpl_test(fabs(x - 0.765000) < kLimitPPl && fabs(y - (-0.765000)) < kLimitPPl);
1520 cpl_msg_debug(__func__, "SE corner: %f,%f (%e,%e <? %e", x, y, x - 0.765000,
1521 y - (-0.765000), kLimitPPl);
1522 cpl_test(hdrl_resample_wcs_projplane_from_celestial(par, 47.595581, 64.324332,
1523 &x, &y) == CPL_ERROR_NONE);
1524 cpl_test(fabs(x - 0.765000) < kLimitPPl && fabs(y - 0.765000) < kLimitPPl);
1525 cpl_msg_debug(__func__, "NE corner: %f,%f (%e,%e <? %e", x, y, x - 0.765000,
1526 y - 0.765000, kLimitPPl);
1527 cpl_test(hdrl_resample_wcs_projplane_from_celestial(par, 44.064419, 64.324332,
1528 &x, &y) == CPL_ERROR_NONE);
1529 cpl_test(fabs(x - (-0.765000)) < kLimitPPl && fabs(y - 0.765000) < kLimitPPl);
1530 cpl_msg_debug(__func__, "NW corner: %f,%f (%e,%e <? %e", x, y, x - (-0.765000),
1531 y - 0.765000, kLimitPPl);
1532 state = cpl_errorstate_get();
1533 cpl_test(hdrl_resample_wcs_projplane_from_celestial(NULL, 1., 1., &v1, &v2)
1534 == CPL_ERROR_NULL_INPUT);
1535 cpl_test(hdrl_resample_wcs_projplane_from_celestial(par, 1., 1., NULL, &v2)
1536 == CPL_ERROR_NULL_INPUT);
1537 cpl_test(hdrl_resample_wcs_projplane_from_celestial(par, 1., 1., &v1, NULL)
1538 == CPL_ERROR_NULL_INPUT);
1539 cpl_errorstate_set(state);
1540
1541 cpl_test_error(CPL_ERROR_NONE);
1542 cpl_test(hdrl_resample_wcs_projplane_from_celestial(par, 1., 1., &v1, &v2)
1543 == CPL_ERROR_NONE);
1544 cpl_test_error(CPL_ERROR_NONE);
1545 cpl_errorstate_set(state);
1546
1547 cpl_wcs_delete(wcs);
1549 cpl_test_error(CPL_ERROR_NONE);
1550 return cpl_error_get_code();
1551}
1552
1553CPL_DIAG_PRAGMA_POP;
1554/*----------------------------------------------------------------------------*/
1559/*----------------------------------------------------------------------------*/
1560static cpl_error_code
1561test_hdrl_resample_image_to_table(void)
1562{
1563
1564 cpl_table* tab = NULL;
1565 cpl_image* data = NULL;
1566 cpl_image* error = NULL;
1567 cpl_image* quality = NULL;
1568 cpl_wcs* wcs = NULL;
1569
1570 /* test invalid input */
1571 tab = hdrl_resample_image_to_table(NULL, wcs);
1572 cpl_test_error(CPL_ERROR_NULL_INPUT);
1573 cpl_test_null(tab);
1574
1575 /* test valid input */
1576 int sx = HDRL_SIZE_X;
1577 int sy = HDRL_SIZE_Y;
1578 double value = HDRL_FLUX_ADU;
1579
1580 data = cpl_image_new(sx, sy, CPL_TYPE_DOUBLE);
1581 cpl_image_add_scalar(data, value);
1582
1583 error = cpl_image_power_create(data, 0.5);
1584 quality = cpl_image_new(sx, sy, CPL_TYPE_INT);
1585 int naxis = 2;
1586 double ra = 10.;
1587 double dec = 20.;
1588 const double cd11 = -3.47222e-05;
1589 const double cd22 = 3.47222e-05;
1590 const double cd12 = 0;
1591 const double cd21 = 0;
1592 const double crpix1 = 33.5;
1593 const double crpix2 = 33.5;
1594 const double crval1 = 48.0718057375143246;
1595 const double crval2 = -20.6230284673176705;
1596 const double cdelt1 = 0;
1597 const double cdelt2 = 0;
1598 const char* cunit1 = "deg";
1599 const char* cunit2 = "deg";
1600 const char* ctype1 = "RA---TAN";
1601 const char* ctype2 = "DEC--TAN";
1602
1603 cpl_propertylist* plist =
1604 hdrl_resample_util_crea_header_image(naxis, sx, sy, ra, dec,
1605 cd11, cd12, cd21, cd22,
1606 crpix1, crpix2, crval1, crval2,
1607 cdelt1, cdelt2, ctype1, ctype2,
1608 cunit1, cunit2);
1609
1610 wcs = cpl_wcs_new_from_propertylist(plist);
1611 cpl_test_nonnull(wcs);
1612 hdrl_image* hima = hdrl_resample_util_hdrl_image_create(data, error, quality);
1613 tab = hdrl_resample_image_to_table(hima, wcs);
1614 cpl_test_error(CPL_ERROR_NONE);
1615
1616 /* test expected table columns */
1617 cpl_test_eq(1, cpl_table_has_column(tab, HDRL_RESAMPLE_TABLE_RA));
1618 cpl_test_eq(1, cpl_table_has_column(tab, HDRL_RESAMPLE_TABLE_DEC));
1619 cpl_test_eq(1, cpl_table_has_column(tab, HDRL_RESAMPLE_TABLE_LAMBDA));
1620 cpl_test_eq(1, cpl_table_has_column(tab, HDRL_RESAMPLE_TABLE_BPM));
1621 cpl_test_eq(1, cpl_table_has_column(tab, HDRL_RESAMPLE_TABLE_ERRORS));
1622
1623 double* ptablambda = cpl_table_get_data_double(tab, HDRL_RESAMPLE_TABLE_LAMBDA);
1624 double* ptabdata = cpl_table_get_data_double(tab, HDRL_RESAMPLE_TABLE_DATA);
1625 int* ptabbpm = cpl_table_get_data_int(tab, HDRL_RESAMPLE_TABLE_BPM);
1626 double* ptaberr = cpl_table_get_data_double(tab, HDRL_RESAMPLE_TABLE_ERRORS);
1627
1628 cpl_test_abs(0, ptablambda[0], HDRL_EPS_TEST);
1629 cpl_test_abs(HDRL_FLUX_ADU, ptabdata[0], HDRL_EPS_TEST);
1630 cpl_test_abs(0, ptabbpm[0], HDRL_EPS_TEST);
1631 cpl_test_abs(10, ptaberr[0], HDRL_EPS_TEST);
1632
1633 /* free memory */
1634 cpl_table_delete(tab);
1635 cpl_image_delete(data);
1636 cpl_image_delete(error);
1637 cpl_image_delete(quality);
1638 hdrl_image_delete(hima);
1639 cpl_propertylist_delete(plist);
1640 cpl_wcs_delete(wcs);
1641 cpl_test_error(CPL_ERROR_NONE);
1642 return cpl_error_get_code();
1643}
1644/*----------------------------------------------------------------------------*/
1649/*----------------------------------------------------------------------------*/
1650static cpl_error_code
1651test_hdrl_resample_imagelist_to_table(void)
1652{
1653 /* test invalid input */
1654 cpl_table* tab = NULL;
1655 cpl_imagelist* ilist = NULL;
1656 cpl_imagelist* elist = NULL;
1657 cpl_imagelist* qlist = NULL;
1658 cpl_image* data = NULL;
1659 cpl_image* error = NULL;
1660 cpl_image* quality = NULL;
1661 cpl_wcs* wcs = NULL;
1662
1663 /* test invalid input */
1664 tab = hdrl_resample_imagelist_to_table(NULL, wcs);
1665 cpl_test_error(CPL_ERROR_NULL_INPUT);
1666 cpl_test_null(tab);
1667
1668 /* test valid input */
1669 int sx = 67;
1670 int sy = 67;
1671 double value = HDRL_FLUX_ADU;
1672
1673 data = cpl_image_new(sx, sy, CPL_TYPE_DOUBLE);
1674 cpl_image_add_scalar(data, value);
1675
1676 error = cpl_image_power_create(data, 0.5);
1677 quality = cpl_image_new(sx, sy, CPL_TYPE_INT);
1678 int naxis = 3;
1679 double ra = 10.;
1680 double dec = 20.;
1681 const double cd11 = -3.47222e-05;
1682 const double cd22 = 3.47222e-05;
1683 const double cd12 = 0;
1684 const double cd21 = 0;
1685 const double crpix1 = 33.5;
1686 const double crpix2 = 33.5;
1687 const double crval1 = 48.0706;
1688 const double crval2 = -20.6219;
1689 const double cdelt1 = 0;
1690 const double cdelt2 = 0;
1691 const char* cunit1 = "deg";
1692 const char* cunit2 = "deg";
1693 const char* ctype1 = "RA---TAN";
1694 const char* ctype2 = "DEC--TAN";
1695 int sz = 2218;
1696 double cd13 = 0;
1697 double cd31 = 0;
1698 double cd23 = 0;
1699 double cd32 = 0;
1700 double cd33 = 2.45e-10;
1701 const double crpix3 = 1;
1702 const double crval3 = 1.9283e-06;
1703 const double cdelt3 = 0.1;
1704 const char* cunit3 = "m";
1705 const char* ctype3 = "WAVE";
1706
1707 cpl_test_error(CPL_ERROR_NONE);
1708 cpl_propertylist* plist =
1709 hdrl_resample_crea_header_cube(naxis, sx, sy, sz, ra, dec,
1710 cd11, cd12, cd21, cd22,
1711 cd13, cd31, cd23, cd32, cd33,
1712 crpix1, crpix2, crpix3,
1713 crval1, crval2, crval3,
1714 cdelt1, cdelt2, cdelt3,
1715 ctype1, ctype2, ctype3,
1716 cunit1, cunit2, cunit3);
1717
1718 ilist = cpl_imagelist_new();
1719 elist = cpl_imagelist_new();
1720 qlist = cpl_imagelist_new();
1721
1722 cpl_imagelist_set(ilist, data, 0);
1723 cpl_imagelist_set(elist, error, 0);
1724 cpl_imagelist_set(qlist, quality, 0);
1725
1726 wcs = cpl_wcs_new_from_propertylist(plist);
1727 cpl_test_nonnull(wcs);
1728 cpl_test_error(CPL_ERROR_NONE);
1729 hdrl_imagelist* hlist = hdrl_resample_util_hdrl_imagelist_create(ilist, elist,
1730 qlist);
1731 tab = hdrl_resample_imagelist_to_table(hlist, wcs);
1732 cpl_test_error(CPL_ERROR_NONE);
1733
1734 /* test expected table columns */
1735 cpl_test_eq(1, cpl_table_has_column(tab, HDRL_RESAMPLE_TABLE_RA));
1736 cpl_test_eq(1, cpl_table_has_column(tab, HDRL_RESAMPLE_TABLE_DEC));
1737 cpl_test_eq(1, cpl_table_has_column(tab, HDRL_RESAMPLE_TABLE_LAMBDA));
1738 cpl_test_eq(1, cpl_table_has_column(tab, HDRL_RESAMPLE_TABLE_BPM));
1739 cpl_test_eq(1, cpl_table_has_column(tab, HDRL_RESAMPLE_TABLE_ERRORS));
1740
1741 //double* ptabxpos = cpl_table_get_data_double(tab, HDRL_RESAMPLE_TABLE_RA);
1742 //double* ptabypos = cpl_table_get_data_double(tab, HDRL_RESAMPLE_TABLE_DEC);
1743 double* ptablambda = cpl_table_get_data_double(tab, HDRL_RESAMPLE_TABLE_LAMBDA);
1744 double* ptabdata = cpl_table_get_data_double(tab, HDRL_RESAMPLE_TABLE_DATA);
1745 int* ptabbpm = cpl_table_get_data_int(tab, HDRL_RESAMPLE_TABLE_BPM);
1746 double* ptaberr = cpl_table_get_data_double(tab, HDRL_RESAMPLE_TABLE_ERRORS);
1747
1748 /* test expected values */
1749 cpl_test_abs(0, ptablambda[0], HDRL_EPS_TEST);
1750 cpl_test_abs(HDRL_FLUX_ADU, ptabdata[0], HDRL_EPS_TEST);
1751 cpl_test_abs(0, ptabbpm[0], HDRL_EPS_TEST);
1752 cpl_test_abs(10, ptaberr[0], HDRL_EPS_TEST);
1753
1754 /* free memory */
1755 cpl_imagelist_delete(ilist);
1756 cpl_imagelist_delete(elist);
1757 cpl_imagelist_delete(qlist);
1758 hdrl_imagelist_delete(hlist);
1759 cpl_table_delete(tab);
1760 cpl_propertylist_delete(plist);
1761 cpl_wcs_delete(wcs);
1762 cpl_test_error(CPL_ERROR_NONE);
1763 return cpl_error_get_code();
1764}
1765/*----------------------------------------------------------------------------*/
1770/*----------------------------------------------------------------------------*/
1771static cpl_error_code
1772test_hdrl_wcs_to_propertylist(void) {
1773
1774 cpl_propertylist* plist = NULL;
1775 cpl_wcs* wcs = NULL;
1776 cpl_boolean only2d = CPL_TRUE;
1777
1778 /* test improper input */
1779 hdrl_wcs_to_propertylist(NULL, plist, only2d);
1780 cpl_test_error(CPL_ERROR_NULL_INPUT);
1781
1782 hdrl_wcs_to_propertylist(wcs, NULL, only2d);
1783 cpl_test_error(CPL_ERROR_NULL_INPUT);
1784
1785 /* test proper input */
1786 wcs = hdrl_resample_util_crea_wcs_2d();
1787 cpl_test_error(CPL_ERROR_NONE);
1788 plist = cpl_propertylist_new();
1789 hdrl_wcs_to_propertylist(wcs, plist, only2d);
1790 cpl_test_error(CPL_ERROR_NONE);
1791
1792 cpl_wcs_delete(wcs);
1793 wcs = hdrl_resample_util_crea_wcs_3d();
1794 cpl_test_error(CPL_ERROR_NONE);
1795
1796 hdrl_wcs_to_propertylist(wcs, plist, !only2d);
1797 cpl_test_error(CPL_ERROR_NONE);
1798
1799 /* start detailed checks on expected values */
1800 const cpl_array *crval = cpl_wcs_get_crval(wcs);
1801 const cpl_array *crpix = cpl_wcs_get_crpix(wcs);
1802 const cpl_array *ctype = cpl_wcs_get_ctype(wcs);
1803 const cpl_array *cunit = cpl_wcs_get_cunit(wcs);
1804 const cpl_matrix *cd = cpl_wcs_get_cd(wcs);
1805 int naxis_out = cpl_wcs_get_image_naxis(wcs);
1806
1807 int naxis = 3;
1808 int sx = HDRL_SIZE_X;
1809 int sz = HDRL_SIZE_Z;
1810 cpl_test_eq(naxis, naxis_out);
1811
1812 /* Check NAXIS */
1813 for (int i = 0; i < naxis_out; i++) {
1814
1815 char * buf = cpl_sprintf("NAXIS%d", i + 1);
1816 /* sx = sy = HDRL_SIZE_X */
1817 if(i<2) {
1818 cpl_test_eq(sx, cpl_propertylist_get_int(plist, buf));
1819 } else {
1820 cpl_test_eq(sz, cpl_propertylist_get_int(plist, buf));
1821 }
1822 cpl_free(buf);
1823 }
1824
1825 int err = 0;
1826 /* CRVAL */
1827 cpl_test_abs(cpl_propertylist_get_double(plist, "CRVAL1"),
1828 cpl_array_get_double(crval, 0, &err), HDRL_EPS_TEST);
1829
1830 cpl_test_abs(cpl_propertylist_get_double(plist, "CRVAL2"),
1831 cpl_array_get_double(crval, 1, &err), HDRL_EPS_TEST);
1832
1833 cpl_test_abs(cpl_propertylist_get_double(plist, "CRVAL3"),
1834 cpl_array_get_double(crval, 2, &err), HDRL_EPS_TEST);
1835
1836 /* CRPIX */
1837 cpl_test_abs(cpl_propertylist_get_double(plist, "CRPIX1"),
1838 cpl_array_get_double(crpix, 0, &err), HDRL_EPS_TEST);
1839
1840 cpl_test_abs(cpl_propertylist_get_double(plist, "CRPIX2"),
1841 cpl_array_get_double(crpix, 1, &err), HDRL_EPS_TEST);
1842
1843 cpl_test_abs(cpl_propertylist_get_double(plist, "CRPIX3"),
1844 cpl_array_get_double(crpix, 2, &err), HDRL_EPS_TEST);
1845
1846 /* CTYPE */
1847 const char* string_val = NULL;
1848 const char* string_chk = NULL;
1849
1850 string_val = cpl_propertylist_get_string(plist, "CTYPE1");
1851 string_chk = cpl_array_get_string(ctype, 0);
1852 cpl_test_eq(0, strcmp(string_val,string_chk));
1853
1854 string_val = cpl_propertylist_get_string(plist, "CTYPE2");
1855 string_chk = cpl_array_get_string(ctype, 1);
1856 cpl_test_eq(0, strcmp(string_val,string_chk));
1857
1858 string_val = cpl_propertylist_get_string(plist, "CTYPE3");
1859 string_chk = cpl_array_get_string(ctype, 2);
1860 cpl_test_eq(0, strcmp(string_val,string_chk));
1861
1862 /* CUNIT */
1863 string_val = cpl_propertylist_get_string(plist, "CUNIT1");
1864 string_chk = cpl_array_get_string(cunit, 0);
1865 cpl_test_eq(0, strcmp(string_val,string_chk));
1866
1867 string_val = cpl_propertylist_get_string(plist, "CUNIT2");
1868 string_chk = cpl_array_get_string(cunit, 1);
1869 cpl_test_eq(0, strcmp(string_val,string_chk));
1870
1871 string_val = cpl_propertylist_get_string(plist, "CUNIT3");
1872 string_chk = cpl_array_get_string(cunit, 2);
1873 cpl_test_eq(0, strcmp(string_val,string_chk));
1874
1875 /* CD */
1876 double cd11 = 1, cd22 = 1, cd33 = 0.1;
1877 double cd12 = 0, cd21 = 0, cd13 = 0, cd31 = 0, cd23 = 0, cd32 = 0;
1878
1879 cd11 = cpl_matrix_get(cd, 0, 0);
1880 cd12 = cpl_matrix_get(cd, 0, 1);
1881 cd21 = cpl_matrix_get(cd, 1, 0);
1882 cd22 = cpl_matrix_get(cd, 1, 1);
1883 cd13 = cpl_matrix_get(cd, 0, 2);
1884 cd31 = cpl_matrix_get(cd, 2, 0);
1885 cd23 = cpl_matrix_get(cd, 1, 2);
1886 cd32 = cpl_matrix_get(cd, 2, 1);
1887 cd33 = cpl_matrix_get(cd, 2, 2);
1888
1889 cpl_test_abs(cd11, cpl_propertylist_get_double(plist, "CD1_1"), HDRL_EPS_TEST);
1890 cpl_test_abs(cd12, cpl_propertylist_get_double(plist, "CD1_2"), HDRL_EPS_TEST);
1891 cpl_test_abs(cd21, cpl_propertylist_get_double(plist, "CD2_1"), HDRL_EPS_TEST);
1892 cpl_test_abs(cd22, cpl_propertylist_get_double(plist, "CD2_2"), HDRL_EPS_TEST);
1893 cpl_test_abs(cd13, cpl_propertylist_get_double(plist, "CD1_3"), HDRL_EPS_TEST);
1894 cpl_test_abs(cd31, cpl_propertylist_get_double(plist, "CD3_1"), HDRL_EPS_TEST);
1895 cpl_test_abs(cd23, cpl_propertylist_get_double(plist, "CD2_3"), HDRL_EPS_TEST);
1896 cpl_test_abs(cd32, cpl_propertylist_get_double(plist, "CD3_2"), HDRL_EPS_TEST);
1897 cpl_test_abs(cd33, cpl_propertylist_get_double(plist, "CD3_3"), HDRL_EPS_TEST);
1898
1899 cpl_propertylist_delete(plist);
1900 cpl_wcs_delete(wcs);
1901 cpl_test_error(CPL_ERROR_NONE);
1902 return cpl_error_get_code();
1903}
1904
1905static cpl_error_code
1906test_resample_invalid_input_outgrid_param(
1907 const double delta_ra,
1908 const double delta_dec,
1909 const double delta_lambda,
1910 const double ra_min,
1911 const double ra_max,
1912 const double dec_min,
1913 const double dec_max,
1914 const double lambda_min,
1915 const double lambda_max,
1916 const double field_margin) {
1917
1918 hdrl_parameter* pErr = NULL;
1919
1920 pErr = hdrl_resample_parameter_create_outgrid2D(0, delta_dec);
1921 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1922 cpl_test_null(pErr);
1923
1924 pErr = hdrl_resample_parameter_create_outgrid2D(delta_ra, 0);
1925 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1926 cpl_test_null(pErr);
1927
1928 pErr = hdrl_resample_parameter_create_outgrid3D(0, delta_dec, delta_lambda);
1929 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1930 cpl_test_null(pErr);
1931
1932 pErr = hdrl_resample_parameter_create_outgrid3D(delta_ra, 0, delta_lambda);
1933 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1934 cpl_test_null(pErr);
1935
1936 pErr = hdrl_resample_parameter_create_outgrid3D(delta_ra, delta_dec, 0);
1937 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1938 cpl_test_null(pErr);
1939
1940 pErr =
1941 hdrl_resample_parameter_create_outgrid2D_userdef(0, delta_dec, ra_min, ra_max,
1942 dec_min, dec_max, field_margin);
1943 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1944 cpl_test_null(pErr);
1945
1946 pErr =
1947 hdrl_resample_parameter_create_outgrid2D_userdef(delta_ra, 0, ra_min, ra_max,
1948 dec_min, dec_max, field_margin);
1949 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1950 cpl_test_null(pErr);
1951
1953 ra_max, dec_min, dec_max, field_margin);
1954 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1955 cpl_test_null(pErr);
1956
1957 pErr = hdrl_resample_parameter_create_outgrid2D_userdef(delta_ra, 0, ra_min,
1958 -1, dec_min, dec_max, field_margin);
1959 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1960 cpl_test_null(pErr);
1961
1962 pErr = hdrl_resample_parameter_create_outgrid2D_userdef(delta_ra, delta_dec,
1963 2, 1, dec_min, dec_max, field_margin);
1964 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1965 cpl_test_null(pErr);
1966
1967 pErr = hdrl_resample_parameter_create_outgrid2D_userdef(delta_ra, delta_dec,
1968 ra_min, ra_max, 2, 1, field_margin);
1969 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1970 cpl_test_null(pErr);
1971
1972 pErr = hdrl_resample_parameter_create_outgrid2D_userdef(delta_ra, delta_dec,
1973 ra_min, ra_max, dec_min, dec_max, -1);
1974 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1975 cpl_test_null(pErr);
1976
1977 pErr = hdrl_resample_parameter_create_outgrid3D_userdef(delta_ra, delta_dec,
1978 delta_lambda, -1, ra_max,
1979 dec_min, dec_max, lambda_min,
1980 lambda_max,field_margin);
1981 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1982 cpl_test_null(pErr);
1983
1984 pErr = hdrl_resample_parameter_create_outgrid3D_userdef(delta_ra, delta_dec,
1985 delta_lambda, ra_min, -1,
1986 dec_min, dec_max, lambda_min,
1987 lambda_max,field_margin);
1988 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1989 cpl_test_null(pErr);
1990
1991 pErr = hdrl_resample_parameter_create_outgrid3D_userdef(delta_ra, delta_dec,
1992 delta_lambda, 2, 1, dec_min,
1993 dec_max, lambda_min,
1994 lambda_max,field_margin);
1995 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
1996 cpl_test_null(pErr);
1997
1998 pErr = hdrl_resample_parameter_create_outgrid3D_userdef(delta_ra, delta_dec,
1999 delta_lambda, ra_min, ra_max,
2000 2, 1, lambda_min,
2001 lambda_max,field_margin);
2002 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
2003 cpl_test_null(pErr);
2004
2005 pErr = hdrl_resample_parameter_create_outgrid3D_userdef(delta_ra, delta_dec,
2006 delta_lambda, ra_min, ra_max,
2007 dec_min, dec_max, -1,
2008 lambda_max,field_margin);
2009 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
2010 cpl_test_null(pErr);
2011
2012 pErr = hdrl_resample_parameter_create_outgrid3D_userdef(delta_ra, delta_dec,
2013 delta_lambda, ra_min, ra_max,
2014 dec_min, dec_max, lambda_min,
2015 -1,field_margin);
2016 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
2017 cpl_test_null(pErr);
2018
2019 pErr = hdrl_resample_parameter_create_outgrid3D_userdef(delta_ra, delta_dec,
2020 delta_lambda, ra_min, ra_max,
2021 dec_min, dec_max, 2,
2022 1,field_margin);
2023 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
2024 cpl_test_null(pErr);
2025
2026 pErr = hdrl_resample_parameter_create_outgrid3D_userdef(delta_ra, delta_dec,
2027 delta_lambda, ra_min, ra_max,
2028 dec_min, dec_max, lambda_min,
2029 lambda_max,-1);
2030 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
2031 cpl_test_null(pErr);
2032
2033 return cpl_error_get_code();
2034}
2035/*----------------------------------------------------------------------------*/
2040/*----------------------------------------------------------------------------*/
2041static cpl_error_code
2042test_resample_outgrid_param(void) {
2043 /* test invalid input */
2044 const double delta_ra = 0.1;
2045 const double delta_dec = 0.2;
2046 const double delta_lambda = 0.001;
2047
2048 hdrl_resample_outgrid_parameter * aParams_outputgrid =
2049 cpl_calloc (1, sizeof(hdrl_resample_outgrid_parameter));
2050
2051 aParams_outputgrid->delta_ra = delta_ra;
2052 aParams_outputgrid->delta_dec = delta_dec;
2053 aParams_outputgrid->delta_lambda = delta_lambda;
2054 aParams_outputgrid->wcs = hdrl_resample_util_crea_wcs_2d();
2055
2056 double ra_min = HDRL_RA_MIN; /* Minimal Right ascension [deg] */
2057 double ra_max = HDRL_RA_MIN; /* Maximal Right ascension [deg] */
2058 double dec_min = HDRL_DEC_MIN; /* Minimal Declination [deg] */
2059 double dec_max = HDRL_DEC_MIN; /* Maximal Declination [deg] */
2060 double lambda_min = HDRL_LAMBDA_MIN; /* Minimal wavelength [m] */
2061 double lambda_max = HDRL_LAMBDA_MIN; /* Maximal wavelength [m] */
2062 double field_margin = 5;
2063 aParams_outputgrid->dec_min = dec_min;
2064 aParams_outputgrid->dec_max = dec_max;
2065 aParams_outputgrid->ra_min = ra_min;
2066 aParams_outputgrid->ra_max = ra_max;
2067 aParams_outputgrid->lambda_min = lambda_min;
2068 aParams_outputgrid->lambda_max = lambda_max;
2069 hdrl_parameter* pErr = NULL;
2070 cpl_wcs_delete((cpl_wcs *)aParams_outputgrid->wcs);
2071
2072 /* test invalid input */
2073 test_resample_invalid_input_outgrid_param(delta_ra, delta_dec, delta_lambda,
2074 ra_min, ra_max, dec_min, dec_max, lambda_min, lambda_max, field_margin);
2075
2076 /* test valid input */
2077 pErr = hdrl_resample_parameter_create_outgrid2D(delta_ra, delta_dec);
2078 cpl_test_error(CPL_ERROR_NONE);
2079 cpl_test_nonnull(pErr);
2081 cpl_test_error(CPL_ERROR_NONE);
2082
2083 cpl_test_eq(CPL_ERROR_NONE, hdrl_resample_parameter_outgrid_verify(pErr));
2084 cpl_test_error(CPL_ERROR_NONE);
2085
2087 pErr = hdrl_resample_parameter_create_outgrid3D(delta_ra, delta_dec, delta_lambda);
2088 cpl_test_error(CPL_ERROR_NONE);
2089 cpl_test_nonnull(pErr);
2091 cpl_test_error(CPL_ERROR_NONE);
2092
2093 cpl_test_eq(CPL_ERROR_NONE, hdrl_resample_parameter_outgrid_verify(pErr));
2094 cpl_test_error(CPL_ERROR_NONE);
2095
2097 pErr =
2099 ra_min, ra_max,
2100 dec_min, dec_max, field_margin);
2101 cpl_test_error(CPL_ERROR_NONE);
2102 cpl_test_nonnull(pErr);
2104 cpl_test_error(CPL_ERROR_NONE);
2105
2106 cpl_test_eq(CPL_ERROR_NONE, hdrl_resample_parameter_outgrid_verify(pErr));
2107 cpl_test_error(CPL_ERROR_NONE);
2108
2109
2111 pErr = hdrl_resample_parameter_create_outgrid3D_userdef(delta_ra, delta_dec,
2112 delta_lambda, ra_min, ra_max,
2113 dec_min, dec_max, lambda_min,
2114 lambda_max,field_margin);
2115 cpl_test_error(CPL_ERROR_NONE);
2116 cpl_test_nonnull(pErr);
2117
2119 cpl_test_error(CPL_ERROR_NONE);
2120
2121 cpl_test_eq(CPL_ERROR_NONE, hdrl_resample_parameter_outgrid_verify(pErr));
2122 cpl_test_error(CPL_ERROR_NONE);
2124
2125 cpl_free(aParams_outputgrid);
2126
2127 return cpl_error_get_code();
2128}
2129/*----------------------------------------------------------------------------*/
2134/*----------------------------------------------------------------------------*/
2135static cpl_error_code
2136test_hdrl_resample_parameter_create_nearest(void) {
2137 /* test invalid input */
2138 hdrl_parameter *pErr;
2139
2141 cpl_test_error(CPL_ERROR_NONE);
2142 cpl_test_nonnull(pErr);
2144
2145 hdrl_parameter* p = hdrl_resample_parameter_create_nearest();
2146 cpl_test_nonnull(p);
2147
2149 cpl_test_error(CPL_ERROR_NONE);
2150
2151 cpl_test_eq(CPL_ERROR_NONE, hdrl_resample_parameter_method_verify(p));
2152 cpl_test_error(CPL_ERROR_NONE);
2153
2155
2156 return cpl_error_get_code();
2157}
2158/*----------------------------------------------------------------------------*/
2163/*----------------------------------------------------------------------------*/
2164static cpl_error_code
2165test_hdrl_resample_parameter_create_lanczos(void) {
2166 /* test invalid input */
2167 const double loop_distance = 2;
2168 const int kernel_size = 2;
2169 cpl_boolean use_errorweights= CPL_TRUE;
2170 hdrl_parameter *pErr;
2171 /* test invalid input */
2172 pErr = hdrl_resample_parameter_create_lanczos(1, use_errorweights, 0);
2173 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
2174 pErr = hdrl_resample_parameter_create_lanczos(-1, use_errorweights,
2175 kernel_size);
2176 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
2177 cpl_test_null(pErr);
2178 cpl_test_error(CPL_ERROR_NONE);
2179
2180 /* test valid input */
2181 hdrl_parameter* p = hdrl_resample_parameter_create_lanczos(loop_distance,
2182 use_errorweights,
2183 kernel_size);
2184 cpl_test_error(CPL_ERROR_NONE);
2185 cpl_test_nonnull(p);
2186
2188 cpl_test_error(CPL_ERROR_NONE);
2189
2190 cpl_test_eq(CPL_ERROR_NONE, hdrl_resample_parameter_method_verify(p));
2191 cpl_test_error(CPL_ERROR_NONE);
2192
2194
2195 return cpl_error_get_code();
2196}
2197/*----------------------------------------------------------------------------*/
2202/*----------------------------------------------------------------------------*/
2203static cpl_error_code
2204test_hdrl_resample_parameter_create_linear(void) {
2205 /* test invalid input */
2206 const double loop_distance = 2;
2207 cpl_boolean use_errorweights= CPL_TRUE;
2208
2209 hdrl_parameter *pErr;
2210 /* test invalid input */
2211 pErr = hdrl_resample_parameter_create_linear(-1, use_errorweights);
2212 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
2213 cpl_test_null(pErr);
2214
2215 /* test valid input */
2216 hdrl_parameter* p = hdrl_resample_parameter_create_linear(loop_distance,
2217 use_errorweights);
2218 cpl_test_error(CPL_ERROR_NONE);
2219 cpl_test_nonnull(p);
2220
2222 cpl_test_error(CPL_ERROR_NONE);
2223
2224 cpl_test_eq(CPL_ERROR_NONE, hdrl_resample_parameter_method_verify(p));
2225 cpl_test_error(CPL_ERROR_NONE);
2226
2228
2229 return cpl_error_get_code();
2230}
2231/*----------------------------------------------------------------------------*/
2236/*----------------------------------------------------------------------------*/
2237static cpl_error_code
2238test_hdrl_resample_parameter_create_quadratic(void) {
2239 /* test invalid input */
2240 const double loop_distance = 2;
2241 cpl_boolean use_errorweights= CPL_TRUE;
2242 hdrl_parameter *pErr;
2243
2244 /* test invalid input */
2245 pErr = hdrl_resample_parameter_create_quadratic(-1, use_errorweights);
2246 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
2247 cpl_test_null(pErr);
2248
2249 /* test valid input */
2250 hdrl_parameter* p = hdrl_resample_parameter_create_quadratic(loop_distance,
2251 use_errorweights);
2252 cpl_test_error(CPL_ERROR_NONE);
2253 cpl_test_nonnull(p);
2254
2256 cpl_test_error(CPL_ERROR_NONE);
2257
2258 cpl_test_eq(CPL_ERROR_NONE, hdrl_resample_parameter_method_verify(p));
2259 cpl_test_error(CPL_ERROR_NONE);
2260
2262
2263 return cpl_error_get_code();
2264}
2265/*----------------------------------------------------------------------------*/
2270/*----------------------------------------------------------------------------*/
2271static cpl_error_code
2272test_hdrl_resample_parameter_create_renka(void) {
2273 /* test invalid input */
2274 const double loop_distance = 2;
2275 const double critical_radius_renka = 3;
2276 cpl_boolean use_errorweights= CPL_TRUE;
2277 hdrl_parameter *pErr;
2278
2279 /* test invalid input */
2280 pErr = hdrl_resample_parameter_create_renka(-1, use_errorweights,
2281 critical_radius_renka);
2282 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
2283 cpl_test_null(pErr);
2284
2285 pErr = hdrl_resample_parameter_create_renka(loop_distance,
2286 use_errorweights, -1);
2287 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
2288 cpl_test_null(pErr);
2289
2290 /* test valid input */
2291 hdrl_parameter* p =
2292 hdrl_resample_parameter_create_renka(loop_distance, use_errorweights,
2293 critical_radius_renka);
2294
2296 cpl_test_error(CPL_ERROR_NONE);
2297
2298 cpl_test_eq(CPL_ERROR_NONE, hdrl_resample_parameter_method_verify(p));
2299 cpl_test_error(CPL_ERROR_NONE);
2300
2302
2303 return cpl_error_get_code();
2304}
2305static cpl_error_code
2306test_invalid_input_hdrl_resample_parameter_create_drizzle(
2307 const double loop_distance,
2308 const double pix_frac_drizzle_x,
2309 const double pix_frac_drizzle_y,
2310 const double pix_frac_drizzle_lambda,
2311 cpl_boolean use_errorweights
2312)
2313{
2314 hdrl_parameter *pErr;
2315
2316 /* test invalid input */
2317 pErr = hdrl_resample_parameter_create_drizzle(-1, use_errorweights,
2318 pix_frac_drizzle_x,
2319 pix_frac_drizzle_y,
2320 pix_frac_drizzle_lambda);
2321 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
2322 cpl_test_null(pErr);
2323
2324 pErr = hdrl_resample_parameter_create_drizzle(loop_distance, use_errorweights,
2325 -1,
2326 pix_frac_drizzle_y,
2327 pix_frac_drizzle_lambda);
2328 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
2329 cpl_test_null(pErr);
2330
2331 pErr = hdrl_resample_parameter_create_drizzle(loop_distance, use_errorweights,
2332 pix_frac_drizzle_x,
2333 -1,
2334 pix_frac_drizzle_lambda);
2335 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
2336 cpl_test_null(pErr);
2337
2338 pErr = hdrl_resample_parameter_create_drizzle(loop_distance, use_errorweights,
2339 pix_frac_drizzle_x,
2340 pix_frac_drizzle_y,
2341 -1);
2342 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
2343 cpl_test_null(pErr);
2344
2345 return cpl_error_get_code();
2346}
2347/*----------------------------------------------------------------------------*/
2352/*----------------------------------------------------------------------------*/
2353static cpl_error_code
2354test_hdrl_resample_parameter_create_drizzle(void) {
2355 /* test invalid input */
2356 const double loop_distance = 2;
2357 const double pix_frac_drizzle_x = 0.8;
2358 const double pix_frac_drizzle_y = 0.8;
2359 const double pix_frac_drizzle_lambda = 1;
2360 cpl_boolean use_errorweights= CPL_TRUE;
2361
2362 /* test valid input */
2363 test_invalid_input_hdrl_resample_parameter_create_drizzle(loop_distance,
2364 pix_frac_drizzle_x, pix_frac_drizzle_y, pix_frac_drizzle_lambda,
2365 use_errorweights);
2366
2367 /* test valid input */
2368 hdrl_parameter* p =
2369 hdrl_resample_parameter_create_drizzle(loop_distance, use_errorweights,
2370 pix_frac_drizzle_x,
2371 pix_frac_drizzle_y,
2372 pix_frac_drizzle_lambda);
2373
2375 cpl_test_error(CPL_ERROR_NONE);
2376
2377 cpl_test_eq(CPL_ERROR_NONE, hdrl_resample_parameter_method_verify(p));
2378 cpl_test_error(CPL_ERROR_NONE);
2379
2381
2382 return cpl_error_get_code();
2383}
2384/*----------------------------------------------------------------------------*/
2389/*----------------------------------------------------------------------------*/
2390static cpl_error_code
2391test_resample_parameters(void) {
2392
2393 test_resample_outgrid_param();
2394 cpl_test_error(CPL_ERROR_NONE);
2395
2396 test_hdrl_resample_parameter_create_nearest();
2397 cpl_test_error(CPL_ERROR_NONE);
2398
2399 test_hdrl_resample_parameter_create_lanczos();
2400 cpl_test_error(CPL_ERROR_NONE);
2401
2402 test_hdrl_resample_parameter_create_linear();
2403 cpl_test_error(CPL_ERROR_NONE);
2404
2405 test_hdrl_resample_parameter_create_quadratic();
2406 cpl_test_error(CPL_ERROR_NONE);
2407
2408 test_hdrl_resample_parameter_create_renka();
2409 cpl_test_error(CPL_ERROR_NONE);
2410
2411 test_hdrl_resample_parameter_create_drizzle();
2412 cpl_test_error(CPL_ERROR_NONE);
2413
2414 return cpl_error_get_code();
2415}
2416/*----------------------------------------------------------------------------*/
2421/*----------------------------------------------------------------------------*/
2422static cpl_error_code
2423test_hdrl_resample_parameter_create_outgrid2D(void){
2424 const double delta_ra = 0.1;
2425 const double delta_dec = 0.1;
2426 hdrl_parameter *pErr;
2427 /* test invalid input: nothing all values are allowed */
2428 /* test valid input */
2429 pErr = hdrl_resample_parameter_create_outgrid2D(delta_ra, delta_dec);
2430 cpl_test_error(CPL_ERROR_NONE);
2431 cpl_test_nonnull(pErr);
2432
2434 cpl_test_error(CPL_ERROR_NONE);
2435
2437 cpl_test_error(CPL_ERROR_NONE);
2439 return cpl_error_get_code();
2440}
2441/*----------------------------------------------------------------------------*/
2446/*----------------------------------------------------------------------------*/
2447static cpl_error_code
2448test_hdrl_resample_parameter_create_outgrid3D(void){
2449 const double delta_ra = 0.1;
2450 const double delta_dec = 0.1;
2451 const double delta_lambda = 0.1;
2452 hdrl_parameter *pErr;
2453
2454 /* test invalid input: nothing all values are allowed */
2455
2456 /* test valid input */
2457 pErr = hdrl_resample_parameter_create_outgrid3D(delta_ra, delta_dec, delta_lambda);
2458 cpl_test_error(CPL_ERROR_NONE);
2459 cpl_test_nonnull(pErr);
2460
2462 cpl_test_error(CPL_ERROR_NONE);
2463
2465 cpl_test_error(CPL_ERROR_NONE);
2467 return cpl_error_get_code();
2468}
2469
2470static cpl_error_code
2471test_invalid_input_hdrl_resample_parameter_create_outgrid2D_userdef(
2472 const double delta_ra,
2473 const double delta_dec,
2474 const double ra_min,
2475 const double ra_max,
2476 const double dec_min,
2477 const double dec_max,
2478 const double fieldmargin
2479){
2480
2481 hdrl_parameter *pErr;
2482
2483 /* test invalid input */
2484 pErr = hdrl_resample_parameter_create_outgrid2D_userdef(delta_ra, delta_dec,
2485 1, 0,
2486 dec_min, dec_max,
2487 fieldmargin);
2488 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
2489 cpl_test_null(pErr);
2490
2491 pErr = hdrl_resample_parameter_create_outgrid2D_userdef(delta_ra, delta_dec,
2492 ra_min, ra_max,
2493 1, 0,
2494 fieldmargin);
2495 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
2496 cpl_test_null(pErr);
2497
2498 pErr = hdrl_resample_parameter_create_outgrid2D_userdef(delta_ra, delta_dec,
2499 ra_min, ra_max,
2500 dec_min, dec_max,
2501 -1);
2502 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
2503 cpl_test_null(pErr);
2504
2505 return cpl_error_get_code();
2506}
2507/*----------------------------------------------------------------------------*/
2512/*----------------------------------------------------------------------------*/
2513static cpl_error_code
2514test_hdrl_resample_parameter_create_outgrid2D_userdef(void){
2515 const double delta_ra = 0.1;
2516 const double delta_dec = 0.1;
2517 const double ra_min = 1;
2518 const double ra_max = 2;
2519 const double dec_min = 0;
2520 const double dec_max = 1;
2521 double fieldmargin = 5;
2522 hdrl_parameter *pErr;
2523
2524 /* test invalid input */
2525 test_invalid_input_hdrl_resample_parameter_create_outgrid2D_userdef(delta_ra,
2526 delta_dec,
2527 ra_min, ra_max, dec_min, dec_max, fieldmargin);
2528 /* test valid input */
2529 pErr = hdrl_resample_parameter_create_outgrid2D_userdef(delta_ra, delta_dec,
2530 ra_min, ra_max,
2531 dec_min, dec_max,
2532 fieldmargin);
2533 cpl_test_error(CPL_ERROR_NONE);
2534 cpl_test_nonnull(pErr);
2535
2537 cpl_test_error(CPL_ERROR_NONE);
2538
2540 cpl_test_error(CPL_ERROR_NONE);
2542 return cpl_error_get_code();
2543}
2544static cpl_error_code
2545test_invalid_input_hdrl_resample_parameter_create_outgrid3D_userdef(
2546 const double delta_ra,
2547 const double delta_dec,
2548 const double delta_lambda,
2549 const double ra_min,
2550 const double ra_max,
2551 const double dec_min,
2552 const double dec_max,
2553 const double lambda_min,
2554 const double lambda_max,
2555 const double fieldmargin
2556){
2557 hdrl_parameter *pErr;
2558
2559 /* test invalid input */
2560 pErr =
2561 hdrl_resample_parameter_create_outgrid3D_userdef(delta_ra, delta_dec, delta_lambda,
2562 2, 1,
2563 dec_min, dec_max,
2564 lambda_min, lambda_max,
2565 fieldmargin);
2566 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
2567 cpl_test_null(pErr);
2568
2569 pErr =
2570 hdrl_resample_parameter_create_outgrid3D_userdef(delta_ra, delta_dec, delta_lambda,
2571 ra_min, ra_max,
2572 2, 1,
2573 lambda_min, lambda_max,
2574 fieldmargin);
2575 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
2576 cpl_test_null(pErr);
2577
2578 pErr =
2579 hdrl_resample_parameter_create_outgrid3D_userdef(delta_ra, delta_dec, delta_lambda,
2580 ra_min, ra_max,
2581 dec_min, dec_max,
2582 550, 500,
2583 fieldmargin);
2584 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
2585 cpl_test_null(pErr);
2586
2587 pErr =
2588 hdrl_resample_parameter_create_outgrid3D_userdef(delta_ra, delta_dec, delta_lambda,
2589 ra_min, ra_max,
2590 dec_min, dec_max,
2591 lambda_min, lambda_max,
2592 -1);
2593 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
2594 cpl_test_null(pErr);
2595
2596 return cpl_error_get_code();
2597}
2598/*----------------------------------------------------------------------------*/
2603/*----------------------------------------------------------------------------*/
2604static cpl_error_code
2605test_hdrl_resample_parameter_create_outgrid3D_userdef(void){
2606 const double delta_ra = 0.1;
2607 const double delta_dec = 0.1;
2608 const double delta_lambda = 0.1;
2609 const double ra_min = 1;
2610 const double ra_max = 2;
2611 const double dec_min = 0;
2612 const double dec_max = 1;
2613 const double lambda_min = 500;
2614 const double lambda_max = 550;
2615
2616 double fieldmargin = 5;
2617 hdrl_parameter *pErr;
2618
2619 /* test invalid input */
2620 test_invalid_input_hdrl_resample_parameter_create_outgrid3D_userdef(delta_ra,
2621 delta_dec, delta_lambda, ra_min, ra_max, dec_min, dec_max, lambda_min,
2622 lambda_max, fieldmargin);
2623 /* test valid input */
2624 pErr =
2625 hdrl_resample_parameter_create_outgrid3D_userdef(delta_ra, delta_dec, delta_lambda,
2626 ra_min, ra_max,
2627 dec_min, dec_max,
2628 lambda_min, lambda_max,
2629 fieldmargin);
2630 cpl_test_error(CPL_ERROR_NONE);
2631 cpl_test_nonnull(pErr);
2632
2634 cpl_test_error(CPL_ERROR_NONE);
2635
2637 cpl_test_error(CPL_ERROR_NONE);
2638
2640 return cpl_error_get_code();
2641}
2642/*----------------------------------------------------------------------------*/
2647/*----------------------------------------------------------------------------*/
2648static cpl_error_code
2649test_hdrl_resample_wcs_print(void){
2650
2651 cpl_wcs* wcs = NULL;
2652
2653 /* verify invalid input */
2654 hdrl_resample_wcs_print(NULL);
2655 cpl_test_error(CPL_ERROR_NULL_INPUT);
2656
2657 /* verify valid input: 3D case */
2658 wcs = hdrl_resample_util_crea_wcs_3d();
2659 hdrl_resample_wcs_print(wcs);
2660 cpl_test_error(CPL_ERROR_NONE);
2661 cpl_wcs_delete(wcs);
2662
2663 /* verify valid input: 2D case */
2664 wcs = hdrl_resample_util_crea_wcs_2d();
2665 hdrl_resample_wcs_print(wcs);
2666 cpl_test_error(CPL_ERROR_NONE);
2667 cpl_wcs_delete(wcs);
2668
2669 return cpl_error_get_code();
2670}
2671/*----------------------------------------------------------------------------*/
2677/*----------------------------------------------------------------------------*/
2678static cpl_error_code
2679hdrl_resample_util_fill_outputgrid(hdrl_resample_outgrid_parameter * aParams_outputgrid)
2680{
2681 /*Assign the wcs*/
2682 cpl_wcs* wcs = hdrl_resample_util_crea_wcs_2d();
2683 cpl_test_nonnull(wcs);
2684
2685 aParams_outputgrid->wcs = wcs;
2686
2687 /* Recalculate the limits if the user did not specify any */
2688 cpl_boolean recalc_limits = aParams_outputgrid->recalc_limits;
2689
2690 if (recalc_limits == CPL_TRUE) {
2691
2692 aParams_outputgrid->ra_min = HDRL_RA_MIN;
2693 aParams_outputgrid->ra_max = HDRL_RA_MAX;
2694 aParams_outputgrid->dec_min = HDRL_DEC_MIN;
2695 aParams_outputgrid->dec_max = HDRL_DEC_MAX;
2696 aParams_outputgrid->lambda_min = HDRL_LAMBDA_MIN;
2697 aParams_outputgrid->lambda_max = HDRL_LAMBDA_MAX;
2698 }
2699 cpl_test_error(CPL_ERROR_NONE);
2700 return cpl_error_get_code();
2701
2702}
2703/*----------------------------------------------------------------------------*/
2708/*----------------------------------------------------------------------------*/
2709static cpl_error_code
2710test_hdrl_resample_outgrid_parameter_print(void){
2711
2712 /* verify invalid input */
2713 hdrl_resample_outgrid_parameter_print(NULL);
2714 cpl_test_error(CPL_ERROR_NULL_INPUT);
2715
2716 hdrl_parameter * outputgrid =
2718
2719 hdrl_resample_outgrid_parameter *aParams_outputgrid =
2720 (hdrl_resample_outgrid_parameter *) outputgrid;
2721
2722 cpl_test_nonnull(aParams_outputgrid);
2723
2724 /*Assign the wcs*/
2725 hdrl_resample_util_fill_outputgrid(aParams_outputgrid);
2726 cpl_test_error(CPL_ERROR_NONE);
2727
2728 /* verify valid input */
2729 hdrl_resample_outgrid_parameter_print(aParams_outputgrid);
2730 cpl_test_error(CPL_ERROR_NONE);
2731
2732 cpl_wcs_delete((cpl_wcs *)aParams_outputgrid->wcs);
2733 cpl_free(aParams_outputgrid);
2734
2735 return cpl_error_get_code();
2736}
2737/*----------------------------------------------------------------------------*/
2742/*----------------------------------------------------------------------------*/
2743static cpl_error_code
2744test_hdrl_resample_method_parameter_print(void){
2745
2746 /* verify invalid input */
2747 hdrl_resample_method_parameter_print(NULL);
2748 cpl_test_error(CPL_ERROR_NULL_INPUT);
2749
2750 hdrl_parameter * wrong = hdrl_resample_parameter_create_outgrid2D(0.1, 0.1);
2751 hdrl_resample_method_parameter * pwrong =
2752 (hdrl_resample_method_parameter *) wrong;
2753 cpl_test_nonnull(pwrong);
2754 hdrl_resample_method_parameter_print(pwrong);
2755 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
2756 cpl_free(pwrong);
2757
2758 /* verify valid input */
2759 hdrl_parameter * method = hdrl_resample_parameter_create_nearest();
2760 hdrl_resample_method_parameter * p =
2761 (hdrl_resample_method_parameter *) method;
2762 cpl_test_nonnull(p);
2763
2764 hdrl_resample_method_parameter_print(p);
2765 cpl_test_error(CPL_ERROR_NONE);
2766
2767 cpl_free(p);
2768 return cpl_error_get_code();
2769}
2770/*----------------------------------------------------------------------------*/
2775/*----------------------------------------------------------------------------*/
2776static cpl_error_code
2777test_hdrl_wcs_xy_to_radec(void) {
2778
2779 double x = 2;
2780 double y = 2;
2781 double ra = 2;
2782 double dec = 2;
2783
2784 /* verify invalid input */
2785 hdrl_wcs_xy_to_radec(NULL, x, y, &ra, &dec);
2786 cpl_test_error(CPL_ERROR_NULL_INPUT);
2787
2788 cpl_wcs* wcs = hdrl_resample_util_crea_wcs_2d();
2789 cpl_test_nonnull(wcs);
2790
2791 hdrl_wcs_xy_to_radec(wcs, x, y, NULL, &dec);
2792 cpl_test_error(CPL_ERROR_NULL_INPUT);
2793
2794 hdrl_wcs_xy_to_radec(wcs, x, y, &ra, NULL);
2795 cpl_test_error(CPL_ERROR_NULL_INPUT);
2796
2797 /* verify valid input */
2798 hdrl_wcs_xy_to_radec(wcs, x, y, &ra, &dec);
2799 cpl_test_error(CPL_ERROR_NONE);
2800 cpl_msg_warning(cpl_func,"ra: %20.18g",ra);
2801 cpl_msg_warning(cpl_func,"dec: %20.18g",dec);
2802 cpl_test_abs(48.0716937492999961, ra, HDRL_EPS_TEST);
2803 cpl_test_abs(-20.6229937493000008, dec, HDRL_EPS_TEST);
2804
2805 cpl_wcs_delete(wcs);
2806 cpl_test_error(CPL_ERROR_NONE);
2807 return cpl_error_get_code();
2808}
2809/*----------------------------------------------------------------------------*/
2814/*----------------------------------------------------------------------------*/
2815static cpl_error_code
2816test_hdrl_resample_pfits_get(void) {
2817
2818 cpl_wcs* wcs = hdrl_resample_util_crea_wcs_3d();
2819 cpl_test_nonnull(wcs);
2820 cpl_propertylist* header = cpl_propertylist_new();
2821 hdrl_wcs_to_propertylist(wcs, header, CPL_FALSE);
2822 cpl_test_nonnull(header);
2823 double crpix = 0;
2824 double crval = 0;
2825 double cd = 0;
2826
2827 /* test invalid input */
2828 crpix = hdrl_resample_pfits_get_crpix(NULL, 1);
2829 cpl_test_error(CPL_ERROR_NULL_INPUT);
2830 cpl_test_abs(crpix, 0, HDRL_EPS_TEST);
2831
2832 crval = hdrl_resample_pfits_get_crval(NULL, 1);
2833 cpl_test_error(CPL_ERROR_NULL_INPUT);
2834 cpl_test_abs(crval, 0, HDRL_EPS_TEST);
2835
2836 cd = hdrl_resample_pfits_get_cd(NULL, 1, 1);
2837 cpl_test_error(CPL_ERROR_NULL_INPUT);
2838 cpl_test_abs(cd, 0, HDRL_EPS_TEST);
2839
2840 /* test valid input */
2841 cpl_test_abs(HDRL_CRPIX1,hdrl_resample_pfits_get_crpix(header, 1), HDRL_EPS_TEST);
2842 cpl_test_abs(HDRL_CRPIX2,hdrl_resample_pfits_get_crpix(header, 2), HDRL_EPS_TEST);
2843 cpl_test_abs(HDRL_CRPIX3,hdrl_resample_pfits_get_crpix(header, 3), HDRL_EPS_TEST);
2844
2845 cpl_test_abs(HDRL_CRVAL1,hdrl_resample_pfits_get_crval(header, 1), HDRL_EPS_TEST);
2846 cpl_test_abs(HDRL_CRVAL2,hdrl_resample_pfits_get_crval(header, 2), HDRL_EPS_TEST);
2847 cpl_test_abs(HDRL_CRVAL3,hdrl_resample_pfits_get_crval(header, 3), HDRL_EPS_TEST);
2848
2849 cpl_test_abs(HDRL_CD11,hdrl_resample_pfits_get_cd(header, 1, 1), HDRL_EPS_TEST);
2850 cpl_test_abs(HDRL_CD12,hdrl_resample_pfits_get_cd(header, 1, 2), HDRL_EPS_TEST);
2851 cpl_test_abs(HDRL_CD21,hdrl_resample_pfits_get_cd(header, 2, 1), HDRL_EPS_TEST);
2852 cpl_test_abs(HDRL_CD22,hdrl_resample_pfits_get_cd(header, 2, 2), HDRL_EPS_TEST);
2853
2854 cpl_test_abs(HDRL_CD13,hdrl_resample_pfits_get_cd(header, 1, 3), HDRL_EPS_TEST);
2855 cpl_test_abs(HDRL_CD31,hdrl_resample_pfits_get_cd(header, 3, 1), HDRL_EPS_TEST);
2856 cpl_test_abs(HDRL_CD23,hdrl_resample_pfits_get_cd(header, 2, 3), HDRL_EPS_TEST);
2857 cpl_test_abs(HDRL_CD32,hdrl_resample_pfits_get_cd(header, 3, 1), HDRL_EPS_TEST);
2858 cpl_test_abs(HDRL_CD33,hdrl_resample_pfits_get_cd(header, 3, 3), HDRL_EPS_TEST);
2859
2860 cpl_propertylist_delete(header);
2861 cpl_wcs_delete(wcs);
2862 cpl_test_error(CPL_ERROR_NONE);
2863 return cpl_error_get_code();
2864}
2865/*----------------------------------------------------------------------------*/
2870/*----------------------------------------------------------------------------*/
2871static cpl_error_code
2872test_hdrl_resample_smallwcs_new(void){
2873
2874 cpl_wcs* wcs = hdrl_resample_util_crea_wcs_3d();
2875 cpl_test_nonnull(wcs);
2876 cpl_propertylist* header = cpl_propertylist_new();
2877 hdrl_wcs_to_propertylist(wcs, header, CPL_FALSE);
2878 cpl_test_nonnull(header);
2879
2880 /* test invalid input */
2881 hdrl_resample_smallwcs* swcs = NULL;
2882 swcs = hdrl_resample_smallwcs_new(NULL);
2883 cpl_test_error(CPL_ERROR_NULL_INPUT);
2884 cpl_test_null(swcs);
2885
2886 /* test valid input */
2887 swcs = hdrl_resample_smallwcs_new(header);
2888 cpl_test_nonnull(swcs);
2889 cpl_test_error(CPL_ERROR_NONE);
2890 cpl_test_nonnull(swcs);
2891
2892 cpl_test_rel(swcs->cd11, HDRL_CD11, HDRL_EPS_TEST);
2893 cpl_test_rel(swcs->cd22, HDRL_CD22, HDRL_EPS_TEST);
2894 cpl_test_rel(swcs->cd12, HDRL_CD12, HDRL_EPS_TEST);
2895 cpl_test_rel(swcs->cd21, HDRL_CD21, HDRL_EPS_TEST);
2896 cpl_test_rel(swcs->crpix1, HDRL_CRPIX1, HDRL_EPS_TEST);
2897 cpl_test_rel(swcs->crpix2, HDRL_CRPIX2, HDRL_EPS_TEST);
2898 cpl_test_rel(swcs->crval1, HDRL_CRVAL1, HDRL_EPS_TEST);
2899 cpl_test_rel(swcs->crval2, HDRL_CRVAL2, HDRL_EPS_TEST);
2900
2901 cpl_free(swcs);
2902 cpl_propertylist_erase(header, "CRPIX1");
2903 swcs = hdrl_resample_smallwcs_new(header);
2904 cpl_test_nonnull(swcs);
2905 cpl_test_error(CPL_ERROR_NONE);
2906 cpl_test_nonnull(swcs);
2907 cpl_test_rel(swcs->crpix1, 0., HDRL_EPS_TEST);
2908
2909 cpl_free(swcs);
2910 cpl_propertylist_erase(header, "CD1_1");
2911 swcs = hdrl_resample_smallwcs_new(header);
2912 cpl_test_nonnull(swcs);
2913 cpl_test_error(CPL_ERROR_SINGULAR_MATRIX);
2914
2915 cpl_free(swcs);
2916 cpl_propertylist_erase_regexp(header, "CD?_?", 0);
2917 swcs = hdrl_resample_smallwcs_new(header);
2918 cpl_test_nonnull(swcs);
2919 cpl_test_error(CPL_ERROR_NONE);
2920 cpl_test_nonnull(swcs);
2921 cpl_test_rel(swcs->crpix1, 0., HDRL_EPS_TEST);
2922
2923 cpl_free(swcs);
2924 cpl_wcs_delete(wcs);
2925 cpl_propertylist_delete(header);
2926 cpl_test_error(CPL_ERROR_NONE);
2927 return cpl_error_get_code();
2928}
2929/*----------------------------------------------------------------------------*/
2934/*----------------------------------------------------------------------------*/
2935static hdrl_resample_pixgrid*
2936hdrl_resample_util_pixgrid_new(void) {
2937
2938 cpl_size aSizeX = 10;
2939 cpl_size aSizeY = 10;
2940 cpl_size aSizeZ = 10;
2941 unsigned short aNMaps = 10;
2942
2943 /* test valid input */
2944 hdrl_resample_pixgrid *aGrid =
2945 hdrl_resample_pixgrid_new(aSizeX, aSizeY, aSizeZ, aNMaps);
2946
2947 return aGrid;
2948}
2949/*----------------------------------------------------------------------------*/
2954/*----------------------------------------------------------------------------*/
2955static cpl_error_code
2956test_hdrl_resample_pixgrid_delete(void) {
2957
2958 /* test invalid input */
2959 hdrl_resample_pixgrid_delete(NULL);
2960 /* Nothing to check on error code as in this case function returns void */
2961
2962 /* test valid input */
2963 hdrl_resample_pixgrid *aGrid = hdrl_resample_util_pixgrid_new();
2964 cpl_test_nonnull(aGrid);
2965
2966 hdrl_resample_pixgrid_delete(aGrid);
2967 cpl_test_error(CPL_ERROR_NONE);
2968
2969 return cpl_error_get_code();
2970}
2971/*----------------------------------------------------------------------------*/
2976/*----------------------------------------------------------------------------*/
2977static cpl_table*
2978hdrl_resample_util_crea_pixel_table()
2979{
2980 cpl_wcs* wcs = hdrl_resample_util_crea_wcs_3d();
2981 cpl_imagelist* ilist = NULL;
2982 cpl_imagelist* elist = NULL;
2983
2984 ilist = cpl_imagelist_new();
2985 elist = cpl_imagelist_new();
2986 cpl_image* simul = hdrl_resample_util_crea_image_dice_5(HDRL_SIZE_X, HDRL_SIZE_X,
2987 HDRL_FLUX_ADU);
2988 cpl_image* errs = cpl_image_duplicate(simul);
2989 cpl_image_power(errs, 0.5);
2990 cpl_imagelist_set(ilist, simul, 0);
2991 cpl_imagelist_set(elist, errs, 0);
2992 hdrl_imagelist* hlist = hdrl_resample_util_hdrl_imagelist_create(ilist,
2993 elist, NULL);
2994 cpl_table* pixel_table = hdrl_resample_imagelist_to_table(hlist, wcs);
2995
2996 cpl_imagelist_delete(ilist);
2997 cpl_imagelist_delete(elist);
2998 hdrl_imagelist_delete(hlist);
2999
3000 cpl_wcs_delete(wcs);
3001 cpl_test_error(CPL_ERROR_NONE);
3002
3003 return pixel_table;
3004}
3005/*----------------------------------------------------------------------------*/
3012/*----------------------------------------------------------------------------*/
3013
3014static cpl_error_code
3015test_hdrl_resample_compute_method(hdrl_resample_method aMethod,
3016 cpl_boolean use_errorweights) {
3017
3018 const double delta_ra = HDRL_CDELT1;
3019 const double delta_dec = HDRL_CDELT2;
3020 const double delta_lambda = HDRL_CDELT3;
3021 const double ramin = HDRL_RA_MIN;
3022 const double ramax = HDRL_RA_MAX;
3023 const double decmin = HDRL_DEC_MIN;
3024 const double decmax = HDRL_DEC_MAX;
3025 const double lambmin = HDRL_LAMBDA_MIN;
3026 const double lambmax = HDRL_LAMBDA_MAX;
3027
3028 cpl_wcs* wcs = hdrl_resample_util_crea_wcs_3d();
3029
3030 cpl_table* pixel_table = hdrl_resample_util_crea_pixel_table();
3031
3032 hdrl_parameter * aParams_method =
3033 hdrl_resample_util_methodparam_create (
3034 LOOP_DISTANCE,
3035 RENKA_CRITICAL_RADIUS,
3036 LANCZOS_KERNEL_SIZE,
3037 DRIZZLE_DOWN_SCALING_FACTOR_X,
3038 DRIZZLE_DOWN_SCALING_FACTOR_Y,
3039 DRIZZLE_DOWN_SCALING_FACTOR_Z,
3040 aMethod, use_errorweights);
3041
3042 hdrl_parameter* aParams_outputgrid =
3044 delta_lambda, ramin, ramax, decmin, decmax, lambmin, lambmax, 0.);
3045 /* we use 0 field margin to check later NAXISi values vs cube expected size */
3046
3047 /* Create resampling table starting from a data cube */
3048 int sx = HDRL_SIZE_X, sy = HDRL_SIZE_Z, sz = HDRL_SIZE_Z;
3049 cpl_image* ima = cpl_image_new(sx, sy, CPL_TYPE_INT);
3050 cpl_image_add_scalar(ima, 1);
3051 cpl_imagelist* iml = cpl_imagelist_new();
3052 for(int i = 0; i< sz;i++) {
3053 cpl_imagelist_set(iml, ima, i);
3054 }
3055 hdrl_imagelist* hlist = hdrl_resample_util_hdrl_imagelist_create(iml,
3056 NULL, NULL);
3057
3058 cpl_table * ResTable = hdrl_resample_imagelist_to_table(hlist, wcs);
3059 cpl_imagelist_delete(iml);
3060 hdrl_imagelist_delete(hlist);
3061
3062 cpl_test_error(CPL_ERROR_NONE);
3063 cpl_test_nonnull(ResTable);
3064 cpl_test_nonnull(aParams_method);
3065 cpl_test_nonnull(aParams_outputgrid);
3066 cpl_test_nonnull(wcs);
3067 hdrl_resample_result *cube =
3068 hdrl_resample_compute(ResTable, aParams_method, aParams_outputgrid,
3069 wcs);
3070 cpl_test_nonnull(cube);
3071 cpl_test_error(CPL_ERROR_NONE);
3072
3073 /* test valid input */
3074 /* test 3D case */
3075 hdrl_parameter_delete(aParams_outputgrid);
3076
3077 aParams_outputgrid =
3078 hdrl_resample_parameter_create_outgrid3D(delta_ra, delta_dec, delta_lambda);
3079
3080 /* test case: recalc_limits == CPL_TRUE */
3082 cube = hdrl_resample_compute(ResTable, aParams_method, aParams_outputgrid,
3083 wcs);
3084 cpl_test_nonnull(cube);
3085 cpl_test_error(CPL_ERROR_NONE);
3086
3087 /* test 2D case */
3088 hdrl_parameter_delete(aParams_outputgrid);
3089 aParams_outputgrid =
3091 ramin, ramax,
3092 decmin, decmax,
3093 5.);
3094
3096 cube = hdrl_resample_compute(ResTable, aParams_method, aParams_outputgrid,
3097 wcs);
3098 cpl_test_nonnull(cube);
3099 cpl_test_error(CPL_ERROR_NONE);
3100
3101 hdrl_parameter_delete(aParams_outputgrid);
3102 hdrl_parameter_delete(aParams_method);
3103 cpl_table_delete(ResTable);
3104 cpl_wcs_delete(wcs);
3105 cpl_table_delete(pixel_table);
3107
3108 return cpl_error_get_code();
3109}
3110/*----------------------------------------------------------------------------*/
3115/*----------------------------------------------------------------------------*/
3116static cpl_error_code
3117test_hdrl_resample_compute(void) {
3118
3119 test_hdrl_resample_compute_method(HDRL_RESAMPLE_METHOD_NEAREST, CPL_TRUE);
3120 cpl_test_error(CPL_ERROR_NONE);
3121 test_hdrl_resample_compute_method(HDRL_RESAMPLE_METHOD_RENKA, CPL_TRUE);
3122 cpl_test_error(CPL_ERROR_NONE);
3123 test_hdrl_resample_compute_method(HDRL_RESAMPLE_METHOD_LINEAR, CPL_TRUE);
3124 cpl_test_error(CPL_ERROR_NONE);
3125 test_hdrl_resample_compute_method(HDRL_RESAMPLE_METHOD_QUADRATIC, CPL_TRUE);
3126 cpl_test_error(CPL_ERROR_NONE);
3127 test_hdrl_resample_compute_method(HDRL_RESAMPLE_METHOD_DRIZZLE, CPL_TRUE);
3128 cpl_test_error(CPL_ERROR_NONE);
3129 test_hdrl_resample_compute_method(HDRL_RESAMPLE_METHOD_LANCZOS, CPL_TRUE);
3130 cpl_test_error(CPL_ERROR_NONE);
3131 test_hdrl_resample_compute_method(HDRL_RESAMPLE_METHOD_NONE, CPL_TRUE);
3132 cpl_test_error(CPL_ERROR_NONE);
3133 test_hdrl_resample_compute_method(HDRL_RESAMPLE_METHOD_LINEAR, CPL_FALSE);
3134 cpl_test_error(CPL_ERROR_NONE);
3135
3136 return cpl_error_get_code();
3137}
3138/*----------------------------------------------------------------------------*/
3143/*----------------------------------------------------------------------------*/
3144static cpl_error_code
3145test_hdrl_resample_wcs_projplane_from_celestial(void) {
3146
3147 hdrl_parameter * outputgrid =
3149
3150 hdrl_resample_outgrid_parameter *pogrid =
3151 (hdrl_resample_outgrid_parameter *) outputgrid;
3152
3153 double ra = HDRL_RA;
3154 double dec = HDRL_DEC;
3155 double x_out = HDRL_RA;
3156 double y_out = HDRL_DEC;
3157
3158 /* test invalid input */
3159 hdrl_resample_wcs_projplane_from_celestial(NULL, ra, dec, &x_out, &y_out);
3160 cpl_test_error(CPL_ERROR_NULL_INPUT);
3161
3162 /* test valid input */
3163 hdrl_resample_util_fill_outputgrid(pogrid);
3164 hdrl_resample_wcs_projplane_from_celestial(pogrid, ra, dec, &x_out, &y_out);
3165 cpl_test_error(CPL_ERROR_NONE);
3166 cpl_test_abs(x_out, -0.000561558354797, HDRL_DELTA_COMPARE_VALUE_ABS);
3167 cpl_test_abs(y_out, 0.000899999036676, HDRL_DELTA_COMPARE_VALUE_ABS);
3168
3169 cpl_wcs_delete((cpl_wcs *)pogrid->wcs);
3170 cpl_free(pogrid);
3171 cpl_test_error(CPL_ERROR_NONE);
3172 return cpl_error_get_code();
3173
3174}
3175/*----------------------------------------------------------------------------*/
3180/*----------------------------------------------------------------------------*/
3181static cpl_error_code
3182test_hdrl_resample_wcs_pixel_from_celestial_fast(void){
3183
3184 double ra = HDRL_RA;
3185 double dec = HDRL_DEC;
3186 double x_out = HDRL_RA;
3187 double y_out = HDRL_DEC;
3188 /* test invalid input */
3189 hdrl_resample_wcs_pixel_from_celestial_fast(NULL, ra, dec, &x_out, &y_out);
3190 cpl_wcs* wcs = hdrl_resample_util_crea_wcs_3d();
3191 cpl_test_nonnull(wcs);
3192 cpl_propertylist* header = cpl_propertylist_new();
3193 hdrl_wcs_to_propertylist(wcs, header, CPL_FALSE);
3194 cpl_test_nonnull(header);
3195
3196 hdrl_resample_smallwcs * swcs = hdrl_resample_smallwcs_new(header);
3197 cpl_test_nonnull(swcs);
3198
3199 hdrl_resample_wcs_pixel_from_celestial_fast(swcs, ra, dec, &x_out, &y_out);
3200 cpl_test_error(CPL_ERROR_NONE);
3201
3202 /*
3203 This function uses many trigonometric functions and thus accumulates differences between
3204 e.g. linux 64 bit, linux 32 bit and macosx
3205 */
3206 cpl_test_rel(x_out, -163.82544787203, 1.e-11);
3207 cpl_test_rel(y_out, 1518.66596649235, 1.e-11);
3208
3209 cpl_free(swcs);
3210 cpl_wcs_delete(wcs);
3211 cpl_propertylist_delete(header);
3212 cpl_test_error(CPL_ERROR_NONE);
3213 return cpl_error_get_code();
3214}
3215
3216/*----------------------------------------------------------------------------*/
3221/*----------------------------------------------------------------------------*/
3222static cpl_error_code
3223test_hdrl_resample_compute_size(void){
3224
3225 hdrl_parameter * outputgrid =
3227
3228 hdrl_resample_outgrid_parameter *pogrid =
3229 (hdrl_resample_outgrid_parameter *) outputgrid;
3230
3231 int x, y, z;
3232
3233 /* test invalid input */
3234 hdrl_resample_compute_size(NULL, &x, &y, &z);
3235 cpl_test_error(CPL_ERROR_NULL_INPUT);
3236
3237 /* test valid input */
3238 hdrl_resample_util_fill_outputgrid(pogrid);
3239 hdrl_resample_compute_size(pogrid, &x, &y, &z);
3240 cpl_test_error(CPL_ERROR_NONE);
3241
3242 cpl_test_eq(x, 225); /* values determined on fc32 */
3243 cpl_test_eq(y, 229); /* values determined on fc32 */
3244 cpl_test_eq(z, 2); /* values determined on fc32 */
3245
3246 cpl_wcs_delete((cpl_wcs *)pogrid->wcs);
3247 cpl_free(pogrid);
3248 cpl_test_error(CPL_ERROR_NONE);
3249 return cpl_error_get_code();
3250}
3251/*----------------------------------------------------------------------------*/
3256/*----------------------------------------------------------------------------*/
3257static cpl_error_code
3258test_hdrl_resample_pixgrid_add(void){
3259
3260 hdrl_resample_pixgrid *aGrid = hdrl_resample_util_pixgrid_new();
3261 cpl_test_nonnull(aGrid);
3262
3263 cpl_size aIndex = 1;
3264 cpl_size aRow = 1;
3265 unsigned short aXIdx = 1;
3266
3267 /* test invalid input */
3268 hdrl_resample_pixgrid_add(NULL, aIndex, aRow, aXIdx);
3269 hdrl_resample_pixgrid_add(aGrid, -1, aRow, aXIdx);
3270
3271 /* test valid input */
3272 hdrl_resample_pixgrid_add(aGrid, aIndex, aRow, aXIdx);
3273 /* As hdrl_resample_pixgrid_add returns void we just test error code */
3274 cpl_test_error(CPL_ERROR_NONE);
3275
3276 hdrl_resample_pixgrid_delete(aGrid);
3277 cpl_test_error(CPL_ERROR_NONE);
3278
3279 return cpl_error_get_code();
3280}
3281/*----------------------------------------------------------------------------*/
3286/*----------------------------------------------------------------------------*/
3287static cpl_error_code
3288test_hdrl_resample_pixgrid_get_count(void){
3289 cpl_size aIndex = 1;
3290 /* test invalid input */
3291 hdrl_resample_pixgrid_get_count(NULL, aIndex);
3292
3293 hdrl_resample_pixgrid *aGrid = hdrl_resample_util_pixgrid_new();
3294 cpl_test_nonnull(aGrid);
3295
3296 hdrl_resample_pixgrid_get_count(aGrid, -1);
3297
3298 /* test valid input */
3299 cpl_size n = hdrl_resample_pixgrid_get_count(aGrid, aIndex);
3300
3301 cpl_test_rel(n, 0, HDRL_EPS_TEST);
3302
3303 hdrl_resample_pixgrid_delete(aGrid);
3304 cpl_test_error(CPL_ERROR_NONE);
3305 return cpl_error_get_code();
3306
3307}
3308/*----------------------------------------------------------------------------*/
3313/*----------------------------------------------------------------------------*/
3314static cpl_error_code
3315test_hdrl_resample_pixgrid_get_index(void)
3316{
3317 cpl_size x = 1;
3318 cpl_size y = 1;
3319 cpl_size z = 1;
3320 cpl_boolean aAllowOutside = CPL_TRUE;
3321
3322 hdrl_resample_pixgrid *aGrid = hdrl_resample_util_pixgrid_new();
3323 cpl_test_nonnull(aGrid);
3324 cpl_msg_warning(cpl_func,"x: %lld",aGrid->nx);
3325 cpl_msg_warning(cpl_func,"y: %lld",aGrid->ny);
3326 cpl_msg_warning(cpl_func,"z: %lld",aGrid->nz);
3327 cpl_size index = 0;
3328
3329 /* test invalid input */
3330 index = hdrl_resample_pixgrid_get_index(NULL, x, y, z, aAllowOutside);
3331 cpl_test_eq(index, -1);
3332 index = hdrl_resample_pixgrid_get_index(aGrid, -1, y, z, CPL_FALSE);
3333 cpl_test_eq(index, -1);
3334 index = hdrl_resample_pixgrid_get_index(aGrid, x, -1, z, CPL_FALSE);
3335 cpl_test_eq(index, -1);
3336 index = hdrl_resample_pixgrid_get_index(aGrid, x, y, -1, CPL_FALSE);
3337 cpl_test_eq(index, -1);
3338
3339 index = hdrl_resample_pixgrid_get_index(aGrid, aGrid->nx+1, y, z, CPL_FALSE);
3340 cpl_test_eq(index, -1);
3341 index = hdrl_resample_pixgrid_get_index(aGrid, x, aGrid->ny+1, z, CPL_FALSE);
3342 cpl_test_eq(index, -1);
3343 index = hdrl_resample_pixgrid_get_index(aGrid, x, y, aGrid->nz+1, CPL_FALSE);
3344 cpl_test_eq(index, -1);
3345
3346 index = hdrl_resample_pixgrid_get_index(aGrid, aGrid->nx + 1, y, z, CPL_TRUE);
3347 cpl_test_eq(index, 119);
3348 index = hdrl_resample_pixgrid_get_index(aGrid, x, aGrid->ny + 1, z, CPL_TRUE);
3349 cpl_test_eq(index, 191);
3350 index = hdrl_resample_pixgrid_get_index(aGrid, x, y, aGrid->nz + 1, CPL_TRUE);
3351 cpl_test_eq(index, 911);
3352
3353 /* test valid input */
3354 cpl_size index_res = 111;
3355 cpl_msg_warning(cpl_func,"index: %lld",
3356 hdrl_resample_pixgrid_get_index(aGrid, x, y, z, aAllowOutside));
3357 index = hdrl_resample_pixgrid_get_index(aGrid, x, y, z, aAllowOutside);
3358 cpl_test_eq(index_res, index);
3359
3360 hdrl_resample_pixgrid_delete(aGrid);
3361 cpl_test_error(CPL_ERROR_NONE);
3362 return cpl_error_get_code();
3363}
3364/*----------------------------------------------------------------------------*/
3369/*----------------------------------------------------------------------------*/
3370static cpl_error_code
3371test_hdrl_resample_pixgrid_new(void) {
3372 cpl_size x = 1;
3373 cpl_size y = 1;
3374 cpl_size z = 1;
3375 unsigned short aNMaps = 1;
3376 hdrl_resample_pixgrid * pGrid = NULL;
3377
3378 /* test invalid input */
3379 pGrid = hdrl_resample_pixgrid_new(-1, y, z, aNMaps);
3380 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
3381 cpl_test_null(pGrid);
3382
3383 pGrid = hdrl_resample_pixgrid_new(x, -1, z, aNMaps);
3384 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
3385 cpl_test_null(pGrid);
3386
3387 pGrid = hdrl_resample_pixgrid_new(x, y, -1, aNMaps);
3388 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
3389 cpl_test_null(pGrid);
3390
3391 pGrid = hdrl_resample_pixgrid_new(x, y, z, 0);
3392 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
3393 cpl_test_null(pGrid);
3394
3395 /* test valid input */
3396 pGrid = hdrl_resample_pixgrid_new(x, y, z, aNMaps);
3397 cpl_test_error(CPL_ERROR_NONE);
3398 cpl_test_nonnull(pGrid);
3399
3400 hdrl_resample_pixgrid_delete(pGrid);
3401 return cpl_error_get_code();
3402}
3403/*----------------------------------------------------------------------------*/
3408/*----------------------------------------------------------------------------*/
3409static cpl_error_code
3410test_hdrl_resample_pixgrid_create(void) {
3411
3412 cpl_size x = 1;
3413 cpl_size y = 1;
3414 cpl_size z = 1;
3415 cpl_table* pixel_table = NULL;
3416 cpl_wcs* wcs = hdrl_resample_util_crea_wcs_3d();
3417 cpl_test_nonnull(wcs);
3418 cpl_propertylist* header = cpl_propertylist_new();
3419 hdrl_wcs_to_propertylist(wcs, header, CPL_FALSE);
3420 hdrl_resample_pixgrid * pGrid= NULL;
3421
3422 /* test invalid input */
3423 pixel_table = cpl_table_new(0);
3424 pGrid = hdrl_resample_pixgrid_create(pixel_table, header, x, y, z);
3425 cpl_test_error(CPL_ERROR_NULL_INPUT);
3426 cpl_test_null(pGrid);
3427 cpl_table_delete(pixel_table);
3428
3429 pixel_table = cpl_table_new(1);
3430 pGrid = hdrl_resample_pixgrid_create(pixel_table, header, x, y, z);
3431 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
3432 cpl_test_null(pGrid);
3433 cpl_table_delete(pixel_table);
3434
3435 pixel_table = hdrl_resample_util_crea_pixel_table();
3436
3437 /* test invalid input */
3438 pGrid = hdrl_resample_pixgrid_create(pixel_table, NULL, x, y, z);
3439 cpl_test_error(CPL_ERROR_NULL_INPUT);
3440 cpl_test_null(pGrid);
3441
3442 pGrid = hdrl_resample_pixgrid_create(pixel_table, header, -1, y, z);
3443 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
3444 cpl_test_null(pGrid);
3445
3446 pGrid = hdrl_resample_pixgrid_create(pixel_table, header, x, -1, z);
3447 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
3448 cpl_test_null(pGrid);
3449
3450 pGrid = hdrl_resample_pixgrid_create(pixel_table, header, x, y, -1);
3451 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
3452 cpl_test_null(pGrid);
3453
3454 /* test valid input */
3455 pGrid = hdrl_resample_pixgrid_create(pixel_table, header, x, y, z);
3456 cpl_test_error(CPL_ERROR_NONE);
3457 cpl_test_nonnull(pGrid);
3458 hdrl_resample_pixgrid_delete(pGrid);
3459
3460 cpl_table_unselect_row(pixel_table, 1);
3461 pGrid = hdrl_resample_pixgrid_create(pixel_table, header, x, y, z);
3462 cpl_test_error(CPL_ERROR_NONE);
3463 cpl_test_nonnull(pGrid);
3464
3465 cpl_wcs_delete(wcs);
3466 cpl_table_delete(pixel_table);
3467 cpl_propertylist_delete(header);
3468 hdrl_resample_pixgrid_delete(pGrid);
3469 return cpl_error_get_code();
3470}
3471/*----------------------------------------------------------------------------*/
3476/*----------------------------------------------------------------------------*/
3477static cpl_error_code
3478test_hdrl_resample_wcs_get_scales(void) {
3479
3480 double aXScale = 1;
3481 double aYScale = 1;
3482 hdrl_parameter * outputgrid =
3484
3485 hdrl_resample_outgrid_parameter *pogrid =
3486 (hdrl_resample_outgrid_parameter *) outputgrid;
3487 hdrl_resample_util_fill_outputgrid(pogrid);
3488 hdrl_parameter * method = hdrl_resample_parameter_create_nearest();
3489
3490 hdrl_resample_method_parameter * p =
3491 (hdrl_resample_method_parameter *) method;
3492 cpl_test_nonnull(p);
3493
3494 /* test invalid input */
3495 hdrl_resample_wcs_get_scales(NULL, &aXScale, &aYScale);
3496 cpl_test_error(CPL_ERROR_NULL_INPUT);
3497
3498 hdrl_resample_wcs_get_scales(pogrid, NULL, &aYScale);
3499 cpl_test_error(CPL_ERROR_NULL_INPUT);
3500
3501 hdrl_resample_wcs_get_scales(pogrid, &aXScale, NULL);
3502 cpl_test_error(CPL_ERROR_NULL_INPUT);
3503
3504 /* test valid input */
3505 hdrl_resample_wcs_get_scales(pogrid, &aXScale, &aYScale);
3506 cpl_msg_warning(cpl_func,"x: %16.10g",aXScale);
3507 cpl_msg_warning(cpl_func,"y: %16.10g",aYScale);
3508 cpl_test_error(CPL_ERROR_NONE);
3509 /* clean memory */
3510 cpl_wcs_delete((cpl_wcs *)pogrid->wcs);
3511 hdrl_parameter_delete(outputgrid);
3512 hdrl_parameter_delete(method);
3513 return cpl_error_get_code();
3514}
3515/*----------------------------------------------------------------------------*/
3520/*----------------------------------------------------------------------------*/
3521static cpl_error_code
3522test_hdrl_resample_create_table(void){
3523
3524 const cpl_size size = 10;
3525 cpl_table* tab = NULL;
3526
3527 /* test invalid input */
3528 hdrl_resample_create_table(NULL, size);
3529 cpl_test_error(CPL_ERROR_NULL_INPUT);
3530
3531 hdrl_resample_create_table(&tab, -1);
3532 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
3533
3534 /* test valid input */
3535 hdrl_resample_create_table(&tab, size);
3536 cpl_test_error(CPL_ERROR_NONE);
3537
3538 cpl_table_delete(tab);
3539 return cpl_error_get_code();
3540}
3541/*----------------------------------------------------------------------------*/
3546/*----------------------------------------------------------------------------*/
3547static cpl_error_code
3548test_hdrl_resample_pixgrid_get_rows(void) {
3549
3550 cpl_size aIndex = 1;
3551 hdrl_resample_pixgrid *aGrid = NULL;
3552 cpl_size x = 2;
3553 cpl_size y = 1;
3554 cpl_size z = 1;
3555 unsigned short aNMaps = 1;
3556
3557 /* test invalid input */
3558 hdrl_resample_pixgrid_get_rows(NULL, aIndex);
3559 cpl_test_error(CPL_ERROR_NULL_INPUT);
3560
3561 aGrid = hdrl_resample_pixgrid_new(x, y, z, aNMaps);
3562 cpl_test_error(CPL_ERROR_NONE);
3563 cpl_test_nonnull(aGrid);
3564
3565 hdrl_resample_pixgrid_get_rows(aGrid, -1);
3566 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
3567
3568 /* test valid input */
3569 hdrl_resample_pixgrid_get_rows(aGrid, aIndex);
3570 cpl_test_error(CPL_ERROR_NONE);
3571 hdrl_resample_pixgrid_delete(aGrid);
3572
3573 return cpl_error_get_code();
3574}
3575/*----------------------------------------------------------------------------*/
3580/*----------------------------------------------------------------------------*/
3581static cpl_error_code
3582test_hdrl_resample_cube_nearest(void){
3583
3584 cpl_table *ResTable = NULL;
3585 const cpl_size size = 10;
3586 cpl_size x = 2;
3587 cpl_size y = 2;
3588 cpl_size z = 2;
3589 unsigned short aNMaps = 1;
3590
3591 /* prepare re-sample table */
3592 hdrl_resample_create_table(&ResTable, size);
3593
3594 /* prepare a Grid */
3595 hdrl_resample_pixgrid *aGrid = hdrl_resample_pixgrid_new(x, y, z, aNMaps);
3596
3597 /* prepare output-grid parameter */
3598 hdrl_parameter * outputgrid =
3600 HDRL_CDELT2, HDRL_CDELT3,
3601 HDRL_RA_MIN, HDRL_RA_MAX, HDRL_DEC_MIN, HDRL_DEC_MAX,
3602 HDRL_LAMBDA_MIN, HDRL_LAMBDA_MAX,5.);
3603
3604 /* creates the cube */
3605 hdrl_resample_method aMethod = HDRL_RESAMPLE_METHOD_DRIZZLE;
3606 cpl_boolean use_errorweights = CPL_TRUE;
3607 hdrl_parameter * aParams_method =
3608 hdrl_resample_util_methodparam_create (
3609 LOOP_DISTANCE,
3610 RENKA_CRITICAL_RADIUS,
3611 LANCZOS_KERNEL_SIZE,
3612 DRIZZLE_DOWN_SCALING_FACTOR_X,
3613 DRIZZLE_DOWN_SCALING_FACTOR_Y,
3614 DRIZZLE_DOWN_SCALING_FACTOR_Z,
3615 aMethod, use_errorweights);
3616 hdrl_resample_outgrid_parameter *aParams_outputgrid =
3617 (hdrl_resample_outgrid_parameter *) outputgrid;
3618 hdrl_resample_util_fill_outputgrid(aParams_outputgrid);
3619 cpl_wcs_delete((cpl_wcs *)aParams_outputgrid->wcs);
3620 aParams_outputgrid->wcs = hdrl_resample_util_crea_wcs_3d();
3621
3622 /* generates a cube to be resampled */
3623 hdrl_resample_result * cube = hdrl_resample_compute(ResTable, aParams_method, outputgrid,
3624 aParams_outputgrid->wcs);
3625
3626 /* test invalid input */
3627 hdrl_resample_cube_nearest(NULL, ResTable, aGrid, aParams_outputgrid);
3628 cpl_test_error(CPL_ERROR_NULL_INPUT);
3629
3630 hdrl_resample_cube_nearest(cube, NULL, aGrid, aParams_outputgrid);
3631 cpl_test_error(CPL_ERROR_NULL_INPUT);
3632
3633 hdrl_resample_cube_nearest(cube, ResTable, NULL, aParams_outputgrid);
3634 cpl_test_error(CPL_ERROR_NULL_INPUT);
3635
3636 hdrl_resample_cube_nearest(cube, ResTable, aGrid, NULL);
3637 cpl_test_error(CPL_ERROR_NULL_INPUT);
3638
3639 /* test invalid input */
3640 hdrl_resample_cube_nearest(cube, ResTable, aGrid,aParams_outputgrid);
3641 cpl_test_error(CPL_ERROR_NONE);
3642
3643 /* clean memory */
3644 cpl_wcs_delete((cpl_wcs *)aParams_outputgrid->wcs);
3645 hdrl_resample_pixgrid_delete(aGrid);
3646 cpl_table_delete(ResTable);
3647 hdrl_parameter_delete(outputgrid);
3648 hdrl_parameter_delete(aParams_method);
3650 return cpl_error_get_code();
3651}
3652/*----------------------------------------------------------------------------*/
3657/*----------------------------------------------------------------------------*/
3658static cpl_error_code
3659test_hdrl_resample_cube_weighted(void) {
3660
3661 cpl_table *ResTable = NULL;
3662 const cpl_size size = 10;
3663 cpl_size x = 2;
3664 cpl_size y = 2;
3665 cpl_size z = 2;
3666 unsigned short aNMaps = 1;
3667
3668 /* prepare re-sample table */
3669 hdrl_resample_create_table(&ResTable, size);
3670
3671 /* prepare a Grid */
3672 hdrl_resample_pixgrid *aGrid = hdrl_resample_pixgrid_new(x, y, z, aNMaps);
3673
3674 /* prepare output-grid parameter */
3675 hdrl_parameter * outputgrid =
3677 HDRL_CDELT2, HDRL_CDELT3,
3678 HDRL_RA_MIN, HDRL_RA_MAX, HDRL_DEC_MIN, HDRL_DEC_MAX,
3679 HDRL_LAMBDA_MIN, HDRL_LAMBDA_MAX,5.);
3680
3681 /* creates the cube */
3682 hdrl_resample_method aMethod = HDRL_RESAMPLE_METHOD_DRIZZLE;
3683 cpl_boolean use_errorweights = CPL_TRUE;
3684 hdrl_parameter * aParams_method =
3685 hdrl_resample_util_methodparam_create (
3686 LOOP_DISTANCE,
3687 RENKA_CRITICAL_RADIUS,
3688 LANCZOS_KERNEL_SIZE,
3689 DRIZZLE_DOWN_SCALING_FACTOR_X,
3690 DRIZZLE_DOWN_SCALING_FACTOR_Y,
3691 DRIZZLE_DOWN_SCALING_FACTOR_Z,
3692 aMethod, use_errorweights);
3693 hdrl_resample_outgrid_parameter *aParams_outputgrid =
3694 (hdrl_resample_outgrid_parameter *) outputgrid;
3695 hdrl_resample_util_fill_outputgrid(aParams_outputgrid);
3696 cpl_wcs_delete((cpl_wcs *)aParams_outputgrid->wcs);
3697 aParams_outputgrid->wcs = hdrl_resample_util_crea_wcs_3d();
3698
3699 hdrl_resample_method_parameter * mp =
3700 (hdrl_resample_method_parameter *) aParams_method;
3701 cpl_test_nonnull(mp);
3702 /* generates a cube to be resampled */
3703 hdrl_resample_result * cube = hdrl_resample_compute(ResTable, aParams_method, outputgrid,
3704 aParams_outputgrid->wcs);
3705
3706 /* test invalid input */
3707 hdrl_resample_cube_weighted(NULL, ResTable, aGrid, mp,
3708 aParams_outputgrid);
3709 cpl_test_error(CPL_ERROR_NULL_INPUT);
3710
3711 hdrl_resample_cube_weighted(cube, NULL, aGrid, mp,
3712 aParams_outputgrid);
3713 cpl_test_error(CPL_ERROR_NULL_INPUT);
3714
3715 hdrl_resample_cube_weighted(cube, ResTable, NULL, mp,
3716 aParams_outputgrid);
3717 cpl_test_error(CPL_ERROR_NULL_INPUT);
3718
3719 hdrl_resample_cube_weighted(cube, ResTable, aGrid, NULL,
3720 aParams_outputgrid);
3721 cpl_test_error(CPL_ERROR_NULL_INPUT);
3722
3723 hdrl_resample_cube_weighted(cube, ResTable, aGrid, mp,
3724 NULL);
3725 cpl_test_error(CPL_ERROR_NULL_INPUT);
3726
3727 /* test valid input */
3728 hdrl_resample_cube_weighted(cube, ResTable, aGrid, mp,
3729 aParams_outputgrid);
3730 cpl_test_error(CPL_ERROR_NONE);
3731
3732 mp->loop_distance = -1;
3733 mp->lanczos_kernel_size = 0;
3734 hdrl_resample_cube_weighted(cube, ResTable, aGrid, mp,
3735 aParams_outputgrid);
3736 cpl_test_error(CPL_ERROR_NONE);
3737
3738 /* clean memory */
3739 cpl_wcs_delete((cpl_wcs *)aParams_outputgrid->wcs);
3740 hdrl_resample_pixgrid_delete(aGrid);
3741 cpl_table_delete(ResTable);
3742 hdrl_parameter_delete(outputgrid);
3743 hdrl_parameter_delete(aParams_method);
3745
3746 return cpl_error_get_code();
3747}
3748/*----------------------------------------------------------------------------*/
3753/*----------------------------------------------------------------------------*/
3754static cpl_error_code
3755test_hdrl_resample_cube(void) {
3756 cpl_table *ResTable = NULL;
3757 const cpl_size size = 10;
3758
3759 /* prepare re-sample table */
3760 hdrl_resample_create_table(&ResTable, size);
3761
3762 /* prepare a Grid */
3763 hdrl_resample_pixgrid *aGrid = NULL;
3764 /* prepare output-grid parameter */
3765 hdrl_parameter * outputgrid =
3767 HDRL_CDELT2, HDRL_CDELT3,
3768 HDRL_RA_MIN, HDRL_RA_MAX, HDRL_DEC_MIN, HDRL_DEC_MAX,
3769 HDRL_LAMBDA_MIN, HDRL_LAMBDA_MAX,5.);
3770
3771 /* creates the cube */
3772 hdrl_resample_method aMethod = HDRL_RESAMPLE_METHOD_DRIZZLE;
3773 cpl_boolean use_errorweights = CPL_TRUE;
3774 hdrl_parameter * aParams_method =
3775 hdrl_resample_util_methodparam_create (
3776 LOOP_DISTANCE,
3777 RENKA_CRITICAL_RADIUS,
3778 LANCZOS_KERNEL_SIZE,
3779 DRIZZLE_DOWN_SCALING_FACTOR_X,
3780 DRIZZLE_DOWN_SCALING_FACTOR_Y,
3781 DRIZZLE_DOWN_SCALING_FACTOR_Z,
3782 aMethod, use_errorweights);
3783 hdrl_resample_outgrid_parameter *aParams_outputgrid =
3784 (hdrl_resample_outgrid_parameter *) outputgrid;
3785 hdrl_resample_util_fill_outputgrid(aParams_outputgrid);
3786 cpl_wcs_delete((cpl_wcs *)aParams_outputgrid->wcs);
3787 aParams_outputgrid->wcs = hdrl_resample_util_crea_wcs_3d();
3788
3789 hdrl_resample_method_parameter * mp =
3790 (hdrl_resample_method_parameter *) aParams_method;
3791 cpl_test_nonnull(mp);
3792 /* test invalid input */
3793 hdrl_resample_cube(NULL, mp, aParams_outputgrid, &aGrid);
3794 cpl_test_error(CPL_ERROR_NULL_INPUT);
3795
3796 hdrl_resample_cube(ResTable, NULL, aParams_outputgrid, &aGrid);
3797 cpl_test_error(CPL_ERROR_NULL_INPUT);
3798
3799 hdrl_resample_cube(ResTable, mp, NULL, &aGrid);
3800 cpl_test_error(CPL_ERROR_NULL_INPUT);
3801
3802 hdrl_resample_cube(ResTable, mp, aParams_outputgrid, NULL);
3803 cpl_test_error(CPL_ERROR_NULL_INPUT);
3804
3805 /* test valid input */
3806 hdrl_resample_result * cube = hdrl_resample_cube(ResTable, mp, aParams_outputgrid, &aGrid);
3807 cpl_test_error(CPL_ERROR_NONE);
3809 hdrl_resample_pixgrid_delete(aGrid);
3810
3811 /* test wrong method input */
3812 mp->method = 10;
3813 cube = hdrl_resample_cube(ResTable, mp, aParams_outputgrid, &aGrid);
3814 cpl_test_error(CPL_ERROR_UNSUPPORTED_MODE);
3816 cpl_table_delete(ResTable);
3817 hdrl_resample_pixgrid_delete(aGrid);
3818
3819 /* test invalid grid creation input */
3820 ResTable = cpl_table_new(0);
3821 cube = hdrl_resample_cube(ResTable, mp, aParams_outputgrid, &aGrid);
3822 cpl_test_error(CPL_ERROR_DATA_NOT_FOUND);
3823
3824 /* clean memory */
3825 cpl_wcs_delete((cpl_wcs *)aParams_outputgrid->wcs);
3826 hdrl_resample_pixgrid_delete(aGrid);
3827 cpl_table_delete(ResTable);
3828 hdrl_parameter_delete(outputgrid);
3829 hdrl_parameter_delete(aParams_method);
3831
3832 cpl_test_error(CPL_ERROR_NONE);
3833 return cpl_error_get_code();
3834}
3835/*----------------------------------------------------------------------------*/
3840/*----------------------------------------------------------------------------*/
3841static cpl_error_code
3842test_hdrl_resampling_set_outputgrid(void)
3843{
3844 int xsize = HDRL_SIZE_X;
3845 int ysize = HDRL_SIZE_Y;
3846 int zsize = HDRL_SIZE_Z;
3847
3848 cpl_table *ResTable = NULL;
3849 const cpl_size size = 10;
3850
3851 /* prepare re-sample table */
3852 hdrl_resample_create_table(&ResTable, size);
3853
3854 /* prepare a Grid */
3855 hdrl_resample_pixgrid *aGrid = NULL;
3856
3857 /* prepare output-grid parameter */
3858 hdrl_parameter * outputgrid =
3860 HDRL_CDELT2, HDRL_CDELT3,
3861 HDRL_RA_MIN, HDRL_RA_MAX, HDRL_DEC_MIN, HDRL_DEC_MAX,
3862 HDRL_LAMBDA_MIN, HDRL_LAMBDA_MAX,5.);
3863
3864 /* creates the cube */
3865 hdrl_resample_method aMethod = HDRL_RESAMPLE_METHOD_DRIZZLE;
3866 cpl_boolean use_errorweights = CPL_TRUE;
3867 hdrl_parameter * aParams_method =
3868 hdrl_resample_util_methodparam_create (
3869 LOOP_DISTANCE,
3870 RENKA_CRITICAL_RADIUS,
3871 LANCZOS_KERNEL_SIZE,
3872 DRIZZLE_DOWN_SCALING_FACTOR_X,
3873 DRIZZLE_DOWN_SCALING_FACTOR_Y,
3874 DRIZZLE_DOWN_SCALING_FACTOR_Z,
3875 aMethod, use_errorweights);
3876 hdrl_resample_outgrid_parameter *aParams_outputgrid =
3877 (hdrl_resample_outgrid_parameter *) outputgrid;
3878 hdrl_resample_util_fill_outputgrid(aParams_outputgrid);
3879 cpl_wcs_delete((cpl_wcs *)aParams_outputgrid->wcs);
3880 aParams_outputgrid->wcs = hdrl_resample_util_crea_wcs_3d();
3881
3882 hdrl_resample_method_parameter * mp =
3883 (hdrl_resample_method_parameter *) aParams_method;
3884 cpl_test_nonnull(mp);
3885
3886 hdrl_resample_result * cube = hdrl_resample_cube(ResTable, mp,
3887 aParams_outputgrid, &aGrid);
3888
3889 /* test invalid input */
3890 hdrl_resampling_set_outputgrid (-1, ysize, zsize, cube, aParams_outputgrid);
3891 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
3892
3893 hdrl_resampling_set_outputgrid (xsize, -1, zsize, cube, aParams_outputgrid);
3894 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
3895
3896 hdrl_resampling_set_outputgrid (xsize, ysize, -1, cube, aParams_outputgrid);
3897 cpl_test_error(CPL_ERROR_ILLEGAL_INPUT);
3898
3899 hdrl_resampling_set_outputgrid (xsize, ysize, zsize, NULL, aParams_outputgrid);
3900 cpl_test_error(CPL_ERROR_NULL_INPUT);
3901
3902 hdrl_resampling_set_outputgrid (xsize, ysize, zsize, cube, NULL);
3903 cpl_test_error(CPL_ERROR_NULL_INPUT);
3904 /* test valid input */
3905 /* We need to do delete the header cube->header, as
3906 * hdrl_resampling_set_outputgrid allocates mem for cube->header
3907 * even if cube->header might already exists
3908 */
3909 cpl_propertylist_delete(cube->header);
3910
3911 hdrl_resampling_set_outputgrid (xsize, ysize, zsize, cube, aParams_outputgrid);
3912 cpl_test_error(CPL_ERROR_NONE);
3913
3914 cpl_wcs_delete((cpl_wcs *)aParams_outputgrid->wcs);
3915 hdrl_resample_pixgrid_delete(aGrid);
3916 cpl_table_delete(ResTable);
3917 hdrl_parameter_delete(outputgrid);
3918 hdrl_parameter_delete(aParams_method);
3920 cpl_test_error(CPL_ERROR_NONE);
3921 return cpl_error_get_code();
3922}
3923static cpl_error_code
3924test_hdrl_resample_inputtable_verify(void)
3925{
3926 cpl_table* tab = NULL;
3927 hdrl_resample_inputtable_verify(NULL);
3928 cpl_test_error(CPL_ERROR_NULL_INPUT);
3929
3930 /* verify column existence */
3931 tab= cpl_table_new(1);
3932 cpl_table_new_column(tab, HDRL_RESAMPLE_TABLE_RA, CPL_TYPE_DOUBLE);
3933 hdrl_resample_inputtable_verify(tab);
3934 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
3935
3936 cpl_table_new_column(tab, HDRL_RESAMPLE_TABLE_DEC, CPL_TYPE_DOUBLE);
3937 hdrl_resample_inputtable_verify(tab);
3938 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
3939
3940 cpl_table_new_column(tab, HDRL_RESAMPLE_TABLE_LAMBDA, CPL_TYPE_DOUBLE);
3941 hdrl_resample_inputtable_verify(tab);
3942 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
3943
3944 cpl_table_new_column(tab, HDRL_RESAMPLE_TABLE_BPM, CPL_TYPE_INT);
3945 hdrl_resample_inputtable_verify(tab);
3946 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
3947
3948 cpl_table_new_column(tab, HDRL_RESAMPLE_TABLE_ERRORS, CPL_TYPE_DOUBLE);
3949 hdrl_resample_inputtable_verify(tab);
3950 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
3951
3952 cpl_table_new_column(tab, HDRL_RESAMPLE_TABLE_DATA, CPL_TYPE_DOUBLE);
3953 hdrl_resample_inputtable_verify(tab);
3954 cpl_test_error(CPL_ERROR_NONE);
3955 cpl_table_delete(tab);
3956
3957 /* verify column type */
3958 tab= cpl_table_new(1);
3959 cpl_table_new_column(tab, HDRL_RESAMPLE_TABLE_RA, CPL_TYPE_INT);
3960 hdrl_resample_inputtable_verify(tab);
3961 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
3962 cpl_table_erase_column(tab, HDRL_RESAMPLE_TABLE_RA);
3963 cpl_table_new_column(tab, HDRL_RESAMPLE_TABLE_RA, CPL_TYPE_DOUBLE);
3964
3965 cpl_table_new_column(tab, HDRL_RESAMPLE_TABLE_DEC, CPL_TYPE_INT);
3966 hdrl_resample_inputtable_verify(tab);
3967 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
3968 cpl_table_erase_column(tab, HDRL_RESAMPLE_TABLE_DEC);
3969 cpl_table_new_column(tab, HDRL_RESAMPLE_TABLE_DEC, CPL_TYPE_DOUBLE);
3970
3971 cpl_table_new_column(tab, HDRL_RESAMPLE_TABLE_LAMBDA, CPL_TYPE_INT);
3972 hdrl_resample_inputtable_verify(tab);
3973 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
3974 cpl_table_erase_column(tab, HDRL_RESAMPLE_TABLE_LAMBDA);
3975 cpl_table_new_column(tab, HDRL_RESAMPLE_TABLE_LAMBDA, CPL_TYPE_DOUBLE);
3976
3977 cpl_table_new_column(tab, HDRL_RESAMPLE_TABLE_BPM, CPL_TYPE_DOUBLE);
3978 hdrl_resample_inputtable_verify(tab);
3979 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
3980 cpl_table_erase_column(tab, HDRL_RESAMPLE_TABLE_BPM);
3981 cpl_table_new_column(tab, HDRL_RESAMPLE_TABLE_BPM, CPL_TYPE_INT);
3982
3983 cpl_table_new_column(tab, HDRL_RESAMPLE_TABLE_ERRORS, CPL_TYPE_INT);
3984 hdrl_resample_inputtable_verify(tab);
3985 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
3986 cpl_table_erase_column(tab, HDRL_RESAMPLE_TABLE_ERRORS);
3987 cpl_table_new_column(tab, HDRL_RESAMPLE_TABLE_ERRORS, CPL_TYPE_DOUBLE);
3988
3989 cpl_table_new_column(tab, HDRL_RESAMPLE_TABLE_DATA, CPL_TYPE_INT);
3990 hdrl_resample_inputtable_verify(tab);
3991 cpl_test_error(CPL_ERROR_INCOMPATIBLE_INPUT);
3992 cpl_table_erase_column(tab, HDRL_RESAMPLE_TABLE_DATA);
3993 cpl_table_new_column(tab, HDRL_RESAMPLE_TABLE_DATA, CPL_TYPE_DOUBLE);
3994 hdrl_resample_inputtable_verify(tab);
3995 cpl_test_error(CPL_ERROR_NONE);
3996
3997 cpl_table_delete(tab);
3998 return cpl_error_get_code();
3999}
4000
4004static cpl_propertylist*
4005hdrl_resample_util_header_create(const int sx, const int sy,
4006 const double dx, const double dy)
4007{
4008
4009 cpl_propertylist* plist = cpl_propertylist_new();
4010 cpl_propertylist_append_bool(plist,"SIMPLE", CPL_TRUE);
4011 cpl_propertylist_append_int(plist,"NAXIS", 2);
4012 cpl_propertylist_append_int(plist,"NAXIS1", sx);
4013 cpl_propertylist_append_int(plist,"NAXIS2", sy);
4014 cpl_propertylist_append_bool(plist,"EXTEND", CPL_TRUE);
4015 cpl_propertylist_append_double(plist,"CRPIX1", 0.5 * sx);
4016 cpl_propertylist_append_double(plist,"CRPIX2", 0.5 * sy);
4017 cpl_propertylist_append_double(plist,"CRVAL1", 0.5 * sx);
4018 cpl_propertylist_append_double(plist,"CRVAL2", 0.5 * sy);
4019 cpl_propertylist_append_double(plist,"CDELT1", dx );
4020 cpl_propertylist_append_double(plist,"CDELT2", dy );
4021 cpl_propertylist_append_double(plist,"CD1_1", -dx );
4022 cpl_propertylist_append_double(plist,"CD1_2", 0. );
4023 cpl_propertylist_append_double(plist,"CD2_1", 0. );
4024 cpl_propertylist_append_double(plist,"CD2_2", dy );
4025 cpl_propertylist_append_string(plist,"CTYPE1","PIXEL");
4026 cpl_propertylist_append_string(plist,"CTYPE2","PIXEL");
4027 cpl_propertylist_append_string(plist,"CUNIT1","PIXEL");
4028 cpl_propertylist_append_string(plist,"CUNIT2","PIXEL");
4029
4030 return plist;
4031}
4032
4036static cpl_image*
4037hdrl_resample_util_crea_image_uniform(const cpl_size sx, const cpl_size sy,
4038 const double value)
4039{
4040 assert(value > 0);
4041 cpl_image * image = cpl_image_new(sx, sy, CPL_TYPE_DOUBLE);
4042 cpl_image_add_scalar(image,value);
4043 return image;
4044}
4045
4046static double
4047hdrldemo_get_resampled_pix_value(const char* type, const double pix_value,
4048 const double outlier, cpl_boolean is_bad,
4049 hdrl_resample_method aMethod)
4050{
4051 cpl_size sx = HDRL_SIZE_X;
4052 cpl_size sy = HDRL_SIZE_X;
4053 cpl_size xc = 0.5 * sx;
4054 cpl_size yc = 0.5 * sy;
4055
4056 const double value = pix_value;
4057 const double dx = 0.01;
4058 const double dy = 0.01;
4059 cpl_image* simul = NULL;
4060 cpl_image* errs = NULL;
4061
4062 cpl_test_error(CPL_ERROR_NONE);
4063 if(strcmp(type,"uniform") == 0) {
4064 simul = hdrl_resample_util_crea_image_uniform(sx, sy, value);
4065 } else {
4066 simul = hdrl_resample_util_crea_image_dice_5(sx, sy, value);
4067 }
4068 cpl_test_error(CPL_ERROR_NONE);
4069
4070 char* fname;
4071 if( is_bad ) {
4072 cpl_image_set(simul, xc, yc, outlier);
4073 fname = cpl_sprintf("cube_and_bp.fits");
4074 } else {
4075 fname = cpl_sprintf("cube_not_bp.fits");
4076 }
4077 cpl_free(fname);
4078 cpl_test_error(CPL_ERROR_NONE);
4079 errs = cpl_image_duplicate(simul);
4080 cpl_image_power(errs, 0.5);
4081
4082 /* We need to add wcs */
4083 cpl_propertylist* plist = NULL;
4084 plist = hdrl_resample_util_header_create(sx, sy, dx, dy);
4085 cpl_image_save(simul, "image.fits", CPL_TYPE_DOUBLE,plist,CPL_IO_DEFAULT);
4086 cpl_propertylist_delete(plist);
4087 plist = cpl_propertylist_load("image.fits",0);
4088 cpl_wcs *wcs = cpl_wcs_new_from_propertylist(plist);
4089 cpl_test_nonnull(wcs);
4090 cpl_test_error(CPL_ERROR_NONE);
4091
4092 /* we now create the MUSE table */
4093 cpl_imagelist* ilist = NULL;
4094 cpl_imagelist* elist = NULL;
4095 ilist = cpl_imagelist_new();
4096 elist = cpl_imagelist_new();
4097
4098 cpl_imagelist_set(ilist, simul, 0);
4099 cpl_imagelist_set(elist, errs, 0);
4100 cpl_table* pixel_table = NULL;
4101 hdrl_imagelist* hlist = NULL;
4102 if( is_bad == CPL_TRUE) {
4103 cpl_image* qual = cpl_image_new(sx, sy, CPL_TYPE_INT);
4104 cpl_image_set(qual, xc, yc, 1);
4105 cpl_imagelist* qlist = cpl_imagelist_new();
4106 cpl_imagelist_set(qlist, qual, 0);
4107 hlist = hdrl_imagelist_create(ilist, elist);
4108 pixel_table = hdrl_resample_imagelist_to_table(hlist, wcs);
4109 cpl_imagelist_delete(qlist);
4110 } else {
4111 hlist = hdrl_imagelist_create(ilist, elist);
4112 pixel_table = hdrl_resample_imagelist_to_table(hlist, wcs);
4113 }
4114 cpl_imagelist_delete(ilist);
4115 cpl_imagelist_delete(elist);
4116 hdrl_imagelist_delete(hlist);
4117
4118 cpl_frameset* frameset = cpl_frameset_new();
4119
4120 /* now we resample */
4121 cpl_msg_info(cpl_func,"start resample");
4122
4123 cpl_test_error(CPL_ERROR_NONE);
4124 cpl_wcs_delete(wcs);
4125 cpl_propertylist* p = cpl_propertylist_new();
4126 cpl_propertylist_append_string(p,"CTYPE1", "RA---TAN");
4127 cpl_propertylist_append_string(p,"CTYPE2", "DEC--TAN");
4128 cpl_propertylist_append_double(p,"CRVAL1", 0.);
4129 cpl_propertylist_append_double(p,"CRVAL2", 0.);
4130 cpl_propertylist_append_double(p,"CRPIX1", xc);
4131 cpl_propertylist_append_double(p,"CRPIX2", yc);
4132 cpl_propertylist_append_double(p,"CD1_1", -dx);
4133 cpl_propertylist_append_double(p,"CD1_2", 0.1); /* add rotation if not 0 */
4134 cpl_propertylist_append_double(p,"CD2_1", 0.1); /* add rotation if not 0 */
4135 cpl_propertylist_append_double(p,"CD2_2", dy);
4136 wcs = cpl_wcs_new_from_propertylist(p);
4137 cpl_test_nonnull(wcs);
4138 cpl_propertylist_delete(p);
4139
4140 const double ramin = xc - 0.5*sx*dx;
4141 const double ramax = xc + 0.5*sx*dx;
4142 const double decmin = yc - 0.5*sy*dy;
4143 const double decmax = yc + 0.5*sy*dy;
4144 const double lambmin = 550;
4145 const double lambmax = 551;
4146 const double dlambda = 1;
4147
4148 hdrl_parameter* aParams_outputgrid =
4150 ramin, ramax, decmin, decmax, lambmin, lambmax, 5.);
4151
4152 cpl_boolean use_errorweights = CPL_FALSE;
4153 hdrl_parameter * aParams_method =
4154 hdrl_resample_util_methodparam_create (
4155 LOOP_DISTANCE,
4156 RENKA_CRITICAL_RADIUS,
4157 LANCZOS_KERNEL_SIZE,
4158 DRIZZLE_DOWN_SCALING_FACTOR_X,
4159 DRIZZLE_DOWN_SCALING_FACTOR_Y,
4160 DRIZZLE_DOWN_SCALING_FACTOR_Z,
4161 aMethod, use_errorweights);
4162
4163 hdrl_resample_result *cube = NULL;
4164 cube = hdrl_resample_compute(pixel_table, aParams_method, aParams_outputgrid, wcs);
4165 cpl_test_error(CPL_ERROR_NONE);
4166
4167 hdrl_imagelist* himlist = cube->himlist;
4168 hdrl_image* hima = hdrl_imagelist_get(himlist, 0);
4169 double* data = cpl_image_get_data(hdrl_image_get_image(hima));
4170 cpl_size rsx = hdrl_imagelist_get_size_x(himlist);
4171 cpl_size rsy = hdrl_imagelist_get_size_y(himlist);
4172 cpl_size rpix = 0.5 * rsy * rsx + rsx;
4173
4174 double pix_ref = data[rpix];
4175 cpl_test_error(CPL_ERROR_NONE);
4176 cpl_test_error(CPL_ERROR_NONE);
4177
4178 /* clean memory */
4179 cpl_free(aParams_method);
4180 cpl_wcs_delete(wcs);
4181 hdrl_parameter_destroy(aParams_outputgrid);
4182 cpl_table_delete(pixel_table);
4184 cpl_frameset_delete(frameset);
4185 cpl_propertylist_delete(plist);
4186 return pix_ref;
4187}
4188
4189static cpl_error_code
4190test_resample_image_dice(hdrl_resample_method aMethod)
4191{
4192
4193 /* Create an image with the number 5 of a dice.
4194 Central point is round
4195 Other points are elliptical with major axis oriented along different
4196 directions
4197 */
4198 cpl_test_error(CPL_ERROR_NONE);
4199 double ref_value =
4200 hdrldemo_get_resampled_pix_value("uniform", HDRL_FLUX_ADU, 1000., CPL_FALSE,
4201 aMethod );
4202
4203 double check_value =
4204 hdrldemo_get_resampled_pix_value("uniform", HDRL_FLUX_ADU, 100000., CPL_TRUE,
4205 aMethod);
4206
4207 cpl_test_abs(check_value, ref_value, HDRL_EPS_TEST);
4208 /* possible further tests:
4209 move the image horizontally
4210 move the image vertically
4211 move the image diagonally
4212 rotate the image around a point: around the center, at the edge
4213 over-sample the image
4214 sub-sample the image
4215 */
4216 return cpl_error_get_code();
4217}
4218
4219static hdrl_resample_result *
4220hdrl_resample_util_get_resampled_pix_cube(const char* type, const double pix_value,
4221 const double outlier, cpl_boolean is_bad, const char* suffix)
4222{
4223 cpl_size sx = HDRL_SIZE_X;
4224 cpl_size sy = HDRL_SIZE_Y;
4225 cpl_size xc = 0.5 * sx;
4226 cpl_size yc = 0.5 * sy;
4227 const double value = pix_value;
4228 const double dx = 0.01;
4229 const double dy = 0.01;
4230 cpl_image* simul = NULL;
4231 cpl_image* errs = NULL;
4232
4233 cpl_test_error(CPL_ERROR_NONE);
4234 if(strcmp(type,"uniform") == 0) {
4235 simul = hdrl_resample_util_crea_image_uniform(sx, sy, value);
4236 } else {
4237 simul = hdrl_resample_util_crea_image_dice_5(sx, sy, value);
4238 }
4239 cpl_test_error(CPL_ERROR_NONE);
4240
4241 char* bname;
4242 if( is_bad ) {
4243 cpl_msg_warning(cpl_func,"is bad");
4244 cpl_image_set(simul, xc, yc, outlier);
4245 bname = cpl_sprintf("%s_%s.fits","cube_and_bp",suffix);
4246 } else {
4247 cpl_msg_warning(cpl_func,"is not bad");
4248 bname = cpl_sprintf("%s_%s.fits","cube_not_bp",suffix);
4249 }
4250 cpl_test_error(CPL_ERROR_NONE);
4251
4252 errs = cpl_image_duplicate(simul);
4253 cpl_image_power(errs, 0.5);
4254
4255 /* Add wcs */
4256 cpl_propertylist* plist = NULL;
4257 plist = hdrl_resample_util_header_create(sx, sy, dx, dy);
4258 cpl_image_save(simul, "image.fits", CPL_TYPE_DOUBLE,plist,CPL_IO_DEFAULT);
4259 cpl_propertylist_delete(plist);
4260 plist = cpl_propertylist_load("image.fits",0);
4261 cpl_wcs *wcs = cpl_wcs_new_from_propertylist(plist);
4262 cpl_test_nonnull(wcs);
4263
4264 /* we now create the pixel table */
4265 cpl_imagelist* ilist = NULL;
4266 cpl_imagelist* elist = NULL;
4267 cpl_table* pixel_table = NULL;
4268 ilist = cpl_imagelist_new();
4269 elist = cpl_imagelist_new();
4270 cpl_imagelist_set(ilist, simul, 0);
4271 cpl_imagelist_set(elist, errs, 0);
4272 cpl_test_error(CPL_ERROR_NONE);
4273 cpl_imagelist_save(ilist,bname, CPL_TYPE_DOUBLE, NULL, CPL_IO_DEFAULT);
4274 cpl_imagelist_save(elist,bname, CPL_TYPE_DOUBLE, NULL, CPL_IO_EXTEND);
4275 cpl_test_error(CPL_ERROR_NONE);
4276 hdrl_imagelist* hlist;
4277 if( is_bad == CPL_TRUE) {
4278 cpl_image* qual = cpl_image_new(sx, sy, CPL_TYPE_INT);
4279 cpl_image_set(qual, xc, yc, 1);
4280 cpl_imagelist* qlist = cpl_imagelist_new();
4281 cpl_imagelist_set(qlist, qual, 0);
4282 cpl_imagelist_save(qlist,bname, CPL_TYPE_INT, NULL, CPL_IO_EXTEND);
4283 hlist = hdrl_imagelist_create(ilist, elist);
4284 pixel_table = hdrl_resample_imagelist_to_table(hlist, wcs);
4285 cpl_imagelist_delete(qlist);
4286 } else {
4287 hlist = hdrl_imagelist_create(ilist, elist);
4288 pixel_table = hdrl_resample_imagelist_to_table(hlist, wcs);
4289 }
4290 cpl_test_error(CPL_ERROR_NONE);
4291
4292 cpl_imagelist_delete(ilist);
4293 cpl_imagelist_delete(elist);
4294 hdrl_imagelist_delete(hlist);
4295 cpl_free(bname);
4296 cpl_frameset* frameset = cpl_frameset_new();
4297
4298 /* now we resample */
4299 cpl_msg_info(cpl_func,"start resample");
4300 const double ramin = xc - 0.5*sx*dx;
4301 const double ramax = xc + 0.5*sx*dx;
4302 const double decmin = yc - 0.5*sy*dy;
4303 const double decmax = yc + 0.5*sy*dy;
4304 const double lambmin = 550;
4305 const double lambmax = 551;
4306 const double dlambda = 1;
4307 cpl_wcs_delete(wcs);
4308 cpl_propertylist* p = cpl_propertylist_new();
4309 cpl_propertylist_append_string(p,"CTYPE1", "RA---TAN");
4310 cpl_propertylist_append_string(p,"CTYPE2", "DEC--TAN");
4311 cpl_propertylist_append_double(p,"CRVAL1", 0.);
4312 cpl_propertylist_append_double(p,"CRVAL2", 0.);
4313 cpl_propertylist_append_double(p,"CRPIX1", xc);
4314 cpl_propertylist_append_double(p,"CRPIX2", yc);
4315 cpl_propertylist_append_double(p,"CD1_1", -dx);
4316 cpl_propertylist_append_double(p,"CD1_2", 0.);
4317 cpl_propertylist_append_double(p,"CD2_1", 0.);
4318 cpl_propertylist_append_double(p,"CD2_2", dy);
4319 wcs = cpl_wcs_new_from_propertylist(p);
4320 cpl_propertylist_delete(p);
4321
4322 hdrl_parameter* aParams_outputgrid =
4324 ramin, ramax, decmin, decmax, lambmin, lambmax, 5.);
4325
4326 cpl_boolean use_errorweights = CPL_FALSE;
4327 /* RENKA, LANCZOS, DRIZZLE generate a cube with all flagged pixels */
4328 hdrl_resample_method aMethod = HDRL_RESAMPLE_METHOD_QUADRATIC;
4329 hdrl_parameter * aParams_method =
4330 hdrl_resample_util_methodparam_create (
4331 LOOP_DISTANCE,
4332 RENKA_CRITICAL_RADIUS,
4333 LANCZOS_KERNEL_SIZE,
4334 DRIZZLE_DOWN_SCALING_FACTOR_X,
4335 DRIZZLE_DOWN_SCALING_FACTOR_Y,
4336 DRIZZLE_DOWN_SCALING_FACTOR_Z,
4337 aMethod, use_errorweights);
4338
4339 hdrl_resample_result *cube = NULL;
4340 cube = hdrl_resample_compute(pixel_table, aParams_method,
4341 aParams_outputgrid, wcs);
4342
4343 cpl_msg_info(cpl_func,"end resample");
4344 /* clean memory */
4345 cpl_table_delete(pixel_table);
4346 cpl_wcs_delete(wcs);
4347 hdrl_parameter_destroy(aParams_outputgrid);
4348 hdrl_parameter_destroy(aParams_method);
4349 cpl_frameset_delete(frameset);
4350 cpl_propertylist_delete(plist);
4351
4352 return cube;
4353}
4354
4355static cpl_error_code
4356test_resample_image_with_outlier(void)
4357{
4358 cpl_test_error(CPL_ERROR_NONE);
4359
4360 hdrl_resample_result *cube1 =
4361 hdrl_resample_util_get_resampled_pix_cube("uniform", HDRL_FLUX_ADU, 1000., CPL_FALSE,"one");
4362 hdrl_image* hima1 = hdrl_imagelist_get(cube1->himlist,0);
4363
4364 hdrl_resample_result *cube2 =
4365 hdrl_resample_util_get_resampled_pix_cube("uniform", HDRL_FLUX_ADU, 100000., CPL_FALSE,"two");
4366
4367 hdrl_image* hima2 = hdrl_imagelist_get(cube2->himlist,0);
4368 hdrl_image* hdiff = hdrl_image_sub_image_create(hima1, hima2);
4369 cpl_image* diff = hdrl_image_get_image(hdiff);
4370
4371 cpl_image_save(diff,"diff.fits",CPL_TYPE_DOUBLE,NULL,CPL_IO_DEFAULT);
4372 cpl_test_error(CPL_ERROR_NONE);
4373
4374 cpl_test_abs(0,cpl_image_get_mean(diff), HDRL_EPS_TEST);
4375 cpl_test_abs(0,cpl_image_get_stdev(diff), HDRL_EPS_TEST);
4376 cpl_test_abs(0,cpl_image_get_min(diff), HDRL_EPS_TEST);
4377 cpl_test_abs(0,cpl_image_get_max(diff), HDRL_EPS_TEST);
4378
4379 hdrl_image_delete(hdiff);
4382 cpl_test_error(CPL_ERROR_NONE);
4383 return cpl_error_get_code();
4384}
4385
4386/*----------------------------------------------------------------------------*/
4390/*----------------------------------------------------------------------------*/
4391int main()
4392{
4393 cpl_test_init(PACKAGE_BUGREPORT, CPL_MSG_WARNING);
4394
4395 test_resample_wcs_as_muse();
4396 test_hdrl_resample_wcs_print();
4397 test_hdrl_resample_outgrid_parameter_print();
4398 test_hdrl_resample_method_parameter_print();
4399 test_hdrl_wcs_xy_to_radec();
4400 test_hdrl_resample_pfits_get();
4401 test_hdrl_resample_smallwcs_new();
4402 test_hdrl_resample_pixgrid_delete();
4403 test_hdrl_resample_compute();
4404
4405 test_resample_parameters();
4406 test_hdrl_wcs_to_propertylist();
4407 test_hdrl_resample_image_to_table();
4408 test_hdrl_resample_imagelist_to_table();
4409 test_hdrl_resample_parameter_create_outgrid2D();
4410 test_hdrl_resample_parameter_create_outgrid3D();
4411 test_hdrl_resample_parameter_create_outgrid2D_userdef();
4412 test_hdrl_resample_parameter_create_outgrid3D_userdef();
4413
4414 test_hdrl_resample_weight_function_renka();
4415 test_hdrl_resample_weight_function_linear();
4416 test_hdrl_resample_weight_function_quadratic();
4417 test_hdrl_resample_weight_function_sinc();
4418 test_hdrl_resample_weight_function_lanczos();
4419 test_hdrl_resample_weight_function_drizzle();
4420
4421 test_hdrl_resample_wcs_projplane_from_celestial();
4422 test_hdrl_resample_wcs_pixel_from_celestial_fast();
4423 test_hdrl_resample_compute_size();
4424 test_hdrl_resample_pixgrid_add();
4425 test_hdrl_resample_pixgrid_get_count();
4426 test_hdrl_resample_pixgrid_get_index();
4427 test_hdrl_resample_pixgrid_new();
4428
4429 test_hdrl_resample_wcs_get_scales();
4430 test_hdrl_resample_create_table();
4431 test_hdrl_resample_pixgrid_get_rows();
4432 test_hdrl_resample_pixgrid_create();
4433 test_hdrl_resample_cube_nearest();
4434 test_hdrl_resample_cube_weighted();
4435 test_hdrl_resample_cube();
4436
4437 test_hdrl_resampling_set_outputgrid();
4438 test_hdrl_resample_compute2D_multiple();
4439 test_hdrl_resample_compute3D_multiple();
4440 test_hdrl_resample_inputtable_verify();
4441
4442 test_resample_image_dice(HDRL_RESAMPLE_METHOD_LINEAR);
4443 test_resample_image_dice(HDRL_RESAMPLE_METHOD_QUADRATIC);
4444 test_resample_image_dice(HDRL_RESAMPLE_METHOD_NEAREST);
4445 test_resample_image_dice(HDRL_RESAMPLE_METHOD_RENKA);
4446 test_resample_image_dice(HDRL_RESAMPLE_METHOD_DRIZZLE);
4447 test_resample_image_dice(HDRL_RESAMPLE_METHOD_LANCZOS);
4448
4449 test_resample_image_with_outlier();
4450 return cpl_test_end(0);
4451}
4452
hdrl_image * hdrl_image_sub_image_create(const hdrl_image *self, const hdrl_image *other)
Subtract two images.
cpl_mask * hdrl_image_get_mask(hdrl_image *himg)
get cpl bad pixel mask from image
Definition: hdrl_image.c:157
cpl_image * hdrl_image_get_error(hdrl_image *himg)
get error as cpl image
Definition: hdrl_image.c:131
const cpl_mask * hdrl_image_get_mask_const(const hdrl_image *himg)
get cpl bad pixel mask from image
Definition: hdrl_image.c:175
const cpl_image * hdrl_image_get_error_const(const hdrl_image *himg)
get error as cpl image
Definition: hdrl_image.c:144
hdrl_image * hdrl_image_create(const cpl_image *image, const cpl_image *error)
create a new hdrl_image from to existing images by copying them
Definition: hdrl_image.c:295
cpl_image * hdrl_image_get_image(hdrl_image *himg)
get data as cpl image
Definition: hdrl_image.c:105
const cpl_image * hdrl_image_get_image_const(const hdrl_image *himg)
get data as cpl image
Definition: hdrl_image.c:118
void hdrl_image_delete(hdrl_image *himg)
delete hdrl_image
Definition: hdrl_image.c:379
cpl_size hdrl_imagelist_get_size_y(const hdrl_imagelist *himlist)
Get number of rows of images in the imagelist.
hdrl_imagelist * hdrl_imagelist_create(cpl_imagelist *imlist, cpl_imagelist *errlist)
Create an hdrl_imagelist out of 2 cpl_imagelist.
void hdrl_imagelist_delete(hdrl_imagelist *himlist)
Free all memory used by a hdrl_imagelist object including the images.
const hdrl_image * hdrl_imagelist_get_const(const hdrl_imagelist *himlist, cpl_size inum)
Get an image from a list of images.
cpl_size hdrl_imagelist_get_size(const hdrl_imagelist *himlist)
Get the number of images in the imagelist.
cpl_size hdrl_imagelist_get_size_x(const hdrl_imagelist *himlist)
Get number of colums of images in the imagelist.
hdrl_image * hdrl_imagelist_get(const hdrl_imagelist *himlist, cpl_size inum)
Get an image from a list of images.
void hdrl_parameter_destroy(hdrl_parameter *obj)
deep delete of a parameter
void hdrl_parameter_delete(hdrl_parameter *obj)
shallow delete of a parameter
hdrl_parameter * hdrl_resample_parameter_create_nearest(void)
Creates a resample nearest neighbor hdrl parameter object. The algorithm does not use any weighting f...
cpl_error_code hdrl_resample_parameter_method_verify(const hdrl_parameter *hp)
verify parameters have proper values
int hdrl_resample_parameter_method_check(const hdrl_parameter *self)
check method is of proper type
hdrl_parameter * hdrl_resample_parameter_create_renka(const int loop_distance, cpl_boolean use_errorweights, const double critical_radius)
Creates a resample renka hdrl parameter object. The algorithm uses a modified Shepard-like distance w...
hdrl_parameter * hdrl_resample_parameter_create_lanczos(const int loop_distance, cpl_boolean use_errorweights, const int kernel_size)
Creates a resample Lanczos hdrl parameter object. The algorithm uses a restricted SINC distance weigh...
hdrl_parameter * hdrl_resample_parameter_create_drizzle(const int loop_distance, cpl_boolean use_errorweights, const double pix_frac_x, const double pix_frac_y, const double pix_frac_lambda)
Creates a resample drizzle hdrl parameter object. The algorithm uses a drizzle-like distance weightin...
hdrl_parameter * hdrl_resample_parameter_create_quadratic(const int loop_distance, cpl_boolean use_errorweights)
Creates a resample quadratic hdrl parameter object. The algorithm uses a quadratic inverse distance w...
hdrl_parameter * hdrl_resample_parameter_create_linear(const int loop_distance, cpl_boolean use_errorweights)
Creates a resample linear hdrl parameter object. The algorithm uses a linear inverse distance weighti...
hdrl_parameter * hdrl_resample_parameter_create_outgrid3D(const double delta_ra, const double delta_dec, const double delta_lambda)
Creates a resample_outgrid hdrl parameter object for a 3 dimensional interpolation,...
hdrl_parameter * hdrl_resample_parameter_create_outgrid3D_userdef(const double delta_ra, const double delta_dec, const double delta_lambda, const double ra_min, const double ra_max, const double dec_min, const double dec_max, const double lambda_min, const double lambda_max, const double fieldmargin)
Creates a resample_outgrid hdrl parameter object for a 3 dimensional interpolation,...
int hdrl_resample_parameter_outgrid_check(const hdrl_parameter *self)
check method is of proper type
hdrl_parameter * hdrl_resample_parameter_create_outgrid2D(const double delta_ra, const double delta_dec)
Creates a resample_outgrid hdrl parameter object for a 2 dimensional interpolation,...
hdrl_parameter * hdrl_resample_parameter_create_outgrid2D_userdef(const double delta_ra, const double delta_dec, const double ra_min, const double ra_max, const double dec_min, const double dec_max, const double fieldmargin)
Creates a resample_outgrid hdrl parameter object for a 2 dimensional interpolation,...
cpl_error_code hdrl_resample_parameter_outgrid_verify(const hdrl_parameter *hp)
verify parameters have proper values
hdrl_resample_result * hdrl_resample_compute(const cpl_table *ResTable, hdrl_parameter *method, hdrl_parameter *outputgrid, const cpl_wcs *wcs)
High level resampling function.
void hdrl_resample_result_delete(hdrl_resample_result *aCube)
Deallocates the memory associated to a hdrl_resample_result object.
cpl_table * hdrl_resample_image_to_table(const hdrl_image *hima, const cpl_wcs *wcs)
Convert a hdrl image into a cpl table that can be given as input to hdrl_resample_compute()
cpl_table * hdrl_resample_imagelist_to_table(const hdrl_imagelist *himlist, const cpl_wcs *wcs)
Convert a hdrl imagelist into a cpl table that can be given as input to hdrl_resample_compute().