44 #if defined(__linux__) && defined(__GLIBC__) 48 #include "gravi_data.h" 49 #include "gravi_pfits.h" 50 #include "gravi_dfs.h" 52 #include "gravi_utils.h" 54 #include "gravi_calib.h" 55 #include "gravi_wave.h" 56 #include "gravi_p2vmred.h" 57 #include "gravi_acqcam.h" 58 #include "gravi_eop.h" 59 #include "gravi_metrology.h" 61 #include "gravi_signal.h" 62 #include "gravi_vis.h" 65 #include "gravi_preproc.h" 71 static int gravity_vis_create(cpl_plugin *);
72 static int gravity_vis_exec(cpl_plugin *);
73 static int gravity_vis_destroy(cpl_plugin *);
74 static int gravity_vis(cpl_frameset *,
const cpl_parameterlist *);
79 static char gravity_vis_short[] =
"Compute the visibilities from raw observation of OBJECT.";
80 static char gravity_vis_description[] =
81 "This recipe is associated to the observations template. Its reduces the raw data acquired on calibrator or science targets and computes the uncalibrated visibilities, saved in an OIFITS file. If several OBJECT are provided, the recipe will reduce all of them and merge the resulting data into a single OIFITS. If several SKY_RAW are provided, the recipe reduces the first OBJECT with the first SKY file. Then each new OBJECT with the next SKY. When the number of SKYs is reached, the recipe loops back to first SKY file (so if the number of SKYs is larger than the number of OBJECTs, the last SKY won't be used). The recipe will reduce the data even if no SKY or no DARK is provided. However this will lead to wrong estimate of the visibility and squared visibility of the object. If the file DIAMETER_CAT is not provided, the recipe will use the diameter provided in the header to compute the transfer function QC parameters." 83 "The tag in the DO category can be SINGLE/DUAL and CAL/SCI. They should reflect the instrument mode (SINGLE or DUAL) and the DPR.CATG of the observation (SCIENCE or CALIB). The tag in the PRO.CATG category will be SINGLE/DUAL and CAL/SCI depending on the input tag.\n" 85 "* Load the input file (loop on input OBJECT files)\n" 86 "* Extract the spectra (use BAD, DARK, SKY, FLAT files)\n" 87 "* Interpolate the spectra into a common wavelength table (use WAVE file)\n" 88 "* Compute the real-time visibilities (use P2VM file)\n" 89 "* Compute additional real-time signals (SNR, GDELAY...)\n" 90 "* Compute selection flags (= flag frames with SNR lower than threshold, vFactor lower than threshold...)\n" 91 "* Average the real-time visibilities, considering the selection flag\n" 92 "* Write the product\n" 93 GRAVI_RECIPE_INPUT
"\n" 94 GRAVI_FLAT_MAP
" : flat calibration (PRO.CATG="GRAVI_FLAT_MAP
")\n" 95 GRAVI_BAD_MAP
" : badpixel calibration (PRO.CATG="GRAVI_BAD_MAP
") \n" 96 GRAVI_WAVE_MAP
" : wave calibration (PRO.CATG="GRAVI_WAVE_MAP
")\n" 97 GRAVI_P2VM_MAP
" : p2vm calibration (PRO.CATG="GRAVI_P2VM_MAP
")\n" 98 GRAVI_DARK_MAP
" : dark calibration (PRO.CATG="GRAVI_DARK_MAP
")\n" 99 GRAVI_SINGLE_SCIENCE_RAW
" : raw object (DPR.TYPE=OBJECT,SINGLE)\n" 100 GRAVI_SINGLE_SKY_RAW
" : raw sky (DPR.TYPE=SKY,SINGLE)\n" 101 GRAVI_DISP_MODEL
" (opt) : fiber dispersion model (PRO.CATG="GRAVI_DISP_MODEL
")\n" 102 GRAVI_DIODE_POSITION
" (opt) : met receiver position (PRO.CATG="GRAVI_DIODE_POSITION
")\n" 103 GRAVI_DIAMETER_CAT
" (opt) : catalog of diameter (PRO.CATG="GRAVI_DIAMETER_CAT
")\n" 104 GRAVI_RECIPE_OUTPUT
"\n" 105 GRAVI_VIS_SINGLE_SCIENCE
" : OIFITS file with uncalibrated visibilities\n" 106 GRAVI_SINGLE_SKY_MAP
" (opt) : sky map\n" 107 GRAVI_P2VMRED_SINGLE_SCIENCE
" (opt) : intermediate product (see detailled description of data)\n" 108 GRAVI_SPECTRUM
" (opt) : intermediate product (see detailled description of data)\n" 109 GRAVI_PREPROC
" (opt) : intermediate product (see detailled description of data)\n" 127 int cpl_plugin_get_info(cpl_pluginlist * list)
129 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe );
130 cpl_plugin * plugin = &recipe->interface;
132 if (cpl_plugin_init(plugin,
134 GRAVI_BINARY_VERSION,
135 CPL_PLUGIN_TYPE_RECIPE,
138 gravity_vis_description,
139 "Nabih Azouaoui, Vincent Lapeyrere, JB. Le Bouquin",
144 gravity_vis_destroy)) {
145 cpl_msg_error(cpl_func,
"Plugin initialization failed");
146 (void)cpl_error_set_where(cpl_func);
150 if (cpl_pluginlist_append(list, plugin)) {
151 cpl_msg_error(cpl_func,
"Error adding plugin to list");
152 (void)cpl_error_set_where(cpl_func);
168 static int gravity_vis_create(cpl_plugin * plugin)
174 if (cpl_error_get_code() != CPL_ERROR_NONE) {
175 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
176 cpl_func, __LINE__, cpl_error_get_where());
177 return (
int)cpl_error_get_code();
180 if (plugin == NULL) {
181 cpl_msg_error(cpl_func,
"Null plugin");
182 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
186 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
187 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
188 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
192 recipe = (cpl_recipe *)plugin;
195 recipe->parameters = cpl_parameterlist_new();
196 if (recipe->parameters == NULL) {
197 cpl_msg_error(cpl_func,
"Parameter list allocation failed");
198 cpl_ensure_code(0, (
int)CPL_ERROR_ILLEGAL_OUTPUT);
205 gravi_parameter_add_static_name (recipe->parameters);
208 gravi_parameter_add_biassub_file (recipe->parameters);
209 gravi_parameter_add_spectrum_file (recipe->parameters);
210 gravi_parameter_add_preproc_file (recipe->parameters);
211 gravi_parameter_add_p2vmred_file (recipe->parameters);
212 gravi_parameter_add_astro_file (recipe->parameters);
215 gravi_parameter_add_average_vis (recipe->parameters);
218 gravi_parameter_add_biasmethod (recipe->parameters);
221 gravi_parameter_add_extract (recipe->parameters);
222 gravi_parameter_add_metrology (recipe->parameters);
226 gravi_parameter_add_compute_snr (recipe->parameters, isCalib);
227 gravi_parameter_add_compute_signal (recipe->parameters, isCalib);
229 gravi_parameter_add_compute_vis (recipe->parameters, isCalib);
232 p = cpl_parameter_new_value (
"gravity.vis.flat-flux", CPL_TYPE_BOOL,
233 "Normalize the flux (stored in OI_FLUX binary extension) with " 234 "instrument transmission recorded in the \n" 235 "input P2VM calibration map. Consequently, the flux quantity is either " 236 "the intensity level recorded \n" 237 "in the detector, thus including the instrument transmission (FALSE); " 238 "or the intensity level at the instrument entrance (TRUE).",
239 "gravity.vis", FALSE);
240 cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI,
"flat-flux");
241 cpl_parameter_disable (p, CPL_PARAMETER_MODE_ENV);
242 cpl_parameterlist_append (recipe->parameters, p);
245 p = cpl_parameter_new_value (
"gravity.preproc.average-sky", CPL_TYPE_BOOL,
246 "Average the SKYs into a master SKY. If FALSE, the recipe loops\n " 247 "over the SKY to reduce each OBJECT with a different SKY",
248 "gravity.preproc", FALSE);
249 cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI,
"average-sky");
250 cpl_parameter_disable (p, CPL_PARAMETER_MODE_ENV);
251 cpl_parameterlist_append (recipe->parameters, p);
254 p = cpl_parameter_new_value (
"gravity.test.reduce-acq-cam", CPL_TYPE_BOOL,
255 "If TRUE, reduced ACQ_CAM images",
256 "gravity.test", FALSE);
257 cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI,
"reduce-acq-cam");
258 cpl_parameter_disable (p, CPL_PARAMETER_MODE_ENV);
259 cpl_parameterlist_append (recipe->parameters, p);
262 p = cpl_parameter_new_value (
"gravity.vis.color-wave-correction", CPL_TYPE_BOOL,
263 "If TRUE, creates a new OI_WAVELENGTH_EFF with corrected wavelength",
264 "gravity.vis", FALSE);
265 cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI,
"color-wave-correction");
266 cpl_parameter_disable (p, CPL_PARAMETER_MODE_ENV);
267 cpl_parameterlist_append (recipe->parameters, p);
279 static int gravity_vis_exec(cpl_plugin * plugin)
284 cpl_errorstate initial_errorstate = cpl_errorstate_get();
288 if (cpl_error_get_code() != CPL_ERROR_NONE) {
289 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
290 cpl_func, __LINE__, cpl_error_get_where());
291 return (
int)cpl_error_get_code();
294 if (plugin == NULL) {
295 cpl_msg_error(cpl_func,
"Null plugin");
296 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
300 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
301 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
302 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
306 recipe = (cpl_recipe *)plugin;
309 if (recipe->parameters == NULL) {
310 cpl_msg_error(cpl_func,
"Recipe invoked with NULL parameter list");
311 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
313 if (recipe->frames == NULL) {
314 cpl_msg_error(cpl_func,
"Recipe invoked with NULL frame set");
315 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
319 recipe_status = gravity_vis(recipe->frames, recipe->parameters);
322 if (cpl_dfs_update_product_header(recipe->frames)) {
324 recipe_status = (int)cpl_error_get_code();
328 if (!cpl_errorstate_is_equal(initial_errorstate)) {
331 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
334 return recipe_status;
344 static int gravity_vis_destroy(cpl_plugin * plugin)
348 if (plugin == NULL) {
349 cpl_msg_error(cpl_func,
"Null plugin");
350 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
354 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
355 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
356 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
360 recipe = (cpl_recipe *)plugin;
362 cpl_parameterlist_delete(recipe->parameters);
377 static int gravity_vis(cpl_frameset * frameset,
378 const cpl_parameterlist * parlist)
380 cpl_frameset * recipe_frameset=NULL, * wavecalib_frameset=NULL, * dark_frameset=NULL,
381 * darkcalib_frameset=NULL, * sky_frameset=NULL, * flatcalib_frameset=NULL, * p2vmcalib_frameset=NULL,
382 * badcalib_frameset=NULL, *used_frameset=NULL, * current_frameset=NULL, * dispcalib_frameset=NULL,
383 * metpos_frameset=NULL, * diamcat_frameset = NULL, *eop_frameset = NULL, *patch_frameset = NULL,
384 * static_param_frameset=NULL;
386 cpl_frame * frame=NULL;
388 const char * frame_tag=NULL;
389 char * proCatg = NULL, * mode=NULL, * redCatg = NULL, * skyCatg = NULL;
391 gravi_data * p2vm_map=NULL, * data=NULL, * wave_map=NULL, * dark_map=NULL,
392 * profile_map=NULL, * badpix_map=NULL, * preproc_data=NULL, * p2vmred_data=NULL, * tmpvis_data=NULL,
393 * vis_data=NULL, * disp_map=NULL, * diodepos_data=NULL, * diamcat_data=NULL, *eop_map=NULL, *static_param_data=NULL;
394 gravi_data ** sky_maps = NULL;
396 int nb_frame, nb_sky;
399 gravity_print_banner ();
400 cpl_msg_set_time_on();
401 cpl_msg_set_component_on();
402 gravi_msg_function_start(1);
405 cpl_error_get_code()) ;
408 p2vmcalib_frameset = gravi_frameset_extract_p2vm_map (frameset);
409 darkcalib_frameset = gravi_frameset_extract_dark_map (frameset);
410 wavecalib_frameset = gravi_frameset_extract_wave_map (frameset);
412 flatcalib_frameset = gravi_frameset_extract_flat_map (frameset);
413 badcalib_frameset = gravi_frameset_extract_bad_map (frameset);
414 dispcalib_frameset = gravi_frameset_extract_disp_map (frameset);
415 metpos_frameset = gravi_frameset_extract_met_pos (frameset);
416 diamcat_frameset = gravi_frameset_extract_diamcat_map (frameset);
417 eop_frameset = gravi_frameset_extract_eop_map (frameset);
418 patch_frameset = gravi_frameset_extract_patch (frameset);
419 static_param_frameset = gravi_frameset_extract_static_param (frameset);
421 recipe_frameset = gravi_frameset_extract_fringe_data (frameset);
422 sky_frameset = gravi_frameset_extract_sky_data (frameset);
426 if ( cpl_frameset_get_size (p2vmcalib_frameset) !=1 ||
427 cpl_frameset_get_size (wavecalib_frameset) !=1 ||
428 cpl_frameset_get_size (flatcalib_frameset) !=1 ||
429 cpl_frameset_get_size (badcalib_frameset) != 1 ||
430 cpl_frameset_get_size (recipe_frameset) < 1 ||
431 (cpl_frameset_is_empty (dark_frameset) &&
432 cpl_frameset_is_empty (darkcalib_frameset) &&
433 cpl_frameset_is_empty (sky_frameset)) ) {
434 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
435 "Illegal number of P2VM, FLAT, WAVE, BAD, DARK or SKY, OBJECT file on the frameset");
436 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
437 "See online help: esorex --man gravity_vis");
442 used_frameset = cpl_frameset_new();
448 if (!cpl_frameset_is_empty (dark_frameset)) {
450 frame = cpl_frameset_get_position (dark_frameset, 0);
459 CPLCHECK_CLEAN (
"Could not compute the DARK map");
463 NULL, frame,
"gravity_vis",
464 NULL, GRAVI_DARK_MAP);
466 CPLCHECK_CLEAN (
"Could not save the DARK map");
468 else if (!cpl_frameset_is_empty (darkcalib_frameset)) {
470 frame = cpl_frameset_get_position (darkcalib_frameset, 0);
473 CPLCHECK_CLEAN (
"Could not load the DARK map");
476 cpl_msg_info (cpl_func,
"There is no DARK in the frame set");
479 frame = cpl_frameset_get_position (badcalib_frameset, 0);
483 frame = cpl_frameset_get_position (flatcalib_frameset, 0);
487 frame = cpl_frameset_get_position (wavecalib_frameset, 0);
491 frame = cpl_frameset_get_position (p2vmcalib_frameset, 0);
495 if (!cpl_frameset_is_empty (dispcalib_frameset)) {
496 frame = cpl_frameset_get_position (dispcalib_frameset, 0);
500 cpl_msg_info (cpl_func,
"There is no DISP_MODEL in the frameset");
503 if (!cpl_frameset_is_empty (metpos_frameset)) {
504 frame = cpl_frameset_get_position (metpos_frameset, 0);
508 cpl_msg_info (cpl_func,
"There is no DIODE_POSITION in the frameset");
511 if ( !cpl_frameset_is_empty (eop_frameset) ) {
512 frame = cpl_frameset_get_position (eop_frameset, 0);
516 cpl_msg_info (cpl_func,
"There is no EOP_PARAM in the frameset");
520 if (!cpl_frameset_is_empty (static_param_frameset)) {
521 frame = cpl_frameset_get_position (static_param_frameset, 0);
525 cpl_msg_info (cpl_func,
"There is no STATIC_PARAM in the frameset");
528 if ( !cpl_frameset_is_empty (diamcat_frameset) ) {
529 frame = cpl_frameset_get_position (diamcat_frameset, 0);
533 cpl_msg_info (cpl_func,
"There is no DIAMETER_CAT in the frameset");
536 CPLCHECK_CLEAN (
"Error while loading the calibration maps");
542 frame_tag = cpl_frame_get_tag (cpl_frameset_get_position (recipe_frameset, 0));
544 if ((strcmp(frame_tag, GRAVI_DUAL_CALIB_RAW) == 0)) {
545 redCatg = cpl_sprintf (GRAVI_P2VMRED_DUAL_CALIB);
546 proCatg = cpl_sprintf (GRAVI_VIS_DUAL_CALIB);
547 skyCatg = cpl_sprintf (GRAVI_DUAL_SKY_MAP);
548 mode = cpl_sprintf (
"gravi_dual");
550 else if ((strcmp(frame_tag, GRAVI_DUAL_SCIENCE_RAW) == 0)) {
551 redCatg = cpl_sprintf (GRAVI_P2VMRED_DUAL_SCIENCE);
552 proCatg = cpl_sprintf (GRAVI_VIS_DUAL_SCIENCE);
553 skyCatg = cpl_sprintf (GRAVI_DUAL_SKY_MAP);
554 mode = cpl_sprintf (
"gravi_dual");
556 else if ((strcmp(frame_tag, GRAVI_SINGLE_CALIB_RAW) == 0)) {
557 redCatg = cpl_sprintf (GRAVI_P2VMRED_SINGLE_CALIB);
558 proCatg = cpl_sprintf (GRAVI_VIS_SINGLE_CALIB);
559 skyCatg = cpl_sprintf (GRAVI_SINGLE_SKY_MAP);
560 mode = cpl_sprintf (
"gravi_single");
562 else if ((strcmp(frame_tag, GRAVI_SINGLE_SCIENCE_RAW) == 0)) {
563 redCatg = cpl_sprintf (GRAVI_P2VMRED_SINGLE_SCIENCE);
564 proCatg = cpl_sprintf (GRAVI_VIS_SINGLE_SCIENCE);
565 skyCatg = cpl_sprintf (GRAVI_SINGLE_SKY_MAP);
566 mode = cpl_sprintf (
"gravi_single");
569 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
570 "Cannot recognize the input DO.CATG");
574 cpl_msg_info (cpl_func,
"Mode of the first frame is: %s (will be used for all frames)", mode);
579 int averageSky = gravi_param_get_bool (parlist,
"gravity.preproc.average-sky");
584 nb_sky = cpl_frameset_get_size (sky_frameset);
585 sky_maps = cpl_calloc (CPL_MAX(nb_sky,1),
sizeof(gravi_data*));
587 for (
int isky = 0; isky < nb_sky; isky++){
590 cpl_msg_info (cpl_func,
" ***** SKY %d over %d ***** ", isky+1, nb_sky);
591 frame = cpl_frameset_get_position (sky_frameset, isky);
600 CPLCHECK_CLEAN (
"Error while computing the sky_map");
603 if (averageSky == 0) {
604 char filename_suffix[10];
605 snprintf(filename_suffix, 10,
"%d", isky);
607 parlist, NULL, frame,
"gravity_vis",
609 CPLCHECK_CLEAN (
"Could not save the sky");
617 if (averageSky == 1) {
618 cpl_msg_info (cpl_func,
"Do a MASTER SKY from the %d skys", nb_sky);
620 gravi_data * msky_map;
622 CPLCHECK_CLEAN (
"Cannot do master sky");
625 parlist, sky_frameset,
626 cpl_frameset_get_position (sky_frameset, 0),
627 "gravity_vis", NULL, skyCatg);
628 CPLCHECK_CLEAN (
"Cannot save master sky");
631 cpl_frameset_join (used_frameset, sky_frameset);
632 for (
int isky = 0; isky < nb_sky; isky++)
634 sky_maps[0] = msky_map;
642 nb_frame = cpl_frameset_get_size (recipe_frameset);
644 for (
int ivis = 0; ivis < nb_frame; ivis++){
646 char filename_suffix[10];
647 snprintf(filename_suffix, 10,
"%d", ivis);
648 current_frameset = cpl_frameset_duplicate (used_frameset);
650 cpl_msg_info (cpl_func,
" ***** OBJECT %d over %d ***** ", ivis+1, nb_frame);
655 isky = nb_sky>0 ? ivis % nb_sky : 0;
659 cpl_msg_info (cpl_func,
"There is no SKY in the frameset");
661 else if (averageSky) {
663 cpl_msg_info (cpl_func,
"Use MASTER SKY (already reduced)");
667 cpl_msg_info (cpl_func,
"Use SKY %i over %i (already reduced)", isky+1, nb_sky);
668 frame = cpl_frameset_get_position (sky_frameset, isky);
671 cpl_frameset_insert (current_frameset, cpl_frame_duplicate (frame));
678 frame = cpl_frameset_get_position (recipe_frameset, ivis);
684 if (gravi_param_get_bool (parlist,
"gravity.dfs.bias-subtracted-file")) {
687 current_frameset, frame,
"gravity_vis",
688 NULL,
"BIAS_SUBTRACTED");
690 CPLCHECK_CLEAN (
"Cannot save the BIAS_SUBTRACTED product");
694 if ( !gravi_data_check_shutter_open (data) ) {
695 cpl_msg_warning (cpl_func,
"Shutter problem in the OBJECT");
700 badpix_map, sky_maps[isky],
701 parlist, GRAVI_DET_ALL);
702 CPLCHECK_CLEAN (
"Cannot extract spectrum");
705 if (gravi_param_get_bool (parlist,
"gravity.dfs.spectrum-file")) {
707 parlist, current_frameset, frame,
708 "gravity_vis", NULL, GRAVI_SPECTRUM);
709 CPLCHECK_CLEAN (
"Cannot save the SPECTRUM product");
714 CPLCHECK_CLEAN (
"Cannot re-interpolate spectrum");
717 if (gravi_param_get_bool (parlist,
"gravity.test.reduce-acq-cam")) {
719 CPLCHECK_CLEAN (
"Cannot preproc ACQ");
723 if (gravi_param_get_bool (parlist,
"gravity.dfs.preproc-file")) {
725 parlist, current_frameset, frame,
726 "gravity_vis", NULL, GRAVI_PREPROC);
727 CPLCHECK_CLEAN (
"Cannot save the PREPROC product");
732 if (dark_map != NULL)
741 CPLCHECK_CLEAN (
"Cannot move ext");
746 parlist, GRAVI_DET_ALL);
747 CPLCHECK_CLEAN (
"Cannot apply p2vm to the preproc data");
750 if (gravi_param_get_bool (parlist,
"gravity.test.reduce-acq-cam")) {
760 CPLCHECK_CLEAN (
"Cannot delete preproc");
764 CPLCHECK_CLEAN (
"Cannot reduce OPDC");
768 CPLCHECK_CLEAN (
"Cannot reduce metrology");
772 CPLCHECK_CLEAN (
"Cannot compute pointing");
776 CPLCHECK_CLEAN (
"Cannot compute QC for tau0");
780 CPLCHECK_CLEAN (
"Cannot compute QC for FT injection");
784 CPLCHECK_CLEAN (
"Cannot compute QC for FT OPD estimator");
788 CPLCHECK_MSG (
"Cannot compute SNR");
792 CPLCHECK_MSG (
"Cannot compute signals");
796 CPLCHECK_MSG (
"Cannot compute rejection flags signals");
799 if (gravi_param_get_bool (parlist,
"gravity.dfs.p2vmred-file")) {
802 parlist, current_frameset, frame,
803 "gravity_vis", NULL, redCatg);
805 CPLCHECK_CLEAN (
"Cannot save the P2VMREDUCED product");
809 cpl_size current_frame = 0;
810 while (current_frame >= 0)
816 CPLCHECK_CLEAN (
"Cannot average the P2VMRED frames into VIS");
819 if (gravi_param_get_bool (parlist,
"gravity.vis.force-same-time") ) {
820 cpl_msg_info (cpl_func,
"Force same time for all quantities/baselines");
822 CPLCHECK_CLEAN (
"Cannot average the TIME in OI_VIS");
826 if (vis_data == NULL) {
827 vis_data = tmpvis_data; tmpvis_data = NULL;
830 cpl_msg_info (cpl_func,
"Merge with previous OI_VIS");
839 if (gravi_param_get_bool (parlist,
"gravity.dfs.astro-file")) {
843 parlist, current_frameset, frame,
844 "gravity_vis", NULL, GRAVI_ASTROREDUCED);
846 CPLCHECK_CLEAN (
"Cannot save the ASTROREDUCED product");
849 cpl_msg_info (cpl_func,
"Free the p2vmreduced");
850 FREE (cpl_frameset_delete, current_frameset);
864 if (gravi_param_get_bool (parlist,
"gravity.vis.flat-flux")) {
866 cpl_msg_info (cpl_func,
"Flatten the FLUX with the internal P2VM spectrum");
868 CPLCHECK_CLEAN (
"Cannot flat the OI_FLUX");
871 cpl_msg_info (cpl_func,
"Don't flatten the FLUX with the internal P2VM spectrum");
876 if (!strcmp (gravi_param_get_string (parlist,
"gravity.vis.vis-correction-sc"),
"FORCE")) {
878 cpl_msg_info (cpl_func,
"Align the SC visibilities on the FT");
882 cpl_msg_info (cpl_func,
"Don't align the SC visibilities on the FT");
886 if (gravi_param_get_bool (parlist,
"gravity.vis.color-wave-correction") ) {
887 cpl_msg_info (cpl_func,
"Compute the wavelength shift due to target color");
889 CPLCHECK_CLEAN (
"Cannot compute the wavelength in OI_VIS");
891 cpl_msg_info (cpl_func,
"Don't compute the wavelength shift due to target color");
895 if (gravi_param_get_bool (parlist,
"gravity.postprocess.average-vis")) {
899 cpl_msg_info (cpl_func,
"Don't average the different observation (if any)");
907 cpl_frameset_join (used_frameset, recipe_frameset);
908 frame = cpl_frameset_get_position (recipe_frameset, 0);
911 used_frameset, frame,
"gravity_vis", NULL, proCatg);
913 CPLCHECK_CLEAN (
"Cannot save the VIS product");
920 cpl_msg_info(cpl_func,
"Memory cleanup");
937 FREE (cpl_frameset_delete,darkcalib_frameset);
938 FREE (cpl_frameset_delete,wavecalib_frameset);
939 FREE (cpl_frameset_delete,flatcalib_frameset);
940 FREE (cpl_frameset_delete,badcalib_frameset);
941 FREE (cpl_frameset_delete,p2vmcalib_frameset);
942 FREE (cpl_frameset_delete,metpos_frameset);
943 FREE (cpl_frameset_delete,dark_frameset);
944 FREE (cpl_frameset_delete,diamcat_frameset);
945 FREE (cpl_frameset_delete,sky_frameset);
946 FREE (cpl_frameset_delete,dispcalib_frameset);
947 FREE (cpl_frameset_delete,eop_frameset);
948 FREE (cpl_frameset_delete,patch_frameset);
949 FREE (cpl_frameset_delete,recipe_frameset);
950 FREE (cpl_frameset_delete,current_frameset);
951 FREE (cpl_frameset_delete,used_frameset);
952 FREE (cpl_free,proCatg);
953 FREE (cpl_free,redCatg);
954 FREE (cpl_free,skyCatg);
955 FREE (cpl_free,mode);
964 #if defined(__linux__) && defined(__GLIBC__) 969 gravi_msg_function_exit(1);
970 return (
int)cpl_error_get_code();
cpl_error_code gravi_compute_opdc_state(gravi_data *p2vmred_data)
Compute the real-time tracking state from OPDC.
gravi_data * gravi_data_load_frame(cpl_frame *frame, cpl_frameset *used_frameset)
Load a FITS file and create a gravi_data.
cpl_error_code gravi_wave_correct_color(gravi_data *vis_data)
Create a OI_WAVELENGTH_CORR table with color corrected wavelength.
cpl_frameset * gravi_frameset_extract_dark_data(cpl_frameset *frameset)
Extract DARK_RAW frame from the input frameset.
gravi_data * gravi_data_load_rawframe(cpl_frame *frame, cpl_frameset *used_frameset)
Load a RAW FITS file and create a gravi_data.
cpl_error_code gravi_data_move_ext(gravi_data *output, gravi_data *input, const char *name)
Move extensions from one data to another.
cpl_error_code gravi_compute_vis_qc(gravi_data *vis_data)
The function compute the QC parameters for a VIS (averaged) data.
cpl_error_code gravi_preproc_acqcam(gravi_data *output_data, gravi_data *input_data, gravi_data *bad_map)
Preprocess the ACQ images: correct bad pixels, clean from pupil background via blinking, filter median bias.
cpl_error_code gravi_compute_tf_qc(gravi_data *oi_vis, gravi_data *diamcat_data)
Fill QC parameters related to transfer function.
cpl_error_code gravi_compute_snr(gravi_data *p2vmred_data, const cpl_parameterlist *parlist)
Compute real-time SNR and Group-Delay of the observation.
gravi_data * gravi_compute_vis(gravi_data *p2vmred_data, const cpl_parameterlist *parlist, cpl_size *current_frame)
The function average the individual frames of a P2VMREDUCED file into a final, single observation per...
cpl_error_code gravi_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
cpl_error_code gravi_vis_mjd_to_time(gravi_data *vis_data)
Recompute the TIME column of all OIFITS extension from the MJD column, following the OIFITS standard ...
gravi_data * gravi_average_dark(gravi_data **data, cpl_size ndata)
Average several DARK calibration map.
cpl_error_code gravi_compute_signals(gravi_data *p2vmred_data, gravi_data *disp_data, const cpl_parameterlist *parlist)
Create intermediate signal in the P2VMREDUCED file.
gravi_data * gravi_compute_p2vmred(gravi_data *preproc_data, gravi_data *p2vm_map, const char *mode, const cpl_parameterlist *parlist, enum gravi_detector_type det_type)
Converts preprocessed data into coherent fluxes using the P2VM.
cpl_error_code gravi_compute_rejection(gravi_data *p2vmred_data, const cpl_parameterlist *parlist)
Create rejection flags P2VMREDUCED file.
cpl_error_code gravi_compute_tau0(gravi_data *data)
Compute the QC TAU0 parameter.
cpl_error_code gravi_compute_qc_injection(gravi_data *data)
Compute the QC for the injection stability.
const char * gravi_get_license(void)
Get the pipeline copyright and license.
cpl_error_code gravi_parameter_add_rejection(cpl_parameterlist *self, int isCalib)
Add rejection parameters to the input parameter list.
cpl_error_code gravi_compute_qc_ft_opd_estimator(gravi_data *p2vmred_data)
Compute the QC for the FT linearity.
cpl_error_code gravi_data_detector_cleanup(gravi_data *data, const cpl_parameterlist *parlist)
Perform self-bias correction to the SC raw data.
cpl_error_code gravi_data_save_new(gravi_data *self, cpl_frameset *allframes, const char *filename, const char *suffix, const cpl_parameterlist *parlist, cpl_frameset *usedframes, cpl_frame *frame, const char *recipe, cpl_propertylist *applist, const char *proCatg)
Save a gravi data in a CPL-complian FITS file.
cpl_error_code gravi_average_vis(gravi_data *oi_data)
Coadd the observations together.
cpl_error_code gravi_compute_pointing_uv(gravi_data *p2vmred_data, gravi_data *eop_data)
Compute the pointing directions and projected baselines in OI_VIS.
cpl_error_code gravi_data_clean_for_astro(gravi_data *data)
Clean the data to keep only OIFITS extensions related to SC.
cpl_error_code gravi_align_spectrum(gravi_data *spectrum_data, gravi_data *wave_map, gravi_data *p2vm_map, enum gravi_detector_type det_type, const cpl_parameterlist *parlist)
Regrid the regions into a common wavelength (in-place)
cpl_error_code gravi_vis_force_time(gravi_data *oi_data)
Force all data in OI_TABLE to have the same TIME and MJD.
cpl_error_code gravi_normalize_sc_to_ft(gravi_data *vis_data)
Align the SC visibilities on the FT visibilities.
cpl_error_code gravi_flat_flux(gravi_data *vis_data, gravi_data *p2vm_map)
Divide the OI_FLUX by OI_FLUX from the P2VM (no checks, no time distance...)
void gravi_data_delete(gravi_data *self)
Delete a gravi data.
int gravi_data_patch(gravi_data *file_to_patch, cpl_frameset *patch_frameset)
Load a RAW FITS file and create a gravi_data.
cpl_error_code gravi_metrology_reduce(gravi_data *data, gravi_data *eop_data, gravi_data *static_param_data, gravi_data *met_pos, const cpl_parameterlist *parlist)
Reduce the metrology.
cpl_error_code gravi_data_append(gravi_data *first, const gravi_data *second, int force)
Append a gravi_data into another existing one.
cpl_error_code gravi_subtract_met_dark(gravi_data *preproc_data, gravi_data *dark_map)
Substract metrology dark.
gravi_data * gravi_extract_spectrum(gravi_data *raw_data, gravi_data *profile_map, gravi_data *dark_map, gravi_data *bad_map, gravi_data *sky_map, const cpl_parameterlist *parlist, enum gravi_detector_type det_type)
Create the SPECTRUM gravi_data with extracted spectrum per region.
cpl_error_code gravi_reduce_acqcam(gravi_data *output_data, gravi_data *input_data, gravi_data *static_param_data)
Reduce the ACQ camera images.
gravi_data * gravi_compute_dark(gravi_data *raw_data)
Compute the DARK calibration map.