35#define omp_get_max_threads() 1
36#define omp_get_thread_num() 0
48#if !defined(_POSIX_C_SOURCE)
49#define _POSIX_C_SOURCE 200112L
50#elif (_POSIX_C_SOURCE - 0) < 200112L
52#define _POSIX_C_SOURCE 200112L
57#define KEYWORD_LENGTH 81
65#define PT_IDX_MASK 0x1FFFFFFFFFFFFFll
69#define XMAP_BITMASK 0x3FFll
70#define XMAP_LSHIFT 53ll
75 double cd11, cd12, cd21, cd22;
210 double delta_lambda ;
212 cpl_boolean recalc_limits;
220} hdrl_resample_outgrid_parameter;
223static hdrl_parameter_typeobj hdrl_resample_outgrid_parameter_type = {
224 HDRL_PARAMETER_RESAMPLE_OUTGRID,
228 sizeof(hdrl_resample_outgrid_parameter),
236 cpl_boolean use_errorweights;
240 double drizzle_pix_frac_x;
241 double drizzle_pix_frac_y;
242 double drizzle_pix_frac_lambda;
244 double renka_critical_radius;
246 int lanczos_kernel_size;
247} hdrl_resample_method_parameter;
250static hdrl_parameter_typeobj hdrl_resample_method_parameter_type = {
251 HDRL_PARAMETER_RESAMPLE_METHOD,
255 sizeof(hdrl_resample_method_parameter),
264hdrl_resample_cube(
const cpl_table *ResTable,
265 hdrl_resample_method_parameter *aParams_method,
266 hdrl_resample_outgrid_parameter *aParams_outputgrid,
270hdrl_resample_inputtable_verify(
const cpl_table *ResTable);
281hdrl_resample_wcs_print(
const cpl_wcs *wcs)
283 cpl_ensure_code(wcs, CPL_ERROR_NULL_INPUT);
285 const cpl_array *crval = cpl_wcs_get_crval(wcs);
286 const cpl_array *crpix = cpl_wcs_get_crpix(wcs);
287 const cpl_array *ctype = cpl_wcs_get_ctype(wcs);
288 const cpl_array *cunit = cpl_wcs_get_cunit(wcs);
290 const cpl_matrix *cd = cpl_wcs_get_cd(wcs);
291 const cpl_array *dims = cpl_wcs_get_image_dims(wcs);
292 int naxis = cpl_wcs_get_image_naxis(wcs);
294 cpl_msg_debug(cpl_func,
"NAXIS: %d", naxis);
298 cpl_msg_indent_more();
300 for (cpl_size i = 0; i < naxis; i++) {
301 cpl_msg_debug(cpl_func,
"NAXIS%lld: %d", i + 1,
302 cpl_array_get_int(dims, i, &testerr));
304 cpl_msg_indent_less();
306 double cd11 = cpl_matrix_get(cd, 0, 0);
307 double cd12 = cpl_matrix_get(cd, 0, 1);
308 double cd21 = cpl_matrix_get(cd, 1, 0);
309 double cd22 = cpl_matrix_get(cd, 1, 1);
310 double crpix1 = cpl_array_get_double(crpix, 0, &testerr);
311 double crpix2 = cpl_array_get_double(crpix, 1, &testerr);
312 double crval1 = cpl_array_get_double(crval, 0, &testerr);
313 double crval2 = cpl_array_get_double(crval, 1, &testerr);
315 cpl_msg_debug(cpl_func,
"1st and 2nd dimension");
316 cpl_msg_indent_more();
317 cpl_msg_debug(cpl_func,
"CD1_1: %g", cd11);
318 cpl_msg_debug(cpl_func,
"CD1_2: %g", cd12);
319 cpl_msg_debug(cpl_func,
"CD2_1: %g", cd21);
320 cpl_msg_debug(cpl_func,
"CD2_2: %g", cd22);
322 cpl_msg_debug(cpl_func,
"CRPIX1: %g", crpix1);
323 cpl_msg_debug(cpl_func,
"CRPIX2: %g", crpix2);
324 cpl_msg_debug(cpl_func,
"CRVAL1: %g", crval1);
325 cpl_msg_debug(cpl_func,
"CRVAL2: %g", crval2);
327 cpl_msg_debug(cpl_func,
"CTYPE1: %s", cpl_array_get_string(ctype, 0));
328 cpl_msg_debug(cpl_func,
"CTYPE2: %s", cpl_array_get_string(ctype, 1));
332 cpl_msg_debug(cpl_func,
"CUNIT1: %s", cpl_array_get_string(cunit, 0));
333 cpl_msg_debug(cpl_func,
"CUNIT2: %s", cpl_array_get_string(cunit, 1));
335 cpl_msg_indent_less();
338 cpl_size cdncol = cpl_matrix_get_ncol(cd);
341 double cd13 = cpl_matrix_get(cd, 0, 2);
342 double cd23 = cpl_matrix_get(cd, 1, 2);
343 double cd31 = cpl_matrix_get(cd, 2, 0);
344 double cd32 = cpl_matrix_get(cd, 2, 1);
345 double cd33 = cpl_matrix_get(cd, 2, 2);
346 double crval3 = cpl_array_get_double(crval, 2, &testerr);
347 double crpix3 = cpl_array_get_double(crpix, 2, &testerr);
349 cpl_msg_debug(cpl_func,
"3rd dimension");
350 cpl_msg_indent_more();
351 cpl_msg_debug(cpl_func,
"CD1_3: %g", cd13);
352 cpl_msg_debug(cpl_func,
"CD2_3: %g", cd23);
353 cpl_msg_debug(cpl_func,
"CD3_1: %g", cd31);
354 cpl_msg_debug(cpl_func,
"CD3_2: %g", cd32);
355 cpl_msg_debug(cpl_func,
"CD3_3: %g", cd33);
357 cpl_msg_debug(cpl_func,
"CRPIX3: %g", crpix3);
358 cpl_msg_debug(cpl_func,
"CRVAL3: %g", crval3);
361 cpl_msg_debug(cpl_func,
"CTYPE3: %s", cpl_array_get_string(ctype, 2));
365 cpl_msg_debug(cpl_func,
"CUNIT3: %s", cpl_array_get_string(cunit, 2));
368 cpl_msg_indent_less();
371 return cpl_error_get_code();
382hdrl_resample_outgrid_parameter_print(hdrl_resample_outgrid_parameter* p)
385 cpl_ensure_code(p, CPL_ERROR_NULL_INPUT);
388 cpl_msg_indent_more();
389 cpl_msg_debug(cpl_func,
"delta_ra: %g", p->delta_ra);
390 cpl_msg_debug(cpl_func,
"delta_dec: %g", p->delta_dec);
391 cpl_msg_debug(cpl_func,
"delta_lambda: %g", p->delta_lambda);
392 cpl_msg_debug(cpl_func,
"ra_min: %g", p->ra_min);
393 cpl_msg_debug(cpl_func,
"ra_max: %g", p->ra_max);
394 cpl_msg_debug(cpl_func,
"dec_min: %g", p->dec_min);
395 cpl_msg_debug(cpl_func,
"dec_max: %g", p->dec_max);
396 cpl_msg_debug(cpl_func,
"lambda_min: %g", p->lambda_min);
397 cpl_msg_debug(cpl_func,
"lambda_max: %g", p->lambda_max);
398 cpl_msg_debug(cpl_func,
"fieldmargin: %g", p->fieldmargin);
399 cpl_msg_debug(cpl_func,
"recalc_limits: %d", p->recalc_limits);
402 hdrl_resample_wcs_print(p->wcs);
403 cpl_msg_indent_less();
404 return cpl_error_get_code();
415hdrl_resample_method_parameter_print(hdrl_resample_method_parameter* p)
418 return cpl_error_get_code();
423 cpl_msg_indent_more();
425 cpl_msg_debug(cpl_func,
"method: %s",
"NEAREST" );
427 cpl_msg_debug(cpl_func,
"method: %s",
"RENKA" );
428 cpl_msg_debug(cpl_func,
"loop_distance: %d", p->loop_distance);
429 cpl_msg_debug(cpl_func,
"use_errorweights: %s",
430 p->use_errorweights == CPL_TRUE ?
"TRUE" :
"FALSE");
431 cpl_msg_debug(cpl_func,
"renka_critical_radius: %g", p->renka_critical_radius);
433 cpl_msg_debug(cpl_func,
"method: %s",
"LINEAR" );
434 cpl_msg_debug(cpl_func,
"loop_distance: %d", p->loop_distance);
435 cpl_msg_debug(cpl_func,
"use_errorweights: %s",
436 p->use_errorweights == CPL_TRUE ?
"TRUE" :
"FALSE");
438 cpl_msg_debug(cpl_func,
"method: %s",
"QUADRATIC)" );
439 cpl_msg_debug(cpl_func,
"loop_distance: %d", p->loop_distance);
440 cpl_msg_debug(cpl_func,
"use_errorweights: %s",
441 p->use_errorweights == CPL_TRUE ?
"TRUE" :
"FALSE");
443 cpl_msg_debug(cpl_func,
"method: %s",
"DRIZZLE" );
444 cpl_msg_debug(cpl_func,
"loop_distance: %d", p->loop_distance);
445 cpl_msg_debug(cpl_func,
"use_errorweights: %s",
446 p->use_errorweights == CPL_TRUE ?
"TRUE" :
"FALSE");
447 cpl_msg_debug(cpl_func,
"drizzle_pix_frac_x: %g", p->drizzle_pix_frac_x);
448 cpl_msg_debug(cpl_func,
"drizzle_pix_frac_y: %g", p->drizzle_pix_frac_y);
449 cpl_msg_debug(cpl_func,
"drizzle_pix_frac_lambda: %g", p->drizzle_pix_frac_lambda);
451 cpl_msg_debug(cpl_func,
"method: %s",
"LANCZOS" );
452 cpl_msg_debug(cpl_func,
"loop_distance: %d", p->loop_distance);
453 cpl_msg_debug(cpl_func,
"use_errorweights: %s",
454 p->use_errorweights == CPL_TRUE ?
"TRUE" :
"FALSE");
455 cpl_msg_debug(cpl_func,
"lanczos_kernel_size: %d", p->lanczos_kernel_size);
458 cpl_msg_indent_less();
459 return cpl_error_get_code();
477hdrl_wcs_xy_to_radec(
const cpl_wcs *wcs,
double x,
double y,
double *ra,
479 cpl_ensure_code(wcs && ra && dec, CPL_ERROR_NULL_INPUT);
481 double * radec = NULL;
482 cpl_matrix * from = NULL;
483 cpl_matrix * to = NULL;
484 cpl_array * status = NULL;
487 int naxis = cpl_wcs_get_image_naxis(wcs);
488 from = cpl_matrix_new(1, naxis);
489 xy = cpl_matrix_get_data(from);
495 cpl_wcs_convert(wcs, from, &to, &status, CPL_WCS_PHYS2WORLD);
499 radec = cpl_matrix_get_data(to);
505 cpl_matrix_delete(from);
506 cpl_matrix_delete(to);
507 cpl_array_delete(status);
508 return cpl_error_get_code();
523hdrl_resample_pfits_get_crpix(
const cpl_propertylist *aHeaders,
unsigned int aAxis)
525 cpl_errorstate prestate = cpl_errorstate_get();
526 cpl_ensure(aHeaders, CPL_ERROR_NULL_INPUT, 0);
530 const double value = cpl_propertylist_get_double(aHeaders, keyword);
532 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
547hdrl_resample_pfits_get_crval(
const cpl_propertylist *aHeaders,
unsigned int aAxis)
549 cpl_errorstate prestate = cpl_errorstate_get();
550 cpl_ensure(aHeaders, CPL_ERROR_NULL_INPUT, 0);
554 const double value = cpl_propertylist_get_double(aHeaders, keyword);
556 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
572hdrl_resample_pfits_get_cd(
const cpl_propertylist *aHeaders,
unsigned int aAxisI,
575 cpl_errorstate prestate = cpl_errorstate_get();
576 cpl_ensure(aHeaders, CPL_ERROR_NULL_INPUT, 0);
580 const double value = cpl_propertylist_get_double(aHeaders, keyword);
582 cpl_ensure(cpl_errorstate_is_equal(prestate), cpl_error_get_code(), 0.0);
605hdrl_resample_smallwcs_new(cpl_propertylist *aHeader)
608 cpl_ensure(aHeader, CPL_ERROR_NULL_INPUT, NULL);
611 cpl_errorstate prestate = cpl_errorstate_get();
612 wcs->
crpix1 = hdrl_resample_pfits_get_crpix(aHeader, 1);
613 wcs->
crpix2 = hdrl_resample_pfits_get_crpix(aHeader, 2);
614 wcs->
crval1 = hdrl_resample_pfits_get_crval(aHeader, 1);
615 wcs->
crval2 = hdrl_resample_pfits_get_crval(aHeader, 2);
616 if (!cpl_errorstate_is_equal(prestate)) {
619 cpl_errorstate_set(prestate);
622 prestate = cpl_errorstate_get();
623 wcs->
cd11 = hdrl_resample_pfits_get_cd(aHeader, 1, 1);
624 wcs->
cd22 = hdrl_resample_pfits_get_cd(aHeader, 2, 2);
625 wcs->
cd12 = hdrl_resample_pfits_get_cd(aHeader, 1, 2);
626 wcs->
cd21 = hdrl_resample_pfits_get_cd(aHeader, 2, 1);
627 if (!cpl_errorstate_is_equal(prestate) &&
632 cpl_errorstate_set(prestate);
635 if (wcs->
cddet == 0.) {
636 cpl_error_set(cpl_func, CPL_ERROR_SINGULAR_MATRIX);
655 cpl_free(aGrid->
pix);
659 for (ix = 0; ix < aGrid->
nmaps; ix++) {
661 for (iext = 0; iext < aGrid->
nxalloc[ix]; iext++) {
662 cpl_free(aGrid->
xmaps[ix][iext].
pix);
665 cpl_free(aGrid->
xmaps[ix]);
667 cpl_free(aGrid->
xmaps);
669 cpl_free(aGrid->
nxmap);
740 cpl_ensure(ResTable && method, CPL_ERROR_NULL_INPUT, NULL);
741 cpl_ensure(wcs != NULL, CPL_ERROR_NULL_INPUT, NULL);
743 if (hdrl_resample_inputtable_verify(ResTable)) {
753 if (hdrl_resample_inputtable_verify(ResTable)) {
757 hdrl_resample_outgrid_parameter *aParams_outputgrid =
758 (hdrl_resample_outgrid_parameter *) outputgrid;
759 hdrl_resample_method_parameter *aParams_method =
760 (hdrl_resample_method_parameter *) method;
763 aParams_outputgrid->wcs = wcs;
766 cpl_boolean recalc_limits = aParams_outputgrid->recalc_limits;
768 if (recalc_limits == CPL_TRUE) {
777 if(ramax - ramin > 180){
778 const double *ra = cpl_table_get_data_double_const(ResTable,
784 cpl_size nrow = cpl_table_get_nrow(ResTable);
786 for (cpl_size i = 0; i < nrow; i++) {
787 if (ra[i] > ramin && ra[i] <= 180.) ramin = ra[i];
788 if (ra[i] < ramax && ra[i] > 180.) ramax = ra[i];
792 aParams_outputgrid->ra_min = ramin;
793 aParams_outputgrid->ra_max = ramax;
794 aParams_outputgrid->dec_min = decmin;
795 aParams_outputgrid->dec_max = decmax;
796 aParams_outputgrid->lambda_min = lmin;
797 aParams_outputgrid->lambda_max = lmax;
800 cpl_msg_debug(cpl_func,
"Content of the outgrid parameter structure "
801 "hdrl_resample_outgrid_parameter when resampling starts:");
802 hdrl_resample_outgrid_parameter_print(aParams_outputgrid);
804 cpl_msg_debug(cpl_func,
"Content of the method parameter structure "
805 "hdrl_resample_method_parameter when resampling starts:");
806 hdrl_resample_method_parameter_print(aParams_method);
812 cpl_msg_debug(cpl_func,
"Resampling starts ...");
813 cpl_msg_indent_more();
814 cube = hdrl_resample_cube(ResTable,
815 (hdrl_resample_method_parameter *)aParams_method,
816 (hdrl_resample_outgrid_parameter *)aParams_outputgrid,
818 cpl_msg_indent_less();
819 cpl_ensure(cube, CPL_ERROR_NULL_INPUT, NULL);
820 cpl_ensure(cube->
header, CPL_ERROR_NULL_INPUT, NULL);
821 cpl_ensure(cube->
himlist, CPL_ERROR_NULL_INPUT, NULL);
826 cpl_propertylist *header = cpl_propertylist_new();
827 cpl_wcs* wcs_local = cpl_wcs_new_from_propertylist(cube->
header);
828 hdrl_wcs_to_propertylist(wcs_local, header, CPL_TRUE);
829 cpl_wcs_delete(wcs_local);
830 cpl_propertylist_delete(cube->
header);
831 cpl_propertylist_set_comment(header,
"CTYPE1",
"Gnomonic projection");
832 cpl_propertylist_set_comment(header,
"CTYPE2",
"Gnomonic projection");
837 hdrl_resample_pixgrid_delete(grid);
861 cpl_propertylist_delete(aCube->
header);
896hdrl_resample_wcs_projplane_from_celestial(hdrl_resample_outgrid_parameter *
897 aParams_outputgrid,
double aRA,
898 double aDEC,
double *aX,
double *aY)
900 cpl_ensure_code(aParams_outputgrid && aX && aY, CPL_ERROR_NULL_INPUT);
911 const cpl_array *crval = cpl_wcs_get_crval(aParams_outputgrid->wcs);
912 double crval1 = cpl_array_get_double(crval, 0, &err);
913 double crval2 = cpl_array_get_double(crval, 1, &err);
916 double a = aRA / CPL_MATH_DEG_RAD,
917 d = aDEC / CPL_MATH_DEG_RAD,
921 ap = crval1 / CPL_MATH_DEG_RAD,
922 dp = crval2 / CPL_MATH_DEG_RAD,
923 phi = atan2(-cos(d) * sin(a - ap),
924 sin(d) * cos(dp) - cos(d) * sin(dp) * cos(a-ap))
925 + 180 / CPL_MATH_DEG_RAD,
926 theta = asin(sin(d) * sin(dp) + cos(d) * cos(dp) * cos(a-ap)),
927 R_theta = CPL_MATH_DEG_RAD / tan(theta);
929 *aX = R_theta * sin(phi),
930 *aY = -R_theta * cos(phi);
932 return CPL_ERROR_NONE;
956 double aRA,
double aDEC,
double *aX,
double *aY)
964 double phi = atan2(-cos(aDEC) * sin(aRA - aWCS->
crval1),
965 sin(aDEC) * cos(aWCS->
crval2)
966 - cos(aDEC) * sin(aWCS->
crval2) * cos(aRA - aWCS->
crval1))
967 + 180 / CPL_MATH_DEG_RAD,
968 theta = asin(sin(aDEC) * sin(aWCS->
crval2)
969 + cos(aDEC) * cos(aWCS->
crval2) * cos(aRA - aWCS->
crval1)),
970 R_theta = CPL_MATH_DEG_RAD / tan(theta);
972 double x = R_theta * sin(phi),
973 y = -R_theta * cos(phi);
996hdrl_resample_wcs_get_scales(hdrl_resample_outgrid_parameter *aParams_outputgrid,
997 double *aXScale,
double *aYScale);
1000hdrl_resample_compute_size(hdrl_resample_outgrid_parameter *aParams_outputgrid,
1001 int *aX,
int *aY,
int *aZ)
1003 cpl_ensure_code(aParams_outputgrid && aX && aY && aZ, CPL_ERROR_NULL_INPUT);
1004 const char func[] =
"hdrl_resample_compute_size";
1005 double x1, y1, x2, y2;
1011 if (aParams_outputgrid->wcs) {
1012 double wcs_delta_ra, wcs_delta_dec;
1013 if (hdrl_resample_wcs_get_scales(aParams_outputgrid, &wcs_delta_ra, &wcs_delta_dec)
1014 == CPL_ERROR_NONE) {
1016 const double BUG_THRESHOLD = 0.01;
1017 if (fabs(wcs_delta_ra) > 1e-15 &&
1018 fabs(aParams_outputgrid->delta_ra) < BUG_THRESHOLD * fabs(wcs_delta_ra)) {
1019 aParams_outputgrid->delta_ra = wcs_delta_ra;
1021 if (fabs(wcs_delta_dec) > 1e-15 &&
1022 fabs(aParams_outputgrid->delta_dec) < BUG_THRESHOLD * fabs(wcs_delta_dec)) {
1023 aParams_outputgrid->delta_dec = wcs_delta_dec;
1028 double ramin = aParams_outputgrid->ra_min;
1029 double ramax = aParams_outputgrid->ra_max;
1030 double decmin = aParams_outputgrid->dec_min;
1031 double decmax = aParams_outputgrid->dec_max;
1032 hdrl_resample_wcs_projplane_from_celestial(aParams_outputgrid, ramin, decmin,
1034 hdrl_resample_wcs_projplane_from_celestial(aParams_outputgrid, ramax, decmax,
1036 *aX = lround(fabs(x2 - x1) / aParams_outputgrid->delta_ra) + 1;
1037 *aY = lround(fabs(y2 - y1) / aParams_outputgrid->delta_dec) + 1;
1039 double lmin = aParams_outputgrid->lambda_min;
1040 double lmax = aParams_outputgrid->lambda_max;
1042 *aZ = (int)ceil((lmax - lmin) / aParams_outputgrid->delta_lambda) + 1;
1044 cpl_msg_debug(func,
"Output cube size %d x %d x %d (fit to data)",
1046 return CPL_ERROR_NONE;
1068 cpl_size aRow,
unsigned short aXIdx)
1071 if (aIndex < 0 || aGrid == NULL) {
1075 if (aGrid->
pix[aIndex] == 0 && aRow > 0) {
1077 aGrid->
pix[aIndex] = aRow;
1078 }
else if (aGrid->
pix[aIndex] == 0 && aRow == 0) {
1080 cpl_size iext = aGrid->
nxmap[aXIdx]++;
1084 aGrid->
xmaps[aXIdx] = cpl_realloc(aGrid->
xmaps[aXIdx],
1089 aGrid->
xmaps[aXIdx][iext].
pix = cpl_malloc(
sizeof(cpl_size));
1090 aGrid->
xmaps[aXIdx][iext].
pix[0] = aRow;
1091 aGrid->
pix[aIndex] = -(iext + 1 + ((cpl_size)aXIdx <<
XMAP_LSHIFT));
1092 }
else if (aGrid->
pix[aIndex] > 0) {
1094 cpl_size iext = aGrid->
nxmap[aXIdx]++;
1098 aGrid->
xmaps[aXIdx] = cpl_realloc(aGrid->
xmaps[aXIdx],
1103 aGrid->
xmaps[aXIdx][iext].
pix = cpl_malloc(2 *
sizeof(cpl_size));
1104 aGrid->
xmaps[aXIdx][iext].
pix[0] = aGrid->
pix[aIndex];
1105 aGrid->
xmaps[aXIdx][iext].
pix[1] = aRow;
1106 aGrid->
pix[aIndex] = -(iext + 1 + ((cpl_size)aXIdx <<
XMAP_LSHIFT));
1111 unsigned int ipix = aGrid->
xmaps[aXIdx][iext].
npix;
1114 (ipix + 1) *
sizeof(cpl_size));
1115 aGrid->
xmaps[aXIdx][iext].
pix[ipix] = aRow;
1129static inline cpl_size
1132 if (aIndex < 0 || aGrid == NULL) {
1136 cpl_size p = aGrid->
pix[aIndex];
1165static inline cpl_size
1167 cpl_size aY, cpl_size aZ, cpl_boolean aAllowOutside)
1169 if (aGrid == NULL) {
1172 if (!aAllowOutside &&
1173 (aX < 0 || aX >= aGrid->
nx || aY < 0 || aY >= aGrid->
ny ||
1174 aZ < 0 || aZ >= aGrid->
nz)) {
1180 if (aX >= aGrid->
nx) {
1186 if (aY >= aGrid->
ny) {
1192 if (aZ >= aGrid->
nz) {
1195 return aX + aGrid->
nx * (aY + aGrid->
ny * aZ);
1210hdrl_resample_pixgrid_new(cpl_size aSizeX, cpl_size aSizeY, cpl_size aSizeZ,
1211 unsigned short aNMaps)
1213 cpl_ensure(aSizeX > 0 && aSizeY > 0 && aSizeZ > 0 && aNMaps > 0,
1214 CPL_ERROR_ILLEGAL_INPUT, NULL);
1216 pixels->
nx = aSizeX;
1217 pixels->
ny = aSizeY;
1218 pixels->
nz = aSizeZ;
1219 pixels->
pix = cpl_calloc(aSizeX * aSizeY * aSizeZ,
sizeof(cpl_size));
1221 pixels->
nmaps = aNMaps;
1222 pixels->
nxalloc = cpl_calloc(aNMaps,
sizeof(cpl_size));
1224 pixels->
nxmap = cpl_calloc(aNMaps,
sizeof(cpl_size));
1263hdrl_resample_pixgrid_create(
const cpl_table *ResTable, cpl_propertylist *aHeader,
1264 cpl_size aXSize, cpl_size aYSize, cpl_size aZSize)
1266 cpl_ensure(ResTable, CPL_ERROR_NULL_INPUT, NULL);
1267 cpl_ensure(aHeader, CPL_ERROR_NULL_INPUT, NULL);
1268 cpl_size nrow = cpl_table_get_nrow(ResTable);
1270 cpl_msg_error(cpl_func,
"Invalid pixel table (no entries?)");
1271 cpl_error_set(cpl_func, CPL_ERROR_NULL_INPUT);
1274 cpl_ensure(aXSize > 0 && aYSize > 0 && aZSize > 0, CPL_ERROR_ILLEGAL_INPUT,
1278 double crval3 = hdrl_resample_pfits_get_crval(aHeader, 3),
1279 crpix3 = hdrl_resample_pfits_get_crpix(aHeader, 3),
1280 cd33 = hdrl_resample_pfits_get_cd(aHeader, 3, 3);
1289 if (!xpos || !ypos || !lbda) {
1290 cpl_msg_error(cpl_func,
"Missing pixel table column (%p %p %p): %s",
1291 (
void *)xpos, (
void *)ypos, (
void *)lbda,
1292 cpl_error_get_message());
1293 cpl_error_set(cpl_func, CPL_ERROR_DATA_NOT_FOUND);
1298 wcs->
crval1 /= CPL_MATH_DEG_RAD;
1299 wcs->
crval2 /= CPL_MATH_DEG_RAD;
1301 double timeinit = cpl_test_get_walltime(),
1302 timeprogress = timeinit,
1303 cpuinit = cpl_test_get_cputime();
1304 cpl_boolean showprogress = cpl_msg_get_level() == CPL_MSG_DEBUG
1305 || cpl_msg_get_log_level() == CPL_MSG_DEBUG;
1311 cpl_array *asel = NULL;
1312 const cpl_size *sel = NULL;
1313 cpl_size nsel = cpl_table_count_selected(ResTable);
1315 asel = cpl_table_where_selected(ResTable);
1316 sel = cpl_array_get_data_cplsize_const(asel);
1324 cpl_array *az1 = cpl_array_new(nth, CPL_TYPE_INT),
1325 *az2 = cpl_array_new(nth, CPL_TYPE_INT);
1328 cpl_array_fill_window_int(az1, aZSize, nth, -1);
1329 cpl_array_fill_window_int(az2, aZSize, nth, -2);
1332 double base = nth > aZSize ? 1. : (double)aZSize / nth;
1334 for (ith = 0; ith < nth && ith < aZSize; ith++) {
1335 cpl_array_set_int(az1, ith, lround(base * ith));
1336 cpl_array_set_int(az2, ith, lround(base * (ith + 1) - 1));
1342 cpl_array_set_int(az1, 0, -INT_MAX / 2 + 1);
1343 cpl_array_set_int(az2, ith - 1, INT_MAX / 2 - 1);
1350 struct timeval tv1, tv2;
1352 cpl_msg_debug(cpl_func,
"Starting parallel loop in hdrl_resample_pixgrid_create");
1353 gettimeofday(&tv1, NULL);
1355#pragma omp parallel num_threads(nth) \
1356 shared(aXSize, aYSize, aZSize, az1, az2, cd33, crpix3, crval3, grid, \
1357 lbda, nsel, sel, showprogress, \
1358 timeinit, timeprogress, wcs, xpos, ypos)
1363 int z1 = cpl_array_get_int(az1, ithread, NULL),
1364 z2 = cpl_array_get_int(az2, ithread, NULL),
1365 zrange = z2 - z1 + 1;
1372 for (isel = 0 ; zrange > 0 && isel < nsel; isel++) {
1374 if (showprogress && !((isel+1) % 1000000ll)) {
1375 double timenow = cpl_test_get_walltime();
1376 if (timenow - timeprogress > 30.) {
1377 timeprogress = timenow;
1378 double percent = 100. * (isel + 1.) / nsel,
1379 elapsed = timeprogress - timeinit,
1380 remaining = (100. - percent) * elapsed / percent;
1383 cpl_msg_info_overwritable(cpl_func,
"pixel grid creation is %.1f%% "
1384 "complete, %.1fs elapsed, ~%.1fs remaining",
1385 percent, elapsed, remaining);
1391 cpl_size n = sel ? sel[isel] : isel;
1394 z = lround((lbda[n] - crval3) / cd33 + crpix3) - 1;
1396 if (z < z1 || z > z2) {
1401 double xpx = 0., ypx = 0.;
1403 hdrl_resample_wcs_pixel_from_celestial_fast(wcs, (xpos[n]) / CPL_MATH_DEG_RAD,
1404 (ypos[n]) / CPL_MATH_DEG_RAD,
1407 int x = lround(xpx) - 1,
1408 y = lround(ypx) - 1;
1409 cpl_size idx = hdrl_resample_pixgrid_get_index(grid, x, y, z, CPL_TRUE);
1413 hdrl_resample_pixgrid_add(grid, idx, n, ithread);
1418 grid->
xmaps[ithread] = cpl_realloc(grid->
xmaps[ithread],
1419 grid->
nxmap[ithread]
1424 gettimeofday(&tv2, NULL);
1425 cpl_msg_debug(cpl_func,
"Wall time for hdrl_resample_pixgrid_create was %f seconds\n",
1426 (
double) (tv2.tv_usec - tv1.tv_usec) / 1000000 +
1427 (
double) (tv2.tv_sec - tv1.tv_sec));
1429 cpl_array_delete(asel);
1431 cpl_array_delete(az1);
1432 cpl_array_delete(az2);
1435 cpl_size idx, npix = 0;
1436 for (idx = 0; idx < aXSize * aYSize * aZSize; idx++) {
1437 npix += hdrl_resample_pixgrid_get_count(grid, idx);
1440 for (idx = 0; idx < (cpl_size)grid->
nmaps; idx++) {
1441 nxmap += grid->
nxmap[idx];
1444 char *msg = cpl_sprintf(
"Pixels got lost while creating the cube (input "
1445 "pixel table: %"CPL_SIZE_FORMAT
", output pixel grid"
1446 ": %"CPL_SIZE_FORMAT
")", nsel, npix);
1447 cpl_msg_error(cpl_func,
"%s:", msg);
1448 cpl_error_set_message(cpl_func, CPL_ERROR_ILLEGAL_OUTPUT,
"%s!", msg);
1451 double timefini = cpl_test_get_walltime(),
1452 cpufini = cpl_test_get_cputime();
1453 cpl_msg_debug(cpl_func,
"pixel grid: %dx%dx%d, %"CPL_SIZE_FORMAT
" pixels "
1454 "total, %"CPL_SIZE_FORMAT
" (%.1f%%) in %hu extension maps; took"
1455 " %gs (wall-clock) and %gs (CPU) to create", (
int)grid->
nx,
1456 (
int)grid->
ny, (
int)grid->
nz, npix, nxmap,
1457 (
double)nxmap / npix * 100., grid->
nmaps, timefini - timeinit,
1484static cpl_error_code
1485hdrl_resample_wcs_get_scales(hdrl_resample_outgrid_parameter *aParams_outputgrid,
1486 double *aXScale,
double *aYScale)
1488 cpl_ensure_code(aParams_outputgrid && aXScale && aYScale, CPL_ERROR_NULL_INPUT);
1490 cpl_errorstate prestate = cpl_errorstate_get();
1492 const cpl_matrix *cd = cpl_wcs_get_cd(aParams_outputgrid->wcs);
1497 double cd11 = cpl_matrix_get(cd, 0, 0);
1498 double cd12 = cpl_matrix_get(cd, 0, 1);
1499 double cd21 = cpl_matrix_get(cd, 1, 0);
1500 double cd22 = cpl_matrix_get(cd, 1, 1);
1503 double det = cd11 * cd22 - cd12 * cd21;
1504 cpl_ensure_code(cpl_errorstate_is_equal(prestate), cpl_error_get_code());
1510 if (cd12 == 0. && cd21 == 0.) {
1513 return CPL_ERROR_NONE;
1515 *aXScale = sqrt(cd11*cd11 + cd12*cd12);
1516 *aYScale = sqrt(cd22*cd22 + cd21*cd21);
1517 return CPL_ERROR_NONE;
1529static inline const cpl_size *
1533 cpl_ensure(aGrid , CPL_ERROR_NULL_INPUT, 0);
1534 cpl_ensure(aIndex >= 0 , CPL_ERROR_ILLEGAL_INPUT, 0);
1535 cpl_ensure(aIndex < aGrid->nx * aGrid->
ny * aGrid->
nz, CPL_ERROR_ILLEGAL_INPUT, 0);
1537 cpl_size p = aGrid->
pix[aIndex];
1542 return aGrid->
pix + aIndex;
1570static cpl_error_code
1573 hdrl_resample_outgrid_parameter *aParams_outputgrid)
1575 cpl_ensure_code(aCube && ResTable && aGrid && aParams_outputgrid,
1576 CPL_ERROR_NULL_INPUT);
1577 cpl_ensure_code(cpl_propertylist_has(aCube->
header,
"CRVAL3") == 1,
1578 CPL_ERROR_ILLEGAL_INPUT);
1579 cpl_ensure_code(cpl_propertylist_has(aCube->
header,
"CRPIX3") == 1,
1580 CPL_ERROR_ILLEGAL_INPUT);
1581 cpl_ensure_code(cpl_propertylist_has(aCube->
header,
"CD3_3") == 1,
1582 CPL_ERROR_ILLEGAL_INPUT);
1584 double crval3 = hdrl_resample_pfits_get_crval(aCube->
header, 3);
1585 double crpix3 = hdrl_resample_pfits_get_crpix(aCube->
header, 3);
1586 double cd33 = hdrl_resample_pfits_get_cd(aCube->
header, 3, 3);
1587 cpl_ensure_code(cd33 != 0, CPL_ERROR_ILLEGAL_INPUT);
1589 cpl_wcs *wcscpl = cpl_wcs_new_from_propertylist(aCube->
header);
1591 if (hdrl_resample_inputtable_verify(ResTable)) {
1592 return CPL_ERROR_ILLEGAL_INPUT;
1608 double xnorm = 1., ynorm = 1., znorm = 1. ;
1611 hdrl_resample_wcs_get_scales(aParams_outputgrid, &xnorm, &ynorm);
1616 const cpl_matrix *cd = cpl_wcs_get_cd(aParams_outputgrid->wcs);
1617 if (cpl_matrix_get_ncol(cd) == 3) {
1618 znorm = 1. / cpl_matrix_get(cd, 2, 2);
1629 struct timeval tv1, tv2;
1630 cpl_msg_debug(cpl_func,
"Starting parallel loop in hdrl_resample_cube_nearest");
1631 gettimeofday(&tv1, NULL);
1633#pragma omp parallel for default(none) \
1634 shared(aCube, aGrid, cd33, crpix3, crval3, data, dq, lbda, \
1635 stat, stdout, wcscpl, \
1636 xnorm, xpos, ynorm, ypos, znorm) collapse(2)
1638 for (cpl_size l = 0; l < aGrid->
nz; l++) {
1639 for (cpl_size i = 0; i < aGrid->
nx; i++) {
1644 double lambda = (l + 1. - crpix3) * cd33 + crval3;
1647 for (j = 0; j < aGrid->
ny; j++) {
1648 cpl_size idx = hdrl_resample_pixgrid_get_index(aGrid, i, j, l, CPL_FALSE),
1649 n_rows = hdrl_resample_pixgrid_get_count(aGrid, idx);
1650 const cpl_size *rows = hdrl_resample_pixgrid_get_rows(aGrid, idx);
1653 double x = 0., y = 0.;
1657 hdrl_wcs_xy_to_radec(wcscpl, i + 1, j + 1, &x, &y);
1660 if ((cpl_binary)dq[rows[0]] == CPL_BINARY_0) {
1662 pdata[i + j * aGrid->
nx] = data[rows[0]];
1663 pstat[i + j * aGrid->
nx] = stat[rows[0]];
1664 pdq[i + j * aGrid->
nx] = (cpl_binary)dq[rows[0]];
1666 pdq[i + j * aGrid->
nx] = CPL_BINARY_1;
1668 }
else if (n_rows >= 2) {
1670 cpl_size n, nbest = -1;
1671 double dbest = FLT_MAX;
1672 for (n = 0; n < n_rows; n++) {
1674 if((cpl_binary)dq[rows[n]] != CPL_BINARY_0) {
1678 double dx = fabs(x - xpos[rows[n]]) * xnorm,
1679 dy = fabs(y - ypos[rows[n]]) * ynorm,
1680 dlambda = fabs(lambda - lbda[rows[n]]) * znorm,
1681 dthis = sqrt(dx*dx + dy*dy + dlambda*dlambda);
1685 dx *= cos(y * CPL_MATH_RAD_DEG);
1687 if (dthis < dbest) {
1693 pdata[i + j * aGrid->
nx] = data[rows[nbest]];
1694 pstat[i + j * aGrid->
nx] = stat[rows[nbest]];
1695 pdq[i + j * aGrid->
nx] = (cpl_binary)dq[rows[nbest]];
1699 pdq[i + j * aGrid->
nx] = CPL_BINARY_1;
1705 gettimeofday(&tv2, NULL);
1706 cpl_msg_debug(cpl_func,
"Wall time for hdrl_resample_cube_nearest was %f seconds\n",
1707 (
double) (tv2.tv_usec - tv1.tv_usec) / 1000000 +
1708 (
double) (tv2.tv_sec - tv1.tv_sec));
1713 for(cpl_size i = 0; i < size; i++){
1719 cpl_wcs_delete(wcscpl);
1721 return CPL_ERROR_NONE;
1739hdrl_resample_weight_function_renka(
double r,
double r_c)
1743 }
else if (r >= r_c) {
1746 double p = (r_c - r) / (r_c * r);
1772hdrl_resample_weight_function_drizzle(
double xin,
double yin,
double zin,
1773 double xout,
double yout,
double zout,
1774 double dx,
double dy,
double dz)
1779 double x = (dx + xout / 2.) <= xin / 2. ? xout : (xin + xout) / 2. - dx,
1780 y = (dy + yout / 2.) <= yin / 2. ? yout : (yin + yout) / 2. - dy,
1781 z = (dz + zout / 2.) <= zin / 2. ? zout : (zin + zout) / 2. - dz;
1784 if (x <= 0 || y <= 0 || z <= 0) {
1789 return (x > xin ? xin : x) * (y > yin ? yin : y) * (z > zin ? zin : z)
1790 / (xin * yin * zin);
1807hdrl_resample_weight_function_linear(
double r)
1809 return r == 0 ? FLT_MAX : 1. / r;
1825hdrl_resample_weight_function_quadratic(
double r2)
1827 return r2 == 0 ? FLT_MAX : 1. / r2;
1839hdrl_resample_weight_function_sinc(
double r)
1841 return fabs(r) < DBL_EPSILON ? 1. : sin(CPL_MATH_PI * r) / (CPL_MATH_PI * r);
1857hdrl_resample_weight_function_lanczos(
double dx,
double dy,
double dz,
1858 unsigned int ld,
unsigned int lks)
1862 return (fabs(dx) >= (ld + 0.5) || fabs(dy) >= (ld + 0.5) || fabs(dz) > (ld + 0.5)) ? 0.
1863 : hdrl_resample_weight_function_sinc(dx) * hdrl_resample_weight_function_sinc(dx / lks)
1864 * hdrl_resample_weight_function_sinc(dy) * hdrl_resample_weight_function_sinc(dy / lks)
1865 * hdrl_resample_weight_function_sinc(dz) * hdrl_resample_weight_function_sinc(dz / lks);
1891static cpl_error_code
1893 const cpl_table *ResTable,
1895 hdrl_resample_method_parameter *aParams_method,
1896 hdrl_resample_outgrid_parameter *aParams_outputgrid)
1899 cpl_ensure_code(aCube && ResTable && aGrid && aParams_method &&
1900 aParams_outputgrid, CPL_ERROR_NULL_INPUT);
1901 cpl_ensure_code(cpl_propertylist_has(aCube->
header,
"CRVAL3") == 1,
1902 CPL_ERROR_ILLEGAL_INPUT);
1903 cpl_ensure_code(cpl_propertylist_has(aCube->
header,
"CRPIX3") == 1,
1904 CPL_ERROR_ILLEGAL_INPUT);
1905 cpl_ensure_code(cpl_propertylist_has(aCube->
header,
"CD3_3") == 1,
1906 CPL_ERROR_ILLEGAL_INPUT);
1908 double crval3 = hdrl_resample_pfits_get_crval(aCube->
header, 3),
1909 crpix3 = hdrl_resample_pfits_get_crpix(aCube->
header, 3),
1910 cd33 = hdrl_resample_pfits_get_cd(aCube->
header, 3, 3);
1913 cpl_wcs *wcscpl = cpl_wcs_new_from_propertylist(aCube->
header);
1927 double xnorm = 1., ynorm = 1., znorm = 1. ;
1929 hdrl_resample_wcs_get_scales(aParams_outputgrid, &xnorm, &ynorm);
1933 const cpl_matrix *cd = cpl_wcs_get_cd(aParams_outputgrid->wcs);
1934 if (cpl_matrix_get_ncol(cd) == 3) {
1935 znorm = 1. / cpl_matrix_get(cd, 2, 2);
1948 double renka_rc = aParams_method->renka_critical_radius
1949 * sqrt((wcs->
cd11*xnorm)*(wcs->
cd11*xnorm)
1950 + (wcs->
cd22*ynorm)*(wcs->
cd22*ynorm)
1951 + (cd33*znorm)*(cd33*znorm));
1954 int ld = aParams_method->loop_distance;
1957 cpl_msg_debug(cpl_func,
"Overriding loop distance ld=%d", ld);
1961 int lks = aParams_method->lanczos_kernel_size;
1964 cpl_msg_debug(cpl_func,
"Overriding lanczos kernel size lks=%d", lks);
1968 cpl_boolean wght = aParams_method->use_errorweights;
1972 double xsz = aParams_method->drizzle_pix_frac_x / xnorm,
1973 ysz = aParams_method->drizzle_pix_frac_y / ynorm,
1974 zsz = aParams_method->drizzle_pix_frac_lambda / znorm,
1975 xout = fabs(wcs->
cd11), yout = fabs(wcs->
cd22), zout = fabs(cd33);
1977 struct timeval tv1, tv2;
1978 cpl_msg_debug(cpl_func,
"Starting parallel loop in hdrl_resample_cube_weighted");
1979 gettimeofday(&tv1, NULL);
1981#pragma omp parallel for default(none) \
1982 shared(aCube, aParams_method, aParams_outputgrid, aGrid, ResTable, cd33, crpix3, crval3, data, \
1983 dq, lbda, ld, lks, renka_rc, stat, \
1984 stdout, wcs, wcscpl, wght, xnorm, xout, xpos, xsz, ynorm, yout,\
1985 ypos, ysz, znorm, zout, zsz) collapse(2)
1987 for (cpl_size l = 0; l < aGrid->
nz; l++) {
1988 for (cpl_size i = 0; i < aGrid->
nx; i++) {
1994 double lambda = (l + 1. - crpix3) * cd33 + crval3;
1995 double zout2 = zout;
1997 for (cpl_size j = 0; j < aGrid->
ny; j++) {
2003 hdrl_wcs_xy_to_radec(wcscpl, i + 1, j + 1, &x, &y);
2006 double sumdata = 0, sumstat = 0, sumweight = 0;
2007 cpl_size npoints = 0;
2011 for (i2 = i - ld; i2 <= i + ld; i2++) {
2013 for (j2 = j - ld; j2 <= j + ld; j2++) {
2015 for (l2 = l - ld; l2 <= l + ld; l2++) {
2016 cpl_size idx2 = hdrl_resample_pixgrid_get_index(aGrid, i2, j2, l2, CPL_FALSE);
2017 if (idx2 < 0)
continue;
2018 cpl_size n_rows2 = hdrl_resample_pixgrid_get_count(aGrid, idx2);
2020 const cpl_size *rows2 = hdrl_resample_pixgrid_get_rows(aGrid, idx2);
2022 for (n = 0; n < n_rows2; n++) {
2028 double dx = fabs(x - (xpos[rows2[n]])),
2029 dy = fabs(y - (ypos[rows2[n]])),
2030 dlambda = fabs(lambda - lbda[rows2[n]]),
2040 dx *= cos(y * CPL_MATH_RAD_DEG);
2046 r2 = dx * dx + dy * dy + dlambda * dlambda;
2051 weight = hdrl_resample_weight_function_renka(sqrt(r2), renka_rc);
2053 weight = hdrl_resample_weight_function_drizzle(xsz, ysz, zsz,
2058 weight = hdrl_resample_weight_function_linear(sqrt(r2));
2061 weight = hdrl_resample_weight_function_quadratic(r2);
2063 weight = hdrl_resample_weight_function_lanczos(dx, dy,
2067 if (wght && stat[rows2[n]] > 0.) {
2069 weight /= (stat[rows2[n]] * stat[rows2[n]]);
2072 sumweight += weight;
2073 sumdata += data[rows2[n]] * weight;
2074 sumstat += stat[rows2[n]] * stat[rows2[n]] * weight * weight;
2089 if (!npoints || !isnormal(sumweight) || !isnormal(sumweight * sumweight)) {
2090 pdq[i + j * aGrid->
nx] = CPL_BINARY_1;
2095 sumdata /= sumweight;
2096 sumstat /= sumweight * sumweight;
2098 pdata[i + j * aGrid->
nx] = sumdata;
2100 pstat[i + j * aGrid->
nx] = sqrt(sumstat);
2101 pdq[i + j * aGrid->
nx] = CPL_BINARY_0;
2107 gettimeofday(&tv2, NULL);
2108 cpl_msg_debug(cpl_func,
"Wall time for hdrl_resample_cube_weighted was %f seconds\n",
2109 (
double) (tv2.tv_usec - tv1.tv_usec) / 1000000 +
2110 (
double) (tv2.tv_sec - tv1.tv_sec));
2115 for(cpl_size i = 0; i < size; i++){
2122 cpl_wcs_delete(wcscpl);
2124 return CPL_ERROR_NONE;
2146static cpl_error_code hdrl_resampling_set_outputgrid (
2148 hdrl_resample_outgrid_parameter *aParams_outputgrid)
2150 cpl_ensure_code(xsize > 0, CPL_ERROR_ILLEGAL_INPUT);
2151 cpl_ensure_code(ysize > 0,CPL_ERROR_ILLEGAL_INPUT);
2152 cpl_ensure_code(zsize >= 0, CPL_ERROR_ILLEGAL_INPUT);
2154 cpl_ensure_code(cube && aParams_outputgrid, CPL_ERROR_NULL_INPUT);
2158 cube->
header = cpl_propertylist_new ();
2159 hdrl_wcs_to_propertylist (aParams_outputgrid->wcs, cube->
header,
2162 cpl_propertylist_update_string (cube->
header,
"CTYPE1",
"RA---TAN");
2163 cpl_propertylist_update_string (cube->
header,
"CTYPE2",
"DEC--TAN");
2164 cpl_propertylist_set_comment(cube->
header,
"CTYPE1",
"Gnomonic projection");
2165 cpl_propertylist_set_comment(cube->
header,
"CTYPE2",
"Gnomonic projection");
2170 cpl_propertylist_update_int (cube->
header,
"NAXIS", 3);
2171 cpl_propertylist_update_int (cube->
header,
"NAXIS1", xsize);
2172 cpl_propertylist_update_int (cube->
header,
"NAXIS2", ysize);
2173 cpl_propertylist_update_int (cube->
header,
"NAXIS3", zsize);
2178 cpl_propertylist_update_double (cube->
header,
"CD1_1",
2179 -aParams_outputgrid->delta_ra);
2180 cpl_propertylist_update_double (cube->
header,
"CD2_2",
2181 aParams_outputgrid->delta_dec);
2182 cpl_propertylist_update_double (cube->
header,
"CD1_2", 0.);
2183 cpl_propertylist_update_double (cube->
header,
"CD2_1", 0.);
2185 double ramin = aParams_outputgrid->ra_min;
2186 double ramax = aParams_outputgrid->ra_max;
2187 double decmin = aParams_outputgrid->dec_min;
2188 double decmax = aParams_outputgrid->dec_max;
2191 cpl_propertylist_update_double(cube->
header,
"CRPIX1", (
double)((xsize + 1) / 2.));
2192 cpl_propertylist_update_double(cube->
header,
"CRPIX2", (
double)((ysize + 1) / 2.));
2194 if(ramax - ramin < 180) {
2196 cpl_propertylist_update_double(cube->
header,
"CRVAL1", (ramin + ramax) / 2.);
2198 double diff1 = 360. - ramax;
2199 double diff2 = ramin - 0.;
2200 if (diff1 < diff2) {
2201 cpl_propertylist_update_double(cube->
header,
"CRVAL1", ramin - (diff1 + diff2) / 2);
2203 cpl_propertylist_update_double(cube->
header,
"CRVAL1", ramax + (diff1 + diff2) / 2.);
2206 cpl_propertylist_update_double(cube->
header,
"CRVAL2", (decmin + decmax) / 2.);
2207 cpl_propertylist_update_double (cube->
header,
"CD3_3",
2208 aParams_outputgrid->delta_lambda);
2209 cpl_propertylist_update_double (cube->
header,
"CRPIX3", 1.);
2210 cpl_propertylist_update_double (cube->
header,
"CRVAL3",
2211 aParams_outputgrid->lambda_min);
2213 cpl_propertylist_update_double (cube->
header,
"CD1_3", 0.);
2214 cpl_propertylist_update_double (cube->
header,
"CD2_3", 0.);
2215 cpl_propertylist_update_double (cube->
header,
"CD3_1", 0.);
2216 cpl_propertylist_update_double (cube->
header,
"CD3_2", 0.);
2218 return cpl_error_get_code();
2277hdrl_resample_cube(
const cpl_table *ResTable,
2278 hdrl_resample_method_parameter *aParams_method,
2279 hdrl_resample_outgrid_parameter *aParams_outputgrid,
2282 cpl_ensure(ResTable && aParams_method && aParams_outputgrid && aGrid,
2283 CPL_ERROR_NULL_INPUT, NULL);
2292 int xsize = 0, ysize = 0, zsize = 0;
2294 hdrl_resample_compute_size(aParams_outputgrid, &xsize, &ysize, &zsize);
2298 xsize *= (100. + aParams_outputgrid->fieldmargin)/100.;
2299 ysize *= (100. + aParams_outputgrid->fieldmargin)/100.;
2301 cpl_ensure(xsize > 0 && ysize > 0 && zsize > 0, CPL_ERROR_ILLEGAL_OUTPUT,
2304 double time = cpl_test_get_walltime();
2309 hdrl_resampling_set_outputgrid (xsize, ysize, zsize, cube, aParams_outputgrid);
2315 for (cpl_size i = 0; i < zsize; i++) {
2320 for (cpl_size j = 1; j <= xsize; j++) {
2321 for (cpl_size k = 1; k <= ysize; k++) {
2332 xsize, ysize, zsize);
2335 cpl_error_set_message(cpl_func, CPL_ERROR_DATA_NOT_FOUND,
"Could not create"
2343 double timeinit = cpl_test_get_walltime(),
2344 cpuinit = cpl_test_get_cputime();
2347 cpl_error_code rc = CPL_ERROR_NONE;
2348 switch (aParams_method->method) {
2350 cpl_msg_debug(cpl_func,
"Starting resampling, using method \"nearest\"");
2351 rc = hdrl_resample_cube_nearest(cube, ResTable, grid, aParams_outputgrid);
2354 cpl_msg_debug(cpl_func,
"Starting resampling, using method \"renka\" "
2355 "(critical radius rc=%f, loop distance ld=%d)",
2356 aParams_method->renka_critical_radius,
2357 aParams_method->loop_distance);
2358 rc = hdrl_resample_cube_weighted(cube, ResTable, grid, aParams_method,
2359 aParams_outputgrid);
2364 cpl_msg_debug(cpl_func,
"Starting resampling, using method \"%s\" (loop "
2371 aParams_method->loop_distance);
2372 rc = hdrl_resample_cube_weighted(cube, ResTable, grid, aParams_method,
2373 aParams_outputgrid);
2376 cpl_msg_debug(cpl_func,
"Starting resampling, using method \"drizzle\" "
2377 "(pixfrac f=%.3f,%.3f,%.3f, loop distance ld=%d)",
2378 aParams_method->drizzle_pix_frac_x,
2379 aParams_method->drizzle_pix_frac_y,
2380 aParams_method->drizzle_pix_frac_lambda,
2381 aParams_method->loop_distance);
2382 rc = hdrl_resample_cube_weighted(cube, ResTable, grid,
2384 aParams_outputgrid);
2390 cpl_msg_error(cpl_func,
"Don't know this resampling method: %d",
2391 aParams_method->method);
2392 cpl_error_set(cpl_func, CPL_ERROR_UNSUPPORTED_MODE);
2393 rc = CPL_ERROR_UNSUPPORTED_MODE;
2396 double timefini = cpl_test_get_walltime(),
2397 cpufini = cpl_test_get_cputime();
2403 hdrl_resample_pixgrid_delete(grid);
2406 cpl_msg_debug(cpl_func,
"resampling took %.3fs (wall-clock) and %.3fs "
2407 "(%.3fs CPU, %d CPUs) for hdrl_resample_cube*() alone",
2408 timefini - time, timefini - timeinit, cpufini - cpuinit,
2410 if (rc != CPL_ERROR_NONE) {
2411 cpl_msg_error(cpl_func,
"resampling failed: %s", cpl_error_get_message());
2431hdrl_wcs_to_propertylist(
const cpl_wcs * wcs, cpl_propertylist * header,
2434 cpl_ensure_code(wcs && header, CPL_ERROR_NULL_INPUT);
2436 const cpl_array *crval = cpl_wcs_get_crval(wcs);
2437 const cpl_array *crpix = cpl_wcs_get_crpix(wcs);
2438 const cpl_array *ctype = cpl_wcs_get_ctype(wcs);
2439 const cpl_array *cunit = cpl_wcs_get_cunit(wcs);
2441 const cpl_matrix *cd = cpl_wcs_get_cd(wcs);
2443 const cpl_array *dims = cpl_wcs_get_image_dims(wcs);
2444 int naxis = cpl_wcs_get_image_naxis(wcs);
2448 for (cpl_size i = 0; i < naxis; i++) {
2450 cpl_propertylist_update_int(header,
"NAXIS", naxis);
2452 char * buf = cpl_sprintf(
"NAXIS%lld", i + 1);
2453 cpl_propertylist_update_int(header, buf,
2454 cpl_array_get_int(dims, i, &err));
2459 if (only2d == TRUE) {
2460 cpl_propertylist_update_int(header,
"NAXIS", 2);
2462 if(cpl_propertylist_has(header,
"NAXIS3")){
2463 cpl_propertylist_erase(header,
"NAXIS3");
2469 cpl_propertylist_update_double(header,
"CRVAL1",
2470 cpl_array_get_double(crval, 0, &err));
2471 cpl_propertylist_update_double(header,
"CRVAL2",
2472 cpl_array_get_double(crval, 1, &err));
2476 cpl_propertylist_update_double(header,
"CRPIX1",
2477 cpl_array_get_double(crpix, 0, &err));
2478 cpl_propertylist_update_double(header,
"CRPIX2",
2479 cpl_array_get_double(crpix, 1, &err));
2483 cpl_propertylist_update_string(header,
"CTYPE1",
2484 cpl_array_get_string(ctype, 0));
2485 cpl_propertylist_update_string(header,
"CTYPE2",
2486 cpl_array_get_string(ctype, 1));
2490 cpl_propertylist_update_string(header,
"CUNIT1",
2491 cpl_array_get_string(cunit, 0));
2492 cpl_propertylist_update_string(header,
"CUNIT2",
2493 cpl_array_get_string(cunit, 1));
2497 double cd11 = cpl_matrix_get(cd, 0, 0);
2498 double cd12 = cpl_matrix_get(cd, 0, 1);
2499 double cd21 = cpl_matrix_get(cd, 1, 0);
2500 double cd22 = cpl_matrix_get(cd, 1, 1);
2501 cpl_propertylist_update_double(header,
"CD1_1", cd11);
2502 cpl_propertylist_update_double(header,
"CD1_2", cd12);
2503 cpl_propertylist_update_double(header,
"CD2_1", cd21);
2504 cpl_propertylist_update_double(header,
"CD2_2", cd22);
2508 if (only2d == FALSE && cpl_array_get_size(crval) > 2) {
2511 cpl_propertylist_update_double(header,
"CRVAL3",
2512 cpl_array_get_double(crval, 2, &err));
2516 cpl_propertylist_update_double(header,
"CRPIX3",
2517 cpl_array_get_double(crpix, 2, &err));
2521 cpl_propertylist_update_string(header,
"CTYPE3",
2522 cpl_array_get_string(ctype, 2));
2526 cpl_propertylist_update_string(header,
"CUNIT3",
2527 cpl_array_get_string(cunit, 2));
2531 double cd13 = cpl_matrix_get(cd, 0, 2);
2532 double cd23 = cpl_matrix_get(cd, 1, 2);
2533 double cd31 = cpl_matrix_get(cd, 2, 0);
2534 double cd32 = cpl_matrix_get(cd, 2, 1);
2535 double cd33 = cpl_matrix_get(cd, 2, 2);
2536 cpl_propertylist_update_double(header,
"CD1_3", cd13);
2537 cpl_propertylist_update_double(header,
"CD2_3", cd23);
2538 cpl_propertylist_update_double(header,
"CD3_1", cd31);
2539 cpl_propertylist_update_double(header,
"CD3_2", cd32);
2540 cpl_propertylist_update_double(header,
"CD3_3", cd33);
2543 return CPL_ERROR_NONE;
2555static cpl_error_code
2556hdrl_resample_create_table(cpl_table** tab,
const cpl_size size)
2559 cpl_ensure_code(tab, CPL_ERROR_NULL_INPUT);
2560 cpl_ensure_code(size > 0 , CPL_ERROR_ILLEGAL_INPUT);
2562 *tab = cpl_table_new(size);
2571 cpl_table_new_column(*tab,
2573 cpl_table_new_column(*tab,
2575 cpl_table_new_column(*tab,
2577 cpl_table_new_column(*tab,
2579 cpl_table_new_column(*tab,
2581 cpl_table_new_column(*tab,
2592 return cpl_error_get_code();
2607 cpl_ensure(hima, CPL_ERROR_NULL_INPUT, NULL);
2608 cpl_ensure(wcs, CPL_ERROR_NULL_INPUT, NULL);
2609 cpl_msg_debug(cpl_func,
"Converting Data to table");
2639 cpl_ensure(himlist, CPL_ERROR_NULL_INPUT, NULL);
2640 cpl_ensure(wcs, CPL_ERROR_NULL_INPUT, NULL);
2642 cpl_msg_debug(cpl_func,
"Converting Dataset to table");
2648 cpl_msg_debug(cpl_func,
"Dataset dimentions (x, y, l): (%lld, %lld, %lld)",
2649 naxis1, naxis2, naxis3);
2651 const cpl_array *crval = cpl_wcs_get_crval(wcs);
2652 const cpl_array *crpix = cpl_wcs_get_crpix(wcs);
2653 const cpl_matrix *cd = cpl_wcs_get_cd(wcs);
2661 crpix3 = cpl_array_get_double(crpix, 2, &testerr);
2662 crval3 = cpl_array_get_double(crval, 2, &testerr);
2663 cdelt3 = cpl_matrix_get(cd, 2, 2);
2670 cpl_size tab_size = naxis1 * naxis2 * naxis3;
2671 cpl_table* tab = NULL;
2673 hdrl_resample_create_table(&tab, tab_size);
2682 struct timeval tv1, tv2;
2683 cpl_msg_debug(cpl_func,
"Starting parallel loop in hdrl_imagelist_to_table");
2684 gettimeofday(&tv1, NULL);
2686 HDRL_OMP(omp parallel
for collapse(2))
2687 for(cpl_size k = 0; k < naxis3; k++) {
2688 for(cpl_size j = 0; j < naxis2; j++) {
2689 const double* pimaerr = NULL;
2690 const cpl_binary * pimabpm = NULL;
2697 const double* pimadata = cpl_image_get_data_double_const(imadata);
2700 pimaerr = cpl_image_get_data_double_const(imaerrs);
2703 pimabpm = cpl_mask_get_data_const(imamask);
2706 cpl_size k_naxis1_naxis2 = naxis1 * naxis2 * k;
2707 cpl_size j_naxis1 = j * naxis1;
2708 for(cpl_size i = 0; i < naxis1; i++) {
2709 cpl_size raw = k_naxis1_naxis2 + j_naxis1 + i;
2710 hdrl_wcs_xy_to_radec(wcs, i+1 , j+1 , &ptabxpos[raw],
2712 ptabdata[raw] = pimadata[j_naxis1 + i];
2713 if (naxis3 > 1) ptablambda[raw] = crval3 + cdelt3 * (k - crpix3 + 1.);
2714 if (imaerrs) ptaberr[raw] = pimaerr[j_naxis1 + i];
2715 if (imamask) ptabbpm[raw] = pimabpm[j_naxis1 + i];
2717 if (!isfinite(pimadata[j_naxis1 + i]) ||
2718 ptabbpm[raw] != CPL_BINARY_0 ){
2719 ptabbpm[raw] = CPL_BINARY_1;
2726 gettimeofday(&tv2, NULL);
2727 cpl_msg_debug(cpl_func,
"Wall time for hdrl_imagelist_to_table was %f seconds\n",
2728 (
double) (tv2.tv_usec - tv1.tv_usec) / 1000000 +
2729 (
double) (tv2.tv_sec - tv1.tv_sec));
2758 const double delta_dec)
2761 hdrl_resample_outgrid_parameter * p = (hdrl_resample_outgrid_parameter *)
2762 hdrl_parameter_new(&hdrl_resample_outgrid_parameter_type);
2764 p->delta_ra = delta_ra;
2765 p->delta_dec = delta_dec;
2767 p->recalc_limits = CPL_TRUE;
2780 p->delta_lambda = 1;
2820 const double delta_dec,
const double delta_lambda)
2823 hdrl_resample_outgrid_parameter * p = (hdrl_resample_outgrid_parameter *)
2824 hdrl_parameter_new(&hdrl_resample_outgrid_parameter_type);
2826 p->delta_ra = delta_ra;
2827 p->delta_dec = delta_dec;
2828 p->delta_lambda = delta_lambda;
2830 p->recalc_limits = CPL_TRUE;
2880 const double delta_dec,
2881 const double ra_min,
2882 const double ra_max,
2883 const double dec_min,
2884 const double dec_max,
2885 const double fieldmargin)
2888 hdrl_resample_outgrid_parameter * p = (hdrl_resample_outgrid_parameter *)
2889 hdrl_parameter_new(&hdrl_resample_outgrid_parameter_type);
2891 p->delta_ra = delta_ra;
2892 p->delta_dec = delta_dec;
2895 p->recalc_limits = CPL_FALSE;
2896 p->dec_min = dec_min;
2897 p->dec_max = dec_max;
2904 p->delta_lambda = 1.;
2906 p->fieldmargin = fieldmargin;
2949 const double delta_dec,
2950 const double delta_lambda,
2951 const double ra_min,
2952 const double ra_max,
2953 const double dec_min,
2954 const double dec_max,
2955 const double lambda_min,
2956 const double lambda_max,
2957 const double fieldmargin)
2960 hdrl_resample_outgrid_parameter * p = (hdrl_resample_outgrid_parameter *)
2961 hdrl_parameter_new(&hdrl_resample_outgrid_parameter_type);
2963 p->delta_ra = delta_ra;
2964 p->delta_dec = delta_dec;
2965 p->delta_lambda = delta_lambda;
2967 p->recalc_limits = CPL_FALSE;
2969 p->dec_min = dec_min;
2970 p->dec_max = dec_max;
2974 p->lambda_min = lambda_min;
2975 p->lambda_max = lambda_max;
2977 p->fieldmargin = fieldmargin;
3014 cpl_boolean use_errorweights,
3015 const double critical_radius)
3018 hdrl_resample_method_parameter * p = (hdrl_resample_method_parameter *)
3019 hdrl_parameter_new(&hdrl_resample_method_parameter_type);
3022 p->loop_distance = loop_distance;
3023 p->use_errorweights = use_errorweights;
3024 p->renka_critical_radius = critical_radius;
3027 p->drizzle_pix_frac_x = 0.1;
3028 p->drizzle_pix_frac_y = 0.1;
3029 p->drizzle_pix_frac_lambda = 0.1;
3030 p->lanczos_kernel_size = 2;
3061 cpl_boolean use_errorweights)
3064 hdrl_resample_method_parameter * p = (hdrl_resample_method_parameter *)
3065 hdrl_parameter_new(&hdrl_resample_method_parameter_type);
3069 p->loop_distance = loop_distance;
3070 p->use_errorweights = use_errorweights;
3073 p->renka_critical_radius = 0.1;
3074 p->drizzle_pix_frac_x = 0.1;
3075 p->drizzle_pix_frac_y = 0.1;
3076 p->drizzle_pix_frac_lambda = 0.1;
3077 p->lanczos_kernel_size = 2;
3109 cpl_boolean use_errorweights)
3112 hdrl_resample_method_parameter * p = (hdrl_resample_method_parameter *)
3113 hdrl_parameter_new(&hdrl_resample_method_parameter_type);
3116 p->loop_distance = loop_distance;
3117 p->use_errorweights = use_errorweights;
3120 p->renka_critical_radius = 0.1;
3121 p->drizzle_pix_frac_x = 0.1;
3122 p->drizzle_pix_frac_y = 0.1;
3123 p->drizzle_pix_frac_lambda = 0.1;
3124 p->lanczos_kernel_size = 2;
3153 hdrl_resample_method_parameter * p = (hdrl_resample_method_parameter *)
3154 hdrl_parameter_new(&hdrl_resample_method_parameter_type);
3158 p->loop_distance = 0;
3159 p->use_errorweights = CPL_FALSE;
3162 p->renka_critical_radius = 0.1;
3163 p->drizzle_pix_frac_x = 0.1;
3164 p->drizzle_pix_frac_y = 0.1;
3165 p->drizzle_pix_frac_lambda = 0.1;
3166 p->lanczos_kernel_size = 2;
3199 cpl_boolean use_errorweights,
3200 const int kernel_size)
3203 hdrl_resample_method_parameter * p = (hdrl_resample_method_parameter *)
3204 hdrl_parameter_new(&hdrl_resample_method_parameter_type);
3207 p->loop_distance = loop_distance;
3208 p->use_errorweights = use_errorweights;
3209 p->lanczos_kernel_size = kernel_size;
3211 p->renka_critical_radius = 0.1;
3212 p->drizzle_pix_frac_x = 0.1;
3213 p->drizzle_pix_frac_y = 0.1;
3214 p->drizzle_pix_frac_lambda = 0.1;
3254 cpl_boolean use_errorweights,
3255 const double pix_frac_x,
3256 const double pix_frac_y,
3257 const double pix_frac_lambda)
3260 hdrl_resample_method_parameter * p = (hdrl_resample_method_parameter *)
3261 hdrl_parameter_new(&hdrl_resample_method_parameter_type);
3264 p->loop_distance = loop_distance;
3265 p->use_errorweights = use_errorweights;
3266 p->drizzle_pix_frac_x = pix_frac_x;
3267 p->drizzle_pix_frac_y = pix_frac_y;
3268 p->drizzle_pix_frac_lambda = pix_frac_lambda;
3271 p->renka_critical_radius = 0.1;
3272 p->lanczos_kernel_size = 2;
3294 const hdrl_resample_outgrid_parameter * param_loc =
3295 (
const hdrl_resample_outgrid_parameter *)hp ;
3297 cpl_error_ensure(hp != NULL, CPL_ERROR_NULL_INPUT,
3298 return CPL_ERROR_NULL_INPUT,
"NULL Input Parameters");
3301 CPL_ERROR_ILLEGAL_INPUT,
return CPL_ERROR_ILLEGAL_INPUT,
3302 "Here we expect a resample outgrid parameter") ;
3305 param_loc->recalc_limits == CPL_TRUE ||
3306 param_loc->recalc_limits == CPL_FALSE,
3307 CPL_ERROR_ILLEGAL_INPUT,
return CPL_ERROR_ILLEGAL_INPUT,
3308 "Unsupported resample recalc_limits value");
3319 cpl_error_ensure(param_loc->delta_ra > 0, CPL_ERROR_ILLEGAL_INPUT,
3320 return CPL_ERROR_ILLEGAL_INPUT,
"right ascension "
3321 "stepsize must be > 0");
3323 cpl_error_ensure(param_loc->delta_dec > 0, CPL_ERROR_ILLEGAL_INPUT,
3324 return CPL_ERROR_ILLEGAL_INPUT,
"declination stepsize "
3327 cpl_error_ensure(param_loc->delta_lambda > 0, CPL_ERROR_ILLEGAL_INPUT,
3328 return CPL_ERROR_ILLEGAL_INPUT,
"wavelength stepsize "
3332 cpl_error_ensure(param_loc->ra_min >= 0,
3333 CPL_ERROR_ILLEGAL_INPUT,
return CPL_ERROR_ILLEGAL_INPUT,
3334 "Minimum right ascension must be >= 0");
3336 cpl_error_ensure(param_loc->ra_max >= 0,
3337 CPL_ERROR_ILLEGAL_INPUT,
return CPL_ERROR_ILLEGAL_INPUT,
3338 "Maximum right ascension must be >= 0");
3341 cpl_error_ensure(param_loc->lambda_min >= 0,
3342 CPL_ERROR_ILLEGAL_INPUT,
return CPL_ERROR_ILLEGAL_INPUT,
3343 "Minimum wavelength must be >= 0");
3345 cpl_error_ensure(param_loc->lambda_max >= 0,
3346 CPL_ERROR_ILLEGAL_INPUT,
return CPL_ERROR_ILLEGAL_INPUT,
3347 "Maximum wavelength must be >= 0");
3349 cpl_error_ensure(param_loc->fieldmargin >= 0., CPL_ERROR_ILLEGAL_INPUT,
3350 return CPL_ERROR_ILLEGAL_INPUT,
"The field margin must"
3353 cpl_error_ensure(param_loc->ra_max >= param_loc->ra_min ,
3354 CPL_ERROR_ILLEGAL_INPUT,
return CPL_ERROR_ILLEGAL_INPUT,
3355 "The maximum right ascension must be >= "
3356 "the minimum right ascension");
3357 cpl_error_ensure(param_loc->dec_max >= param_loc->dec_min ,
3358 CPL_ERROR_ILLEGAL_INPUT,
return CPL_ERROR_ILLEGAL_INPUT,
3359 "The maximum declination must be >= "
3360 "the minimum declination");
3362 cpl_error_ensure(param_loc->lambda_max >= param_loc->lambda_min ,
3363 CPL_ERROR_ILLEGAL_INPUT,
return CPL_ERROR_ILLEGAL_INPUT,
3364 "The maximum wavelength must be >= "
3365 "the minimum wavelength");
3367 return CPL_ERROR_NONE ;
3383 const hdrl_resample_method_parameter * param_loc =
3384 (
const hdrl_resample_method_parameter *)hp ;
3385 cpl_error_ensure(hp != NULL, CPL_ERROR_NULL_INPUT,
3386 return CPL_ERROR_NULL_INPUT,
"NULL Input Parameters");
3389 CPL_ERROR_ILLEGAL_INPUT,
return CPL_ERROR_ILLEGAL_INPUT,
3390 "Here we expect a resample method parameter") ;
3400 CPL_ERROR_ILLEGAL_INPUT,
return CPL_ERROR_ILLEGAL_INPUT,
3401 "Unsupported resample method");
3404 cpl_error_ensure(param_loc->loop_distance >= 0, CPL_ERROR_ILLEGAL_INPUT,
3405 return CPL_ERROR_ILLEGAL_INPUT,
"The loop distance must "
3408 cpl_error_ensure(param_loc->use_errorweights == CPL_TRUE ||
3409 param_loc->use_errorweights == CPL_FALSE,
3410 CPL_ERROR_ILLEGAL_INPUT,
return CPL_ERROR_ILLEGAL_INPUT,
3411 "Unsupported resample use_errorweights value");
3413 switch (param_loc->method) {
3421 cpl_error_ensure(param_loc->renka_critical_radius > 0.,
3422 CPL_ERROR_ILLEGAL_INPUT,
return CPL_ERROR_ILLEGAL_INPUT,
3423 "Critical radius of the Renka method must be > 0");
3428 cpl_error_ensure(param_loc->drizzle_pix_frac_x > 0.,
3429 CPL_ERROR_ILLEGAL_INPUT,
return CPL_ERROR_ILLEGAL_INPUT,
3430 "Drizzle down-scaling factor in x direction "
3433 cpl_error_ensure(param_loc->drizzle_pix_frac_y > 0.,
3434 CPL_ERROR_ILLEGAL_INPUT,
return CPL_ERROR_ILLEGAL_INPUT,
3435 "Drizzle down-scaling factor in y direction "
3438 cpl_error_ensure(param_loc->drizzle_pix_frac_lambda > 0.,
3439 CPL_ERROR_ILLEGAL_INPUT,
return CPL_ERROR_ILLEGAL_INPUT,
3440 "Drizzle down-scaling factor in z/lambda direction "
3446 cpl_error_ensure(param_loc->lanczos_kernel_size > 0,
3447 CPL_ERROR_ILLEGAL_INPUT,
return CPL_ERROR_ILLEGAL_INPUT,
3448 "The kernel size of the Lanczos method must be > 0");
3452 return CPL_ERROR_NONE ;
3467 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
3469 return hdrl_parameter_check_type(self, &hdrl_resample_outgrid_parameter_type);
3484 cpl_ensure_code(self != NULL, CPL_ERROR_NULL_INPUT);
3485 return hdrl_parameter_check_type(self, &hdrl_resample_method_parameter_type);
3497static cpl_error_code
3498hdrl_resample_inputtable_verify(
const cpl_table *ResTable){
3500 cpl_error_ensure(ResTable != NULL, CPL_ERROR_NULL_INPUT,
3501 return CPL_ERROR_NULL_INPUT,
"No Table as input");
3505 == 1, CPL_ERROR_INCOMPATIBLE_INPUT,
3506 return CPL_ERROR_INCOMPATIBLE_INPUT,
3507 "Missing data table column");
3509 == 1, CPL_ERROR_INCOMPATIBLE_INPUT,
3510 return CPL_ERROR_INCOMPATIBLE_INPUT,
3511 "Missing bpm table column");
3513 == 1, CPL_ERROR_INCOMPATIBLE_INPUT,
3514 return CPL_ERROR_INCOMPATIBLE_INPUT,
3515 "Missing error table column");
3517 == 1, CPL_ERROR_INCOMPATIBLE_INPUT,
3518 return CPL_ERROR_INCOMPATIBLE_INPUT,
3519 "Missing right ascension table column");
3521 == 1, CPL_ERROR_INCOMPATIBLE_INPUT,
3522 return CPL_ERROR_INCOMPATIBLE_INPUT,
3523 "Missing declination table column");
3525 == 1, CPL_ERROR_INCOMPATIBLE_INPUT,
3526 return CPL_ERROR_INCOMPATIBLE_INPUT,
3527 "Missing wavelength table column");
3532 return CPL_ERROR_INCOMPATIBLE_INPUT,
3533 "Data table column has wrong format");
3536 return CPL_ERROR_INCOMPATIBLE_INPUT,
3537 "Bpm table column has wrong format");
3540 return CPL_ERROR_INCOMPATIBLE_INPUT,
3541 "Error table column has wrong format");
3544 return CPL_ERROR_INCOMPATIBLE_INPUT,
3545 "Right ascension table column has wrong format");
3548 return CPL_ERROR_INCOMPATIBLE_INPUT,
3549 "Declination table column has wrong format");
3552 return CPL_ERROR_INCOMPATIBLE_INPUT,
3553 "Wavelength table column has wrong format");
3555 return cpl_error_get_code();
hdrl_resample_outgrid
Definition hdrl_resample.h:67
@ HDRL_RESAMPLE_OUTGRID_3D
Definition hdrl_resample.h:69
@ HDRL_RESAMPLE_OUTGRID_2D
Definition hdrl_resample.h:68
#define HDRL_RESAMPLE_TABLE_DATA_TYPE
Definition hdrl_resample.h:51
#define HDRL_RESAMPLE_TABLE_RA_TYPE
Definition hdrl_resample.h:45
#define HDRL_RESAMPLE_TABLE_LAMBDA_TYPE
Definition hdrl_resample.h:49
#define HDRL_RESAMPLE_TABLE_DATA
Definition hdrl_resample.h:40
#define HDRL_RESAMPLE_TABLE_RA
Definition hdrl_resample.h:37
#define HDRL_RESAMPLE_TABLE_DEC
Definition hdrl_resample.h:38
#define HDRL_RESAMPLE_TABLE_ERRORS_TYPE
Definition hdrl_resample.h:55
hdrl_resample_method
Definition hdrl_resample.h:57
@ HDRL_RESAMPLE_METHOD_NONE
Definition hdrl_resample.h:64
@ HDRL_RESAMPLE_METHOD_RENKA
Definition hdrl_resample.h:59
@ HDRL_RESAMPLE_METHOD_DRIZZLE
Definition hdrl_resample.h:62
@ HDRL_RESAMPLE_METHOD_LANCZOS
Definition hdrl_resample.h:63
@ HDRL_RESAMPLE_METHOD_LINEAR
Definition hdrl_resample.h:60
@ HDRL_RESAMPLE_METHOD_QUADRATIC
Definition hdrl_resample.h:61
@ HDRL_RESAMPLE_METHOD_NEAREST
Definition hdrl_resample.h:58
#define HDRL_RESAMPLE_TABLE_BPM_TYPE
Definition hdrl_resample.h:53
#define HDRL_RESAMPLE_TABLE_LAMBDA
Definition hdrl_resample.h:39
#define HDRL_RESAMPLE_TABLE_DEC_TYPE
Definition hdrl_resample.h:47
#define HDRL_RESAMPLE_TABLE_ERRORS
Definition hdrl_resample.h:42
#define HDRL_RESAMPLE_TABLE_BPM
Definition hdrl_resample.h:41
void *() hdrl_alloc(size_t)
Definition hdrl_types.h:38
void() hdrl_free(void *)
Definition hdrl_types.h:39
#define HDRL_OMP(x)
Definition hdrl_cat_def.h:35
#define XMAP_BITMASK
Definition hdrl_resample.c:69
#define FIELDMARGIN
Definition hdrl_resample.c:61
#define omp_get_max_threads()
Definition hdrl_resample.c:35
#define XMAP_LSHIFT
Definition hdrl_resample.c:70
#define omp_get_thread_num()
Definition hdrl_resample.c:36
#define KEYWORD_LENGTH
Definition hdrl_resample.c:57
#define PT_IDX_MASK
Definition hdrl_resample.c:65
struct _hdrl_parameter_ hdrl_parameter
Definition hdrl_parameter.h:27
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
cpl_image * hdrl_image_get_image(hdrl_image *himg)
get data as cpl image
Definition hdrl_image.c:105
cpl_error_code hdrl_image_reject(hdrl_image *self, cpl_size xpos, cpl_size ypos)
mark pixel as bad
Definition hdrl_image.c:427
const cpl_image * hdrl_image_get_image_const(const hdrl_image *himg)
get data as cpl image
Definition hdrl_image.c:118
hdrl_image * hdrl_image_new(cpl_size nx, cpl_size ny)
create new zero filled hdrl image
Definition hdrl_image.c:311
hdrl_image * hdrl_imagelist_unset(hdrl_imagelist *himlist, cpl_size pos)
Remove an image from an imagelist.
Definition hdrl_imagelist_io.c:347
cpl_error_code hdrl_imagelist_set(hdrl_imagelist *himlist, hdrl_image *himg, cpl_size pos)
Insert an image into an imagelist.
Definition hdrl_imagelist_io.c:274
cpl_size hdrl_imagelist_get_size_y(const hdrl_imagelist *himlist)
Get number of rows of images in the imagelist.
Definition hdrl_imagelist_io.c:188
void hdrl_imagelist_delete(hdrl_imagelist *himlist)
Free all memory used by a hdrl_imagelist object including the images.
Definition hdrl_imagelist_io.c:384
const hdrl_image * hdrl_imagelist_get_const(const hdrl_imagelist *himlist, cpl_size inum)
Get an image from a list of images.
Definition hdrl_imagelist_io.c:229
cpl_size hdrl_imagelist_get_size(const hdrl_imagelist *himlist)
Get the number of images in the imagelist.
Definition hdrl_imagelist_io.c:148
hdrl_imagelist * hdrl_imagelist_new(void)
Create an empty imagelist.
Definition hdrl_imagelist_io.c:84
cpl_size hdrl_imagelist_get_size_x(const hdrl_imagelist *himlist)
Get number of colums of images in the imagelist.
Definition hdrl_imagelist_io.c:168
hdrl_image * hdrl_imagelist_get(const hdrl_imagelist *himlist, cpl_size inum)
Get an image from a list of images.
Definition hdrl_imagelist_io.c:210
hdrl_resample_result * hdrl_resample_compute(const cpl_table *ResTable, hdrl_parameter *method, hdrl_parameter *outputgrid, const cpl_wcs *wcs)
High level resampling function.
Definition hdrl_resample.c:735
void hdrl_resample_result_delete(hdrl_resample_result *aCube)
Deallocates the memory associated to a hdrl_resample_result object.
Definition hdrl_resample.c:848
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()
Definition hdrl_resample.c:2605
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().
Definition hdrl_resample.c:2635
hdrl_parameter * hdrl_resample_parameter_create_nearest(void)
Creates a resample nearest neighbor hdrl parameter object. The algorithm does not use any weighting f...
Definition hdrl_resample.c:3150
cpl_error_code hdrl_resample_parameter_method_verify(const hdrl_parameter *hp)
verify parameters have proper values
Definition hdrl_resample.c:3381
int hdrl_resample_parameter_method_check(const hdrl_parameter *self)
check method is of proper type
Definition hdrl_resample.c:3482
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...
Definition hdrl_resample.c:3013
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...
Definition hdrl_resample.c:3198
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...
Definition hdrl_resample.c:3253
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...
Definition hdrl_resample.c:3108
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...
Definition hdrl_resample.c:3060
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,...
Definition hdrl_resample.c:2819
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,...
Definition hdrl_resample.c:2948
int hdrl_resample_parameter_outgrid_check(const hdrl_parameter *self)
check method is of proper type
Definition hdrl_resample.c:3465
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,...
Definition hdrl_resample.c:2757
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,...
Definition hdrl_resample.c:2879
cpl_error_code hdrl_resample_parameter_outgrid_verify(const hdrl_parameter *hp)
verify parameters have proper values
Definition hdrl_resample.c:3292
Definition hdrl_image_defs.h:40
Definition hdrl_imagelist_defs.h:42
Definition hdrl_resample.c:72
double crval1
Definition hdrl_resample.c:74
double cd22
Definition hdrl_resample.c:75
double cd12
Definition hdrl_resample.c:75
double crval2
Definition hdrl_resample.c:74
double crpix1
Definition hdrl_resample.c:73
double cddet
Definition hdrl_resample.c:76
double cd21
Definition hdrl_resample.c:75
double crpix2
Definition hdrl_resample.c:73
double cd11
Definition hdrl_resample.c:75
Definition hdrl_resample.c:79
unsigned int npix
Definition hdrl_resample.c:80
cpl_size * pix
Definition hdrl_resample.c:81
Definition hdrl_resample.c:84
unsigned short nmaps
Definition hdrl_resample.c:94
cpl_size * pix
Definition hdrl_resample.c:90
cpl_size nx
Definition hdrl_resample.c:91
cpl_size nz
Definition hdrl_resample.c:93
cpl_size * nxalloc
Definition hdrl_resample.c:96
cpl_size * nxmap
Definition hdrl_resample.c:95
cpl_size ny
Definition hdrl_resample.c:92
hdrl_resample_pixels_ext ** xmaps
Definition hdrl_resample.c:97
Definition hdrl_resample.h:72
hdrl_imagelist * himlist
Definition hdrl_resample.h:74
cpl_propertylist * header
Definition hdrl_resample.h:73