392 cpl_parameterlist * parlist)
394 cpl_frameset * recipe_frameset=NULL, * wavecalib_frameset=NULL, * dark_frameset=NULL,
395 * darkcalib_frameset=NULL, * sky_frameset=NULL, * flatcalib_frameset=NULL, * p2vmcalib_frameset=NULL,
396 * badcalib_frameset=NULL, *used_frameset=NULL, * current_frameset=NULL, * dispcalib_frameset=NULL,
397 * metpos_frameset=NULL, * diamcat_frameset = NULL, *eop_frameset = NULL, *patch_frameset = NULL,
398 * static_param_frameset=NULL, * pcacalib_frameset = NULL;
400 cpl_frame * frame=NULL;
402 const char * frame_tag=NULL;
403 char * proCatg = NULL;
404 char * mode=NULL, * redCatg = NULL, * skyCatg = NULL;
406 gravi_data * p2vm_map=NULL, * data=NULL, * wave_map=NULL, * dark_map=NULL,
407 * profile_map=NULL, * badpix_map=NULL, * preproc_data=NULL, * p2vmred_data=NULL, * tmpvis_data=NULL,
408 * vis_data=NULL, * disp_map=NULL, * diodepos_data=NULL, * diamcat_data=NULL, *eop_map=NULL,
409 * static_param_data=NULL, * pca_calib_data=NULL;
411 cpl_propertylist ** p2vm_qcs = NULL;
413 int nb_frame, nb_sky;
414 char * input_data_type = NULL;
421 cpl_error_get_code()) ;
443 if ( cpl_frameset_is_empty (recipe_frameset) ) {
444 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
445 "Input SOF must contain at least a calibrator or science file");
446 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
447 "See online help: esorex --man gravity_vis");
451 if ( cpl_frameset_get_size (p2vmcalib_frameset) !=1 ||
452 cpl_frameset_get_size (wavecalib_frameset) !=1 ||
453 cpl_frameset_get_size (flatcalib_frameset) !=1 ||
454 cpl_frameset_get_size (badcalib_frameset) != 1 ||
455 (cpl_frameset_is_empty (dark_frameset) &&
456 cpl_frameset_is_empty (darkcalib_frameset) &&
457 cpl_frameset_is_empty (sky_frameset)) ) {
458 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
459 "Illegal number of P2VM, FLAT, WAVE, BAD, DARK or SKY, OBJECT file on the frameset");
460 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
461 "See online help: esorex --man gravity_vis");
467 cpl_parameter *phase_ref = cpl_parameterlist_find (parlist,
"gravity.vis.phase-ref-sc");
468 cpl_parameter *output_phase = cpl_parameterlist_find (parlist,
"gravity.vis.output-phase-sc");
470 if (strcmp (cpl_parameter_get_string(phase_ref),
"SELF_REF") != 0) {
471 cpl_msg_warning (cpl_func,
"VISPHI flattening requires phase-ref-sc=SELF_REF, forcing");
472 cpl_parameter_set_string (phase_ref,
"SELF_REF");
475 if (strcmp (cpl_parameter_get_string(output_phase),
"SELF_VISPHI") != 0) {
476 cpl_msg_warning (cpl_func,
"VISPHI flattening requires output-phase-sc=SELF_VISPHI, forcing");
477 cpl_parameter_set_string (output_phase,
"SELF_VISPHI");
482 used_frameset = cpl_frameset_new();
488 if (!cpl_frameset_is_empty (dark_frameset)) {
490 frame = cpl_frameset_get_position (dark_frameset, 0);
503 NULL, frame,
"gravity_vis",
508 else if (!cpl_frameset_is_empty (darkcalib_frameset)) {
510 frame = cpl_frameset_get_position (darkcalib_frameset, 0);
516 cpl_msg_info (cpl_func,
"There is no DARK in the frame set");
519 frame = cpl_frameset_get_position (badcalib_frameset, 0);
523 frame = cpl_frameset_get_position (flatcalib_frameset, 0);
527 frame = cpl_frameset_get_position (wavecalib_frameset, 0);
531 frame = cpl_frameset_get_position (p2vmcalib_frameset, 0);
534 cpl_parameterlist_append(parlist, param_extrapixel);
537 if (!cpl_frameset_is_empty (dispcalib_frameset)) {
538 frame = cpl_frameset_get_position (dispcalib_frameset, 0);
542 cpl_msg_info (cpl_func,
"There is no DISP_MODEL in the frameset");
545 if (!cpl_frameset_is_empty (metpos_frameset)) {
546 frame = cpl_frameset_get_position (metpos_frameset, 0);
550 cpl_msg_info (cpl_func,
"There is no DIODE_POSITION in the frameset");
553 if ( !cpl_frameset_is_empty (eop_frameset) ) {
554 frame = cpl_frameset_get_position (eop_frameset, 0);
558 cpl_msg_info (cpl_func,
"There is no EOP_PARAM in the frameset");
562 if (!cpl_frameset_is_empty (static_param_frameset)) {
563 frame = cpl_frameset_get_position (static_param_frameset, 0);
567 cpl_msg_info (cpl_func,
"There is no STATIC_PARAM in the frameset");
570 if ( !cpl_frameset_is_empty (diamcat_frameset) ) {
571 frame = cpl_frameset_get_position (diamcat_frameset, 0);
575 cpl_msg_info (cpl_func,
"There is no DIAMETER_CAT in the frameset");
577 if ( !cpl_frameset_is_empty (pcacalib_frameset)) {
578 frame = cpl_frameset_get_position (pcacalib_frameset, 0);
581 cpl_msg_info (cpl_func,
"There is no PHASE_PCA in the frameset");
589 frame_tag = cpl_frame_get_tag (cpl_frameset_get_position (recipe_frameset, 0));
595 mode = cpl_sprintf (
"gravi_dual");
596 input_data_type = cpl_sprintf (
"raw_calibrator");
602 mode = cpl_sprintf (
"gravi_dual");
603 input_data_type = cpl_sprintf (
"raw_science");
609 mode = cpl_sprintf (
"gravi_single");
610 input_data_type = cpl_sprintf (
"raw_calibrator");
616 mode = cpl_sprintf (
"gravi_single");
617 input_data_type = cpl_sprintf (
"raw_science");
620 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
621 "Cannot recognize the input DO.CATG");
625 cpl_msg_info (cpl_func,
"Mode of the first frame is: %s (will be used for all frames)", mode);
635 nb_sky = cpl_frameset_get_size (sky_frameset);
636 sky_maps = cpl_calloc (CPL_MAX(nb_sky,1),
sizeof(
gravi_data*));
638 for (
int isky = 0; isky < nb_sky; isky++){
641 cpl_msg_info (cpl_func,
" ***** SKY %d over %d ***** ", isky+1, nb_sky);
642 frame = cpl_frameset_get_position (sky_frameset, isky);
654 if (averageSky == 0) {
655 char filename_suffix[20];
656 snprintf(filename_suffix, 16,
"%d", isky);
658 parlist, NULL, frame,
"gravity_vis",
668 if (averageSky == 1) {
669 cpl_msg_info (cpl_func,
"Do a MASTER SKY from the %d skys", nb_sky);
676 parlist, sky_frameset,
677 cpl_frameset_get_position (sky_frameset, 0),
678 "gravity_vis", NULL, skyCatg);
682 cpl_frameset_join (used_frameset, sky_frameset);
683 for (
int isky = 0; isky < nb_sky; isky++)
685 sky_maps[0] = msky_map;
693 nb_frame = cpl_frameset_get_size (recipe_frameset);
694 p2vm_qcs = cpl_malloc(
sizeof(cpl_propertylist*) * nb_frame);
696 for (
int ivis = 0; ivis < nb_frame; ivis++){
697 p2vm_qcs[ivis] = cpl_propertylist_new();
699 char filename_suffix[20];
700 snprintf(filename_suffix, 16,
"%d", ivis);
701 current_frameset = cpl_frameset_duplicate (used_frameset);
703 cpl_msg_info (cpl_func,
" ***** OBJECT %d over %d ***** ", ivis+1, nb_frame);
708 isky = nb_sky>0 ? ivis % nb_sky : 0;
712 cpl_msg_info (cpl_func,
"There is no SKY in the frameset");
714 else if (averageSky) {
716 cpl_msg_info (cpl_func,
"Use MASTER SKY (already reduced)");
720 cpl_msg_info (cpl_func,
"Use SKY %i over %i (already reduced)", isky+1, nb_sky);
721 frame = cpl_frameset_get_position (sky_frameset, isky);
724 cpl_frameset_insert (current_frameset, cpl_frame_duplicate (frame));
731 frame = cpl_frameset_get_position (recipe_frameset, ivis);
733 cpl_frameset_insert(used_frameset, cpl_frame_duplicate (frame));
744 current_frameset, frame,
"gravity_vis",
745 NULL,
"BIAS_SUBTRACTED");
752 cpl_msg_warning (cpl_func,
"Shutter problem in the OBJECT");
757 badpix_map, sky_maps[isky],
764 parlist, current_frameset, frame,
776 parlist, current_frameset, frame,
793 parlist, current_frameset, frame,
800 cpl_boolean subtract_met_dark = dark_map != NULL && cpl_parameter_get_bool(
801 cpl_parameterlist_find_const(parlist,
"gravity.metrology.use-dark-offsets"));
803 if (subtract_met_dark)
829 int saveAcqTable = 1;
830 gravi_reduce_acqcam (p2vmred_data, preproc_data, sky_maps[isky], dark_map, static_param_data, saveAcqTable);
834 int saveAcqTable = 0;
835 gravi_reduce_acqcam (p2vmred_data, preproc_data, sky_maps[isky], dark_map, static_param_data, saveAcqTable);
884 CPLCHECK_MSG (
"Cannot compute rejection flags signals");
890 parlist, current_frameset, frame,
891 "gravity_vis", NULL, redCatg);
901 cpl_size current_frame = 0;
902 while (current_frame >= 0)
911 cpl_msg_info (cpl_func,
"Force same time for all quantities/baselines");
917 if (current_frame < 0 && ( !strcmp (
gravi_param_get_string (parlist,
"gravity.test.reduce-acq-cam"),
"TRUE") ||
925 if (vis_data == NULL) {
926 vis_data = tmpvis_data; tmpvis_data = NULL;
940 parlist, current_frameset, frame,
947 FREE (cpl_frameset_delete, current_frameset);
961 cpl_msg_info (cpl_func,
"Computing QC parameters for visibilities");
966 if(! strcmp(input_data_type,
"raw_calibrator") )
972 cpl_msg_info (cpl_func,
"Flatten the FLUX with the internal P2VM spectrum");
977 cpl_msg_info (cpl_func,
"Don't flatten the FLUX with the internal P2VM spectrum");
984 cpl_msg_info (cpl_func,
"Align the SC visibilities on the FT");
988 cpl_msg_info (cpl_func,
"Don't align the SC visibilities on the FT");
993 cpl_msg_info (cpl_func,
"Compute the wavelength shift due to target color");
997 cpl_msg_info (cpl_func,
"Don't compute the wavelength shift due to target color");
1005 cpl_msg_info (cpl_func,
"Don't average the different observation (if any)");
1013 const cpl_frame *it_frame;
1015 cpl_frameset_iterator *it = cpl_frameset_iterator_new(science_frames);
1016 double mjd_obs_first = DBL_MAX;
1017 while ((it_frame = cpl_frameset_iterator_get(it)) != NULL) {
1018 cpl_propertylist * this_frame_header = cpl_propertylist_load(cpl_frame_get_filename(it_frame), 0);
1020 if (mjd_obs < mjd_obs_first)
1022 mjd_obs_first = mjd_obs;
1023 frame = cpl_frameset_iterator_get(it);
1025 cpl_frameset_iterator_advance(it, 1);
1026 cpl_propertylist_delete(this_frame_header);
1028 cpl_frameset_iterator_delete(it);
1030 cpl_frameset_join (used_frameset, recipe_frameset);
1036 used_frameset, frame,
"gravity_vis", NULL, proCatg);
1037 cpl_frameset_delete(science_frames);
1065 FREE (cpl_frameset_delete,darkcalib_frameset);
1066 FREE (cpl_frameset_delete,wavecalib_frameset);
1067 FREE (cpl_frameset_delete,flatcalib_frameset);
1068 FREE (cpl_frameset_delete,badcalib_frameset);
1069 FREE (cpl_frameset_delete,p2vmcalib_frameset);
1070 FREE (cpl_frameset_delete,metpos_frameset);
1071 FREE (cpl_frameset_delete,dark_frameset);
1072 FREE (cpl_frameset_delete,diamcat_frameset);
1073 FREE (cpl_frameset_delete,sky_frameset);
1074 FREE (cpl_frameset_delete,dispcalib_frameset);
1075 FREE (cpl_frameset_delete,pcacalib_frameset);
1076 FREE (cpl_frameset_delete,eop_frameset);
1077 FREE (cpl_frameset_delete,patch_frameset);
1078 FREE (cpl_frameset_delete,static_param_frameset);
1079 FREE (cpl_frameset_delete,recipe_frameset);
1080 FREE (cpl_frameset_delete,current_frameset);
1081 FREE (cpl_frameset_delete,used_frameset);
1082 FREE (cpl_free,proCatg);
1083 FREE (cpl_free,redCatg);
1084 FREE (cpl_free,skyCatg);
1085 FREE (cpl_free,mode);
1086 FREE (cpl_free,input_data_type);
1088 FREELOOP(cpl_propertylist_delete, p2vm_qcs, nb_frame);
1092 return (
int)cpl_error_get_code();