30#include "visir_utils.h"
31#include "visir_pfits.h"
32#include "visir_parameter.h"
33#include "visir_pfits.h"
34#include "visir_spc_distortion.h"
35#include "visir_inputs.h"
36#include "irplib_framelist.h"
37#include "irplib_wcs.h"
50#define VISIR_SECS_PER_DAY (24 * 3600)
52#define FIND_BEAM_MAX_APERTURES_SQR (40 * 40)
58#include "visir_destripe.h"
60static cpl_image * visir_load_average(
const char *,
61 const cpl_propertylist *);
62static cpl_imagelist * visir_load_intermint(
const irplib_framelist *,
int);
63static cpl_error_code visir_imagelist_unpack_interm(cpl_imagelist *);
64static cpl_error_code visir_rem_glitch(cpl_image *);
65static cpl_error_code visir_rem_bad_images(cpl_imagelist *);
66static cpl_error_code visir_offset_hcycle(cpl_image *);
68static cpl_image ** visir_img_collapse_beam_four(cpl_propertylist *,
71 double,
double,
double,
72 const cpl_propertylist *);
74static cpl_image ** visir_img_collapse_beam_three(cpl_propertylist *,
78 const cpl_propertylist *);
81static cpl_error_code visir_img_find_beam_three(cpl_propertylist *,
84 double,
double,
double,
88static cpl_error_code visir_img_find_beam_four(cpl_propertylist *,
91 double,
double,
double,
104void visir_aplist_destroy(visir_aplist * list)
106 cx_list_destroy((list), (cx_free_func)visir_apdefs_delete);
125cpl_error_code visir_load_cube2_split_(cpl_imagelist * alist, cpl_imagelist * blist,
126 cpl_imagelist * packed, cpl_image * prevd)
129 int naxis3 = cpl_imagelist_get_size(packed);
130 int prevd_insert_pos = cpl_imagelist_get_size(blist);
132 bug_if(alist == NULL);
133 bug_if(blist == NULL);
137 cpl_imagelist_set(blist, prevd, prevd_insert_pos);
140 for (
int i = 0; i < naxis3/2; i++) {
141 cpl_image * aimage = cpl_imagelist_unset(packed, 0);
142 cpl_image * dimage = cpl_imagelist_unset(packed, 0);
144 cpl_imagelist_set(alist, aimage, cpl_imagelist_get_size(alist));
145 cpl_imagelist_set(blist, dimage, cpl_imagelist_get_size(blist));
149 skip_if_lt(0, cpl_imagelist_get_size(packed),
"Too many packed frames");
152 bug_if(visir_imagelist_unpack_interm(blist));
156 (void)cpl_imagelist_unset(blist, prevd_insert_pos);
158 for (
int i = 0; i < naxis3/2; i++) {
159 cpl_image * aimage = cpl_imagelist_get(alist, i);
160 cpl_image * dimage = cpl_imagelist_get(blist, i);
162 cpl_image * bimage = cpl_image_subtract_create(aimage, dimage);
164 visir_offset_hcycle(aimage);
165 visir_offset_hcycle(bimage);
167 bug_if(cpl_imagelist_set(blist, bimage, i));
171 skip_if_lt(0, cpl_imagelist_get_size(packed),
"Too many packed frames");
175 return cpl_error_get_code();
193static cpl_imagelist * load_range(
const char * filename,
200 cpl_imagelist * self = cpl_imagelist_new();
202 for (
int iplane = pstart; iplane < pend; iplane++) {
203 cpl_image * image = cpl_image_load(filename, im_type, iplane, iext);
205 if (image == NULL)
break;
207 if (cpl_imagelist_set(self, image, selfsize)) {
208 cpl_image_delete(image);
243 const irplib_framelist * rawframes,
int pos,
244 const int planestart,
const int planeend)
247 cpl_imagelist * packed = NULL;
248 const cpl_frame * frame = irplib_framelist_get_const(rawframes, pos);
249 const char * file = cpl_frame_get_filename(frame);
251 visir_data_type data_type;
253 cpl_image * prevd = NULL;
254 const cpl_propertylist * plist =
255 irplib_framelist_get_propertylist_const(rawframes, pos);
256 const int iext = cpl_propertylist_has(plist,
"ZNAXIS3") ? 1 : 0;
261 skip_if(visir_get_data_type(frame, plist, &data_type, NULL));
263 cpl_ensure_code(data_type == VISIR_DATA_CUBE2, CPL_ERROR_ILLEGAL_INPUT);
269 error_if(planestart % 2 == 1, CPL_ERROR_ILLEGAL_INPUT,
270 "Plane start %d wrong. It must be even.", planestart);
271 error_if(planeend < naxis3 && planeend % 2 == 1, CPL_ERROR_ILLEGAL_INPUT,
272 "Plane end %d wrong. It must be even if not larger naxis3=%d",
275 any_if(
"Cannot split non-CUBE2 frame %d/%d in %s", 1+pos,
276 irplib_framelist_get_size(rawframes), file);
277 bug_if(alist == NULL);
278 bug_if(blist == NULL);
280 error_if(data_type != VISIR_DATA_CUBE2, CPL_ERROR_INCOMPATIBLE_INPUT,
281 "Cannot split non-CUBE2 frame %d/%d w. NAXIS3=%d, "
282 "NCYCLES=%d in %s", 1+pos,
283 irplib_framelist_get_size(rawframes), naxis3, nchop, file);
285 if (planeend >= naxis3 || planeend < 0)
290 if (planestart != 0) {
291 packed = load_range(file, CPL_TYPE_UNSPECIFIED,
292 iext, planestart - 1, pend);
293 prevd = cpl_imagelist_unset(packed, 0);
296 packed = load_range(file, CPL_TYPE_UNSPECIFIED, iext, planestart, pend);
298 skip_if(visir_load_cube2_split_(alist, blist, packed, prevd));
302 cpl_image_delete(prevd);
303 cpl_imagelist_delete(packed);
305 return cpl_error_get_code();
328cpl_error_code visir_load_burst_(cpl_imagelist * alist, cpl_imagelist * blist,
329 cpl_imagelist * packed,
330 const int ichopchange,
const int ihalfcycle,
331 const int trimlow,
int const trimhigh)
333 cpl_boolean bon = CPL_TRUE;
334 const int offset = 0;
335 const int pend = cpl_imagelist_get_size(packed);
336 int lorej = ihalfcycle - trimlow;
337 int hirej = trimhigh + 1;
341 int chpmv = ichopchange - ihalfcycle * 2;
343 cpl_ensure_code(trimhigh >= -1, CPL_ERROR_ILLEGAL_INPUT);
344 cpl_ensure_code(trimlow >= 0, CPL_ERROR_ILLEGAL_INPUT);
345 cpl_ensure_code(ichopchange < ihalfcycle * 2, CPL_ERROR_ILLEGAL_INPUT);
346 cpl_ensure_code(alist != NULL, CPL_ERROR_NULL_INPUT);
347 cpl_ensure_code(blist != NULL, CPL_ERROR_NULL_INPUT);
354 for (
int i = chpmv; i < pend; i++) {
355 if ((i + ihalfcycle * 2) % ihalfcycle == ichopchange % ihalfcycle) {
357 hirej = trimhigh + 1;
358 lorej = ihalfcycle - trimlow;
360 if (hirej <= 0 && lorej > 0 && i >= 0) {
362 cpl_image * image= cpl_imagelist_unset(packed, offset);
363 cpl_imagelist_set(alist, image, cpl_imagelist_get_size(alist));
366 cpl_image * image= cpl_imagelist_unset(packed, offset);
367 cpl_imagelist_set(blist, image, cpl_imagelist_get_size(blist));
371 cpl_image_delete(cpl_imagelist_unset(packed, offset));
377 cpl_msg_info(cpl_func,
"On: %d, Off %d, Skipped %d",
378 (
int)cpl_imagelist_get_size(alist),
379 (
int)cpl_imagelist_get_size(blist),
380 (
int)(pend - cpl_imagelist_get_size(alist)
381 - cpl_imagelist_get_size(blist)));
383 skip_if_lt(0, cpl_imagelist_get_size(packed),
"Too many packed frames");
387 return cpl_error_get_code();
401static int get_to_off_plane(
int chopchange,
const int offset,
402 const int ihalfcycle)
404 const int ifullcycle = ihalfcycle * 2;
407 (offset / ifullcycle) * ifullcycle > chopchange)
408 chopchange += ifullcycle - (offset % ifullcycle);
410 chopchange -= (offset % ifullcycle);
437cpl_error_code visir_load_burst(cpl_imagelist * alist, cpl_imagelist * blist,
438 const cpl_frame * frame,
const cpl_propertylist * plist,
439 const int ichopchange,
const int ihalfcycle,
440 const int planestart,
const int planeend,
441 const int trimlow,
const int trimhigh)
443 const char * file = cpl_frame_get_filename(frame);
445 const int pend = planeend <= 0 || planeend > naxis3 ? naxis3 : planeend;
446 cpl_imagelist * packed;
447 int to_off = get_to_off_plane(ichopchange, planestart, ihalfcycle);
449 cpl_msg_info(cpl_func,
"Loading planes %d to %d, to off %d",
450 planestart, pend, planestart + to_off);
452 packed = load_range(file, CPL_TYPE_UNSPECIFIED,
453 cpl_propertylist_has(plist,
"ZNAXIS3") ? 1 : 0,
456 skip_if(packed == NULL);
458 if (cpl_imagelist_get_size(packed) > 0) {
459 cpl_image * timg = cpl_imagelist_get(packed, 0);
460 size_t nbytes = visir_get_nbytes(timg);
461 visir_drop_cache(file, 0, nbytes * pend);
464 skip_if(visir_load_burst_(alist, blist, packed, to_off, ihalfcycle,
469 cpl_imagelist_delete(packed);
471 return cpl_error_get_code();
476visir_load_burst_aqu(cpl_imagelist * alist, cpl_imagelist * blist,
477 const cpl_frame * frame,
const cpl_propertylist * plist,
478 const int ihalfcycle,
479 const int planestart,
const int planeend)
481 const char * file = cpl_frame_get_filename(frame);
483 const size_t pend = planeend <= 0 || planeend > naxis3 ? naxis3 : planeend;
484 cpl_imagelist * packed;
486 cpl_msg_info(cpl_func,
"Loading planes %d to %zu",
489 packed = load_range(file, CPL_TYPE_UNSPECIFIED,
490 cpl_propertylist_has(plist,
"ZNAXIS3") ? 1 : 0,
493 skip_if(packed == NULL);
495 if (cpl_imagelist_get_size(packed) > 0) {
496 cpl_image * timg = cpl_imagelist_get(packed, 0);
497 size_t nbytes = visir_get_nbytes(timg);
498 visir_drop_cache(file, 0, nbytes * pend);
501 cpl_boolean bon = CPL_FALSE;
503 for (
size_t i = planestart; i < pend; i++) {
505 cpl_image * image = cpl_imagelist_unset(packed, 0);
506 cpl_imagelist_set(alist, image, cpl_imagelist_get_size(alist));
509 cpl_image * image = cpl_imagelist_unset(packed, 0);
510 cpl_imagelist_set(blist, image, cpl_imagelist_get_size(blist));
513 if (it == ihalfcycle){
521 cpl_imagelist_delete(packed);
523 return cpl_error_get_code();
538 cpl_bivector * lintable = NULL;
539 const char * extname;
540 cpl_ensure(linframe, CPL_ERROR_NULL_INPUT, NULL);
542 extname =
"SPEC_LIN";
545 extname =
"IMAGE_LIN";
547 const char * fn = cpl_frame_get_filename(linframe);
548 cpl_size iext = cpl_fits_find_extension(fn, extname);
549 error_if(iext < 0, CPL_ERROR_ILLEGAL_INPUT,
550 "Linearity correction extension %s not found in %s", extname, fn);
552 cpl_table * tab = cpl_table_load(fn, iext, 0);
553 const size_t nrow = cpl_table_get_nrow(tab);
554 lintable = cpl_bivector_new(nrow);
555 memcpy(cpl_bivector_get_x_data(lintable),
556 cpl_table_get_data_double(tab,
"dc_level"),
557 sizeof(
double) * nrow);
558 memcpy(cpl_bivector_get_y_data(lintable),
559 cpl_table_get_data_double(tab,
"conv_gain"),
560 sizeof(
double) * nrow);
561 cpl_table_delete(tab);
564 cpl_vector_divide_scalar(cpl_bivector_get_y(lintable),
565 cpl_vector_get_mean(cpl_bivector_get_y(lintable)));
572visir_load_bpm(cpl_frame * frm, visir_data_type dtype, cpl_boolean is_spec)
574 const char * fn = cpl_frame_get_filename(frm);
575 const char * extname;
576 if (visir_data_is_aqu(dtype)) {
577 extname = is_spec ?
"BPM_AQU_SPC" :
"BPM_AQU_IMG";
580 extname = is_spec ?
"BPM_DRS_SPC" :
"BPM_DRS_IMG";
582 cpl_size iext = cpl_fits_find_extension(fn, extname);
583 cpl_msg_info(cpl_func,
"Loading BPM extension %s from %s", extname, fn);
587 return cpl_image_load(fn, CPL_TYPE_UNSPECIFIED, 0, iext);
614 const cpl_image * self,
615 const cpl_parameterlist * parlist,
616 const char * recipename,
617 visir_chopnod_mode mode,
618 const cpl_propertylist * plist)
621 cpl_image ** combined = NULL;
623 cpl_image * inverse = cpl_image_multiply_scalar_create(self, -1.0);
630 const double pthrow = pscale > 0.0
634 skip_if(self == NULL);
635 skip_if(parlist == NULL);
636 skip_if(qclist == NULL);
637 skip_if(plist == NULL);
639 if (mode == VISIR_CHOPNOD_PERPENDICULAR) {
641 combined = visir_img_collapse_beam_four(qclist, self, inverse, eccmax,
642 pthrow, angle, plist);
643 }
else if (mode == VISIR_CHOPNOD_PARALLEL) {
645 combined = visir_img_collapse_beam_three(qclist, self, inverse, eccmax,
647 }
else if (mode == VISIR_CHOPNOD_AUTO) {
648 cpl_errorstate cleanstate = cpl_errorstate_get();
652 if (sdir != NULL && !strcmp(sdir,
"PERPENDICULAR")) {
654 combined = visir_img_collapse_beam_four(qclist, self, inverse,
655 eccmax, pthrow, angle, plist);
656 }
else if (sdir != NULL && !strcmp(sdir,
"PARALLEL")) {
658 combined = visir_img_collapse_beam_three(qclist, self, inverse,
659 eccmax, pthrow, plist);
662 visir_error_reset(
"Could not get FITS key");
664 cpl_msg_warning(cpl_func,
"Unknown chopping direction: %s",
667 cpl_msg_warning(cpl_func,
"Proceeding as if FITS card "
668 VISIR_PFITS_STRING_CHOPNOD_DIR
" had value: %s",
670 combined = visir_img_collapse_beam_four(qclist, self, inverse,
671 eccmax, pthrow, angle, plist);
672 if (combined == NULL) {
673 visir_error_reset(
"Proceeding as if FITS card "
674 VISIR_PFITS_STRING_CHOPNOD_DIR
675 " had value: %s",
"PARALLEL");
676 combined = visir_img_collapse_beam_three(qclist, self, inverse,
677 eccmax, pthrow, plist);
684 skip_if(combined == NULL);
686 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM THROW",
688 bug_if (cpl_propertylist_set_comment(qclist,
"ESO QC ONEBEAM THROW",
689 "The throw in pixels (TEL CHOP THROW "
690 "divided by INS PFOV)"));
692 bug_if (cpl_propertylist_set_comment(qclist,
"ESO QC ONEBEAM XPOS",
693 "The X pixel position (centroid) "
694 "of the one-beam object"));
696 bug_if (cpl_propertylist_set_comment(qclist,
"ESO QC ONEBEAM YPOS",
697 "The Y pixel position (centroid) "
698 "of the one-beam object"));
699 bug_if (cpl_propertylist_set_comment(qclist,
"ESO QC ONEBEAM ECCENTRICITY",
700 "Eccentricity: 0 for perfect, throw-"
701 "sized square/line"));
705 cpl_image_delete(inverse);
796 const cpl_parameterlist * parlist,
797 const irplib_framelist * rawframes,
801 cpl_boolean do_spc_fix,
803 visir_spc_resol resol)
805 const char * fnodpos;
807 cpl_imagelist * in = NULL;
808 cpl_image * collapsed = NULL;
809 cpl_image * prev = NULL;
810 cpl_vector * nods_vec = NULL;
812 int * nod_pos = NULL;
813 cpl_image ** images = NULL;
814 cpl_imagelist * nodded = NULL;
816 cpl_image * flat_image = NULL;
817 cpl_image * bpm_im_int = NULL;
818 cpl_mask * bpm_im_bin = NULL;
819 cpl_imagelist * hcycle = NULL;
821 cpl_boolean is_nodding = CPL_FALSE;
823 cpl_boolean auto_bpm, rem_glitch, rem_bad;
826 cpl_boolean morpho_destripe;
827 double tstart, tstop;
828 const cpl_propertylist * plist1;
830 cpl_errorstate cleanstate = cpl_errorstate_get();
832 cpl_error_code didfail = CPL_ERROR_NONE;
836 skip_if(recipename == NULL);
837 skip_if(parlist == NULL);
838 skip_if(rawframes == NULL);
841 nfiles = irplib_framelist_get_size(rawframes);
845 cpl_msg_warning(cpl_func,
"Expecting even number of files, "
846 "ignoring the last of %d file(s)", nfiles);
847 error_if (nfiles == 1, CPL_ERROR_DATA_NOT_FOUND,
848 "At least two files are required");
856 skip_if(irplib_framelist_contains(rawframes, VISIR_PFITS_STRING_FRAME_TYPE,
857 CPL_TYPE_STRING, CPL_FALSE, 0.0));
858 skip_if(irplib_framelist_contains(rawframes, VISIR_PFITS_DOUBLE_DIT,
859 CPL_TYPE_DOUBLE, CPL_FALSE, 0.0));
861 skip_if (irplib_framelist_contains(rawframes,
"NAXIS1",
862 CPL_TYPE_INT, CPL_TRUE, 0.0));
863 skip_if (irplib_framelist_contains(rawframes,
"NAXIS2",
864 CPL_TYPE_INT, CPL_TRUE, 0.0));
865 skip_if(irplib_framelist_contains(rawframes, VISIR_PFITS_INT_NAXIS3,
866 CPL_TYPE_INT, CPL_FALSE, 0.0));
867 skip_if(irplib_framelist_contains(rawframes, VISIR_PFITS_INT_CHOP_NCYCLES,
868 CPL_TYPE_INT, CPL_FALSE, 0.0));
870 plist1 = irplib_framelist_get_propertylist_const(rawframes, 0);
871 naxis1 = irplib_pfits_get_int(plist1,
"NAXIS1");
872 naxis2 = irplib_pfits_get_int(plist1,
"NAXIS2");
881 VISIR_PARAM_AUTOBPM);
893 VISIR_PARAM_STRIPITE);
896 morpho_destripe = ndestripe <= 0 ? CPL_FALSE :
898 VISIR_PARAM_STRIPMOR);
901 no_rem = !rem_glitch && !rem_bad;
905 nod_pos = nodding_p ? nodding_p : cpl_malloc(nfiles *
sizeof(
int));
907 if (!visir_str_par_is_empty(fnodpos)) {
909 nods_vec = cpl_vector_read(fnodpos);
910 skip_if (cpl_vector_get_size(nods_vec) != nfiles);
911 nods_data = cpl_vector_get_data(nods_vec);
913 for (i=0 ; i<nfiles ; i++) {
914 if ((
int)nods_data[i] == 0) {
917 }
else if ((
int)nods_data[i] == 1) {
919 is_nodding = CPL_TRUE;
921 error_if(1, CPL_ERROR_BAD_FILE_FORMAT,
922 "Wrong values in line %d in %s", i+1, fnodpos);
926 skip_if (irplib_framelist_contains(rawframes, VISIR_PFITS_STRING_NODPOS,
927 CPL_TYPE_STRING, CPL_FALSE, 0.0));
930 if (no_rem) cpl_msg_info(cpl_func,
"No glitch removal and no purge of bad "
931 "frames requested: Using fast I/O method");
934 if (badpix != NULL) {
936 cpl_msg_info(cpl_func,
"Loading bad pixel map from %s", badpix);
938 bpm_im_int = cpl_image_load(badpix, CPL_TYPE_INT, 0, 0);
942 bpm_im_bin = cpl_mask_threshold_image_create(bpm_im_int, -0.5, 0.5);
943 cpl_image_delete(bpm_im_int);
945 skip_if (cpl_mask_not(bpm_im_bin));
946 }
else if (auto_bpm) {
954 cpl_mask_threshold_image_create(cpl_imagelist_get(hcycle,0),
955 VISIR_HCYCLE_BPM_THRESHOLD,
957 cpl_imagelist_delete(hcycle);
964 cpl_msg_info(cpl_func,
"Divide the nodded images by the flatfield");
966 flat_image = cpl_image_load(flat, CPL_TYPE_FLOAT, 0, 0);
967 any_if (
"Cannot load the flat field %s", flat ? flat :
"<NULL>");
971 nodded = cpl_imagelist_new();
973 tstart = cpl_test_get_walltime();
977 for (i=0; i < nfiles/2 ; i++) {
978 cpl_image * empty = cpl_image_new(naxis1, naxis2, CPL_TYPE_FLOAT);
983 bug_if (cpl_imagelist_set(nodded, empty, i));
987#pragma omp parallel for private(i) firstprivate(prev, collapsed) \
990 for (i = 0; i < nfiles ; i++) {
991 cpl_error_code errori = cpl_error_get_code();
999 if (didfail)
continue;
1004 cpl_frame_get_filename(irplib_framelist_get_const(rawframes, i));
1005 const cpl_propertylist * plist;
1011 plist = irplib_framelist_get_propertylist_const(rawframes, i);
1012 if (plist == NULL) {
1013 errori = cpl_error_set_where(cpl_func);
1017 if (nods_vec == NULL) {
1020 errori = cpl_error_set_message(cpl_func,
1021 CPL_ERROR_DATA_NOT_FOUND,
1022 "Cannot get nodding position "
1023 "for file %d/%d", i+1, nfiles);
1026 if (!strcmp(sval,
"A")) {
1034 is_nodding = CPL_TRUE;
1039 cpl_msg_info(cpl_func,
"File %02d: %s (%c)", i+1, file,
1040 nod_pos[i]==1 ?
'+' :
'-');
1043 if (is_nodding && (i & 1) == 1 && nod_pos[i] == nod_pos[i-1]) {
1044 cpl_msg_error(cpl_func,
"Nodding pair (%d,%d) does not comprise an "
1045 "on-object (A) and an off-object (B) image: %s", i-1,
1046 i, nod_pos[i] == 1 ?
"A" :
"B");
1051 if (cpl_error_get_code()) {
1052 errori = cpl_error_set_where(cpl_func);
1057 errori = cpl_error_set_message(cpl_func,
1058 CPL_ERROR_ILLEGAL_INPUT,
1059 "DIT in file %d/%d is too small: "
1060 "%g", i+1, nfiles, dit);
1064 factor = dit * nod_pos[i] * 2.0;
1067 collapsed = visir_load_average(file, plist);
1069 in = visir_load_intermint(rawframes, i);
1071 errori = cpl_error_set_message(cpl_func,
1072 CPL_ERROR_ILLEGAL_INPUT,
1073 "Could not load image set %d",
1079 if (visir_imagelist_unpack_interm(in)) {
1080 errori = cpl_error_set_message(cpl_func,
1081 cpl_error_get_code(),
1082 "Failure for file %d/%d",
1091 for (jj=0 ; jj < cpl_imagelist_get_size(in); jj++) {
1092 if (visir_rem_glitch(cpl_imagelist_get(in, jj))) {
1093 errori = cpl_error_set_message(cpl_func,
1094 cpl_error_get_code(),
1096 "glitch in image %d in "
1097 "set %d", jj+1, i+1);
1105 cpl_msg_info(cpl_func,
"Remove the bad A-B input images");
1106 if (visir_rem_bad_images(in)) {
1107 errori = cpl_error_set_message(cpl_func,
1108 cpl_error_get_code(),
1109 "Could not remove bad "
1110 "images in list %d", i+1);
1115 collapsed = cpl_imagelist_collapse_create(in);
1117 cpl_imagelist_delete(in);
1122 if (cpl_error_get_code()) {
1123 errori = cpl_error_set_message(cpl_func, cpl_error_get_code(),
1124 "Failure for file %d/%d",
1130 if (cpl_image_divide_scalar(collapsed, 2*factor)) {
1131 errori = cpl_error_set_message(cpl_func, cpl_error_get_code(),
1132 "Failure for file %d/%d",
1139 if (cpl_image_add(prev, collapsed)) {
1140 errori = cpl_error_set_message(cpl_func, cpl_error_get_code(),
1141 "Failure for file %d/%d",
1145 cpl_image_delete(collapsed);
1151 if (bpm_im_bin != NULL) {
1153 if (cpl_image_reject_from_mask(prev, bpm_im_bin)) {
1154 errori = cpl_error_set_message(cpl_func,
1155 cpl_error_get_code(),
1156 "Failure for file %d/%d",
1160 if (cpl_detector_interpolate_rejected(prev)) {
1161 errori = cpl_error_set_message(cpl_func,
1162 cpl_error_get_code(),
1163 "Failure for file %d/%d",
1171 VISIR_DESTRIPE_DETECT,
1172 VISIR_DESTRIPE_DETECT_THRESHOLD,
1174 errori = cpl_error_set_message(cpl_func,
1175 cpl_error_get_code(),
1176 "Failure for file %d/%d",
1181 if (flat_image != NULL) {
1183 if (cpl_image_divide(prev, flat_image)) {
1184 errori = cpl_error_set_message(cpl_func,
1185 cpl_error_get_code(),
1186 "Failure for file %d/%d",
1192 if (cpl_imagelist_set(nodded, prev, i/2)) {
1193 errori = cpl_error_set_message(cpl_func, cpl_error_get_code(),
1194 "Failure for file %d/%d",
1209 cpl_errorstate_dump(cleanstate, CPL_FALSE, NULL);
1210 cpl_errorstate_set(cleanstate);
1213 cpl_image_delete(prev); prev = NULL;
1214 cpl_image_delete(collapsed); collapsed = NULL;
1216#pragma omp critical(visir_inputs_combine)
1222 error_if(didfail, didfail,
"Failed to create %d nodded images from %d "
1223 "files", nnod, nfiles);
1225 tstop = cpl_test_get_walltime();
1226 cpl_msg_info(cpl_func,
"Time to create %d nodded images [s]: %g", nnod,
1229 cpl_vector_delete(nods_vec);
1232 cpl_image_delete(flat_image);
1235 cpl_mask_delete(bpm_im_bin);
1238 if (nod_pos != nodding_p) cpl_free(nod_pos);
1241 error_if(is_nodding && j != nnod, CPL_ERROR_INCOMPATIBLE_INPUT,
1242 "With nodding exactly half of the images "
1243 "must be on-object, not %d of %d", j, 2*nnod);
1247 parlist, recipename, VISIR_PARAM_SPECSKEW);
1249 parlist, recipename, VISIR_PARAM_VERTARC);
1251 parlist, recipename, VISIR_PARAM_HORIARC);
1253 parlist, recipename, VISIR_PARAM_SLITSKEW);
1255 parlist, recipename, VISIR_PARAM_PLOT);
1259 images = cpl_malloc(nnod *
sizeof(cpl_image*));
1261 for (j = 0; j < nnod; j++) images[j] = cpl_imagelist_get(nodded, j);
1263 skip_if (visir_spc_det_fix(images, nnod, CPL_TRUE, wlen, resol,
1264 phi, ksi, eps, delta, doplot));
1269 cpl_msg_set_time_off();
1272 cpl_imagelist_delete(in);
1274 if (nod_pos != nodding_p) cpl_free(nod_pos);
1275 cpl_vector_delete(nods_vec);
1276 cpl_image_delete(bpm_im_int);
1277 cpl_mask_delete(bpm_im_bin);
1278 cpl_image_delete(collapsed);
1279 cpl_image_delete(prev);
1280 if (cpl_error_get_code() && nodded != NULL) {
1281 cpl_imagelist_delete(nodded);
1299get_cumoffsets(
const cpl_propertylist * plist,
double * x,
double * y)
1301 cpl_errorstate cleanstate = cpl_errorstate_get();
1303 *x = irplib_pfits_get_double(plist,
"ESO DRS CUMOFFSETX");
1304 *y = irplib_pfits_get_double(plist,
"ESO DRS CUMOFFSETY");
1306 if (cpl_error_get_code() != CPL_ERROR_NONE) {
1307 cpl_errorstate_set(cleanstate);
1308 cpl_msg_info(cpl_func,
"DRS CUMOFFSET[XY] not found, falling back"
1309 " to SEQ CUMOFFSET[XY]");
1313 return cpl_error_get_code();
1333 const cpl_parameterlist * parlist,
1334 cpl_imagelist * nodded,
1335 const cpl_propertylist ** plists,
1336 cpl_geom_combine combine_mode,
1337 cpl_boolean * pdid_resize)
1340 cpl_bivector * offsets_est = NULL;
1341 cpl_bivector * objs = NULL;
1342 cpl_image ** combined = NULL;
1343 cpl_vector * sigmas = NULL;
1344 cpl_propertylist * qclist = cpl_propertylist_new();
1349 bug_if (recipename == NULL);
1350 bug_if (parlist == NULL);
1351 bug_if (pdid_resize == NULL);
1352 bug_if (nodded == NULL);
1354 nnod = cpl_imagelist_get_size(nodded);
1355 cpl_msg_debug(cpl_func,
"nnod = %lld", nnod);
1359 combined = cpl_malloc(2*
sizeof(cpl_image*));
1362 combined[0] = cpl_imagelist_unset(nodded, 0);
1363 bug_if (combined[0] == NULL);
1365 combined[1] = cpl_image_new(cpl_image_get_size_x(combined[0]),
1366 cpl_image_get_size_y(combined[0]),
1368 bug_if (combined[1] == NULL);
1371 bug_if(cpl_image_threshold(combined[1], 1.0, 1.0, 1.0, 1.0));
1373 *pdid_resize = CPL_FALSE;
1376 const double psigmas[] = {5, 2, 1, 0.5};
1378 const char * offsets;
1379 const char * objects;
1381 int rej_low, rej_high;
1386 VISIR_PARAM_REFINE);
1390 VISIR_PARAM_OFFSETS);
1394 VISIR_PARAM_OBJECTS);
1401 if (sscanf(sval,
"%d-%d-%d-%d", &sx, &sy, &mx, &my) != 4)
1402 skip_if (sscanf(sval,
"%d %d %d %d", &sx, &sy, &mx, &my) != 4);
1406 VISIR_PARAM_REJECT);
1409 if (sscanf(sval,
"%d-%d", &rej_low, &rej_high) !=2 )
1410 skip_if (sscanf(sval,
"%d %d", &rej_low, &rej_high) !=2 );
1413 cpl_msg_info(cpl_func,
"Get the offsets estimation");
1414 if (!visir_str_par_is_empty(offsets)) {
1416 offsets_est = cpl_bivector_read(offsets);
1417 skip_if (offsets_est==NULL);
1419 error_if (cpl_bivector_get_size(offsets_est) != nnod,
1420 CPL_ERROR_BAD_FILE_FORMAT,
"The offsets file %s must "
1421 "have %d entries, not %d", offsets, (
int)nnod,
1422 (
int)cpl_bivector_get_size(offsets_est));
1424 double * offsets_est_x;
1425 double * offsets_est_y;
1426 double xoff0, yoff0;
1429 offsets_est = cpl_bivector_new(nnod);
1430 offsets_est_x = cpl_bivector_get_x_data(offsets_est);
1431 offsets_est_y = cpl_bivector_get_y_data(offsets_est);
1435 offsets_est_x[0] = 0.0;
1436 offsets_est_y[0] = 0.0;
1437 get_cumoffsets(plists[0], &xoff0, &yoff0);
1439 for (cpl_size i = 1; i < nnod ; i++) {
1442 skip_if(get_cumoffsets(plists[i], &xoff, &yoff));
1445 offsets_est_x[i] = xoff0 - xoff;
1446 offsets_est_y[i] = yoff0 - yoff;
1452 if (!visir_str_par_is_empty(objects)) {
1453 objs = cpl_bivector_read(objects);
1454 any_if (
"Could not read objects from %s", objects);
1457 cpl_msg_info(cpl_func,
"Recombining the list of nodded images using "
1458 "mode: %d (I=%d:U=%d:F=%d), rej-lo=%d, rej-hi=%d",
1459 combine_mode, CPL_GEOM_INTERSECT, CPL_GEOM_UNION,
1460 CPL_GEOM_FIRST, rej_low, rej_high);
1462 if (cpl_msg_get_level() <= CPL_MSG_DEBUG) {
1463 cpl_msg_debug(cpl_func,
"The offsets for the recombination:");
1464 cpl_bivector_dump(offsets_est, stdout);
1467 IRPLIB_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual);
1468 sigmas = cpl_vector_wrap(4, (
double*)psigmas);
1469 IRPLIB_DIAG_PRAGMA_POP;
1470 combined = cpl_geom_img_offset_combine(nodded, offsets_est, refine,
1471 objs, sigmas, NULL, sx, sy,
1472 mx, my, rej_low, rej_high,
1474 any_if(
"Could not recombine the images");
1476 *pdid_resize = (cpl_boolean)(cpl_image_get_size_x(combined[0])
1477 != cpl_image_get_size_x(cpl_imagelist_get_const(nodded, 0)) ||
1478 cpl_image_get_size_y(combined[0])
1479 != cpl_image_get_size_y(cpl_imagelist_get_const(nodded, 0)));
1483 visir_image_plot(
"",
"t 'The combined image'",
"", combined[0]);
1487 cpl_propertylist_delete(qclist);
1488 cpl_bivector_delete(offsets_est);
1489 cpl_bivector_delete(objs);
1490 cpl_vector_unwrap(sigmas);
1544 const cpl_parameterlist * parlist,
1545 const irplib_framelist * rawframes,
1546 const char * badpix,
1548 cpl_geom_combine combine_mode,
1549 cpl_boolean * pdid_resize,
1550 cpl_boolean do_spc_fix,
1552 visir_spc_resol resol)
1555 int * nod_pos = NULL;
1556 cpl_imagelist * nodded = NULL;
1558 cpl_bivector * objs = NULL;
1559 cpl_propertylist * qclist = cpl_propertylist_new();
1560 const cpl_propertylist ** plists = NULL;
1561 cpl_image ** rec = NULL;
1566 bug_if (recipename == NULL);
1567 bug_if (parlist == NULL);
1568 bug_if (rawframes == NULL);
1569 bug_if (pdid_resize == NULL);
1572 nfiles = irplib_framelist_get_size(rawframes);
1573 cpl_msg_debug(cpl_func,
"nfiles = %d", nfiles);
1577 cpl_msg_warning(cpl_func,
"Expecting even number of files, "
1578 "ignoring the last of %d file(s)", nfiles);
1579 error_if (nfiles == 1, CPL_ERROR_DATA_NOT_FOUND,
1580 "At least two files are required");
1584 skip_if ( nfiles <= 0);
1587 nod_pos = cpl_malloc(nfiles *
sizeof(
int));
1590 cpl_msg_info(cpl_func,
"Combining the input frames into the nodded images");
1592 nod_pos, do_spc_fix, wlen, resol);
1593 skip_if(nodded == NULL);
1595 nnod = cpl_imagelist_get_size(nodded);
1596 cpl_msg_debug(cpl_func,
"nnod = %lld", nnod);
1597 plists = cpl_malloc(nnod *
sizeof(cpl_propertylist *));
1598 for (cpl_size i=0; i < nnod ; i++) {
1599 const cpl_size iframe = nod_pos[2*i] == 1 ? 2*i : 2*i+1;
1601 plists[i] = irplib_framelist_get_propertylist_const(rawframes,
1606 plists, combine_mode, pdid_resize);
1610 cpl_propertylist_delete(qclist);
1613 cpl_imagelist_delete(nodded);
1614 cpl_bivector_delete(objs);
1657 FILE* fp = fopen(apfile,
"r");
1659 cpl_msg_error(cpl_func,
"Cannot open apfile (supply full path): %s",
1661 cpl_error_set(cpl_func, CPL_ERROR_FILE_NOT_FOUND);
1668 visir_aplist* list = visir_aplist_new();
1669 while (getline(&line, &len, fp) != -1) {
1674 visir_aplist_push_back(list, ap);
1682 if (visir_aplist_size(list) < 1) {
1683 cpl_msg_error(cpl_func,
"File has no usable entries: %s", apfile);
1684 cpl_error_set(cpl_func, CPL_ERROR_BAD_FILE_FORMAT);
1700 int offs = snprintf(buf,
sizeof(buf),
"%c %d %d", ap->extract_method,
1701 ap->limits[0].l, ap->limits[0].r);
1702 if (ap->nlimits > 1) {
1703 offs += snprintf(buf+offs,
sizeof(buf)-offs,
" %c", ap->sky_method);
1704 for (
size_t i = 1; i < ap->nlimits; ++i)
1705 offs += snprintf(buf+offs,
sizeof(buf)-offs,
" %d %d",
1706 ap->limits[i].l, ap->limits[i].r);
1708 return cpl_sprintf(
"%s", buf);
1723 char * term = strchr(line,
'#');
1724 if (term) *term =
'\0';
1726 char const *
const intro =
"Error parsing apfile: ";
1727 char* outro = cpl_sprintf(
" on apfile line: %s", line);
1731 char max = 40, * toks[max];
1732 char * state, * tok = strtok_r(line,
"\n\t ", &state);
1733 for (; tok; tok = strtok_r(NULL,
"\n\t ", &state)) {
1734 toks[ntoks++] = tok;
1736 cpl_msg_error(cpl_func,
"%sToo many tokens%s", intro, outro);
1737 cpl_error_set(cpl_func, CPL_ERROR_BAD_FILE_FORMAT);
1744 if (ntoks != 0 && ntoks != 3 && (ntoks < 6 || ntoks % 2)) {
1745 cpl_msg_error(cpl_func,
"%sWrong token count%s", intro, outro);
1746 cpl_error_set(cpl_func, CPL_ERROR_BAD_FILE_FORMAT);
1750 const int nlimits = (ntoks == 3 ? 2 : ntoks-2);
1760 if (toks[0][0] !=
'O') {
1761 cpl_msg_error(cpl_func,
"%sMethod & token count mismatch%s",
1763 cpl_error_set(cpl_func, CPL_ERROR_BAD_FILE_FORMAT);
1768 if (toks[0][0] !=
'A' || !strchr(
"AFM", toks[3][0])) {
1769 cpl_msg_error(cpl_func,
"%sMethod & token count mismatch%s",
1771 cpl_error_set(cpl_func, CPL_ERROR_BAD_FILE_FORMAT);
1778 int nscans = nlimits;
1779 for (
int i = 1; i < ntoks; i += (i==2 ? 2 : 1))
1780 nscans -= sscanf(toks[i],
"%f", &(
float){0});
1782 cpl_msg_error(cpl_func,
"%sToken scan failure%s", intro, outro);
1783 cpl_error_set(cpl_func, CPL_ERROR_BAD_FILE_FORMAT);
1789 visir_apdefs*
new = visir_apdefs_new(nlimits/2, ident, toks[0][0],
1790 ntoks > 3 ? toks[3][0] : 0);
1791 for (
int i = 1, j = 0; i < ntoks; i += (i==2 ? 2 : 1), ++j) {
1793 sscanf(toks[i],
"%f", &temp);
1794 new->limits[j].l = (int)floor(temp);
1795 sscanf(toks[++i],
"%f", &temp);
1796 new->limits[j].r = (int)ceil(temp);
1797 if (new->limits[j].l > new->limits[j].r) {
1798 cpl_msg_error(cpl_func,
1799 "%sLeft aperture limit greater than right%s",
1801 cpl_error_set(cpl_func, CPL_ERROR_BAD_FILE_FORMAT);
1803 visir_apdefs_delete(
new);
1809 if (new->nlimits > 2) {
1812 for (
size_t i = 1; i <
new->nlimits - 1; ++i) {
1814 for (
size_t j = i + 1; j <
new->nlimits; ++j)
1815 if (new->limits[j].l < new->limits[mini].l)
1818 visir_aplimits tmp =
new->limits[mini];
1819 new->limits[mini] =
new->limits[i];
1820 new->limits[i] = tmp;
1824 int nskys =
new->nlimits - 1;
1825 int niterations = nskys - 1;
1826 for (
int i = 0; i < niterations; ++i)
1827 if (new->limits[i+1].r > new->limits[i+2].l) {
1828 cpl_msg_error(cpl_func,
"%sOverlapping apertures found%s",
1830 cpl_error_set(cpl_func, CPL_ERROR_BAD_FILE_FORMAT);
1832 visir_apdefs_delete(
new);
1855 cpl_image * im_bpm = NULL;
1856 cpl_mask * bpm = NULL;
1857 const int upper = VISIR_HCYCLE_BPM_THRESHOLD;
1862 skip_if (self == NULL);
1864 if (bpmfile == NULL) {
1865 bpm = cpl_mask_threshold_image_create(self, upper, DBL_MAX);
1870 cpl_msg_info(cpl_func,
"Clean user specified bad pixels");
1872 im_bpm = cpl_image_load(bpmfile, CPL_TYPE_INT, 0, 0);
1873 any_if (
"Could not load the bad pixel map %s",
1874 bpmfile ? bpmfile :
"<NULL>");
1876 bpm = cpl_mask_threshold_image_create(im_bpm, -0.5, 0.5);
1878 cpl_image_delete(im_bpm);
1881 skip_if (cpl_mask_not(bpm));
1884 skip_if (cpl_image_reject_from_mask(self, bpm));
1888 cpl_image_delete(im_bpm);
1889 cpl_mask_delete(bpm);
1891 return cpl_error_get_code();
1906 cpl_imagelist * self = NULL;
1910 skip_if(irplib_framelist_contains(rawframes, VISIR_PFITS_INT_NAXIS3,
1911 CPL_TYPE_INT, CPL_TRUE, 0.0));
1918 self = irplib_imagelist_load_framelist(rawframes, CPL_TYPE_FLOAT, naxis3-1,
1921 skip_if (self == NULL);
1942 int pos, cpl_boolean is_interm)
1944 cpl_imagelist * self = NULL;
1945 cpl_image * image = NULL;
1946 const cpl_frame * frame = irplib_framelist_get_const(rawframes, pos);
1947 const cpl_propertylist * plist =
1948 irplib_framelist_get_propertylist_const(rawframes, pos);
1949 const char * file = cpl_frame_get_filename(frame);
1952 visir_data_type data_type;
1958 skip_if (plist == NULL);
1960 skip_if(visir_get_data_type(frame, plist, &data_type, NULL));
1962 switch (data_type) {
1963 case VISIR_DATA_AQU_HCYCLE:
1964 case VISIR_DATA_AQU_BURST:
1965 case VISIR_DATA_AQU_BURST_EXT:
1966 error_if(1, CPL_ERROR_UNSUPPORTED_MODE,
1967 "Aquarius data not supported");
1973 bug_if (file == NULL);
1975 if (data_type == VISIR_DATA_CUBE1) {
1977 iplane = is_interm ? 0 : nchop;
1979 nsize = is_interm ? nchop : 1;
1981 }
else if (naxis3 == 1) {
1987 iplane = is_interm ? 1 : 0;
1992 self = cpl_imagelist_new();
1994 for (i=0 ; i < nsize; i++, iplane += plane_step) {
1996 image = cpl_image_load(file, CPL_TYPE_FLOAT, iplane, 0);
1997 skip_if (image == NULL);
1999 skip_if (!is_interm && visir_offset_hcycle(image));
2001 skip_if (cpl_imagelist_set(self, image, i));
2006 skip_if (i < nsize);
2010 if (cpl_error_get_code()) {
2011 if (file != NULL) cpl_msg_warning(cpl_func,
"Could not load the %s "
2012 "frame(s) from: %s",
2013 is_interm ?
"INTERM" :
"Half-Cycle",
2015 cpl_image_delete(image);
2016 cpl_imagelist_delete(self);
2051static cpl_imagelist * visir_load_intermint(
const irplib_framelist * rawframes,
2068static cpl_image * visir_load_average(
const char * file,
2069 const cpl_propertylist * plist)
2071 cpl_errorstate cleanstate = cpl_errorstate_get();
2072 cpl_image * self = NULL;
2077 skip_if (file == NULL);
2078 skip_if (plist == NULL);
2085 if (nchop == 0 && naxis3 == 1) {
2086 self = cpl_image_load(file, CPL_TYPE_FLOAT, 0, 0);
2091 const int plane_offset = (naxis3 == 2 * nchop + 1) ? 2 : 3;
2094 error_if (nchop <= 0, CPL_ERROR_BAD_FILE_FORMAT,
"CHOP NCYCLES in %s "
2095 "is non-positive (and NAXIS3=%d): %d", file, naxis3, nchop);
2097 error_if (plane_offset == 3 && naxis3 != nchop+2,
2098 CPL_ERROR_BAD_FILE_FORMAT,
"NAXIS3=%d and CHOP NCYCLES=%d "
2099 "in %s is not a valid VISIR INTERM+Half-Cycle format", naxis3,
2102 if (plane_offset == 3 && nchop > 1)
2103 cpl_msg_debug(cpl_func,
"%s has %d INTERM-frames and one Half-"
2104 "Cycle frame (old CUBE1-format)", file, nchop);
2110 visir_error_reset(
"Could not get FITS key");
2112 }
else if (strlen(sval) == 0) {
2114 }
else if (plane_offset == 3) {
2115 if (strcmp(sval,
"CUBE2")==0)
2116 cpl_msg_error(cpl_func,
"%s has FRAM TYPE = CUBE2, but NAXIS3="
2117 "%d and CHOP NCYCLES=%d imply a CUBE1. Assuming"
2118 " the frame type is really CUBE1", file,
2120 }
else if (nchop > 1) {
2122 if (strcmp(sval,
"CUBE1")==0)
2123 cpl_msg_error(cpl_func,
"%s has FRAM TYPE = CUBE1, but NAXIS3="
2124 "%d and CHOP NCYCLES=%d imply a CUBE2. Assuming"
2125 "the frame type is really CUBE2", file,
2130 self = cpl_image_load(file, CPL_TYPE_FLOAT, naxis3-plane_offset, 0);
2138 if (cpl_error_get_code()) {
2139 cpl_msg_warning(cpl_func,
"Could not load the last INTERM frame from: "
2140 "%s", file ? file :
"<NULL>");
2141 cpl_image_delete(self);
2172static cpl_error_code visir_imagelist_unpack_interm(cpl_imagelist * self)
2176 const int n = cpl_imagelist_get_size(self);
2181 if (n == 1)
return CPL_ERROR_NONE;
2183 iprev = cpl_imagelist_get(self, n - 1);
2187 skip_if (cpl_image_multiply_scalar(iprev, n));
2190 for (i = n-1 ; i > 1 ; i--, iprev = image) {
2191 image = cpl_imagelist_get(self, i-1);
2195 skip_if (cpl_image_multiply_scalar(image, i));
2197 skip_if (cpl_image_subtract(iprev, image));
2201 image = cpl_imagelist_get(self, 0);
2205 skip_if (cpl_image_subtract(iprev, image));
2209 return cpl_error_get_code();
2226static cpl_error_code visir_rem_glitch(cpl_image * glitchy)
2228 cpl_image * med_filt = NULL;
2229 cpl_mask * bpm = NULL;
2230 cpl_mask * kernel = cpl_mask_new(3, 3);
2232 double low_thresh, high_thresh;
2233 const int nx = cpl_image_get_size_x(glitchy);
2234 const int ny = cpl_image_get_size_y(glitchy);
2238 double factor1 = 3.0;
2239 double factor2 = 10.0;
2240 const int niterations = 5;
2241 const double median_corr = 1.5;
2246 bug_if(cpl_mask_not(kernel));
2249 med_filt = cpl_image_new(cpl_image_get_size_x(glitchy),
2250 cpl_image_get_size_y(glitchy),
2251 cpl_image_get_type(glitchy));
2252 bug_if(med_filt == NULL);
2253 bug_if(cpl_image_filter_mask(med_filt, glitchy, kernel, CPL_FILTER_MEDIAN,
2254 CPL_BORDER_FILTER));
2255 cpl_mask_delete(kernel);
2259 skip_if (cpl_image_subtract(glitchy, med_filt));
2262 for (i=0 ; i < niterations ; i++) {
2264 mean = cpl_image_get_mean(glitchy);
2265 stdev = cpl_image_get_stdev(glitchy);
2270 low_thresh = mean - factor1 * stdev;
2271 high_thresh = mean + factor1 * stdev;
2274 bpm = cpl_mask_threshold_image_create(glitchy,low_thresh,high_thresh);
2275 skip_if (cpl_mask_not(bpm));
2276 skip_if (cpl_image_reject_from_mask(glitchy, bpm));
2277 cpl_mask_delete(bpm);
2281 skip_if (cpl_image_count_rejected(glitchy) == nx*ny);
2286 mean = cpl_image_get_mean(glitchy);
2287 stdev = cpl_image_get_stdev(glitchy) * median_corr;
2291 low_thresh = mean - factor2 * stdev;
2292 high_thresh = mean + factor2 * stdev;
2294 bpm = cpl_mask_threshold_image_create(glitchy, low_thresh, high_thresh);
2295 skip_if (cpl_mask_not(bpm));
2296 skip_if (cpl_image_reject_from_mask(glitchy, bpm));
2297 cpl_mask_delete(bpm);
2301 skip_if (cpl_image_count_rejected(glitchy) == nx*ny);
2304 skip_if (cpl_image_fill_rejected(glitchy, 0.0));
2305 skip_if (cpl_image_accept_all(glitchy));
2308 skip_if (cpl_image_add(glitchy, med_filt));
2312 cpl_image_delete(med_filt);
2313 cpl_mask_delete(bpm);
2314 cpl_mask_delete(kernel);
2316 return cpl_error_get_code();
2331static cpl_error_code visir_rem_bad_images(cpl_imagelist * in)
2333 cpl_vector * medians = NULL;
2334 cpl_vector * stdevs = NULL;
2335 cpl_vector * selection = NULL;
2336 double mean_medians, mean_stdevs, stdev_medians, stdev_stdevs;
2337 const double threshold = 3;
2338 const int nima = cpl_imagelist_get_size(in);
2344 if (nima <= 3)
return CPL_ERROR_NONE;
2347 medians = cpl_vector_new(nima);
2348 stdevs = cpl_vector_new(nima);
2351 for (i=0 ; i < nima ; i++) {
2352 cpl_stats * stats = cpl_stats_new_from_image(cpl_imagelist_get(in, i),
2353 CPL_STATS_STDEV | CPL_STATS_MEDIAN);
2355 cpl_vector_set(medians, i, cpl_stats_get_median(stats));
2356 cpl_vector_set(stdevs, i, cpl_stats_get_stdev(stats));
2357 cpl_stats_delete(stats);
2363 mean_medians = cpl_vector_get_mean(medians);
2364 stdev_medians = cpl_vector_get_stdev(medians);
2365 mean_stdevs = cpl_vector_get_mean(stdevs);
2366 stdev_stdevs = cpl_vector_get_stdev(stdevs);
2368 skip_if (cpl_vector_subtract_scalar(medians, mean_medians));
2369 skip_if (cpl_vector_subtract_scalar(stdevs, mean_stdevs));
2371 stdev_medians *= threshold;
2372 stdev_stdevs *= threshold;
2375 selection = cpl_vector_new(nima);
2376 skip_if( cpl_vector_fill(selection, 0));
2377 for (i=0 ; i < nima ; i++) {
2378 if (fabs(cpl_vector_get(medians, i)) <= stdev_medians &&
2379 fabs(cpl_vector_get(stdevs, i)) <= stdev_stdevs)
continue;
2381 cpl_vector_set(selection, i, -1);
2382 cpl_msg_info(cpl_func,
"Image %d of %d rejected: median=%g, stdev=%g",
2383 i+1, nima, stdev_medians, stdev_stdevs);
2387 cpl_imagelist_erase(in, selection);
2391 cpl_vector_delete(medians);
2392 cpl_vector_delete(stdevs);
2394 cpl_vector_delete(selection);
2396 return CPL_ERROR_NONE;
2409static cpl_error_code visir_offset_hcycle(cpl_image * hcycle)
2415 skip_if (cpl_image_add_scalar(hcycle, VISIR_HCYCLE_OFFSET));
2417 minval = cpl_image_get_min(hcycle);
2420 if (minval < 1) cpl_msg_warning(cpl_func,
"HCycle pixel minval: %g", minval);
2424 return CPL_ERROR_NONE;
2441cpl_image ** visir_img_collapse_beam_four(cpl_propertylist * qclist,
2442 const cpl_image * self,
2443 const cpl_image * inverse,
2447 const cpl_propertylist * plist)
2450 cpl_image ** combined = NULL;
2451 const int nx = cpl_image_get_size_x(self);
2452 const int ny = cpl_image_get_size_y(self);
2453 const cpl_type type = cpl_image_get_type(self);
2454 cpl_imagelist * list4 = cpl_imagelist_new();
2455 IRPLIB_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual);
2456 cpl_image * swrap = type == CPL_TYPE_DOUBLE
2457 ? cpl_image_wrap_double(nx, ny, cpl_image_get_data((cpl_image*)self))
2458 : cpl_image_wrap_float(nx, ny, cpl_image_get_data((cpl_image*)self));
2459 cpl_image * iwrap = type == CPL_TYPE_DOUBLE
2460 ? cpl_image_wrap_double(nx, ny, cpl_image_get_data((cpl_image*)inverse))
2461 : cpl_image_wrap_float(nx, ny, cpl_image_get_data((cpl_image*)inverse));
2462 IRPLIB_DIAG_PRAGMA_POP;
2463 cpl_bivector * offs = cpl_bivector_new(4);
2464 double * x4 = cpl_bivector_get_x_data(offs);
2465 double * y4 = cpl_bivector_get_y_data(offs);
2466 double pos_x, pos_y;
2470 skip_if(plist == NULL);
2472 skip_if(visir_img_find_beam_four(qclist, self, inverse, eccmax, pthrow,
2476 for (
int i = 1; i < 4; i++) {
2477 x4[i] = x4[0] - x4[i];
2478 y4[i] = y4[0] - y4[i];
2481 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM XPOS",
2483 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM YPOS",
2485 x4[0] = y4[0] = 0.0;
2487 IRPLIB_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual);
2488 bug_if(cpl_imagelist_set(list4, (cpl_image*)self, 0));
2489 bug_if(cpl_imagelist_set(list4, swrap, 1));
2490 bug_if(cpl_imagelist_set(list4, (cpl_image*)inverse, 2));
2491 bug_if(cpl_imagelist_set(list4, iwrap, 3));
2492 IRPLIB_DIAG_PRAGMA_POP;
2494 combined = cpl_geom_img_offset_saa(list4, offs, CPL_KERNEL_DEFAULT, 0, 0,
2495 CPL_GEOM_FIRST, &pos_x, &pos_y);
2497 skip_if(combined == NULL);
2501 cpl_bivector_delete(offs);
2502 visir_imagelist_unwrap(list4);
2503 (void)cpl_image_unwrap(swrap);
2504 (void)cpl_image_unwrap(iwrap);
2505 if (cpl_error_get_code() && combined != NULL) {
2506 cpl_image_delete(combined[0]);
2507 cpl_image_delete(combined[1]);
2529visir_chopnod_mode visir_img_find_beam(cpl_propertylist * qclist,
2530 const cpl_image * self,
2531 const cpl_image * inverse,
2532 const cpl_propertylist * plist,
2533 const cpl_parameterlist * parlist,
2534 const char * recipename,
2539 cpl_errorstate cleanstate = cpl_errorstate_get();
2540 visir_chopnod_mode mode = VISIR_CHOPNOD_AUTO;
2543 VISIR_PARAM_ECCMAX);
2549 const double pthrow = pscale > 0.0
2553 skip_if(x4 == NULL);
2554 skip_if(y4 == NULL);
2555 skip_if(self == NULL);
2556 skip_if(inverse == NULL);
2557 skip_if(parlist == NULL);
2558 skip_if(recipename == NULL);
2559 skip_if(qclist == NULL);
2563 if (sdir != NULL && !strcmp(sdir,
"PERPENDICULAR")) {
2566 mode = VISIR_CHOPNOD_PERPENDICULAR;
2568 skip_if (visir_img_find_beam_four(qclist, self, inverse, eccmax,
2569 pthrow, angle, x4, y4));
2571 }
else if (sdir != NULL && !strcmp(sdir,
"PARALLEL")) {
2574 mode = VISIR_CHOPNOD_PARALLEL;
2576 skip_if (visir_img_find_beam_three(qclist, self, inverse, eccmax,
2577 pthrow, angle, x4, y4));
2581 visir_error_reset(
"Could not get FITS key");
2583 cpl_msg_warning(cpl_func,
"Unknown chopping direction: %s",
2586 cpl_msg_warning(cpl_func,
"Proceeding as if FITS card "
2587 VISIR_PFITS_STRING_CHOPNOD_DIR
" had value: %s",
2590 if (visir_img_find_beam_four(qclist, self, inverse, eccmax,
2591 pthrow, angle, x4, y4)) {
2593 visir_error_reset(
"Proceeding as if FITS card "
2594 VISIR_PFITS_STRING_CHOPNOD_DIR
2595 " had value: %s",
"PARALLEL");
2597 skip_if (visir_img_find_beam_three(qclist, self, inverse,
2598 eccmax, pthrow, angle,
2602 mode = VISIR_CHOPNOD_PARALLEL;
2606 mode = VISIR_CHOPNOD_PERPENDICULAR;
2610 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM THROW",
2612 bug_if (cpl_propertylist_set_comment(qclist,
"ESO QC ONEBEAM THROW",
2613 "The throw in pixels (TEL CHOP THROW "
2614 "divided by INS PFOV)"));
2636cpl_error_code visir_img_find_beam_four(cpl_propertylist * qclist,
2637 const cpl_image * self,
2638 const cpl_image * inverse,
2646 cpl_errorstate cleanstate = cpl_errorstate_get();
2647 cpl_apertures * appos = NULL;
2648 cpl_apertures * apneg = NULL;
2649 const double psigmas[] = {2.0, 1.0, 0.5};
2650 const int nsigmas =
sizeof(psigmas)/
sizeof(
double);
2652 int iappos2[] = {1, 2};
2653 int iapneg2[] = {1, 2};
2656 skip_if(self == NULL);
2657 skip_if(qclist == NULL);
2658 skip_if(pthrow <= 0.0);
2659 skip_if(x4 == NULL);
2660 skip_if(y4 == NULL);
2662 cpl_msg_info(cpl_func,
"Detecting the 4-beam object with %g pixel throw "
2663 "using %d sigma-levels ranging from %g down to %g", pthrow,
2664 nsigmas, psigmas[0], psigmas[nsigmas-1]);
2667 for (isigma = 0; isigma < nsigmas; isigma++) {
2672 cpl_apertures_delete(appos);
2673 appos = cpl_apertures_extract_sigma(self, psigmas[isigma]);
2675 if (appos != NULL) {
2676 npos = cpl_apertures_get_size(appos);
2681 cpl_apertures_delete(apneg);
2682 apneg = cpl_apertures_extract_sigma(inverse, psigmas[isigma]);
2683 if (apneg != NULL) {
2684 nneg = cpl_apertures_get_size(apneg);
2687 cpl_msg_info(cpl_func,
"Found %d positive (need 2) and %d negative "
2688 "(need 2) object(s) at sigma=%g (%d of %d)", npos, nneg,
2689 psigmas[isigma], 1+isigma, nsigmas);
2692 error_if(npos * nneg > FIND_BEAM_MAX_APERTURES_SQR,
2693 CPL_ERROR_DATA_NOT_FOUND,
"Too many objects found, aborting");
2697 double eccbest = eccmax;
2698 double eccmin = DBL_MAX;
2699 double fluxbest = 0.0;
2700 double fluxecc = DBL_MAX;
2701 cpl_boolean is_first = CPL_TRUE;
2704#pragma omp parallel for private(ipos1)
2706 for (ipos1 = 2; ipos1 < 1 + npos; ipos1++) {
2707 int ipos2, ineg1, ineg2;
2708 for (ipos2 = 1; ipos2 < ipos1; ipos2++) {
2709 for (ineg1 = 2; ineg1 < 1 + nneg; ineg1++) {
2710 for (ineg2 = 1; ineg2 < ineg1; ineg2++) {
2711 cpl_boolean swappos, swapneg;
2713 = visir_img_check_box(appos, ipos1, ipos2,
2714 apneg, ineg1, ineg2,
2715 pthrow, angle, &swappos,
2719 = cpl_apertures_get_flux(appos, ipos1)
2720 + cpl_apertures_get_flux(appos, ipos2)
2721 + cpl_apertures_get_flux(apneg, ineg1)
2722 + cpl_apertures_get_flux(apneg, ineg2);
2725 if (ecc < 0.0 || flux <= 0.0 ||
2726 !cpl_errorstate_is_equal(cleanstate)) {
2727 irplib_error_recover(cleanstate,
"Invalid 4-"
2728 "object (%d & %d of %d, "
2731 ineg2, ineg1, nneg);
2736#pragma omp critical(visir_img_find_beam_four_min)
2744 if (eccmax <= ecc)
continue;
2747#pragma omp critical(visir_img_find_beam_four_ok)
2749 if (is_first || ecc * fluxbest < eccbest * flux)
2752 is_first = CPL_FALSE;
2753 cpl_msg_info(cpl_func,
"Found 4 object "
2754 "positions with throw-"
2755 "scaled eccentricity %g "
2756 "and flux %g", ecc, flux);
2758 cpl_msg_info(cpl_func,
"Found 4 object "
2759 "positions with throw-"
2760 "scaled eccentricity %g "
2761 "< %g and/or flux %g > %g",
2762 ecc, eccbest, flux, fluxbest);
2766 iappos2[0] = swappos ? ipos2 : ipos1;
2767 iappos2[1] = swappos ? ipos1 : ipos2;
2768 iapneg2[0] = swapneg ? ineg2 : ineg1;
2769 iapneg2[1] = swapneg ? ineg1 : ineg2;
2775 if (eccbest < eccmax) {
2776 bug_if(cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM "
2777 "ECCENTRICITY", eccbest));
2781 if (eccmin < DBL_MAX) {
2782 cpl_msg_info(cpl_func,
"Found 4 sigma-%g object positions with "
2783 "too large throw-scaled eccentricity %g >= %g and "
2784 "flux %g", psigmas[isigma], eccmin, eccmax,
2787 }
else if (npos >= 2 && nneg >= 2) {
2788 cpl_apertures_sort_by_flux(appos);
2789 cpl_apertures_sort_by_flux(apneg);
2793 if (isigma + 1 < nsigmas) {
2794 irplib_error_recover(cleanstate,
"4-Beam positions not found among "
2795 "%d postive and %d negative object(s) at "
2796 "sigma=%g, (%d of %d)", npos, nneg,
2797 psigmas[isigma], 1+isigma, nsigmas);
2801 error_if (isigma == nsigmas, CPL_ERROR_DATA_NOT_FOUND,
2802 "4-Beam positions not found w. %d sigma(s) down to %g",
2803 nsigmas, psigmas[nsigmas - 1]);
2805 if (cpl_msg_get_level() == CPL_MSG_DEBUG) {
2806 cpl_apertures_dump(appos, stdout);
2807 cpl_apertures_dump(apneg, stdout);
2810 x4[0] = cpl_apertures_get_centroid_x(appos, iappos2[0]);
2811 y4[0] = cpl_apertures_get_centroid_y(appos, iappos2[0]);
2812 x4[1] = cpl_apertures_get_centroid_x(appos, iappos2[1]);
2813 y4[1] = cpl_apertures_get_centroid_y(appos, iappos2[1]);
2815 x4[2] = cpl_apertures_get_centroid_x(apneg, iapneg2[0]);
2816 y4[2] = cpl_apertures_get_centroid_y(apneg, iapneg2[0]);
2817 x4[3] = cpl_apertures_get_centroid_x(apneg, iapneg2[1]);
2818 y4[3] = cpl_apertures_get_centroid_y(apneg, iapneg2[1]);
2820 bug_if(cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM FLUX",
2821 cpl_apertures_get_flux(appos,
2824 cpl_msg_info(cpl_func,
"Centroid of positive object 1 [pixel]: %g %g",
2826 cpl_msg_info(cpl_func,
"Centroid of positive object 2 [pixel]: %g %g",
2829 cpl_msg_info(cpl_func,
"Centroid of negative object 1 [pixel]: %g %g",
2831 cpl_msg_info(cpl_func,
"Centroid of negative object 2 [pixel]: %g %g",
2834 cpl_msg_info(cpl_func,
"Expected object distance (chop throw) [pixel]: %g",
2836 cpl_msg_info(cpl_func,
"Object Pos -> Pos x/y-distance [pixel]: %g %g",
2837 x4[1] - x4[0], y4[1] - y4[0]);
2838 cpl_msg_info(cpl_func,
"Object Neg -> Neg x/y-distance [pixel]: %g %g",
2839 x4[3] - x4[2], y4[3] - y4[2]);
2840 cpl_msg_info(cpl_func,
"Object Pos -> Pos angle [degrees]: %g",
2841 atan2(y4[1] - y4[0], x4[1] - x4[0]) * CPL_MATH_DEG_RAD);
2842 cpl_msg_info(cpl_func,
"Object Neg -> Neg angle [degrees]: %g",
2843 atan2(y4[3] - y4[2], x4[3] - x4[2]) * CPL_MATH_DEG_RAD);
2847 cpl_apertures_delete(appos);
2848 cpl_apertures_delete(apneg);
2850 return cpl_error_get_code();
2867cpl_image ** visir_img_collapse_beam_three(cpl_propertylist * qclist,
2868 const cpl_image * self,
2869 const cpl_image * inverse,
2872 const cpl_propertylist * plist)
2875 cpl_image ** combined = NULL;
2876 const int nx = cpl_image_get_size_x(self);
2877 const int ny = cpl_image_get_size_y(self);
2878 const cpl_type type = cpl_image_get_type(self);
2879 cpl_imagelist * list3 = cpl_imagelist_new();
2880 IRPLIB_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual);
2881 cpl_image * iwrap = type == CPL_TYPE_DOUBLE
2882 ? cpl_image_wrap_double(nx, ny, cpl_image_get_data((cpl_image*)inverse))
2883 : cpl_image_wrap_float(nx, ny, cpl_image_get_data((cpl_image*)inverse));
2884 IRPLIB_DIAG_PRAGMA_POP;
2885 cpl_bivector * offs = cpl_bivector_new(3);
2886 double * x3 = cpl_bivector_get_x_data(offs);
2887 double * y3 = cpl_bivector_get_y_data(offs);
2888 double pos_x, pos_y;
2893 skip_if(plist == NULL);
2895 skip_if(visir_img_find_beam_three(qclist, self, inverse, eccmax, pthrow,
2899 for (
int i = 1; i < 3; i++) {
2900 x3[i] = x3[0] - x3[i];
2901 y3[i] = y3[0] - y3[i];
2903 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM XPOS",
2905 bug_if (cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM YPOS",
2908 x3[0] = y3[0] = 0.0;
2910 IRPLIB_DIAG_PRAGMA_PUSH_IGN(-Wcast-qual);
2911 bug_if(cpl_imagelist_set(list3, (cpl_image*)self, 0));
2912 bug_if(cpl_imagelist_set(list3, (cpl_image*)inverse, 1));
2913 bug_if(cpl_imagelist_set(list3, iwrap, 2));
2914 IRPLIB_DIAG_PRAGMA_POP;
2916 combined = cpl_geom_img_offset_saa(list3, offs, CPL_KERNEL_DEFAULT, 0, 0,
2917 CPL_GEOM_FIRST, &pos_x, &pos_y);
2919 skip_if(combined == NULL);
2923 cpl_bivector_delete(offs);
2924 visir_imagelist_unwrap(list3);
2925 (void)cpl_image_unwrap(iwrap);
2926 if (cpl_error_get_code() && combined != NULL) {
2927 cpl_image_delete(combined[0]);
2928 cpl_image_delete(combined[1]);
2952cpl_error_code visir_img_find_beam_three(cpl_propertylist * qclist,
2953 const cpl_image * self,
2954 const cpl_image * inverse,
2962 cpl_errorstate cleanstate = cpl_errorstate_get();
2963 cpl_apertures * appos = NULL;
2964 cpl_apertures * apneg = NULL;
2965 const double psigmas[] = {2.0, 1.0, 0.5};
2966 const int nsigmas =
sizeof(psigmas)/
sizeof(
double);
2968 int iappos [] = {1};
2969 int iapneg2[] = {1, 2};
2972 skip_if(self == NULL);
2973 skip_if(qclist == NULL);
2974 skip_if(pthrow <= 0.0);
2975 skip_if(eccmax < 0.0);
2976 skip_if(x3 == NULL);
2977 skip_if(y3 == NULL);
2980 cpl_msg_info(cpl_func,
"Detecting the 3-beam object with %g pixel throw "
2981 "using %d sigma-levels ranging from %g down to %g", pthrow,
2982 nsigmas, psigmas[0], psigmas[nsigmas-1]);
2985 for (isigma = 0; isigma < nsigmas; isigma++) {
2990 cpl_apertures_delete(appos);
2991 appos = cpl_apertures_extract_sigma(self, psigmas[isigma]);
2993 if (appos != NULL) {
2994 npos = cpl_apertures_get_size(appos);
2999 cpl_apertures_delete(apneg);
3000 apneg = cpl_apertures_extract_sigma(inverse, psigmas[isigma]);
3001 if (apneg != NULL) {
3002 nneg = cpl_apertures_get_size(apneg);
3005 cpl_msg_info(cpl_func,
"Found %d positive (need 1) and %d negative "
3006 "(need 2) object(s) at sigma=%g (%d of %d)", npos, nneg,
3007 psigmas[isigma], 1+isigma, nsigmas);
3010 error_if(npos * nneg > FIND_BEAM_MAX_APERTURES_SQR,
3011 CPL_ERROR_DATA_NOT_FOUND,
"Too many objects found, aborting");
3015 double eccbest = eccmax;
3016 double eccmin = DBL_MAX;
3017 double fluxbest = 0.0;
3018 double fluxecc = DBL_MAX;
3019 cpl_boolean is_first = CPL_TRUE;
3022#pragma omp parallel for private(ipos)
3024 for (ipos = 1; ipos < 1 + npos; ipos++) {
3026 for (ineg1 = 2; ineg1 < 1 + nneg; ineg1++) {
3027 for (ineg2 = 1; ineg2 < ineg1; ineg2++) {
3028 cpl_boolean swapneg;
3031 = visir_img_check_align(appos, ipos, apneg, ineg1,
3032 ineg2, pthrow, angle,
3036 = cpl_apertures_get_flux(appos, ipos)
3037 + cpl_apertures_get_flux(apneg, ineg1)
3038 + cpl_apertures_get_flux(apneg, ineg2);
3041 if (ecc < 0.0 || flux <= 0.0 ||
3042 !cpl_errorstate_is_equal(cleanstate)) {
3043 irplib_error_recover(cleanstate,
"Invalid 3-"
3044 "object (%d of %d, "
3047 ineg2, ineg1, nneg);
3052#pragma omp critical(visir_img_collapse_beam_three_min)
3060 if (eccmax <= ecc)
continue;
3063#pragma omp critical(visir_img_collapse_beam_three_ok)
3065 if (is_first || ecc * fluxbest < eccbest * flux)
3068 is_first = CPL_FALSE;
3069 cpl_msg_info(cpl_func,
"Found 3 object posi"
3070 "tions with throw-scaled "
3071 "eccentricity %g and flux %g",
3074 cpl_msg_info(cpl_func,
"Found 3 object posi"
3075 "tions with throw-scaled "
3076 "eccentricity %g < %g and/or "
3077 "flux %g > %g", ecc, eccbest,
3083 iapneg2[0] = swapneg ? ineg2 : ineg1;
3084 iapneg2[1] = swapneg ? ineg1 : ineg2;
3089 if (eccbest < eccmax) {
3090 bug_if(cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM "
3091 "ECCENTRICITY", eccbest));
3094 if (eccmin < DBL_MAX) {
3095 cpl_msg_info(cpl_func,
"Found 3 sigma-%g object positions with "
3096 "too large throw-scaled eccentricity %g >= %g and "
3097 "flux %g", psigmas[isigma], eccmin, eccmax,
3100 }
else if (npos >= 1 && nneg >= 2) {
3101 cpl_apertures_sort_by_flux(appos);
3102 cpl_apertures_sort_by_flux(apneg);
3106 if (isigma + 1 < nsigmas) {
3107 irplib_error_recover(cleanstate,
"3-Beam positions not found among "
3108 "%d postive and %d negative object(s) at "
3109 "sigma=%g, (%d of %d)", npos, nneg,
3110 psigmas[isigma], 1+isigma, nsigmas);
3114 error_if (isigma == nsigmas, CPL_ERROR_DATA_NOT_FOUND,
3115 "3-Beam positions not found w. %d sigma(s) down to %g",
3116 nsigmas, psigmas[nsigmas - 1]);
3118 if (cpl_msg_get_level() == CPL_MSG_DEBUG) {
3119 cpl_apertures_dump(appos, stdout);
3120 cpl_apertures_dump(apneg, stdout);
3123 x3[0] = cpl_apertures_get_centroid_x(appos, iappos[0]);
3124 y3[0] = cpl_apertures_get_centroid_y(appos, iappos[0]);
3126 x3[1] = cpl_apertures_get_centroid_x(apneg, iapneg2[0]);
3127 y3[1] = cpl_apertures_get_centroid_y(apneg, iapneg2[0]);
3128 x3[2] = cpl_apertures_get_centroid_x(apneg, iapneg2[1]);
3129 y3[2] = cpl_apertures_get_centroid_y(apneg, iapneg2[1]);
3131 bug_if(cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM FLUX",
3132 cpl_apertures_get_flux(appos,
3135 cpl_msg_info(cpl_func,
"Centroid of positive object [pixel]: %g %g",
3138 cpl_msg_info(cpl_func,
"Centroid of negative object 1 [pixel]: %g %g",
3140 cpl_msg_info(cpl_func,
"Centroid of negative object 2 [pixel]: %g %g",
3143 cpl_msg_info(cpl_func,
"Expected object distance (chop throw) [pixel]: %g",
3145 cpl_msg_info(cpl_func,
"Object Neg1 -> Pos x/y-distance [pixel]: %g %g",
3146 x3[2] - x3[0], y3[2] - y3[0]);
3147 cpl_msg_info(cpl_func,
"Object Pos -> Neg2 x/y-distance [pixel]: %g %g",
3148 x3[0] - x3[1], y3[0] - y3[1]);
3152 cpl_apertures_delete(appos);
3153 cpl_apertures_delete(apneg);
3155 return cpl_error_get_code();
3175cpl_error_code visir_img_find_beam_two(cpl_propertylist * qclist,
3176 const cpl_image * self,
3177 const cpl_image * inverse,
3185 cpl_errorstate cleanstate = cpl_errorstate_get();
3186 cpl_apertures * appos = NULL;
3187 cpl_apertures * apneg = NULL;
3188 const double psigmas[] = {2.0, 1.0, 0.5};
3189 const int nsigmas =
sizeof(psigmas)/
sizeof(
double);
3195 skip_if(self == NULL);
3196 skip_if(qclist == NULL);
3197 skip_if(eccmax < 0.0);
3198 skip_if(x2 == NULL);
3199 skip_if(y2 == NULL);
3202 cpl_msg_info(cpl_func,
"Detecting the 2-beam object (Pos -> Neg) with "
3203 "%g pixel throw using %d sigma-levels ranging from %g down"
3204 " to %g", pthrow, nsigmas, psigmas[0], psigmas[nsigmas-1]);
3205 }
else if (pthrow < 0.0) {
3206 cpl_msg_info(cpl_func,
"Detecting the 2-beam object (Neg -> Pos) with "
3207 "%g pixel throw using %d sigma-levels ranging from %g down"
3208 " to %g", pthrow, nsigmas, psigmas[0], psigmas[nsigmas-1]);
3214 for (isigma = 0; isigma < nsigmas; isigma++) {
3219 cpl_apertures_delete(appos);
3220 appos = cpl_apertures_extract_sigma(self, psigmas[isigma]);
3222 if (appos != NULL) {
3223 npos = cpl_apertures_get_size(appos);
3228 cpl_apertures_delete(apneg);
3229 apneg = cpl_apertures_extract_sigma(inverse, psigmas[isigma]);
3230 if (apneg != NULL) {
3231 nneg = cpl_apertures_get_size(apneg);
3234 cpl_msg_info(cpl_func,
"Found %d positive (need 1) and %d negative "
3235 "(need 1) object(s) at sigma=%g (%d of %d)", npos, nneg,
3236 psigmas[isigma], 1+isigma, nsigmas);
3240 double eccbest = eccmax;
3241 double eccmin = DBL_MAX;
3242 double fluxbest = 0.0;
3243 double fluxecc = DBL_MAX;
3244 cpl_boolean is_first = CPL_TRUE;
3247#pragma omp parallel for private(ipos)
3249 for (ipos = 1; ipos < 1 + npos; ipos++) {
3251 for (ineg = 1; ineg < 1 + nneg; ineg++) {
3253 visir_img_check_line(appos, ipos, apneg, ineg,
3257 = cpl_apertures_get_flux(appos, ipos)
3258 + cpl_apertures_get_flux(apneg, ineg);
3261 if (ecc < 0.0 || flux <= 0.0 ||
3262 !cpl_errorstate_is_equal(cleanstate)) {
3263 irplib_error_recover(cleanstate,
"Invalid 2-"
3264 "object (%d of %d, "
3272#pragma omp critical(visir_img_collapse_beam_two_min)
3280 if (eccmax <= ecc)
continue;
3283#pragma omp critical(visir_img_collapse_beam_two_ok)
3285 if (is_first || ecc * fluxbest < eccbest * flux)
3288 is_first = CPL_FALSE;
3289 cpl_msg_info(cpl_func,
"Found 2 object posi"
3290 "tions with throw-scaled eccen"
3291 "tricity %g and flux %g", ecc,
3294 cpl_msg_info(cpl_func,
"Found 2 object posi"
3295 "tions with throw-scaled eccen"
3296 "tricity %g < %g and/or flux %g "
3297 "> %g", ecc, eccbest, flux,
3307 if (eccbest < eccmax) {
3308 bug_if(cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM "
3309 "ECCENTRICITY", eccbest));
3312 if (eccmin < DBL_MAX) {
3313 cpl_msg_info(cpl_func,
"Found 2 sigma-%g object positions with "
3314 "too large throw-scaled eccentricity %g >= %g and "
3315 "flux %g", psigmas[isigma], eccmin, eccmax,
3318 }
else if (npos >= 1 && nneg >= 2) {
3319 cpl_apertures_sort_by_flux(appos);
3320 cpl_apertures_sort_by_flux(apneg);
3324 if (isigma + 1 < nsigmas) {
3325 irplib_error_recover(cleanstate,
"2-Beam positions not found among "
3326 "%d postive and %d negative object(s) at "
3327 "sigma=%g, (%d of %d)", npos, nneg,
3328 psigmas[isigma], 1+isigma, nsigmas);
3332 error_if (isigma == nsigmas, CPL_ERROR_DATA_NOT_FOUND,
3333 "2-Beam positions not found w. %d sigma(s) down to %g",
3334 nsigmas, psigmas[nsigmas - 1]);
3336 if (cpl_msg_get_level() == CPL_MSG_DEBUG) {
3337 cpl_apertures_dump(appos, stdout);
3338 cpl_apertures_dump(apneg, stdout);
3341 x2[0] = cpl_apertures_get_centroid_x(appos, iappos[0]);
3342 y2[0] = cpl_apertures_get_centroid_y(appos, iappos[0]);
3344 x2[1] = cpl_apertures_get_centroid_x(apneg, iapneg[0]);
3345 y2[1] = cpl_apertures_get_centroid_y(apneg, iapneg[0]);
3347 bug_if(cpl_propertylist_append_double(qclist,
"ESO QC ONEBEAM FLUX",
3348 cpl_apertures_get_flux(appos,
3351 cpl_msg_info(cpl_func,
"Centroid of positive object [pixel]: %g %g",
3354 cpl_msg_info(cpl_func,
"Centroid of negative object [pixel]: %g %g",
3358 cpl_msg_info(cpl_func,
"Expected object distance (chop throw) "
3359 "[pixel]: %g", pthrow);
3361 cpl_msg_info(cpl_func,
"Object Pos -> Neg x/y-distance [pixel]: %g %g",
3362 x2[1] - x2[0], y2[1] - y2[0]);
3364 cpl_msg_info(cpl_func,
"Expected object distance (chop throw) "
3365 "[pixel]: %g", -pthrow);
3367 cpl_msg_info(cpl_func,
"Object Neg -> x/y-distance [pixel]: %g %g",
3368 x2[0] - x2[1], y2[0] - y2[1]);
3373 cpl_apertures_delete(appos);
3374 cpl_apertures_delete(apneg);
3376 return cpl_error_get_code();
3402double visir_img_check_box(
const cpl_apertures * appos,
3403 int ipos1,
int ipos2,
3404 const cpl_apertures * apneg,
3405 int ineg1,
int ineg2,
double ssize,
double angle,
3406 cpl_boolean * pswapp, cpl_boolean * pswapn)
3412 double xp1 = cpl_apertures_get_centroid_x(appos, ipos1) * cos(angle) -
3413 cpl_apertures_get_centroid_y(appos, ipos1) * sin(angle);
3414 double yp1 = cpl_apertures_get_centroid_x(appos, ipos1) * sin(angle) +
3415 cpl_apertures_get_centroid_y(appos, ipos1) * cos(angle);
3416 double xp2 = cpl_apertures_get_centroid_x(appos, ipos2) * cos(angle) -
3417 cpl_apertures_get_centroid_y(appos, ipos2) * sin(angle);
3418 double yp2 = cpl_apertures_get_centroid_x(appos, ipos2) * sin(angle) +
3419 cpl_apertures_get_centroid_y(appos, ipos2) * cos(angle);
3422 const double xpl = xp1 < xp2 ? xp1 : xp2;
3423 const double ypl = xp1 < xp2 ? yp1 : yp2;
3426 const double xpr = xp1 < xp2 ? xp2 : xp1;
3427 const double ypr = xp1 < xp2 ? yp2 : yp1;
3430 double xn1 = cpl_apertures_get_centroid_x(apneg, ineg1) * cos(angle) -
3431 cpl_apertures_get_centroid_y(apneg, ineg1) * sin(angle);
3432 double yn1 = cpl_apertures_get_centroid_x(apneg, ineg1) * sin(angle) +
3433 cpl_apertures_get_centroid_y(apneg, ineg1) * cos(angle);
3434 double xn2 = cpl_apertures_get_centroid_x(apneg, ineg2) * cos(angle) -
3435 cpl_apertures_get_centroid_y(apneg, ineg2) * sin(angle);
3436 double yn2 = cpl_apertures_get_centroid_x(apneg, ineg2) * sin(angle) +
3437 cpl_apertures_get_centroid_y(apneg, ineg2) * cos(angle);
3440 const double x_nl = xn1 < xn2 ? xn1 : xn2;
3441 const double y_nl = xn1 < xn2 ? yn1 : yn2;
3444 const double xnr = xn1 < xn2 ? xn2 : xn1;
3445 const double ynr = xn1 < xn2 ? yn2 : yn1;
3447 const double lx1 = xnr - xpl;
3448 const double lx2 = xpr - x_nl;
3449 const double ly1 = ypl - y_nl;
3450 const double ly2 = ynr - ypr;
3452 const double dx1 = lx1 - ssize;
3453 const double dx2 = lx2 - ssize;
3454 const double dy1 = ly1 - ssize;
3455 const double dy2 = ly2 - ssize;
3457 const double ey1 = ynr - ypl;
3458 const double ey2 = ypr - y_nl;
3459 const double ex1 = xpl - x_nl;
3460 const double ex2 = xpr - xnr;
3462 const double ok = sqrt(dx1 * dx1 + dx2 * dx2 + dy1 * dy1 + dy2 * dy2 +
3463 ex1 * ex1 + ex2 * ex2 + ey1 * ey1 + ey2 * ey2);
3465 double result = -1.0;
3469 skip_if(pswapp == NULL);
3470 skip_if(pswapn == NULL);
3471 skip_if(appos == apneg);
3472 skip_if(ipos1 == ipos2);
3473 skip_if(ineg1 == ineg2);
3475 skip_if(ssize <= 0.0);
3477 *pswapp = xp1 < xp2 ? CPL_FALSE : CPL_TRUE;
3478 *pswapn = xn1 < xn2 ? CPL_FALSE : CPL_TRUE;
3508double visir_img_check_align(
const cpl_apertures * appos,
int ipos,
3509 const cpl_apertures * apneg,
int ineg1,
int ineg2,
3510 double ssize,
double angle,
3511 cpl_boolean * pswapn)
3517 double xp = cpl_apertures_get_centroid_x(appos, ipos) * cos(angle) -
3518 cpl_apertures_get_centroid_y(appos, ipos) * sin(angle);
3519 double yp = cpl_apertures_get_centroid_x(appos, ipos) * sin(angle) +
3520 cpl_apertures_get_centroid_y(appos, ipos) * cos(angle);
3523 double xn1 = cpl_apertures_get_centroid_x(apneg, ineg1) * cos(angle) -
3524 cpl_apertures_get_centroid_y(apneg, ineg1) * sin(angle);
3525 double yn1 = cpl_apertures_get_centroid_x(apneg, ineg1) * sin(angle) +
3526 cpl_apertures_get_centroid_y(apneg, ineg1) * cos(angle);
3527 double xn2 = cpl_apertures_get_centroid_x(apneg, ineg2) * cos(angle) -
3528 cpl_apertures_get_centroid_y(apneg, ineg2) * sin(angle);
3529 double yn2 = cpl_apertures_get_centroid_x(apneg, ineg2) * sin(angle) +
3530 cpl_apertures_get_centroid_y(apneg, ineg2) * cos(angle);
3532 double result = -1.0;
3539 const double x_nl = yn1 < yn2 ? xn1 : xn2;
3540 const double y_nl = yn1 < yn2 ? yn1 : yn2;
3543 const double xnr = yn1 < yn2 ? xn2 : xn1;
3544 const double ynr = yn1 < yn2 ? yn2 : yn1;
3546 const double d1 = ynr - yp - ssize;
3547 const double d2 = yp - y_nl - ssize;
3549 const double e1 = xnr - xp;
3550 const double e2 = xp - x_nl;
3552 swapn = yn1 < yn2 ? CPL_FALSE : CPL_TRUE;
3554 ok = sqrt(d1 * d1 + d2 * d2 + e1 * e1 + e2 * e2);
3558 skip_if(pswapn == NULL);
3559 skip_if(appos == apneg);
3560 skip_if(ineg1 == ineg2);
3562 skip_if(ssize <= 0.0);
3592double visir_img_check_line(
const cpl_apertures * apnear,
int inear,
3593 const cpl_apertures * apfar,
int ifar,
3594 double ssize,
double angle)
3600 double x_n = cpl_apertures_get_centroid_x(apnear, inear) * cos(angle) -
3601 cpl_apertures_get_centroid_y(apnear, inear) * sin(angle);
3602 double y_n = cpl_apertures_get_centroid_x(apnear, inear) * sin(angle) +
3603 cpl_apertures_get_centroid_y(apnear, inear) * cos(angle);
3606 double xf = cpl_apertures_get_centroid_x(apfar, ifar) * cos(angle) -
3607 cpl_apertures_get_centroid_y(apfar, ifar) * sin(angle);
3608 double yf = cpl_apertures_get_centroid_x(apfar, ifar) * sin(angle) +
3609 cpl_apertures_get_centroid_y(apfar, ifar) * cos(angle);
3611 double result = -1.0;
3615 const double d = yf - y_n - ssize;
3617 const double e = xf - x_n;
3619 ok = sqrt(d * d + e * e);
3623 skip_if(apnear == apfar);
3625 skip_if(ssize <= 0.0);
3647static cpl_error_code
3648get_aqu_data_type(
const cpl_frame * frame,
const cpl_propertylist * plist,
3649 const cpl_size next, visir_data_type * ptype)
3652 const char * format = NULL;
3653 if (cpl_propertylist_has(plist, VISIR_PFITS_INT_NAXIS3))
3656 if (cpl_propertylist_has(plist,
"ESO DET FRAM FORMAT"))
3657 format = cpl_propertylist_get_string(plist,
"ESO DET FRAM FORMAT");
3660 if (next >= 2 || (format && !strcmp(format,
"extension"))) {
3663 *ptype = VISIR_DATA_AQU_INT;
3666 *ptype = VISIR_DATA_AQU_HCYCLE;
3669 else if (next == 1 && (naxis3 == -1 || naxis3 == 0)) {
3670 *ptype = VISIR_DATA_AQU_BURST_EXT;
3672 else if (next == 0 && naxis3 > 0) {
3673 *ptype = VISIR_DATA_AQU_BURST;
3676 cpl_error_set_message(cpl_func, CPL_ERROR_BAD_FILE_FORMAT,
3677 "Could not determine format of aquarius file %s",
3678 cpl_frame_get_filename(frame));
3681 return cpl_error_get_code();
3697static cpl_error_code
3698get_drs_data_type(
const cpl_frame * frame,
const cpl_propertylist * plist,
3699 visir_data_type * ptype)
3701 cpl_errorstate cleanstate = cpl_errorstate_get();
3706 const char * file = cpl_frame_get_filename(frame);
3707 cpl_boolean known_frametype = CPL_TRUE;
3711 cpl_ensure_code(ptype != NULL, CPL_ERROR_NULL_INPUT);
3715 visir_error_reset(
"Could not get FITS key");
3717 known_frametype = CPL_FALSE;
3718 }
else if (strcmp(sval,
"CUBE1")==0) {
3719 *ptype = VISIR_DATA_CUBE1;
3720 }
else if (strcmp(sval,
"CUBE2")==0) {
3721 *ptype = VISIR_DATA_CUBE2;
3724 known_frametype = CPL_FALSE;
3727 if (known_frametype && *ptype == VISIR_DATA_CUBE2) {
3728 if (naxis3 == 2 * nchop + 1) {
3730 }
else if (naxis3 == nchop + 2) {
3731 cpl_msg_warning(cpl_func,
"%s has FRAM TYPE = '%s', but NAXIS3=%d "
3732 "and CHOP NCYCLES=%d imply a CUBE1. Assuming "
3733 "the frame type is really CUBE1", file, sval,
3735 *ptype = VISIR_DATA_CUBE1;
3737 cpl_msg_warning(cpl_func,
"%s has FRAM TYPE = '%s', but NAXIS3=%d "
3738 "and CHOP NCYCLES=%d is not a valid VISIR INTERM+"
3739 "Half-Cycle format", file, sval, naxis3, nchop);
3742 }
else if (known_frametype && *ptype == VISIR_DATA_CUBE1) {
3743 if (naxis3 == nchop + 2) {
3746 cpl_msg_debug(cpl_func,
"%s has %d INTERM-frames and one Half-"
3747 "Cycle frame (old CUBE1-format)", file, nchop);
3749 }
else if (naxis3 == 2 * nchop + 1) {
3750 cpl_msg_warning(cpl_func,
"%s has FRAM TYPE = '%s', but NAXIS3=%d "
3751 "and CHOP NCYCLES=%d imply a CUBE2. Assuming "
3752 "the frame type is really CUBE2", file, sval,
3754 *ptype = VISIR_DATA_CUBE2;
3756 cpl_msg_warning(cpl_func,
"%s has FRAM TYPE = '%s', but NAXIS3=%d "
3757 "and CHOP NCYCLES=%d is not a valid VISIR INTERM+"
3758 "Half-Cycle format", file, sval, naxis3, nchop);
3761 }
else if (naxis3 == 2 * nchop + 1) {
3762 cpl_msg_warning(cpl_func,
"%s has FRAM TYPE='%s', but NAXIS3=%d and "
3763 "CHOP NCYCLES=%d imply a CUBE2. Assuming the frame "
3764 "type is CUBE2", file, sval ? sval :
"<NULL>", naxis3,
3766 *ptype = VISIR_DATA_CUBE2;
3767 }
else if (naxis3 == nchop + 2) {
3768 cpl_msg_warning(cpl_func,
"%s has FRAM TYPE='%s', but NAXIS3=%d and "
3769 "CHOP NCYCLES=%d imply a CUBE1. Assuming the frame "
3770 "type is CUBE1", file, sval ? sval :
"<NULL>", naxis3,
3772 *ptype = VISIR_DATA_CUBE1;
3774 else if (!known_frametype && nchop * ndit * 2 >= naxis3) {
3775 cpl_msg_info(cpl_func,
"%s has FRAM TYPE='%s', NAXIS3=%d and "
3776 "CHOP NCYCLES=%d imply BURST data.",
3777 file, sval ? sval :
"<NULL>", naxis3, nchop);
3778 *ptype = VISIR_DATA_BURST;
3780 return cpl_error_set_message(cpl_func, CPL_ERROR_BAD_FILE_FORMAT,
3781 "%s has FRAM TYPE='%s', NAXIS3 = %d and "
3782 "CHOP NCYCLES = %d", file,
3783 sval ? sval :
"<NULL>", naxis3, nchop);
3788 return cpl_error_get_code();
3803cpl_error_code visir_get_data_type(
const cpl_frame * frame,
3804 const cpl_propertylist * plist,
3805 visir_data_type * ptype, cpl_size * pnext)
3807 const cpl_size next = cpl_frame_get_nextensions(frame);
3809 cpl_ensure_code(ptype != NULL, CPL_ERROR_NULL_INPUT);
3816 if (cpl_propertylist_has(plist,
"ESO DRS DTYPE"))
3817 *ptype = cpl_propertylist_get_int(plist,
"ESO DRS DTYPE");
3819 if (cpl_propertylist_has(plist, VISIR_PFITS_INT_NAVRG))
3820 skip_if(get_aqu_data_type(frame, plist, next, ptype));
3822 skip_if(get_drs_data_type(frame, plist, ptype));
3827 return cpl_error_get_code();
3840cpl_error_code visir_img_burst_find_delta_chop(
const cpl_propertylist * self,
3841 int * ichopchange,
int * ihalfcycle)
3844 const char * sdateobs =
3845 cpl_propertylist_get_string(self, VISIR_PFITS_STRING_OBS_START);
3846 const char * schopstart =
3847 cpl_propertylist_get_string(self, VISIR_PFITS_STRING_CHOP_START);
3849 const int nditskip =
3850 cpl_propertylist_get_int(self, VISIR_PFITS_INT_NDITSKIP);
3853 double ddateobs, dchopstart;
3858 bug_if(irplib_wcs_mjd_from_string(&ddateobs, sdateobs));
3859 bug_if(irplib_wcs_mjd_from_string(&dchopstart, schopstart));
3861 skip_if(chop_freq <= 0.0);
3862 skip_if(dit <= 0.0);
3866 if (!cpl_propertylist_has(self, VISIR_PFITS_INT_NAVRG)) {
3867 ddateobs += dit * nditskip / (double)VISIR_SECS_PER_DAY;
3870 period = 1.0/(chop_freq * dit);
3873 error_if((
int)(period + 0.5) % 2 != 0, CPL_ERROR_UNSUPPORTED_MODE,
3874 "Period %g not not an even number, chop frequency %g, dit %g",
3875 period, chop_freq, dit);
3877 error_if((
int)(period + 0.5) <= 1, CPL_ERROR_ILLEGAL_INPUT,
3878 "Period %d < 1", (
int)(period + 0.5));
3880 *ihalfcycle = (int)(period + 0.5)/2;
3882 cpl_msg_info(cpl_func,
"Number of A+B frames in one full chopping cycle: %g",
3885 if (dchopstart < ddateobs) {
3886 double tchop = (ddateobs - dchopstart) * (
double)VISIR_SECS_PER_DAY;
3888 double dprecycle = tchop * chop_freq;
3891 const double phase = ceil(dprecycle) - dprecycle;
3894 *ichopchange = (int)ceil(phase * period) - 1;
3896 cpl_msg_info(cpl_func,
"Chopping started %gs (%f cycles) before OBS start: "
3897 "%f < %f", tchop, dprecycle, dchopstart, ddateobs);
3899 }
else if (ddateobs < dchopstart) {
3902 double tchop = (dchopstart - ddateobs) * (
double)VISIR_SECS_PER_DAY;
3903 *ichopchange = (int)ceil(tchop / dit) - 1;
3904 cpl_msg_info(cpl_func,
"Chopping started %gs (wasted %g cycles) after OBS "
3905 "start: %f > %f", tchop, tchop * chop_freq, dchopstart,
3912 cpl_msg_info(cpl_func,
"Chopping started with OBS start: %f == %f",
3913 dchopstart, ddateobs);
3917 *ichopchange = *ichopchange % (*ihalfcycle * 2);
3919 cpl_msg_info(cpl_func,
"Frame of chop change: %d", *ichopchange);
3923 return cpl_error_get_code();
3926#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.