30#define SBRM_UNDERSCORE_MACRO
33#include "visir_utils.h"
34#include "visir_pfits.h"
35#include "visir_parameter.h"
36#include "visir_pfits.h"
37#include "visir_spc_distortion.h"
38#include "visir_inputs.h"
39#include "irplib_framelist.h"
40#include "irplib_wcs.h"
53#define VISIR_SECS_PER_DAY (24 * 3600)
55#define FIND_BEAM_MAX_APERTURES_SQR (40 * 40)
60#define RESET SBRM_RESET
63#define ERROR SBRM_ABORT
64#define CLEANUP SBRM_CLEANUP
71#include "visir_destripe.h"
73static cpl_image * visir_load_average(
const char *,
74 const cpl_propertylist *);
75static cpl_imagelist * visir_load_intermint(
const irplib_framelist *,
int);
76static cpl_error_code visir_imagelist_unpack_interm(cpl_imagelist *);
77static cpl_error_code visir_rem_glitch(cpl_image *);
78static cpl_error_code visir_rem_bad_images(cpl_imagelist *);
79static cpl_error_code visir_offset_hcycle(cpl_image *);
81static cpl_image ** visir_img_collapse_beam_four(cpl_propertylist *,
84 double,
double,
double,
85 const cpl_propertylist *);
87static cpl_image ** visir_img_collapse_beam_three(cpl_propertylist *,
91 const cpl_propertylist *);
94static cpl_error_code visir_img_find_beam_three(cpl_propertylist *,
97 double,
double,
double,
101static cpl_error_code visir_img_find_beam_four(cpl_propertylist *,
104 double,
double,
double,
117void visir_aplist_destroy(visir_aplist * list)
119 cx_list_destroy((list), (cx_free_func)visir_apdefs_delete);
138cpl_error_code visir_load_cube2_split_(cpl_imagelist * alist, cpl_imagelist * blist,
139 cpl_imagelist * packed, cpl_image * prevd)
142 int naxis3 = cpl_imagelist_get_size(packed);
143 int prevd_insert_pos = cpl_imagelist_get_size(blist);
145 bug_if(alist == NULL);
146 bug_if(blist == NULL);
150 cpl_imagelist_set(blist, prevd, prevd_insert_pos);
153 for (
int i = 0; i < naxis3/2; i++) {
154 cpl_image * aimage = cpl_imagelist_unset(packed, 0);
155 cpl_image * dimage = cpl_imagelist_unset(packed, 0);
157 cpl_imagelist_set(alist, aimage, cpl_imagelist_get_size(alist));
158 cpl_imagelist_set(blist, dimage, cpl_imagelist_get_size(blist));
162 skip_if_lt(0, cpl_imagelist_get_size(packed),
"Too many packed frames");
165 bug_if(visir_imagelist_unpack_interm(blist));
169 cpl_imagelist_unset(blist, prevd_insert_pos);
171 for (
int i = 0; i < naxis3/2; i++) {
172 cpl_image * aimage = cpl_imagelist_get(alist, i);
173 cpl_image * dimage = cpl_imagelist_get(blist, i);
175 cpl_image * bimage = cpl_image_subtract_create(aimage, dimage);
177 visir_offset_hcycle(aimage);
178 visir_offset_hcycle(bimage);
180 bug_if(cpl_imagelist_set(blist, bimage, i));
184 skip_if_lt(0, cpl_imagelist_get_size(packed),
"Too many packed frames");
188 return cpl_error_get_code();
206static cpl_imagelist * load_range(
const char * filename,
213 cpl_imagelist * self = cpl_imagelist_new();
215 for (
int iplane = pstart; iplane < pend; iplane++) {
216 cpl_image * image = cpl_image_load(filename, im_type, iplane, iext);
218 if (image == NULL)
break;
220 if (cpl_imagelist_set(self, image, selfsize)) {
221 cpl_image_delete(image);
256 const irplib_framelist * rawframes,
int pos,
257 const int planestart,
const int planeend)
260 cpl_imagelist * packed = NULL;
261 const cpl_frame * frame = irplib_framelist_get_const(rawframes, pos);
262 const char * file = cpl_frame_get_filename(frame);
264 visir_data_type data_type;
266 cpl_image * prevd = NULL;
267 const cpl_propertylist * plist =
268 irplib_framelist_get_propertylist_const(rawframes, pos);
269 const int iext = cpl_propertylist_has(plist,
"ZNAXIS3") ? 1 : 0;
274 skip_if(visir_get_data_type(frame, plist, &data_type, NULL));
276 cpl_ensure_code(data_type == VISIR_DATA_CUBE2, CPL_ERROR_ILLEGAL_INPUT);
282 error_if(planestart % 2 == 1, CPL_ERROR_ILLEGAL_INPUT,
283 "Plane start %d wrong. It must be even.", planestart);
284 error_if(planeend < naxis3 && planeend % 2 == 1, CPL_ERROR_ILLEGAL_INPUT,
285 "Plane end %d wrong. It must be even if not larger naxis3=%d",
288 any_if(
"Cannot split non-CUBE2 frame %d/%d in %s", 1+pos,
289 irplib_framelist_get_size(rawframes), file);
290 bug_if(alist == NULL);
291 bug_if(blist == NULL);
293 error_if(data_type != VISIR_DATA_CUBE2, CPL_ERROR_INCOMPATIBLE_INPUT,
294 "Cannot split non-CUBE2 frame %d/%d w. NAXIS3=%d, "
295 "NCYCLES=%d in %s", 1+pos,
296 irplib_framelist_get_size(rawframes), naxis3, nchop, file);
298 if (planeend >= naxis3 || planeend < 0)
303 if (planestart != 0) {
304 packed = load_range(file, CPL_TYPE_UNSPECIFIED,
305 iext, planestart - 1, pend);
306 prevd = cpl_imagelist_unset(packed, 0);
309 packed = load_range(file, CPL_TYPE_UNSPECIFIED, iext, planestart, pend);
311 skip_if(visir_load_cube2_split_(alist, blist, packed, prevd));
315 cpl_image_delete(prevd);
316 cpl_imagelist_delete(packed);
318 return cpl_error_get_code();
341cpl_error_code visir_load_burst_(cpl_imagelist * alist, cpl_imagelist * blist,
342 cpl_imagelist * packed,
343 const int ichopchange,
const int ihalfcycle,
344 const int trimlow,
int const trimhigh)
346 cpl_boolean bon = CPL_TRUE;
347 const int offset = 0;
348 const int pend = cpl_imagelist_get_size(packed);
349 int lorej = ihalfcycle - trimlow;
350 int hirej = trimhigh + 1;
354 int chpmv = ichopchange - ihalfcycle * 2;
356 cpl_ensure_code(trimhigh >= -1, CPL_ERROR_ILLEGAL_INPUT);
357 cpl_ensure_code(trimlow >= 0, CPL_ERROR_ILLEGAL_INPUT);
358 cpl_ensure_code(ichopchange < ihalfcycle * 2, CPL_ERROR_ILLEGAL_INPUT);
359 cpl_ensure_code(alist != NULL, CPL_ERROR_NULL_INPUT);
360 cpl_ensure_code(blist != NULL, CPL_ERROR_NULL_INPUT);
367 for (
int i = chpmv; i < pend; i++) {
368 if ((i + ihalfcycle * 2) % ihalfcycle == ichopchange % ihalfcycle) {
370 hirej = trimhigh + 1;
371 lorej = ihalfcycle - trimlow;
373 if (hirej <= 0 && lorej > 0 && i >= 0) {
375 cpl_image * image= cpl_imagelist_unset(packed, offset);
376 cpl_imagelist_set(alist, image, cpl_imagelist_get_size(alist));
379 cpl_image * image= cpl_imagelist_unset(packed, offset);
380 cpl_imagelist_set(blist, image, cpl_imagelist_get_size(blist));
384 cpl_image_delete(cpl_imagelist_unset(packed, offset));
390 cpl_msg_info(cpl_func,
"On: %d, Off %d, Skipped %d",
391 (
int)cpl_imagelist_get_size(alist),
392 (
int)cpl_imagelist_get_size(blist),
393 (
int)(pend - cpl_imagelist_get_size(alist)
394 - cpl_imagelist_get_size(blist)));
396 skip_if_lt(0, cpl_imagelist_get_size(packed),
"Too many packed frames");
400 return cpl_error_get_code();
414static int get_to_off_plane(
int chopchange,
const int offset,
415 const int ihalfcycle)
417 const int ifullcycle = ihalfcycle * 2;
420 (offset / ifullcycle) * ifullcycle > chopchange)
421 chopchange += ifullcycle - (offset % ifullcycle);
423 chopchange -= (offset % ifullcycle);
450cpl_error_code visir_load_burst(cpl_imagelist * alist, cpl_imagelist * blist,
451 const cpl_frame * frame,
const cpl_propertylist * plist,
452 const int ichopchange,
const int ihalfcycle,
453 const int planestart,
const int planeend,
454 const int trimlow,
const int trimhigh)
456 const char * file = cpl_frame_get_filename(frame);
458 const int pend = planeend <= 0 || planeend > naxis3 ? naxis3 : planeend;
459 cpl_imagelist * packed;
460 int to_off = get_to_off_plane(ichopchange, planestart, ihalfcycle);
462 cpl_msg_info(cpl_func,
"Loading planes %d to %d, to off %d",
463 planestart, pend, planestart + to_off);
465 packed = load_range(file, CPL_TYPE_UNSPECIFIED,
466 cpl_propertylist_has(plist,
"ZNAXIS3") ? 1 : 0,
469 skip_if(packed == NULL);
471 if (cpl_imagelist_get_size(packed) > 0) {
472 cpl_image * timg = cpl_imagelist_get(packed, 0);
473 size_t nbytes = visir_get_nbytes(timg);
474 visir_drop_cache(file, 0, nbytes * pend);
477 skip_if(visir_load_burst_(alist, blist, packed, to_off, ihalfcycle,
482 cpl_imagelist_delete(packed);
484 return cpl_error_get_code();
489visir_load_burst_aqu(cpl_imagelist * alist, cpl_imagelist * blist,
490 const cpl_frame * frame,
const cpl_propertylist * plist,
491 const int ihalfcycle,
492 const int planestart,
const int planeend)
494 const char * file = cpl_frame_get_filename(frame);
496 const size_t pend = planeend <= 0 || planeend > naxis3 ? naxis3 : planeend;
497 cpl_imagelist * packed;
499 cpl_msg_info(cpl_func,
"Loading planes %d to %zu",
502 packed = load_range(file, CPL_TYPE_UNSPECIFIED,
503 cpl_propertylist_has(plist,
"ZNAXIS3") ? 1 : 0,
506 skip_if(packed == NULL);
508 if (cpl_imagelist_get_size(packed) > 0) {
509 cpl_image * timg = cpl_imagelist_get(packed, 0);
510 size_t nbytes = visir_get_nbytes(timg);
511 visir_drop_cache(file, 0, nbytes * pend);
514 cpl_boolean bon = CPL_FALSE;
516 for (
size_t i = planestart; i < pend; i++) {
518 cpl_image * image = cpl_imagelist_unset(packed, 0);
519 cpl_imagelist_set(alist, image, cpl_imagelist_get_size(alist));
522 cpl_image * image = cpl_imagelist_unset(packed, 0);
523 cpl_imagelist_set(blist, image, cpl_imagelist_get_size(blist));
526 if (it == ihalfcycle){
534 cpl_imagelist_delete(packed);
536 return cpl_error_get_code();
551 cpl_bivector * lintable = NULL;
552 const char * extname;
553 cpl_ensure(linframe, CPL_ERROR_NULL_INPUT, NULL);
555 extname =
"SPEC_LIN";
558 extname =
"IMAGE_LIN";
560 const char * fn = cpl_frame_get_filename(linframe);
561 cpl_size iext = cpl_fits_find_extension(fn, extname);
562 error_if(iext < 0, CPL_ERROR_ILLEGAL_INPUT,
563 "Linearity correction extension %s not found in %s", extname, fn);
565 cpl_table * tab = cpl_table_load(fn, iext, 0);
566 const size_t nrow = cpl_table_get_nrow(tab);
567 lintable = cpl_bivector_new(nrow);
568 memcpy(cpl_bivector_get_x_data(lintable),
569 cpl_table_get_data_double(tab,
"dc_level"),
570 sizeof(
double) * nrow);
571 memcpy(cpl_bivector_get_y_data(lintable),
572 cpl_table_get_data_double(tab,
"conv_gain"),
573 sizeof(
double) * nrow);
574 cpl_table_delete(tab);
577 cpl_vector_divide_scalar(cpl_bivector_get_y(lintable),
578 cpl_vector_get_mean(cpl_bivector_get_y(lintable)));
585visir_load_bpm(cpl_frame * frm, visir_data_type dtype, cpl_boolean is_spec)
587 const char * fn = cpl_frame_get_filename(frm);
588 const char * extname;
589 if (visir_data_is_aqu(dtype)) {
590 extname = is_spec ?
"BPM_AQU_SPC" :
"BPM_AQU_IMG";
593 extname = is_spec ?
"BPM_DRS_SPC" :
"BPM_DRS_IMG";
595 cpl_size iext = cpl_fits_find_extension(fn, extname);
596 cpl_msg_info(cpl_func,
"Loading BPM extension %s from %s", extname, fn);
600 return cpl_image_load(fn, CPL_TYPE_UNSPECIFIED, 0, iext);
627 const cpl_image * self,
628 const cpl_parameterlist * parlist,
629 const char * recipename,
630 visir_chopnod_mode mode,
631 const cpl_propertylist * plist)
634 cpl_image ** combined = NULL;
636 cpl_image * inverse = cpl_image_multiply_scalar_create(self, -1.0);
643 const double pthrow = pscale > 0.0
647 skip_if(self == NULL);
648 skip_if(parlist == NULL);
649 skip_if(qclist == NULL);
650 skip_if(plist == NULL);
652 if (mode == VISIR_CHOPNOD_PERPENDICULAR) {
654 combined = visir_img_collapse_beam_four(qclist, self, inverse, eccmax,
655 pthrow, angle, plist);
656 }
else if (mode == VISIR_CHOPNOD_PARALLEL) {
658 combined = visir_img_collapse_beam_three(qclist, self, inverse, eccmax,
660 }
else if (mode == VISIR_CHOPNOD_AUTO) {
661 cpl_errorstate cleanstate = cpl_errorstate_get();
665 if (sdir != NULL && !strcmp(sdir,
"PERPENDICULAR")) {
667 combined = visir_img_collapse_beam_four(qclist, self, inverse,
668 eccmax, pthrow, angle, plist);
669 }
else if (sdir != NULL && !strcmp(sdir,
"PARALLEL")) {
671 combined = visir_img_collapse_beam_three(qclist, self, inverse,
672 eccmax, pthrow, plist);
675 visir_error_reset(
"Could not get FITS key");
677 cpl_msg_warning(cpl_func,
"Unknown chopping direction: %s",
680 cpl_msg_warning(cpl_func,
"Proceeding as if FITS card "
681 VISIR_PFITS_STRING_CHOPNOD_DIR
" had value: %s",
683 combined = visir_img_collapse_beam_four(qclist, self, inverse,
684 eccmax, pthrow, angle, plist);
685 if (combined == NULL) {
686 visir_error_reset(
"Proceeding as if FITS card "
687 VISIR_PFITS_STRING_CHOPNOD_DIR
688 " had value: %s",
"PARALLEL");
689 combined = visir_img_collapse_beam_three(qclist, self, inverse,
690 eccmax, pthrow, plist);
697 skip_if(combined == NULL);
699 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM THROW",
701 bug_if (cpl_propertylist_set_comment(qclist,
"ESO QC ONEBEAM THROW",
702 "The throw in pixels (TEL CHOP THROW "
703 "divided by INS PFOV)"));
705 bug_if (cpl_propertylist_set_comment(qclist,
"ESO QC ONEBEAM XPOS",
706 "The X pixel position (centroid) "
707 "of the one-beam object"));
709 bug_if (cpl_propertylist_set_comment(qclist,
"ESO QC ONEBEAM YPOS",
710 "The Y pixel position (centroid) "
711 "of the one-beam object"));
712 bug_if (cpl_propertylist_set_comment(qclist,
"ESO QC ONEBEAM ECCENTRICITY",
713 "Eccentricity: 0 for perfect, throw-"
714 "sized square/line"));
718 cpl_image_delete(inverse);
809 const cpl_parameterlist * parlist,
810 const irplib_framelist * rawframes,
814 cpl_boolean do_spc_fix,
816 visir_spc_resol resol)
818 const char * fnodpos;
820 cpl_imagelist * in = NULL;
821 cpl_image * collapsed = NULL;
822 cpl_image * prev = NULL;
823 cpl_vector * nods_vec = NULL;
825 int * nod_pos = NULL;
826 cpl_image ** images = NULL;
827 cpl_imagelist * nodded = NULL;
829 cpl_image * flat_image = NULL;
830 cpl_image * bpm_im_int = NULL;
831 cpl_mask * bpm_im_bin = NULL;
832 cpl_imagelist * hcycle = NULL;
834 cpl_boolean is_nodding = CPL_FALSE;
836 cpl_boolean auto_bpm, rem_glitch, rem_bad;
839 cpl_boolean morpho_destripe;
840 double tstart, tstop;
841 const cpl_propertylist * plist1;
843 cpl_errorstate cleanstate = cpl_errorstate_get();
845 cpl_error_code didfail = CPL_ERROR_NONE;
849 skip_if(recipename == NULL);
850 skip_if(parlist == NULL);
851 skip_if(rawframes == NULL);
854 nfiles = irplib_framelist_get_size(rawframes);
858 cpl_msg_warning(cpl_func,
"Expecting even number of files, "
859 "ignoring the last of %d file(s)", nfiles);
860 error_if (nfiles == 1, CPL_ERROR_DATA_NOT_FOUND,
861 "At least two files are required");
869 skip_if(irplib_framelist_contains(rawframes, VISIR_PFITS_STRING_FRAME_TYPE,
870 CPL_TYPE_STRING, CPL_FALSE, 0.0));
871 skip_if(irplib_framelist_contains(rawframes, VISIR_PFITS_DOUBLE_DIT,
872 CPL_TYPE_DOUBLE, CPL_FALSE, 0.0));
874 skip_if (irplib_framelist_contains(rawframes,
"NAXIS1",
875 CPL_TYPE_INT, CPL_TRUE, 0.0));
876 skip_if (irplib_framelist_contains(rawframes,
"NAXIS2",
877 CPL_TYPE_INT, CPL_TRUE, 0.0));
878 skip_if(irplib_framelist_contains(rawframes, VISIR_PFITS_INT_NAXIS3,
879 CPL_TYPE_INT, CPL_FALSE, 0.0));
880 skip_if(irplib_framelist_contains(rawframes, VISIR_PFITS_INT_CHOP_NCYCLES,
881 CPL_TYPE_INT, CPL_FALSE, 0.0));
883 plist1 = irplib_framelist_get_propertylist_const(rawframes, 0);
884 naxis1 = irplib_pfits_get_int(plist1,
"NAXIS1");
885 naxis2 = irplib_pfits_get_int(plist1,
"NAXIS2");
894 VISIR_PARAM_AUTOBPM);
906 VISIR_PARAM_STRIPITE);
909 morpho_destripe = ndestripe <= 0 ? CPL_FALSE :
911 VISIR_PARAM_STRIPMOR);
914 no_rem = !rem_glitch && !rem_bad;
918 nod_pos = nodding_p ? nodding_p : cpl_malloc(nfiles *
sizeof(
int));
920 if (!visir_str_par_is_empty(fnodpos)) {
922 nods_vec = cpl_vector_read(fnodpos);
923 skip_if (cpl_vector_get_size(nods_vec) != nfiles);
924 nods_data = cpl_vector_get_data(nods_vec);
926 for (i=0 ; i<nfiles ; i++) {
927 if ((
int)nods_data[i] == 0) {
930 }
else if ((
int)nods_data[i] == 1) {
932 is_nodding = CPL_TRUE;
934 error_if(1, CPL_ERROR_BAD_FILE_FORMAT,
935 "Wrong values in line %d in %s", i+1, fnodpos);
939 skip_if (irplib_framelist_contains(rawframes, VISIR_PFITS_STRING_NODPOS,
940 CPL_TYPE_STRING, CPL_FALSE, 0.0));
943 if (no_rem) cpl_msg_info(cpl_func,
"No glitch removal and no purge of bad "
944 "frames requested: Using fast I/O method");
947 if (badpix != NULL) {
949 cpl_msg_info(cpl_func,
"Loading bad pixel map from %s", badpix);
951 bpm_im_int = cpl_image_load(badpix, CPL_TYPE_INT, 0, 0);
955 bpm_im_bin = cpl_mask_threshold_image_create(bpm_im_int, -0.5, 0.5);
956 cpl_image_delete(bpm_im_int);
958 skip_if (cpl_mask_not(bpm_im_bin));
959 }
else if (auto_bpm) {
967 cpl_mask_threshold_image_create(cpl_imagelist_get(hcycle,0),
968 VISIR_HCYCLE_BPM_THRESHOLD,
970 cpl_imagelist_delete(hcycle);
977 cpl_msg_info(cpl_func,
"Divide the nodded images by the flatfield");
979 flat_image = cpl_image_load(flat, CPL_TYPE_FLOAT, 0, 0);
980 any_if (
"Cannot load the flat field %s", flat ? flat :
"<NULL>");
984 nodded = cpl_imagelist_new();
986 tstart = cpl_test_get_walltime();
990 for (i=0; i < nfiles/2 ; i++) {
991 cpl_image * empty = cpl_image_new(naxis1, naxis2, CPL_TYPE_FLOAT);
996 bug_if (cpl_imagelist_set(nodded, empty, i));
1000#pragma omp parallel for private(i) firstprivate(prev, collapsed) \
1003 for (i = 0; i < nfiles ; i++) {
1004 cpl_error_code errori = cpl_error_get_code();
1012 if (didfail)
continue;
1017 cpl_frame_get_filename(irplib_framelist_get_const(rawframes, i));
1018 const cpl_propertylist * plist;
1024 plist = irplib_framelist_get_propertylist_const(rawframes, i);
1025 if (plist == NULL) {
1026 errori = cpl_error_set_where(cpl_func);
1030 if (nods_vec == NULL) {
1033 errori = cpl_error_set_message(cpl_func,
1034 CPL_ERROR_DATA_NOT_FOUND,
1035 "Cannot get nodding position "
1036 "for file %d/%d", i+1, nfiles);
1039 if (!strcmp(sval,
"A")) {
1047 is_nodding = CPL_TRUE;
1052 cpl_msg_info(cpl_func,
"File %02d: %s (%c)", i+1, file,
1053 nod_pos[i]==1 ?
'+' :
'-');
1056 if (is_nodding && (i & 1) == 1 && nod_pos[i] == nod_pos[i-1]) {
1057 cpl_msg_error(cpl_func,
"Nodding pair (%d,%d) does not comprise an "
1058 "on-object (A) and an off-object (B) image: %s", i-1,
1059 i, nod_pos[i] == 1 ?
"A" :
"B");
1064 if (cpl_error_get_code()) {
1065 errori = cpl_error_set_where(cpl_func);
1070 errori = cpl_error_set_message(cpl_func,
1071 CPL_ERROR_ILLEGAL_INPUT,
1072 "DIT in file %d/%d is too small: "
1073 "%g", i+1, nfiles, dit);
1077 factor = dit * nod_pos[i] * 2.0;
1080 collapsed = visir_load_average(file, plist);
1082 in = visir_load_intermint(rawframes, i);
1084 errori = cpl_error_set_message(cpl_func,
1085 CPL_ERROR_ILLEGAL_INPUT,
1086 "Could not load image set %d",
1092 if (visir_imagelist_unpack_interm(in)) {
1093 errori = cpl_error_set_message(cpl_func,
1094 cpl_error_get_code(),
1095 "Failure for file %d/%d",
1104 for (jj=0 ; jj < cpl_imagelist_get_size(in); jj++) {
1105 if (visir_rem_glitch(cpl_imagelist_get(in, jj))) {
1106 errori = cpl_error_set_message(cpl_func,
1107 cpl_error_get_code(),
1109 "glitch in image %d in "
1110 "set %d", jj+1, i+1);
1118 cpl_msg_info(cpl_func,
"Remove the bad A-B input images");
1119 if (visir_rem_bad_images(in)) {
1120 errori = cpl_error_set_message(cpl_func,
1121 cpl_error_get_code(),
1122 "Could not remove bad "
1123 "images in list %d", i+1);
1128 collapsed = cpl_imagelist_collapse_create(in);
1130 cpl_imagelist_delete(in);
1135 if (cpl_error_get_code()) {
1136 errori = cpl_error_set_message(cpl_func, cpl_error_get_code(),
1137 "Failure for file %d/%d",
1143 if (cpl_image_divide_scalar(collapsed, 2*factor)) {
1144 errori = cpl_error_set_message(cpl_func, cpl_error_get_code(),
1145 "Failure for file %d/%d",
1152 if (cpl_image_add(prev, collapsed)) {
1153 errori = cpl_error_set_message(cpl_func, cpl_error_get_code(),
1154 "Failure for file %d/%d",
1158 cpl_image_delete(collapsed);
1164 if (bpm_im_bin != NULL) {
1166 if (cpl_image_reject_from_mask(prev, bpm_im_bin)) {
1167 errori = cpl_error_set_message(cpl_func,
1168 cpl_error_get_code(),
1169 "Failure for file %d/%d",
1173 if (cpl_detector_interpolate_rejected(prev)) {
1174 errori = cpl_error_set_message(cpl_func,
1175 cpl_error_get_code(),
1176 "Failure for file %d/%d",
1184 VISIR_DESTRIPE_DETECT,
1185 VISIR_DESTRIPE_DETECT_THRESHOLD,
1187 errori = cpl_error_set_message(cpl_func,
1188 cpl_error_get_code(),
1189 "Failure for file %d/%d",
1194 if (flat_image != NULL) {
1196 if (cpl_image_divide(prev, flat_image)) {
1197 errori = cpl_error_set_message(cpl_func,
1198 cpl_error_get_code(),
1199 "Failure for file %d/%d",
1205 if (cpl_imagelist_set(nodded, prev, i/2)) {
1206 errori = cpl_error_set_message(cpl_func, cpl_error_get_code(),
1207 "Failure for file %d/%d",
1222 cpl_errorstate_dump(cleanstate, CPL_FALSE, NULL);
1223 cpl_errorstate_set(cleanstate);
1226 cpl_image_delete(prev); prev = NULL;
1227 cpl_image_delete(collapsed); collapsed = NULL;
1229#pragma omp critical(visir_inputs_combine)
1235 error_if(didfail, didfail,
"Failed to create %d nodded images from %d "
1236 "files", nnod, nfiles);
1238 tstop = cpl_test_get_walltime();
1239 cpl_msg_info(cpl_func,
"Time to create %d nodded images [s]: %g", nnod,
1242 cpl_vector_delete(nods_vec);
1245 cpl_image_delete(flat_image);
1248 cpl_mask_delete(bpm_im_bin);
1251 if (nod_pos != nodding_p) cpl_free(nod_pos);
1254 error_if(is_nodding && j != nnod, CPL_ERROR_INCOMPATIBLE_INPUT,
1255 "With nodding exactly half of the images "
1256 "must be on-object, not %d of %d", j, 2*nnod);
1260 parlist, recipename, VISIR_PARAM_SPECSKEW);
1262 parlist, recipename, VISIR_PARAM_VERTARC);
1264 parlist, recipename, VISIR_PARAM_HORIARC);
1266 parlist, recipename, VISIR_PARAM_SLITSKEW);
1268 parlist, recipename, VISIR_PARAM_PLOT);
1272 images = cpl_malloc(nnod *
sizeof(cpl_image*));
1274 for (j = 0; j < nnod; j++) images[j] = cpl_imagelist_get(nodded, j);
1276 skip_if (visir_spc_det_fix(images, nnod, CPL_TRUE, wlen, resol,
1277 phi, ksi, eps, delta, doplot));
1282 cpl_msg_set_time_off();
1285 cpl_imagelist_delete(in);
1287 if (nod_pos != nodding_p) cpl_free(nod_pos);
1288 cpl_vector_delete(nods_vec);
1289 cpl_image_delete(bpm_im_int);
1290 cpl_mask_delete(bpm_im_bin);
1291 cpl_image_delete(collapsed);
1292 cpl_image_delete(prev);
1293 if (cpl_error_get_code() && nodded != NULL) {
1294 cpl_imagelist_delete(nodded);
1312get_cumoffsets(
const cpl_propertylist * plist,
double * x,
double * y)
1314 cpl_errorstate cleanstate = cpl_errorstate_get();
1316 *x = irplib_pfits_get_double(plist,
"ESO DRS CUMOFFSETX");
1317 *y = irplib_pfits_get_double(plist,
"ESO DRS CUMOFFSETY");
1319 if (cpl_error_get_code() != CPL_ERROR_NONE) {
1320 cpl_errorstate_set(cleanstate);
1321 cpl_msg_info(cpl_func,
"DRS CUMOFFSET[XY] not found, falling back"
1322 " to SEQ CUMOFFSET[XY]");
1326 return cpl_error_get_code();
1346 const cpl_parameterlist * parlist,
1347 cpl_imagelist * nodded,
1348 const cpl_propertylist ** plists,
1349 cpl_geom_combine combine_mode,
1350 cpl_boolean * pdid_resize)
1353 cpl_bivector * offsets_est = NULL;
1354 cpl_bivector * objs = NULL;
1355 cpl_image ** combined = NULL;
1356 cpl_vector * sigmas = NULL;
1357 cpl_propertylist * qclist = cpl_propertylist_new();
1362 bug_if (recipename == NULL);
1363 bug_if (parlist == NULL);
1364 bug_if (pdid_resize == NULL);
1365 bug_if (nodded == NULL);
1367 nnod = cpl_imagelist_get_size(nodded);
1368 cpl_msg_debug(cpl_func,
"nnod = %lld", nnod);
1372 combined = cpl_malloc(2*
sizeof(cpl_image*));
1375 combined[0] = cpl_imagelist_unset(nodded, 0);
1376 bug_if (combined[0] == NULL);
1378 combined[1] = cpl_image_new(cpl_image_get_size_x(combined[0]),
1379 cpl_image_get_size_y(combined[0]),
1381 bug_if (combined[1] == NULL);
1384 bug_if(cpl_image_threshold(combined[1], 1.0, 1.0, 1.0, 1.0));
1386 *pdid_resize = CPL_FALSE;
1389 const double psigmas[] = {5, 2, 1, 0.5};
1391 const char * offsets;
1392 const char * objects;
1394 int rej_low, rej_high;
1399 VISIR_PARAM_REFINE);
1403 VISIR_PARAM_OFFSETS);
1407 VISIR_PARAM_OBJECTS);
1414 if (sscanf(sval,
"%d-%d-%d-%d", &sx, &sy, &mx, &my) != 4)
1415 skip_if (sscanf(sval,
"%d %d %d %d", &sx, &sy, &mx, &my) != 4);
1419 VISIR_PARAM_REJECT);
1422 if (sscanf(sval,
"%d-%d", &rej_low, &rej_high) !=2 )
1423 skip_if (sscanf(sval,
"%d %d", &rej_low, &rej_high) !=2 );
1426 cpl_msg_info(cpl_func,
"Get the offsets estimation");
1427 if (!visir_str_par_is_empty(offsets)) {
1429 offsets_est = cpl_bivector_read(offsets);
1430 skip_if (offsets_est==NULL);
1432 error_if (cpl_bivector_get_size(offsets_est) != nnod,
1433 CPL_ERROR_BAD_FILE_FORMAT,
"The offsets file %s must "
1434 "have %d entries, not %d", offsets, (
int)nnod,
1435 (
int)cpl_bivector_get_size(offsets_est));
1437 double * offsets_est_x;
1438 double * offsets_est_y;
1439 double xoff0, yoff0;
1442 offsets_est = cpl_bivector_new(nnod);
1443 offsets_est_x = cpl_bivector_get_x_data(offsets_est);
1444 offsets_est_y = cpl_bivector_get_y_data(offsets_est);
1448 offsets_est_x[0] = 0.0;
1449 offsets_est_y[0] = 0.0;
1450 get_cumoffsets(plists[0], &xoff0, &yoff0);
1452 for (cpl_size i = 1; i < nnod ; i++) {
1455 skip_if(get_cumoffsets(plists[i], &xoff, &yoff));
1458 offsets_est_x[i] = xoff0 - xoff;
1459 offsets_est_y[i] = yoff0 - yoff;
1465 if (!visir_str_par_is_empty(objects)) {
1466 objs = cpl_bivector_read(objects);
1467 any_if (
"Could not read objects from %s", objects);
1470 cpl_msg_info(cpl_func,
"Recombining the list of nodded images using "
1471 "mode: %d (I=%d:U=%d:F=%d), rej-lo=%d, rej-hi=%d",
1472 combine_mode, CPL_GEOM_INTERSECT, CPL_GEOM_UNION,
1473 CPL_GEOM_FIRST, rej_low, rej_high);
1475 if (cpl_msg_get_level() <= CPL_MSG_DEBUG) {
1476 cpl_msg_debug(cpl_func,
"The offsets for the recombination:");
1477 cpl_bivector_dump(offsets_est, stdout);
1480 IRPLIB_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual);
1481 sigmas = cpl_vector_wrap(4, (
double*)psigmas);
1482 IRPLIB_DIAG_PRAGMA_POP;
1483 combined = cpl_geom_img_offset_combine(nodded, offsets_est, refine,
1484 objs, sigmas, NULL, sx, sy,
1485 mx, my, rej_low, rej_high,
1487 any_if(
"Could not recombine the images");
1489 *pdid_resize = (cpl_boolean)(cpl_image_get_size_x(combined[0])
1490 != cpl_image_get_size_x(cpl_imagelist_get_const(nodded, 0)) ||
1491 cpl_image_get_size_y(combined[0])
1492 != cpl_image_get_size_y(cpl_imagelist_get_const(nodded, 0)));
1496 visir_image_plot(
"",
"t 'The combined image'",
"", combined[0]);
1500 cpl_propertylist_delete(qclist);
1501 cpl_bivector_delete(offsets_est);
1502 cpl_bivector_delete(objs);
1503 cpl_vector_unwrap(sigmas);
1557 const cpl_parameterlist * parlist,
1558 const irplib_framelist * rawframes,
1559 const char * badpix,
1561 cpl_geom_combine combine_mode,
1562 cpl_boolean * pdid_resize,
1563 cpl_boolean do_spc_fix,
1565 visir_spc_resol resol)
1568 int * nod_pos = NULL;
1569 cpl_imagelist * nodded = NULL;
1571 cpl_bivector * objs = NULL;
1572 cpl_propertylist * qclist = cpl_propertylist_new();
1573 const cpl_propertylist ** plists = NULL;
1574 cpl_image ** rec = NULL;
1579 bug_if (recipename == NULL);
1580 bug_if (parlist == NULL);
1581 bug_if (rawframes == NULL);
1582 bug_if (pdid_resize == NULL);
1585 nfiles = irplib_framelist_get_size(rawframes);
1586 cpl_msg_debug(cpl_func,
"nfiles = %d", nfiles);
1590 cpl_msg_warning(cpl_func,
"Expecting even number of files, "
1591 "ignoring the last of %d file(s)", nfiles);
1592 error_if (nfiles == 1, CPL_ERROR_DATA_NOT_FOUND,
1593 "At least two files are required");
1597 skip_if ( nfiles <= 0);
1600 nod_pos = cpl_malloc(nfiles *
sizeof(
int));
1603 cpl_msg_info(cpl_func,
"Combining the input frames into the nodded images");
1605 nod_pos, do_spc_fix, wlen, resol);
1606 skip_if(nodded == NULL);
1608 nnod = cpl_imagelist_get_size(nodded);
1609 cpl_msg_debug(cpl_func,
"nnod = %lld", nnod);
1610 plists = cpl_malloc(nnod *
sizeof(cpl_propertylist *));
1611 for (cpl_size i=0; i < nnod ; i++) {
1612 const cpl_size iframe = nod_pos[2*i] == 1 ? 2*i : 2*i+1;
1614 plists[i] = irplib_framelist_get_propertylist_const(rawframes,
1619 plists, combine_mode, pdid_resize);
1623 cpl_propertylist_delete(qclist);
1626 cpl_imagelist_delete(nodded);
1627 cpl_bivector_delete(objs);
1670 INIT(4, rv, visir_aplist) = NULL;
1672 SET(fp, FILE, i, fclose) = fopen(apfile,
"r");
1673 if (!fp->o)
return ERROR(CPL_ERROR_FILE_NOT_FOUND,
1674 "Cannot open apfile (supply full path): %s", apfile);
1677 SET(line,
char, v, free) = NULL;
1678 SET(list, visir_aplist) = visir_aplist_new();
1679 while (getline(&line->o, &(
size_t){0}, fp->o) != -1) {
1682 if (!ap->o)
continue;
1683 visir_aplist_push_back(list->o, YANK(ap));
1687 if (visir_aplist_size(list->o) < 1)
return ERROR(CPL_ERROR_BAD_FILE_FORMAT,
1688 "File has no usable entries: %s", apfile);
1690 return CLEANUP(list);
1702 int offs = snprintf(buf,
sizeof(buf),
"%c %d %d", ap->extract_method,
1703 ap->limits[0].l, ap->limits[0].r);
1704 if (ap->nlimits > 1) {
1705 offs += snprintf(buf+offs,
sizeof(buf)-offs,
" %c", ap->sky_method);
1706 for (
size_t i = 1; i < ap->nlimits; ++i)
1707 offs += snprintf(buf+offs,
sizeof(buf)-offs,
" %d %d",
1708 ap->limits[i].l, ap->limits[i].r);
1710 return cpl_sprintf(
"%s", buf);
1724 INIT(2, rv, visir_apdefs) = NULL;
1727 char * term = strchr(line,
'#');
1728 if (term) *term =
'\0';
1730 char const *
const intro =
"Error parsing apfile: ";
1731 SET(outro,
char, v, cpl_free) = cpl_sprintf _(
" on apfile line: %s", line);
1735 char max = 40, * toks[max];
1736 char * state, * tok = strtok_r(line,
"\n\t ", &state);
1737 for (; tok; tok = strtok_r(NULL,
"\n\t ", &state)) {
1738 toks[ntoks++] = tok;
1739 if (ntoks > max)
return ERROR(
1740 CPL_ERROR_BAD_FILE_FORMAT,
"%sToo many tokens%s", intro, outro->o);
1744 if (ntoks != 0 && ntoks != 3 && (ntoks < 6 || ntoks % 2))
return ERROR(
1745 CPL_ERROR_BAD_FILE_FORMAT,
"%sWrong token count%s", intro, outro->o);
1746 const int nlimits = (ntoks == 3 ? 2 : ntoks-2);
1749 if (!ntoks)
return CLEANUP();
1753 if (toks[0][0] !=
'O')
return ERROR(CPL_ERROR_BAD_FILE_FORMAT,
1754 "%sMethod & token count mismatch%s", intro, outro->o);
1756 if (toks[0][0] !=
'A' || !strchr(
"AFM", toks[3][0]))
return ERROR(
1757 CPL_ERROR_BAD_FILE_FORMAT,
"%sMethod & token count mismatch%s",
1762 int nscans = nlimits;
1763 for (
int i = 1; i < ntoks; i += (i==2 ? 2 : 1))
1764 nscans -= sscanf(toks[i],
"%f", &(
float){0});
1765 if (nscans)
return ERROR(CPL_ERROR_BAD_FILE_FORMAT,
1766 "%sToken scan failure%s", intro, outro->o);
1769 SET(
new, visir_apdefs) = visir_apdefs_new(nlimits/2, ident, toks[0][0],
1770 ntoks > 3 ? toks[3][0] : 0);
1771 for (
int i = 1, j = 0; i < ntoks; i += (i==2 ? 2 : 1), ++j) {
1773 sscanf(toks[i],
"%f", &temp);
1774 new->o->limits[j].l = (int)floor(temp);
1775 sscanf(toks[++i],
"%f", &temp);
1776 new->o->limits[j].r = (int)ceil(temp);
1777 if (new->o->limits[j].l > new->o->limits[j].r)
return ERROR(
1778 CPL_ERROR_BAD_FILE_FORMAT,
"%sLeft aperture limit greater than "
1779 "right%s", intro, outro->o);
1783 if (new->o->nlimits > 2) {
1786 for (
size_t i = 1; i <
new->o->nlimits - 1; ++i) {
1788 for (
size_t j = i + 1; j <
new->o->nlimits; ++j)
1789 if (new->o->limits[j].l < new->o->limits[mini].l)
1792 visir_aplimits tmp =
new->o->limits[mini];
1793 new->o->limits[mini] =
new->o->limits[i];
1794 new->o->limits[i] = tmp;
1798 int nskys =
new->o->nlimits - 1;
1799 int niterations = nskys - 1;
1800 for (
int i = 0; i < niterations; ++i)
1801 if (new->o->limits[i+1].r > new->o->limits[i+2].l)
1802 return ERROR(CPL_ERROR_BAD_FILE_FORMAT,
"%sOverlapping "
1803 "apertures found%s", intro, outro->o);
1806 return CLEANUP(
new);
1824 cpl_image * im_bpm = NULL;
1825 cpl_mask * bpm = NULL;
1826 const int upper = VISIR_HCYCLE_BPM_THRESHOLD;
1831 skip_if (self == NULL);
1833 if (bpmfile == NULL) {
1834 bpm = cpl_mask_threshold_image_create(self, upper, DBL_MAX);
1839 cpl_msg_info(cpl_func,
"Clean user specified bad pixels");
1841 im_bpm = cpl_image_load(bpmfile, CPL_TYPE_INT, 0, 0);
1842 any_if (
"Could not load the bad pixel map %s",
1843 bpmfile ? bpmfile :
"<NULL>");
1845 bpm = cpl_mask_threshold_image_create(im_bpm, -0.5, 0.5);
1847 cpl_image_delete(im_bpm);
1850 skip_if (cpl_mask_not(bpm));
1853 skip_if (cpl_image_reject_from_mask(self, bpm));
1857 cpl_image_delete(im_bpm);
1858 cpl_mask_delete(bpm);
1860 return cpl_error_get_code();
1875 cpl_imagelist * self = NULL;
1879 skip_if(irplib_framelist_contains(rawframes, VISIR_PFITS_INT_NAXIS3,
1880 CPL_TYPE_INT, CPL_TRUE, 0.0));
1887 self = irplib_imagelist_load_framelist(rawframes, CPL_TYPE_FLOAT, naxis3-1,
1890 skip_if (self == NULL);
1911 int pos, cpl_boolean is_interm)
1913 cpl_imagelist * self = NULL;
1914 cpl_image * image = NULL;
1915 const cpl_frame * frame = irplib_framelist_get_const(rawframes, pos);
1916 const cpl_propertylist * plist =
1917 irplib_framelist_get_propertylist_const(rawframes, pos);
1918 const char * file = cpl_frame_get_filename(frame);
1921 visir_data_type data_type;
1927 skip_if (plist == NULL);
1929 skip_if(visir_get_data_type(frame, plist, &data_type, NULL));
1931 switch (data_type) {
1932 case VISIR_DATA_AQU_HCYCLE:
1933 case VISIR_DATA_AQU_BURST:
1934 case VISIR_DATA_AQU_BURST_EXT:
1935 error_if(1, CPL_ERROR_UNSUPPORTED_MODE,
1936 "Aquarius data not supported");
1942 bug_if (file == NULL);
1944 if (data_type == VISIR_DATA_CUBE1) {
1946 iplane = is_interm ? 0 : nchop;
1948 nsize = is_interm ? nchop : 1;
1950 }
else if (naxis3 == 1) {
1956 iplane = is_interm ? 1 : 0;
1961 self = cpl_imagelist_new();
1963 for (i=0 ; i < nsize; i++, iplane += plane_step) {
1965 image = cpl_image_load(file, CPL_TYPE_FLOAT, iplane, 0);
1966 skip_if (image == NULL);
1968 skip_if (!is_interm && visir_offset_hcycle(image));
1970 skip_if (cpl_imagelist_set(self, image, i));
1975 skip_if (i < nsize);
1979 if (cpl_error_get_code()) {
1980 if (file != NULL) cpl_msg_warning(cpl_func,
"Could not load the %s "
1981 "frame(s) from: %s",
1982 is_interm ?
"INTERM" :
"Half-Cycle",
1984 cpl_image_delete(image);
1985 cpl_imagelist_delete(self);
2020static cpl_imagelist * visir_load_intermint(
const irplib_framelist * rawframes,
2037static cpl_image * visir_load_average(
const char * file,
2038 const cpl_propertylist * plist)
2040 cpl_errorstate cleanstate = cpl_errorstate_get();
2041 cpl_image * self = NULL;
2046 skip_if (file == NULL);
2047 skip_if (plist == NULL);
2054 if (nchop == 0 && naxis3 == 1) {
2055 self = cpl_image_load(file, CPL_TYPE_FLOAT, 0, 0);
2060 const int plane_offset = (naxis3 == 2 * nchop + 1) ? 2 : 3;
2063 error_if (nchop <= 0, CPL_ERROR_BAD_FILE_FORMAT,
"CHOP NCYCLES in %s "
2064 "is non-positive (and NAXIS3=%d): %d", file, naxis3, nchop);
2066 error_if (plane_offset == 3 && naxis3 != nchop+2,
2067 CPL_ERROR_BAD_FILE_FORMAT,
"NAXIS3=%d and CHOP NCYCLES=%d "
2068 "in %s is not a valid VISIR INTERM+Half-Cycle format", naxis3,
2071 if (plane_offset == 3 && nchop > 1)
2072 cpl_msg_debug(cpl_func,
"%s has %d INTERM-frames and one Half-"
2073 "Cycle frame (old CUBE1-format)", file, nchop);
2079 visir_error_reset(
"Could not get FITS key");
2081 }
else if (strlen(sval) == 0) {
2083 }
else if (plane_offset == 3) {
2084 if (strcmp(sval,
"CUBE2")==0)
2085 cpl_msg_error(cpl_func,
"%s has FRAM TYPE = CUBE2, but NAXIS3="
2086 "%d and CHOP NCYCLES=%d imply a CUBE1. Assuming"
2087 " the frame type is really CUBE1", file,
2089 }
else if (nchop > 1) {
2091 if (strcmp(sval,
"CUBE1")==0)
2092 cpl_msg_error(cpl_func,
"%s has FRAM TYPE = CUBE1, but NAXIS3="
2093 "%d and CHOP NCYCLES=%d imply a CUBE2. Assuming"
2094 "the frame type is really CUBE2", file,
2099 self = cpl_image_load(file, CPL_TYPE_FLOAT, naxis3-plane_offset, 0);
2107 if (cpl_error_get_code()) {
2108 cpl_msg_warning(cpl_func,
"Could not load the last INTERM frame from: "
2109 "%s", file ? file :
"<NULL>");
2110 cpl_image_delete(self);
2141static cpl_error_code visir_imagelist_unpack_interm(cpl_imagelist * self)
2145 const int n = cpl_imagelist_get_size(self);
2150 if (n == 1)
return CPL_ERROR_NONE;
2152 iprev = cpl_imagelist_get(self, n - 1);
2156 skip_if (cpl_image_multiply_scalar(iprev, n));
2159 for (i = n-1 ; i > 1 ; i--, iprev = image) {
2160 image = cpl_imagelist_get(self, i-1);
2164 skip_if (cpl_image_multiply_scalar(image, i));
2166 skip_if (cpl_image_subtract(iprev, image));
2170 image = cpl_imagelist_get(self, 0);
2174 skip_if (cpl_image_subtract(iprev, image));
2178 return cpl_error_get_code();
2195static cpl_error_code visir_rem_glitch(cpl_image * glitchy)
2197 cpl_image * med_filt = NULL;
2198 cpl_mask * bpm = NULL;
2199 cpl_mask * kernel = cpl_mask_new(3, 3);
2201 double low_thresh, high_thresh;
2202 const int nx = cpl_image_get_size_x(glitchy);
2203 const int ny = cpl_image_get_size_y(glitchy);
2207 double factor1 = 3.0;
2208 double factor2 = 10.0;
2209 const int niterations = 5;
2210 const double median_corr = 1.5;
2215 bug_if(cpl_mask_not(kernel));
2218 med_filt = cpl_image_new(cpl_image_get_size_x(glitchy),
2219 cpl_image_get_size_y(glitchy),
2220 cpl_image_get_type(glitchy));
2221 bug_if(med_filt == NULL);
2222 bug_if(cpl_image_filter_mask(med_filt, glitchy, kernel, CPL_FILTER_MEDIAN,
2223 CPL_BORDER_FILTER));
2224 cpl_mask_delete(kernel);
2228 skip_if (cpl_image_subtract(glitchy, med_filt));
2231 for (i=0 ; i < niterations ; i++) {
2233 mean = cpl_image_get_mean(glitchy);
2234 stdev = cpl_image_get_stdev(glitchy);
2239 low_thresh = mean - factor1 * stdev;
2240 high_thresh = mean + factor1 * stdev;
2243 bpm = cpl_mask_threshold_image_create(glitchy,low_thresh,high_thresh);
2244 skip_if (cpl_mask_not(bpm));
2245 skip_if (cpl_image_reject_from_mask(glitchy, bpm));
2246 cpl_mask_delete(bpm);
2250 skip_if (cpl_image_count_rejected(glitchy) == nx*ny);
2255 mean = cpl_image_get_mean(glitchy);
2256 stdev = cpl_image_get_stdev(glitchy) * median_corr;
2260 low_thresh = mean - factor2 * stdev;
2261 high_thresh = mean + factor2 * stdev;
2263 bpm = cpl_mask_threshold_image_create(glitchy, low_thresh, high_thresh);
2264 skip_if (cpl_mask_not(bpm));
2265 skip_if (cpl_image_reject_from_mask(glitchy, bpm));
2266 cpl_mask_delete(bpm);
2270 skip_if (cpl_image_count_rejected(glitchy) == nx*ny);
2273 skip_if (cpl_image_fill_rejected(glitchy, 0.0));
2274 skip_if (cpl_image_accept_all(glitchy));
2277 skip_if (cpl_image_add(glitchy, med_filt));
2281 cpl_image_delete(med_filt);
2282 cpl_mask_delete(bpm);
2283 cpl_mask_delete(kernel);
2285 return cpl_error_get_code();
2300static cpl_error_code visir_rem_bad_images(cpl_imagelist * in)
2302 cpl_vector * medians = NULL;
2303 cpl_vector * stdevs = NULL;
2304 cpl_vector * selection = NULL;
2305 double mean_medians, mean_stdevs, stdev_medians, stdev_stdevs;
2306 const double threshold = 3;
2307 const int nima = cpl_imagelist_get_size(in);
2313 if (nima <= 3)
return CPL_ERROR_NONE;
2316 medians = cpl_vector_new(nima);
2317 stdevs = cpl_vector_new(nima);
2320 for (i=0 ; i < nima ; i++) {
2321 cpl_stats * stats = cpl_stats_new_from_image(cpl_imagelist_get(in, i),
2322 CPL_STATS_STDEV | CPL_STATS_MEDIAN);
2324 cpl_vector_set(medians, i, cpl_stats_get_median(stats));
2325 cpl_vector_set(stdevs, i, cpl_stats_get_stdev(stats));
2326 cpl_stats_delete(stats);
2332 mean_medians = cpl_vector_get_mean(medians);
2333 stdev_medians = cpl_vector_get_stdev(medians);
2334 mean_stdevs = cpl_vector_get_mean(stdevs);
2335 stdev_stdevs = cpl_vector_get_stdev(stdevs);
2337 skip_if (cpl_vector_subtract_scalar(medians, mean_medians));
2338 skip_if (cpl_vector_subtract_scalar(stdevs, mean_stdevs));
2340 stdev_medians *= threshold;
2341 stdev_stdevs *= threshold;
2344 selection = cpl_vector_new(nima);
2345 skip_if( cpl_vector_fill(selection, 0));
2346 for (i=0 ; i < nima ; i++) {
2347 if (fabs(cpl_vector_get(medians, i)) <= stdev_medians &&
2348 fabs(cpl_vector_get(stdevs, i)) <= stdev_stdevs)
continue;
2350 cpl_vector_set(selection, i, -1);
2351 cpl_msg_info(cpl_func,
"Image %d of %d rejected: median=%g, stdev=%g",
2352 i+1, nima, stdev_medians, stdev_stdevs);
2356 cpl_imagelist_erase(in, selection);
2360 cpl_vector_delete(medians);
2361 cpl_vector_delete(stdevs);
2363 cpl_vector_delete(selection);
2365 return CPL_ERROR_NONE;
2378static cpl_error_code visir_offset_hcycle(cpl_image * hcycle)
2384 skip_if (cpl_image_add_scalar(hcycle, VISIR_HCYCLE_OFFSET));
2386 minval = cpl_image_get_min(hcycle);
2389 if (minval < 1) cpl_msg_warning(cpl_func,
"HCycle pixel minval: %g", minval);
2393 return CPL_ERROR_NONE;
2410cpl_image ** visir_img_collapse_beam_four(cpl_propertylist * qclist,
2411 const cpl_image * self,
2412 const cpl_image * inverse,
2416 const cpl_propertylist * plist)
2419 cpl_image ** combined = NULL;
2420 const int nx = cpl_image_get_size_x(self);
2421 const int ny = cpl_image_get_size_y(self);
2422 const cpl_type type = cpl_image_get_type(self);
2423 cpl_imagelist * list4 = cpl_imagelist_new();
2424 IRPLIB_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual);
2425 cpl_image * swrap = type == CPL_TYPE_DOUBLE
2426 ? cpl_image_wrap_double(nx, ny, cpl_image_get_data((cpl_image*)self))
2427 : cpl_image_wrap_float(nx, ny, cpl_image_get_data((cpl_image*)self));
2428 cpl_image * iwrap = type == CPL_TYPE_DOUBLE
2429 ? cpl_image_wrap_double(nx, ny, cpl_image_get_data((cpl_image*)inverse))
2430 : cpl_image_wrap_float(nx, ny, cpl_image_get_data((cpl_image*)inverse));
2431 IRPLIB_DIAG_PRAGMA_POP;
2432 cpl_bivector * offs = cpl_bivector_new(4);
2433 double * x4 = cpl_bivector_get_x_data(offs);
2434 double * y4 = cpl_bivector_get_y_data(offs);
2435 double pos_x, pos_y;
2439 skip_if(plist == NULL);
2441 skip_if(visir_img_find_beam_four(qclist, self, inverse, eccmax, pthrow,
2445 for (
int i = 1; i < 4; i++) {
2446 x4[i] = x4[0] - x4[i];
2447 y4[i] = y4[0] - y4[i];
2450 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM XPOS",
2452 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM YPOS",
2454 x4[0] = y4[0] = 0.0;
2456 IRPLIB_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual);
2457 bug_if(cpl_imagelist_set(list4, (cpl_image*)self, 0));
2458 bug_if(cpl_imagelist_set(list4, swrap, 1));
2459 bug_if(cpl_imagelist_set(list4, (cpl_image*)inverse, 2));
2460 bug_if(cpl_imagelist_set(list4, iwrap, 3));
2461 IRPLIB_DIAG_PRAGMA_POP;
2463 combined = cpl_geom_img_offset_saa(list4, offs, CPL_KERNEL_DEFAULT, 0, 0,
2464 CPL_GEOM_FIRST, &pos_x, &pos_y);
2466 skip_if(combined == NULL);
2470 cpl_bivector_delete(offs);
2471 visir_imagelist_unwrap(list4);
2472 (void)cpl_image_unwrap(swrap);
2473 (void)cpl_image_unwrap(iwrap);
2474 if (cpl_error_get_code() && combined != NULL) {
2475 cpl_image_delete(combined[0]);
2476 cpl_image_delete(combined[1]);
2498visir_chopnod_mode visir_img_find_beam(cpl_propertylist * qclist,
2499 const cpl_image * self,
2500 const cpl_image * inverse,
2501 const cpl_propertylist * plist,
2502 const cpl_parameterlist * parlist,
2503 const char * recipename,
2508 cpl_errorstate cleanstate = cpl_errorstate_get();
2509 visir_chopnod_mode mode = VISIR_CHOPNOD_AUTO;
2512 VISIR_PARAM_ECCMAX);
2518 const double pthrow = pscale > 0.0
2522 skip_if(x4 == NULL);
2523 skip_if(y4 == NULL);
2524 skip_if(self == NULL);
2525 skip_if(inverse == NULL);
2526 skip_if(parlist == NULL);
2527 skip_if(recipename == NULL);
2528 skip_if(qclist == NULL);
2532 if (sdir != NULL && !strcmp(sdir,
"PERPENDICULAR")) {
2535 mode = VISIR_CHOPNOD_PERPENDICULAR;
2537 skip_if (visir_img_find_beam_four(qclist, self, inverse, eccmax,
2538 pthrow, angle, x4, y4));
2540 }
else if (sdir != NULL && !strcmp(sdir,
"PARALLEL")) {
2543 mode = VISIR_CHOPNOD_PARALLEL;
2545 skip_if (visir_img_find_beam_three(qclist, self, inverse, eccmax,
2546 pthrow, angle, x4, y4));
2550 visir_error_reset(
"Could not get FITS key");
2552 cpl_msg_warning(cpl_func,
"Unknown chopping direction: %s",
2555 cpl_msg_warning(cpl_func,
"Proceeding as if FITS card "
2556 VISIR_PFITS_STRING_CHOPNOD_DIR
" had value: %s",
2559 if (visir_img_find_beam_four(qclist, self, inverse, eccmax,
2560 pthrow, angle, x4, y4)) {
2562 visir_error_reset(
"Proceeding as if FITS card "
2563 VISIR_PFITS_STRING_CHOPNOD_DIR
2564 " had value: %s",
"PARALLEL");
2566 skip_if (visir_img_find_beam_three(qclist, self, inverse,
2567 eccmax, pthrow, angle,
2571 mode = VISIR_CHOPNOD_PARALLEL;
2575 mode = VISIR_CHOPNOD_PERPENDICULAR;
2579 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM THROW",
2581 bug_if (cpl_propertylist_set_comment(qclist,
"ESO QC ONEBEAM THROW",
2582 "The throw in pixels (TEL CHOP THROW "
2583 "divided by INS PFOV)"));
2605cpl_error_code visir_img_find_beam_four(cpl_propertylist * qclist,
2606 const cpl_image * self,
2607 const cpl_image * inverse,
2615 cpl_errorstate cleanstate = cpl_errorstate_get();
2616 cpl_apertures * appos = NULL;
2617 cpl_apertures * apneg = NULL;
2618 const double psigmas[] = {2.0, 1.0, 0.5};
2619 const int nsigmas =
sizeof(psigmas)/
sizeof(
double);
2621 int iappos2[] = {1, 2};
2622 int iapneg2[] = {1, 2};
2625 skip_if(self == NULL);
2626 skip_if(qclist == NULL);
2627 skip_if(pthrow <= 0.0);
2628 skip_if(x4 == NULL);
2629 skip_if(y4 == NULL);
2631 cpl_msg_info(cpl_func,
"Detecting the 4-beam object with %g pixel throw "
2632 "using %d sigma-levels ranging from %g down to %g", pthrow,
2633 nsigmas, psigmas[0], psigmas[nsigmas-1]);
2636 for (isigma = 0; isigma < nsigmas; isigma++) {
2641 cpl_apertures_delete(appos);
2642 appos = cpl_apertures_extract_sigma(self, psigmas[isigma]);
2644 if (appos != NULL) {
2645 npos = cpl_apertures_get_size(appos);
2650 cpl_apertures_delete(apneg);
2651 apneg = cpl_apertures_extract_sigma(inverse, psigmas[isigma]);
2652 if (apneg != NULL) {
2653 nneg = cpl_apertures_get_size(apneg);
2656 cpl_msg_info(cpl_func,
"Found %d positive (need 2) and %d negative "
2657 "(need 2) object(s) at sigma=%g (%d of %d)", npos, nneg,
2658 psigmas[isigma], 1+isigma, nsigmas);
2661 error_if(npos * nneg > FIND_BEAM_MAX_APERTURES_SQR,
2662 CPL_ERROR_DATA_NOT_FOUND,
"Too many objects found, aborting");
2666 double eccbest = eccmax;
2667 double eccmin = DBL_MAX;
2668 double fluxbest = 0.0;
2669 double fluxecc = DBL_MAX;
2670 cpl_boolean is_first = CPL_TRUE;
2673#pragma omp parallel for private(ipos1)
2675 for (ipos1 = 2; ipos1 < 1 + npos; ipos1++) {
2676 int ipos2, ineg1, ineg2;
2677 for (ipos2 = 1; ipos2 < ipos1; ipos2++) {
2678 for (ineg1 = 2; ineg1 < 1 + nneg; ineg1++) {
2679 for (ineg2 = 1; ineg2 < ineg1; ineg2++) {
2680 cpl_boolean swappos, swapneg;
2682 = visir_img_check_box(appos, ipos1, ipos2,
2683 apneg, ineg1, ineg2,
2684 pthrow, angle, &swappos,
2688 = cpl_apertures_get_flux(appos, ipos1)
2689 + cpl_apertures_get_flux(appos, ipos2)
2690 + cpl_apertures_get_flux(apneg, ineg1)
2691 + cpl_apertures_get_flux(apneg, ineg2);
2694 if (ecc < 0.0 || flux <= 0.0 ||
2695 !cpl_errorstate_is_equal(cleanstate)) {
2696 irplib_error_recover(cleanstate,
"Invalid 4-"
2697 "object (%d & %d of %d, "
2700 ineg2, ineg1, nneg);
2705#pragma omp critical(visir_img_find_beam_four_min)
2713 if (eccmax <= ecc)
continue;
2716#pragma omp critical(visir_img_find_beam_four_ok)
2718 if (is_first || ecc * fluxbest < eccbest * flux)
2721 is_first = CPL_FALSE;
2722 cpl_msg_info(cpl_func,
"Found 4 object "
2723 "positions with throw-"
2724 "scaled eccentricity %g "
2725 "and flux %g", ecc, flux);
2727 cpl_msg_info(cpl_func,
"Found 4 object "
2728 "positions with throw-"
2729 "scaled eccentricity %g "
2730 "< %g and/or flux %g > %g",
2731 ecc, eccbest, flux, fluxbest);
2735 iappos2[0] = swappos ? ipos2 : ipos1;
2736 iappos2[1] = swappos ? ipos1 : ipos2;
2737 iapneg2[0] = swapneg ? ineg2 : ineg1;
2738 iapneg2[1] = swapneg ? ineg1 : ineg2;
2744 if (eccbest < eccmax) {
2745 bug_if(cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM "
2746 "ECCENTRICITY", eccbest));
2750 if (eccmin < DBL_MAX) {
2751 cpl_msg_info(cpl_func,
"Found 4 sigma-%g object positions with "
2752 "too large throw-scaled eccentricity %g >= %g and "
2753 "flux %g", psigmas[isigma], eccmin, eccmax,
2756 }
else if (npos >= 2 && nneg >= 2) {
2757 cpl_apertures_sort_by_flux(appos);
2758 cpl_apertures_sort_by_flux(apneg);
2762 if (isigma + 1 < nsigmas) {
2763 irplib_error_recover(cleanstate,
"4-Beam positions not found among "
2764 "%d postive and %d negative object(s) at "
2765 "sigma=%g, (%d of %d)", npos, nneg,
2766 psigmas[isigma], 1+isigma, nsigmas);
2770 error_if (isigma == nsigmas, CPL_ERROR_DATA_NOT_FOUND,
2771 "4-Beam positions not found w. %d sigma(s) down to %g",
2772 nsigmas, psigmas[nsigmas - 1]);
2774 if (cpl_msg_get_level() == CPL_MSG_DEBUG) {
2775 cpl_apertures_dump(appos, stdout);
2776 cpl_apertures_dump(apneg, stdout);
2779 x4[0] = cpl_apertures_get_centroid_x(appos, iappos2[0]);
2780 y4[0] = cpl_apertures_get_centroid_y(appos, iappos2[0]);
2781 x4[1] = cpl_apertures_get_centroid_x(appos, iappos2[1]);
2782 y4[1] = cpl_apertures_get_centroid_y(appos, iappos2[1]);
2784 x4[2] = cpl_apertures_get_centroid_x(apneg, iapneg2[0]);
2785 y4[2] = cpl_apertures_get_centroid_y(apneg, iapneg2[0]);
2786 x4[3] = cpl_apertures_get_centroid_x(apneg, iapneg2[1]);
2787 y4[3] = cpl_apertures_get_centroid_y(apneg, iapneg2[1]);
2789 bug_if(cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM FLUX",
2790 cpl_apertures_get_flux(appos,
2793 cpl_msg_info(cpl_func,
"Centroid of positive object 1 [pixel]: %g %g",
2795 cpl_msg_info(cpl_func,
"Centroid of positive object 2 [pixel]: %g %g",
2798 cpl_msg_info(cpl_func,
"Centroid of negative object 1 [pixel]: %g %g",
2800 cpl_msg_info(cpl_func,
"Centroid of negative object 2 [pixel]: %g %g",
2803 cpl_msg_info(cpl_func,
"Expected object distance (chop throw) [pixel]: %g",
2805 cpl_msg_info(cpl_func,
"Object Pos -> Pos x/y-distance [pixel]: %g %g",
2806 x4[1] - x4[0], y4[1] - y4[0]);
2807 cpl_msg_info(cpl_func,
"Object Neg -> Neg x/y-distance [pixel]: %g %g",
2808 x4[3] - x4[2], y4[3] - y4[2]);
2809 cpl_msg_info(cpl_func,
"Object Pos -> Pos angle [degrees]: %g",
2810 atan2(y4[1] - y4[0], x4[1] - x4[0]) * CPL_MATH_DEG_RAD);
2811 cpl_msg_info(cpl_func,
"Object Neg -> Neg angle [degrees]: %g",
2812 atan2(y4[3] - y4[2], x4[3] - x4[2]) * CPL_MATH_DEG_RAD);
2816 cpl_apertures_delete(appos);
2817 cpl_apertures_delete(apneg);
2819 return cpl_error_get_code();
2836cpl_image ** visir_img_collapse_beam_three(cpl_propertylist * qclist,
2837 const cpl_image * self,
2838 const cpl_image * inverse,
2841 const cpl_propertylist * plist)
2844 cpl_image ** combined = NULL;
2845 const int nx = cpl_image_get_size_x(self);
2846 const int ny = cpl_image_get_size_y(self);
2847 const cpl_type type = cpl_image_get_type(self);
2848 cpl_imagelist * list3 = cpl_imagelist_new();
2849 IRPLIB_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual);
2850 cpl_image * iwrap = type == CPL_TYPE_DOUBLE
2851 ? cpl_image_wrap_double(nx, ny, cpl_image_get_data((cpl_image*)inverse))
2852 : cpl_image_wrap_float(nx, ny, cpl_image_get_data((cpl_image*)inverse));
2853 IRPLIB_DIAG_PRAGMA_POP;
2854 cpl_bivector * offs = cpl_bivector_new(3);
2855 double * x3 = cpl_bivector_get_x_data(offs);
2856 double * y3 = cpl_bivector_get_y_data(offs);
2857 double pos_x, pos_y;
2862 skip_if(plist == NULL);
2864 skip_if(visir_img_find_beam_three(qclist, self, inverse, eccmax, pthrow,
2868 for (
int i = 1; i < 3; i++) {
2869 x3[i] = x3[0] - x3[i];
2870 y3[i] = y3[0] - y3[i];
2872 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM XPOS",
2874 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM YPOS",
2877 x3[0] = y3[0] = 0.0;
2879 IRPLIB_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual);
2880 bug_if(cpl_imagelist_set(list3, (cpl_image*)self, 0));
2881 bug_if(cpl_imagelist_set(list3, (cpl_image*)inverse, 1));
2882 bug_if(cpl_imagelist_set(list3, iwrap, 2));
2883 IRPLIB_DIAG_PRAGMA_POP;
2885 combined = cpl_geom_img_offset_saa(list3, offs, CPL_KERNEL_DEFAULT, 0, 0,
2886 CPL_GEOM_FIRST, &pos_x, &pos_y);
2888 skip_if(combined == NULL);
2892 cpl_bivector_delete(offs);
2893 visir_imagelist_unwrap(list3);
2894 (void)cpl_image_unwrap(iwrap);
2895 if (cpl_error_get_code() && combined != NULL) {
2896 cpl_image_delete(combined[0]);
2897 cpl_image_delete(combined[1]);
2921cpl_error_code visir_img_find_beam_three(cpl_propertylist * qclist,
2922 const cpl_image * self,
2923 const cpl_image * inverse,
2931 cpl_errorstate cleanstate = cpl_errorstate_get();
2932 cpl_apertures * appos = NULL;
2933 cpl_apertures * apneg = NULL;
2934 const double psigmas[] = {2.0, 1.0, 0.5};
2935 const int nsigmas =
sizeof(psigmas)/
sizeof(
double);
2937 int iappos [] = {1};
2938 int iapneg2[] = {1, 2};
2941 skip_if(self == NULL);
2942 skip_if(qclist == NULL);
2943 skip_if(pthrow <= 0.0);
2944 skip_if(eccmax < 0.0);
2945 skip_if(x3 == NULL);
2946 skip_if(y3 == NULL);
2949 cpl_msg_info(cpl_func,
"Detecting the 3-beam object with %g pixel throw "
2950 "using %d sigma-levels ranging from %g down to %g", pthrow,
2951 nsigmas, psigmas[0], psigmas[nsigmas-1]);
2954 for (isigma = 0; isigma < nsigmas; isigma++) {
2959 cpl_apertures_delete(appos);
2960 appos = cpl_apertures_extract_sigma(self, psigmas[isigma]);
2962 if (appos != NULL) {
2963 npos = cpl_apertures_get_size(appos);
2968 cpl_apertures_delete(apneg);
2969 apneg = cpl_apertures_extract_sigma(inverse, psigmas[isigma]);
2970 if (apneg != NULL) {
2971 nneg = cpl_apertures_get_size(apneg);
2974 cpl_msg_info(cpl_func,
"Found %d positive (need 1) and %d negative "
2975 "(need 2) object(s) at sigma=%g (%d of %d)", npos, nneg,
2976 psigmas[isigma], 1+isigma, nsigmas);
2979 error_if(npos * nneg > FIND_BEAM_MAX_APERTURES_SQR,
2980 CPL_ERROR_DATA_NOT_FOUND,
"Too many objects found, aborting");
2984 double eccbest = eccmax;
2985 double eccmin = DBL_MAX;
2986 double fluxbest = 0.0;
2987 double fluxecc = DBL_MAX;
2988 cpl_boolean is_first = CPL_TRUE;
2991#pragma omp parallel for private(ipos)
2993 for (ipos = 1; ipos < 1 + npos; ipos++) {
2995 for (ineg1 = 2; ineg1 < 1 + nneg; ineg1++) {
2996 for (ineg2 = 1; ineg2 < ineg1; ineg2++) {
2997 cpl_boolean swapneg;
3000 = visir_img_check_align(appos, ipos, apneg, ineg1,
3001 ineg2, pthrow, angle,
3005 = cpl_apertures_get_flux(appos, ipos)
3006 + cpl_apertures_get_flux(apneg, ineg1)
3007 + cpl_apertures_get_flux(apneg, ineg2);
3010 if (ecc < 0.0 || flux <= 0.0 ||
3011 !cpl_errorstate_is_equal(cleanstate)) {
3012 irplib_error_recover(cleanstate,
"Invalid 3-"
3013 "object (%d of %d, "
3016 ineg2, ineg1, nneg);
3021#pragma omp critical(visir_img_collapse_beam_three_min)
3029 if (eccmax <= ecc)
continue;
3032#pragma omp critical(visir_img_collapse_beam_three_ok)
3034 if (is_first || ecc * fluxbest < eccbest * flux)
3037 is_first = CPL_FALSE;
3038 cpl_msg_info(cpl_func,
"Found 3 object posi"
3039 "tions with throw-scaled "
3040 "eccentricity %g and flux %g",
3043 cpl_msg_info(cpl_func,
"Found 3 object posi"
3044 "tions with throw-scaled "
3045 "eccentricity %g < %g and/or "
3046 "flux %g > %g", ecc, eccbest,
3052 iapneg2[0] = swapneg ? ineg2 : ineg1;
3053 iapneg2[1] = swapneg ? ineg1 : ineg2;
3058 if (eccbest < eccmax) {
3059 bug_if(cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM "
3060 "ECCENTRICITY", eccbest));
3063 if (eccmin < DBL_MAX) {
3064 cpl_msg_info(cpl_func,
"Found 3 sigma-%g object positions with "
3065 "too large throw-scaled eccentricity %g >= %g and "
3066 "flux %g", psigmas[isigma], eccmin, eccmax,
3069 }
else if (npos >= 1 && nneg >= 2) {
3070 cpl_apertures_sort_by_flux(appos);
3071 cpl_apertures_sort_by_flux(apneg);
3075 if (isigma + 1 < nsigmas) {
3076 irplib_error_recover(cleanstate,
"3-Beam positions not found among "
3077 "%d postive and %d negative object(s) at "
3078 "sigma=%g, (%d of %d)", npos, nneg,
3079 psigmas[isigma], 1+isigma, nsigmas);
3083 error_if (isigma == nsigmas, CPL_ERROR_DATA_NOT_FOUND,
3084 "3-Beam positions not found w. %d sigma(s) down to %g",
3085 nsigmas, psigmas[nsigmas - 1]);
3087 if (cpl_msg_get_level() == CPL_MSG_DEBUG) {
3088 cpl_apertures_dump(appos, stdout);
3089 cpl_apertures_dump(apneg, stdout);
3092 x3[0] = cpl_apertures_get_centroid_x(appos, iappos[0]);
3093 y3[0] = cpl_apertures_get_centroid_y(appos, iappos[0]);
3095 x3[1] = cpl_apertures_get_centroid_x(apneg, iapneg2[0]);
3096 y3[1] = cpl_apertures_get_centroid_y(apneg, iapneg2[0]);
3097 x3[2] = cpl_apertures_get_centroid_x(apneg, iapneg2[1]);
3098 y3[2] = cpl_apertures_get_centroid_y(apneg, iapneg2[1]);
3100 bug_if(cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM FLUX",
3101 cpl_apertures_get_flux(appos,
3104 cpl_msg_info(cpl_func,
"Centroid of positive object [pixel]: %g %g",
3107 cpl_msg_info(cpl_func,
"Centroid of negative object 1 [pixel]: %g %g",
3109 cpl_msg_info(cpl_func,
"Centroid of negative object 2 [pixel]: %g %g",
3112 cpl_msg_info(cpl_func,
"Expected object distance (chop throw) [pixel]: %g",
3114 cpl_msg_info(cpl_func,
"Object Neg1 -> Pos x/y-distance [pixel]: %g %g",
3115 x3[2] - x3[0], y3[2] - y3[0]);
3116 cpl_msg_info(cpl_func,
"Object Pos -> Neg2 x/y-distance [pixel]: %g %g",
3117 x3[0] - x3[1], y3[0] - y3[1]);
3121 cpl_apertures_delete(appos);
3122 cpl_apertures_delete(apneg);
3124 return cpl_error_get_code();
3144cpl_error_code visir_img_find_beam_two(cpl_propertylist * qclist,
3145 const cpl_image * self,
3146 const cpl_image * inverse,
3154 cpl_errorstate cleanstate = cpl_errorstate_get();
3155 cpl_apertures * appos = NULL;
3156 cpl_apertures * apneg = NULL;
3157 const double psigmas[] = {2.0, 1.0, 0.5};
3158 const int nsigmas =
sizeof(psigmas)/
sizeof(
double);
3164 skip_if(self == NULL);
3165 skip_if(qclist == NULL);
3166 skip_if(eccmax < 0.0);
3167 skip_if(x2 == NULL);
3168 skip_if(y2 == NULL);
3171 cpl_msg_info(cpl_func,
"Detecting the 2-beam object (Pos -> Neg) with "
3172 "%g pixel throw using %d sigma-levels ranging from %g down"
3173 " to %g", pthrow, nsigmas, psigmas[0], psigmas[nsigmas-1]);
3174 }
else if (pthrow < 0.0) {
3175 cpl_msg_info(cpl_func,
"Detecting the 2-beam object (Neg -> Pos) with "
3176 "%g pixel throw using %d sigma-levels ranging from %g down"
3177 " to %g", pthrow, nsigmas, psigmas[0], psigmas[nsigmas-1]);
3183 for (isigma = 0; isigma < nsigmas; isigma++) {
3188 cpl_apertures_delete(appos);
3189 appos = cpl_apertures_extract_sigma(self, psigmas[isigma]);
3191 if (appos != NULL) {
3192 npos = cpl_apertures_get_size(appos);
3197 cpl_apertures_delete(apneg);
3198 apneg = cpl_apertures_extract_sigma(inverse, psigmas[isigma]);
3199 if (apneg != NULL) {
3200 nneg = cpl_apertures_get_size(apneg);
3203 cpl_msg_info(cpl_func,
"Found %d positive (need 1) and %d negative "
3204 "(need 1) object(s) at sigma=%g (%d of %d)", npos, nneg,
3205 psigmas[isigma], 1+isigma, nsigmas);
3209 double eccbest = eccmax;
3210 double eccmin = DBL_MAX;
3211 double fluxbest = 0.0;
3212 double fluxecc = DBL_MAX;
3213 cpl_boolean is_first = CPL_TRUE;
3216#pragma omp parallel for private(ipos)
3218 for (ipos = 1; ipos < 1 + npos; ipos++) {
3220 for (ineg = 1; ineg < 1 + nneg; ineg++) {
3222 visir_img_check_line(appos, ipos, apneg, ineg,
3226 = cpl_apertures_get_flux(appos, ipos)
3227 + cpl_apertures_get_flux(apneg, ineg);
3230 if (ecc < 0.0 || flux <= 0.0 ||
3231 !cpl_errorstate_is_equal(cleanstate)) {
3232 irplib_error_recover(cleanstate,
"Invalid 2-"
3233 "object (%d of %d, "
3241#pragma omp critical(visir_img_collapse_beam_two_min)
3249 if (eccmax <= ecc)
continue;
3252#pragma omp critical(visir_img_collapse_beam_two_ok)
3254 if (is_first || ecc * fluxbest < eccbest * flux)
3257 is_first = CPL_FALSE;
3258 cpl_msg_info(cpl_func,
"Found 2 object posi"
3259 "tions with throw-scaled eccen"
3260 "tricity %g and flux %g", ecc,
3263 cpl_msg_info(cpl_func,
"Found 2 object posi"
3264 "tions with throw-scaled eccen"
3265 "tricity %g < %g and/or flux %g "
3266 "> %g", ecc, eccbest, flux,
3276 if (eccbest < eccmax) {
3277 bug_if(cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM "
3278 "ECCENTRICITY", eccbest));
3281 if (eccmin < DBL_MAX) {
3282 cpl_msg_info(cpl_func,
"Found 2 sigma-%g object positions with "
3283 "too large throw-scaled eccentricity %g >= %g and "
3284 "flux %g", psigmas[isigma], eccmin, eccmax,
3287 }
else if (npos >= 1 && nneg >= 2) {
3288 cpl_apertures_sort_by_flux(appos);
3289 cpl_apertures_sort_by_flux(apneg);
3293 if (isigma + 1 < nsigmas) {
3294 irplib_error_recover(cleanstate,
"2-Beam positions not found among "
3295 "%d postive and %d negative object(s) at "
3296 "sigma=%g, (%d of %d)", npos, nneg,
3297 psigmas[isigma], 1+isigma, nsigmas);
3301 error_if (isigma == nsigmas, CPL_ERROR_DATA_NOT_FOUND,
3302 "2-Beam positions not found w. %d sigma(s) down to %g",
3303 nsigmas, psigmas[nsigmas - 1]);
3305 if (cpl_msg_get_level() == CPL_MSG_DEBUG) {
3306 cpl_apertures_dump(appos, stdout);
3307 cpl_apertures_dump(apneg, stdout);
3310 x2[0] = cpl_apertures_get_centroid_x(appos, iappos[0]);
3311 y2[0] = cpl_apertures_get_centroid_y(appos, iappos[0]);
3313 x2[1] = cpl_apertures_get_centroid_x(apneg, iapneg[0]);
3314 y2[1] = cpl_apertures_get_centroid_y(apneg, iapneg[0]);
3316 bug_if(cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM FLUX",
3317 cpl_apertures_get_flux(appos,
3320 cpl_msg_info(cpl_func,
"Centroid of positive object [pixel]: %g %g",
3323 cpl_msg_info(cpl_func,
"Centroid of negative object [pixel]: %g %g",
3327 cpl_msg_info(cpl_func,
"Expected object distance (chop throw) "
3328 "[pixel]: %g", pthrow);
3330 cpl_msg_info(cpl_func,
"Object Pos -> Neg x/y-distance [pixel]: %g %g",
3331 x2[1] - x2[0], y2[1] - y2[0]);
3333 cpl_msg_info(cpl_func,
"Expected object distance (chop throw) "
3334 "[pixel]: %g", -pthrow);
3336 cpl_msg_info(cpl_func,
"Object Neg -> x/y-distance [pixel]: %g %g",
3337 x2[0] - x2[1], y2[0] - y2[1]);
3342 cpl_apertures_delete(appos);
3343 cpl_apertures_delete(apneg);
3345 return cpl_error_get_code();
3371double visir_img_check_box(
const cpl_apertures * appos,
3372 int ipos1,
int ipos2,
3373 const cpl_apertures * apneg,
3374 int ineg1,
int ineg2,
double ssize,
double angle,
3375 cpl_boolean * pswapp, cpl_boolean * pswapn)
3381 double xp1 = cpl_apertures_get_centroid_x(appos, ipos1) * cos(angle) -
3382 cpl_apertures_get_centroid_y(appos, ipos1) * sin(angle);
3383 double yp1 = cpl_apertures_get_centroid_x(appos, ipos1) * sin(angle) +
3384 cpl_apertures_get_centroid_y(appos, ipos1) * cos(angle);
3385 double xp2 = cpl_apertures_get_centroid_x(appos, ipos2) * cos(angle) -
3386 cpl_apertures_get_centroid_y(appos, ipos2) * sin(angle);
3387 double yp2 = cpl_apertures_get_centroid_x(appos, ipos2) * sin(angle) +
3388 cpl_apertures_get_centroid_y(appos, ipos2) * cos(angle);
3391 const double xpl = xp1 < xp2 ? xp1 : xp2;
3392 const double ypl = xp1 < xp2 ? yp1 : yp2;
3395 const double xpr = xp1 < xp2 ? xp2 : xp1;
3396 const double ypr = xp1 < xp2 ? yp2 : yp1;
3399 double xn1 = cpl_apertures_get_centroid_x(apneg, ineg1) * cos(angle) -
3400 cpl_apertures_get_centroid_y(apneg, ineg1) * sin(angle);
3401 double yn1 = cpl_apertures_get_centroid_x(apneg, ineg1) * sin(angle) +
3402 cpl_apertures_get_centroid_y(apneg, ineg1) * cos(angle);
3403 double xn2 = cpl_apertures_get_centroid_x(apneg, ineg2) * cos(angle) -
3404 cpl_apertures_get_centroid_y(apneg, ineg2) * sin(angle);
3405 double yn2 = cpl_apertures_get_centroid_x(apneg, ineg2) * sin(angle) +
3406 cpl_apertures_get_centroid_y(apneg, ineg2) * cos(angle);
3409 const double x_nl = xn1 < xn2 ? xn1 : xn2;
3410 const double y_nl = xn1 < xn2 ? yn1 : yn2;
3413 const double xnr = xn1 < xn2 ? xn2 : xn1;
3414 const double ynr = xn1 < xn2 ? yn2 : yn1;
3416 const double lx1 = xnr - xpl;
3417 const double lx2 = xpr - x_nl;
3418 const double ly1 = ypl - y_nl;
3419 const double ly2 = ynr - ypr;
3421 const double dx1 = lx1 - ssize;
3422 const double dx2 = lx2 - ssize;
3423 const double dy1 = ly1 - ssize;
3424 const double dy2 = ly2 - ssize;
3426 const double ey1 = ynr - ypl;
3427 const double ey2 = ypr - y_nl;
3428 const double ex1 = xpl - x_nl;
3429 const double ex2 = xpr - xnr;
3431 const double ok = sqrt(dx1 * dx1 + dx2 * dx2 + dy1 * dy1 + dy2 * dy2 +
3432 ex1 * ex1 + ex2 * ex2 + ey1 * ey1 + ey2 * ey2);
3434 double result = -1.0;
3438 skip_if(pswapp == NULL);
3439 skip_if(pswapn == NULL);
3440 skip_if(appos == apneg);
3441 skip_if(ipos1 == ipos2);
3442 skip_if(ineg1 == ineg2);
3444 skip_if(ssize <= 0.0);
3446 *pswapp = xp1 < xp2 ? CPL_FALSE : CPL_TRUE;
3447 *pswapn = xn1 < xn2 ? CPL_FALSE : CPL_TRUE;
3477double visir_img_check_align(
const cpl_apertures * appos,
int ipos,
3478 const cpl_apertures * apneg,
int ineg1,
int ineg2,
3479 double ssize,
double angle,
3480 cpl_boolean * pswapn)
3486 double xp = cpl_apertures_get_centroid_x(appos, ipos) * cos(angle) -
3487 cpl_apertures_get_centroid_y(appos, ipos) * sin(angle);
3488 double yp = cpl_apertures_get_centroid_x(appos, ipos) * sin(angle) +
3489 cpl_apertures_get_centroid_y(appos, ipos) * cos(angle);
3492 double xn1 = cpl_apertures_get_centroid_x(apneg, ineg1) * cos(angle) -
3493 cpl_apertures_get_centroid_y(apneg, ineg1) * sin(angle);
3494 double yn1 = cpl_apertures_get_centroid_x(apneg, ineg1) * sin(angle) +
3495 cpl_apertures_get_centroid_y(apneg, ineg1) * cos(angle);
3496 double xn2 = cpl_apertures_get_centroid_x(apneg, ineg2) * cos(angle) -
3497 cpl_apertures_get_centroid_y(apneg, ineg2) * sin(angle);
3498 double yn2 = cpl_apertures_get_centroid_x(apneg, ineg2) * sin(angle) +
3499 cpl_apertures_get_centroid_y(apneg, ineg2) * cos(angle);
3501 double result = -1.0;
3508 const double x_nl = yn1 < yn2 ? xn1 : xn2;
3509 const double y_nl = yn1 < yn2 ? yn1 : yn2;
3512 const double xnr = yn1 < yn2 ? xn2 : xn1;
3513 const double ynr = yn1 < yn2 ? yn2 : yn1;
3515 const double d1 = ynr - yp - ssize;
3516 const double d2 = yp - y_nl - ssize;
3518 const double e1 = xnr - xp;
3519 const double e2 = xp - x_nl;
3521 swapn = yn1 < yn2 ? CPL_FALSE : CPL_TRUE;
3523 ok = sqrt(d1 * d1 + d2 * d2 + e1 * e1 + e2 * e2);
3527 skip_if(pswapn == NULL);
3528 skip_if(appos == apneg);
3529 skip_if(ineg1 == ineg2);
3531 skip_if(ssize <= 0.0);
3561double visir_img_check_line(
const cpl_apertures * apnear,
int inear,
3562 const cpl_apertures * apfar,
int ifar,
3563 double ssize,
double angle)
3569 double x_n = cpl_apertures_get_centroid_x(apnear, inear) * cos(angle) -
3570 cpl_apertures_get_centroid_y(apnear, inear) * sin(angle);
3571 double y_n = cpl_apertures_get_centroid_x(apnear, inear) * sin(angle) +
3572 cpl_apertures_get_centroid_y(apnear, inear) * cos(angle);
3575 double xf = cpl_apertures_get_centroid_x(apfar, ifar) * cos(angle) -
3576 cpl_apertures_get_centroid_y(apfar, ifar) * sin(angle);
3577 double yf = cpl_apertures_get_centroid_x(apfar, ifar) * sin(angle) +
3578 cpl_apertures_get_centroid_y(apfar, ifar) * cos(angle);
3580 double result = -1.0;
3584 const double d = yf - y_n - ssize;
3586 const double e = xf - x_n;
3588 ok = sqrt(d * d + e * e);
3592 skip_if(apnear == apfar);
3594 skip_if(ssize <= 0.0);
3616static cpl_error_code
3617get_aqu_data_type(
const cpl_frame * frame,
const cpl_propertylist * plist,
3618 const cpl_size next, visir_data_type * ptype)
3621 const char * format = NULL;
3622 if (cpl_propertylist_has(plist, VISIR_PFITS_INT_NAXIS3))
3625 if (cpl_propertylist_has(plist,
"ESO DET FRAM FORMAT"))
3626 format = cpl_propertylist_get_string(plist,
"ESO DET FRAM FORMAT");
3629 if (next >= 2 || (format && !strcmp(format,
"extension"))) {
3632 *ptype = VISIR_DATA_AQU_INT;
3635 *ptype = VISIR_DATA_AQU_HCYCLE;
3638 else if (next == 1 && (naxis3 == -1 || naxis3 == 0)) {
3639 *ptype = VISIR_DATA_AQU_BURST_EXT;
3641 else if (next == 0 && naxis3 > 0) {
3642 *ptype = VISIR_DATA_AQU_BURST;
3645 cpl_error_set_message(cpl_func, CPL_ERROR_BAD_FILE_FORMAT,
3646 "Could not determine format of aquarius file %s",
3647 cpl_frame_get_filename(frame));
3650 return cpl_error_get_code();
3666static cpl_error_code
3667get_drs_data_type(
const cpl_frame * frame,
const cpl_propertylist * plist,
3668 visir_data_type * ptype)
3670 cpl_errorstate cleanstate = cpl_errorstate_get();
3675 const char * file = cpl_frame_get_filename(frame);
3676 cpl_boolean known_frametype = CPL_TRUE;
3680 cpl_ensure_code(ptype != NULL, CPL_ERROR_NULL_INPUT);
3684 visir_error_reset(
"Could not get FITS key");
3686 known_frametype = CPL_FALSE;
3687 }
else if (strcmp(sval,
"CUBE1")==0) {
3688 *ptype = VISIR_DATA_CUBE1;
3689 }
else if (strcmp(sval,
"CUBE2")==0) {
3690 *ptype = VISIR_DATA_CUBE2;
3693 known_frametype = CPL_FALSE;
3696 if (known_frametype && *ptype == VISIR_DATA_CUBE2) {
3697 if (naxis3 == 2 * nchop + 1) {
3699 }
else if (naxis3 == nchop + 2) {
3700 cpl_msg_warning(cpl_func,
"%s has FRAM TYPE = '%s', but NAXIS3=%d "
3701 "and CHOP NCYCLES=%d imply a CUBE1. Assuming "
3702 "the frame type is really CUBE1", file, sval,
3704 *ptype = VISIR_DATA_CUBE1;
3706 cpl_msg_warning(cpl_func,
"%s has FRAM TYPE = '%s', but NAXIS3=%d "
3707 "and CHOP NCYCLES=%d is not a valid VISIR INTERM+"
3708 "Half-Cycle format", file, sval, naxis3, nchop);
3711 }
else if (known_frametype && *ptype == VISIR_DATA_CUBE1) {
3712 if (naxis3 == nchop + 2) {
3715 cpl_msg_debug(cpl_func,
"%s has %d INTERM-frames and one Half-"
3716 "Cycle frame (old CUBE1-format)", file, nchop);
3718 }
else if (naxis3 == 2 * nchop + 1) {
3719 cpl_msg_warning(cpl_func,
"%s has FRAM TYPE = '%s', but NAXIS3=%d "
3720 "and CHOP NCYCLES=%d imply a CUBE2. Assuming "
3721 "the frame type is really CUBE2", file, sval,
3723 *ptype = VISIR_DATA_CUBE2;
3725 cpl_msg_warning(cpl_func,
"%s has FRAM TYPE = '%s', but NAXIS3=%d "
3726 "and CHOP NCYCLES=%d is not a valid VISIR INTERM+"
3727 "Half-Cycle format", file, sval, naxis3, nchop);
3730 }
else if (naxis3 == 2 * nchop + 1) {
3731 cpl_msg_warning(cpl_func,
"%s has FRAM TYPE='%s', but NAXIS3=%d and "
3732 "CHOP NCYCLES=%d imply a CUBE2. Assuming the frame "
3733 "type is CUBE2", file, sval ? sval :
"<NULL>", naxis3,
3735 *ptype = VISIR_DATA_CUBE2;
3736 }
else if (naxis3 == nchop + 2) {
3737 cpl_msg_warning(cpl_func,
"%s has FRAM TYPE='%s', but NAXIS3=%d and "
3738 "CHOP NCYCLES=%d imply a CUBE1. Assuming the frame "
3739 "type is CUBE1", file, sval ? sval :
"<NULL>", naxis3,
3741 *ptype = VISIR_DATA_CUBE1;
3743 else if (!known_frametype && nchop * ndit * 2 >= naxis3) {
3744 cpl_msg_info(cpl_func,
"%s has FRAM TYPE='%s', NAXIS3=%d and "
3745 "CHOP NCYCLES=%d imply BURST data.",
3746 file, sval ? sval :
"<NULL>", naxis3, nchop);
3747 *ptype = VISIR_DATA_BURST;
3749 return cpl_error_set_message(cpl_func, CPL_ERROR_BAD_FILE_FORMAT,
3750 "%s has FRAM TYPE='%s', NAXIS3 = %d and "
3751 "CHOP NCYCLES = %d", file,
3752 sval ? sval :
"<NULL>", naxis3, nchop);
3757 return cpl_error_get_code();
3772cpl_error_code visir_get_data_type(
const cpl_frame * frame,
3773 const cpl_propertylist * plist,
3774 visir_data_type * ptype, cpl_size * pnext)
3776 const cpl_size next = cpl_frame_get_nextensions(frame);
3778 cpl_ensure_code(ptype != NULL, CPL_ERROR_NULL_INPUT);
3785 if (cpl_propertylist_has(plist,
"ESO DRS DTYPE"))
3786 *ptype = cpl_propertylist_get_int(plist,
"ESO DRS DTYPE");
3788 if (cpl_propertylist_has(plist, VISIR_PFITS_INT_NAVRG))
3789 skip_if(get_aqu_data_type(frame, plist, next, ptype));
3791 skip_if(get_drs_data_type(frame, plist, ptype));
3796 return cpl_error_get_code();
3809cpl_error_code visir_img_burst_find_delta_chop(
const cpl_propertylist * self,
3810 int * ichopchange,
int * ihalfcycle)
3813 const char * sdateobs =
3814 cpl_propertylist_get_string(self, VISIR_PFITS_STRING_OBS_START);
3815 const char * schopstart =
3816 cpl_propertylist_get_string(self, VISIR_PFITS_STRING_CHOP_START);
3818 const int nditskip =
3819 cpl_propertylist_get_int(self, VISIR_PFITS_INT_NDITSKIP);
3822 double ddateobs, dchopstart;
3827 bug_if(irplib_wcs_mjd_from_string(&ddateobs, sdateobs));
3828 bug_if(irplib_wcs_mjd_from_string(&dchopstart, schopstart));
3830 skip_if(chop_freq <= 0.0);
3831 skip_if(dit <= 0.0);
3835 if (!cpl_propertylist_has(self, VISIR_PFITS_INT_NAVRG)) {
3836 ddateobs += dit * nditskip / (double)VISIR_SECS_PER_DAY;
3839 period = 1.0/(chop_freq * dit);
3842 error_if((
int)(period + 0.5) % 2 != 0, CPL_ERROR_UNSUPPORTED_MODE,
3843 "Period %g not not an even number, chop frequency %g, dit %g",
3844 period, chop_freq, dit);
3846 error_if((
int)(period + 0.5) <= 1, CPL_ERROR_ILLEGAL_INPUT,
3847 "Period %d < 1", (
int)(period + 0.5));
3849 *ihalfcycle = (int)(period + 0.5)/2;
3851 cpl_msg_info(cpl_func,
"Number of A+B frames in one full chopping cycle: %g",
3854 if (dchopstart < ddateobs) {
3855 double tchop = (ddateobs - dchopstart) * (
double)VISIR_SECS_PER_DAY;
3857 double dprecycle = tchop * chop_freq;
3860 const double phase = ceil(dprecycle) - dprecycle;
3863 *ichopchange = (int)ceil(phase * period) - 1;
3865 cpl_msg_info(cpl_func,
"Chopping started %gs (%f cycles) before OBS start: "
3866 "%f < %f", tchop, dprecycle, dchopstart, ddateobs);
3868 }
else if (ddateobs < dchopstart) {
3871 double tchop = (dchopstart - ddateobs) * (
double)VISIR_SECS_PER_DAY;
3872 *ichopchange = (int)ceil(tchop / dit) - 1;
3873 cpl_msg_info(cpl_func,
"Chopping started %gs (wasted %g cycles) after OBS "
3874 "start: %f > %f", tchop, tchop * chop_freq, dchopstart,
3881 cpl_msg_info(cpl_func,
"Chopping started with OBS start: %f == %f",
3882 dchopstart, ddateobs);
3886 *ichopchange = *ichopchange % (*ihalfcycle * 2);
3888 cpl_msg_info(cpl_func,
"Frame of chop change: %d", *ichopchange);
3892 return cpl_error_get_code();
3895#include "visir_destripe.c"
cpl_error_code visir_destripe_image(cpl_image *self, int niter, double threshold, double thres_detect, cpl_boolean morpho)
Remove the stripes frome an image using iterations.
int visir_parameterlist_get_int(const cpl_parameterlist *self, const char *recipe, visir_parameter bitmask)
Retrieve the value of a VISIR integer parameter.
const char * visir_parameterlist_get_string(const cpl_parameterlist *self, const char *recipe, visir_parameter bitmask)
Retrieve the value of a VISIR string parameter.
double visir_parameterlist_get_double(const cpl_parameterlist *self, const char *recipe, visir_parameter bitmask)
Retrieve the value of a VISIR parameter of type double.
cpl_boolean visir_parameterlist_get_bool(const cpl_parameterlist *self, const char *recipe, visir_parameter bitmask)
Retrieve the value of a VISIR boolean parameter.
int visir_pfits_get_navrg(const cpl_propertylist *self)
The NAVRG.
double visir_pfits_get_dit(const cpl_propertylist *self)
The DIT.
int visir_pfits_get_chop_ncycles(const cpl_propertylist *self)
The number of chopping cycles.
double visir_pfits_get_pixscale(const cpl_propertylist *self)
The pixel scale.
double visir_pfits_get_chop_posang(const cpl_propertylist *self)
The chopping position angle in rad.
double visir_pfits_get_cumoffsety(const cpl_propertylist *self)
The cumulative offset in Y.
const char * visir_pfits_get_chopnod_dir(const cpl_propertylist *self)
The chopping direction.
int visir_pfits_get_ndit(const cpl_propertylist *self)
The NDIT keyword.
int visir_pfits_get_naxis3(const cpl_propertylist *self)
The NAXIS3 key.
double visir_pfits_get_chop_throw(const cpl_propertylist *self)
The chopping throw.
double visir_pfits_get_chop_freq(const cpl_propertylist *self)
The chopping frequency.
const char * visir_pfits_get_frame_type(const cpl_propertylist *self)
The frame type.
double visir_pfits_get_cumoffsetx(const cpl_propertylist *self)
The cumulative offset in X.
const char * visir_pfits_get_nodpos(const cpl_propertylist *self)
The nodding position.