43 #if defined(__linux__) && defined(__GLIBC__) 47 #include "gravi_data.h" 48 #include "gravi_pfits.h" 49 #include "gravi_dfs.h" 51 #include "gravi_utils.h" 53 #include "gravi_metrology.h" 54 #include "gravi_calib.h" 55 #include "gravi_preproc.h" 56 #include "gravi_wave.h" 57 #include "gravi_p2vm.h" 59 #include "gravi_p2vmred.h" 66 static int gravity_p2vm_create(cpl_plugin *);
67 static int gravity_p2vm_exec(cpl_plugin *);
68 static int gravity_p2vm_destroy(cpl_plugin *);
69 static int gravity_p2vm(cpl_frameset *,
const cpl_parameterlist *);
75 static char gravity_p2vm_short[] =
"Calibrate the instrument bad pixels, wavelength table, interferometric contrast and phase.";
76 static char gravity_p2vm_description[] =
77 "This recipe reduces the internal calibrations. As a special sequence of shutter opening is required, it is advised to always build the SOF with a complete sequence of files obtained within a single execution of the p2vm calibration template. However it is still possible to input a SOF with DARK_RAW only, or DARK_RAW and FLAT_RAW only. It is also possible to input a SOF with some already processed calibration (e.g WAVE).\n" 79 "* Compute the dark, write product\n" 80 "* Compute the flat, write product\n" 81 "* Compute the badpixels, write product\n" 82 "* Compute the spectral calibration, write product\n" 83 "* Compute the p2vm, write product\n" 84 GRAVI_RECIPE_INPUT
"\n" 85 GRAVI_DARK_RAW
" : raw dark, all shutters closed (DPR.TYPE=DARK)\n" 86 GRAVI_FLAT_RAW
" x4 : raw flats, one shutter open (DPR.TYPE=FLAT)\n" 87 GRAVI_P2VM_RAW
" x6 : raw p2vms, two shutters open (DPR.TYPE=P2VM)\n" 88 GRAVI_WAVE_RAW
" : raw wavelength calibration for FT (DPR.TYPE=WAVE)\n" 89 GRAVI_WAVESC_RAW
" : raw wavelength calibration for SC (DPR.TYPE=WAVE,SC)\n" 90 GRAVI_RECIPE_OUTPUT
"\n" 91 GRAVI_DARK_MAP
" : dark calibration\n" 92 GRAVI_FLAT_MAP
" : flat calibration\n" 93 GRAVI_BAD_MAP
" : badpixel calibration\n" 94 GRAVI_WAVE_MAP
" : wave calibration\n" 95 GRAVI_P2VM_MAP
" : p2vm calibration\n" 113 int cpl_plugin_get_info(cpl_pluginlist * list)
115 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe );
116 cpl_plugin * plugin = &recipe->interface;
118 if (cpl_plugin_init(plugin,
120 GRAVI_BINARY_VERSION,
121 CPL_PLUGIN_TYPE_RECIPE,
124 gravity_p2vm_description,
125 "Nabih Azouaoui, Vincent Lapeyrere, JB. Le Bouquin",
130 gravity_p2vm_destroy)) {
131 cpl_msg_error(cpl_func,
"Plugin initialization failed");
132 (void)cpl_error_set_where(cpl_func);
136 if (cpl_pluginlist_append(list, plugin)) {
137 cpl_msg_error(cpl_func,
"Error adding plugin to list");
138 (void)cpl_error_set_where(cpl_func);
154 static int gravity_p2vm_create(cpl_plugin * plugin)
160 if (cpl_error_get_code() != CPL_ERROR_NONE) {
161 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
162 cpl_func, __LINE__, cpl_error_get_where());
163 return (
int)cpl_error_get_code();
166 if (plugin == NULL) {
167 cpl_msg_error(cpl_func,
"Null plugin");
168 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
172 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
173 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
174 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
178 recipe = (cpl_recipe *)plugin;
181 recipe->parameters = cpl_parameterlist_new();
182 if (recipe->parameters == NULL) {
183 cpl_msg_error(cpl_func,
"Parameter list allocation failed");
184 cpl_ensure_code(0, (
int)CPL_ERROR_ILLEGAL_OUTPUT);
190 gravi_parameter_add_static_name (recipe->parameters);
193 gravi_parameter_add_debug_file (recipe->parameters);
194 gravi_parameter_add_preproc_file (recipe->parameters);
197 gravi_parameter_add_biasmethod (recipe->parameters);
208 p = cpl_parameter_new_enum (
"gravity.calib.phase-calibration", CPL_TYPE_STRING,
209 "This option changes the phase reference of the P2VM:\n " 210 "NONE defines phiA(lbd) at zero for all baselines " 211 "(P2VM calibrates only the internal phase-shift of the beam combiner);\n " 212 "CLOSURE defines phiA(lbd) at zero for baselines 01, 02 and 03 " 213 "(P2VM calibrates the phase-shift and the closure-phase of the beam combiner);\n " 214 "DISP defines phiA(lbd) to have zero mean and minimum GD for baselines (01,02,03); " 215 "(P2VM calibrates the phase-shift, the closure-phase and the " 216 "spectral-dispersion of the beam combiner);\n " 217 "FULL defines phiA(lbd) to have zero-GD for baselines (01,02,03)",
218 "(P2VM calibrates the full phase with respect to zero-astrometry);\n " 219 "gravi.p2vm",
"CLOSURE", 4,
"NONE",
"CLOSURE",
"DISP",
"FULL");
220 cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI,
"phase-calibration");
221 cpl_parameter_disable (p, CPL_PARAMETER_MODE_ENV);
222 cpl_parameterlist_append (recipe->parameters, p);
234 static int gravity_p2vm_exec(cpl_plugin * plugin)
239 cpl_errorstate initial_errorstate = cpl_errorstate_get();
242 if (cpl_error_get_code() != CPL_ERROR_NONE) {
243 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
244 cpl_func, __LINE__, cpl_error_get_where());
245 return (
int)cpl_error_get_code();
248 if (plugin == NULL) {
249 cpl_msg_error(cpl_func,
"Null plugin");
250 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
254 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
255 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
256 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
260 recipe = (cpl_recipe *)plugin;
263 if (recipe->parameters == NULL) {
264 cpl_msg_error(cpl_func,
"Recipe invoked with NULL parameter list");
265 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
267 if (recipe->frames == NULL) {
268 cpl_msg_error(cpl_func,
"Recipe invoked with NULL frame set");
269 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
273 recipe_status = gravity_p2vm(recipe->frames, recipe->parameters);
276 if (cpl_dfs_update_product_header(recipe->frames)) {
277 if (!recipe_status) recipe_status = (int)cpl_error_get_code();
280 if (!cpl_errorstate_is_equal(initial_errorstate)) {
283 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
286 return recipe_status;
296 static int gravity_p2vm_destroy(cpl_plugin * plugin)
300 if (plugin == NULL) {
301 cpl_msg_error(cpl_func,
"Null plugin");
302 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
306 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
307 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
308 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
312 recipe = (cpl_recipe *)plugin;
314 cpl_parameterlist_delete(recipe->parameters);
328 static int gravity_p2vm(cpl_frameset * frameset,
329 const cpl_parameterlist * parlist)
331 cpl_frameset * p2vm_frameset=NULL, * wavecalib_frameset=NULL, * darkcalib_frameset=NULL,
332 * flatcalib_frameset=NULL, * dark_frameset=NULL, * wave_frameset=NULL, * wavesc_frameset=NULL,
333 * badcalib_frameset=NULL, * flat_frameset=NULL, * used_frameset=NULL, * current_frameset=NULL,
334 * wave_param_frameset=NULL;
336 cpl_frame * frame=NULL, * frame_p2vm=NULL;
338 gravi_data * p2vm_map=NULL, * data=NULL, * dark_map=NULL, * wave_map=NULL,
339 * profile_map=NULL, * badpix_map=NULL, * wave_param=NULL;
340 gravi_data * spectrum_data=NULL;
341 gravi_data * preproc_data=NULL;
342 gravi_data ** raw_data=NULL;
343 gravi_data * p2vmred_data = NULL;
345 int nb_frame, nb_frame_gain = 0;
347 cpl_propertylist * met_plist=NULL;
348 int ** valid_trans = cpl_malloc (2 *
sizeof (
int*));
349 int ** valid_CP = cpl_malloc (2 *
sizeof (
int*));
350 char ext_regexp[500];
353 for (
int i = 0 ; i < 2; i++){
354 valid_trans[i] = cpl_calloc (4,
sizeof (
int));
355 valid_CP[i] = cpl_calloc (6,
sizeof (
int));
359 gravity_print_banner ();
360 cpl_msg_set_time_on();
361 cpl_msg_set_component_on();
362 gravi_msg_function_start(1);
369 used_frameset = cpl_frameset_new ();
373 darkcalib_frameset = gravi_frameset_extract_dark_map (frameset);
376 flat_frameset = gravi_frameset_extract_flat_data (frameset);
377 flatcalib_frameset = gravi_frameset_extract_flat_map (frameset);
380 badcalib_frameset = gravi_frameset_extract_bad_map (frameset);
383 wave_frameset = gravi_frameset_extract_wave_data (frameset);
384 wavesc_frameset = gravi_frameset_extract_wavesc_data (frameset);
385 wavecalib_frameset = gravi_frameset_extract_wave_map (frameset);
391 wave_param_frameset = gravi_frameset_extract_wave_param (frameset);
397 if (!cpl_frameset_is_empty (dark_frameset)) {
398 cpl_msg_info (cpl_func,
" ***** Compute DARK map ***** ");
401 frame = cpl_frameset_get_position (dark_frameset, 0);
409 CPLCHECK_CLEAN (
"Cannot compute the DARK map");
413 NULL, frame,
"gravity_p2vm",
414 NULL, GRAVI_DARK_MAP);
416 CPLCHECK_CLEAN (
"Could not save the DARK map");
418 else if (!cpl_frameset_is_empty (darkcalib_frameset)) {
419 cpl_msg_info (cpl_func,
" ***** Get DARK map ***** ");
422 frame = cpl_frameset_get_position (darkcalib_frameset, 0);
425 CPLCHECK_CLEAN (
"Could not load the DARK map");
428 cpl_frameset_insert (dark_frameset, cpl_frame_duplicate (frame));
436 if (!cpl_frameset_is_empty (badcalib_frameset)) {
437 cpl_msg_info (cpl_func,
" ***** Get BAD pixel map ***** ");
440 frame = cpl_frameset_get_position (badcalib_frameset, 0);
443 else if (!cpl_frameset_is_empty (dark_frameset) &&
444 !cpl_frameset_is_empty (flat_frameset)) {
445 cpl_msg_info (cpl_func,
" ***** Compute BAD pixel map from DARK and FLAT_RAW ***** ");
448 nb_frame_gain = cpl_frameset_get_size (flat_frameset);
449 raw_data = cpl_calloc (nb_frame_gain,
sizeof(gravi_data *));
452 for (
int i = 0; i < nb_frame_gain; i++) {
453 frame = cpl_frameset_get_position (flat_frameset, i);
460 nb_frame_gain, parlist);
462 CPLCHECK_CLEAN(
"Cannot compute the BAD pixel from DARK and FLAT");
465 frame = cpl_frameset_get_position (dark_frameset, 0);
467 NULL, frame,
"gravity_p2vm",
468 NULL, GRAVI_BAD_MAP);
470 CPLCHECK_CLEAN (
"Could not save the BAD pixel map");
479 if (!cpl_frameset_is_empty(flatcalib_frameset)) {
480 cpl_msg_info (cpl_func,
" ***** Get FLAT map ***** ");
483 frame = cpl_frameset_get_position (flatcalib_frameset, 0);
486 else if (!cpl_frameset_is_empty (flat_frameset)) {
487 cpl_msg_info (cpl_func,
" ***** Compute FLAT map ***** ");
491 if (!badpix_map || !dark_map) {
492 ERROR_CLEAN (CPL_ERROR_ILLEGAL_INPUT,
"Missing DARK or BAD in frameset");
496 nb_frame_gain = cpl_frameset_get_size (flat_frameset);
497 raw_data = cpl_malloc (nb_frame_gain *
sizeof(gravi_data *));
500 for (
int i = 0; i < nb_frame_gain; i++) {
501 frame = cpl_frameset_get_position (flat_frameset, i);
509 CPLCHECK_CLEAN (
"Cannot compute the FLAT profile");
512 cpl_propertylist * gain_header;
514 CPLCHECK_CLEAN (
"Cannot compute the GAIN");
517 cpl_propertylist * profile_header = gravi_data_get_header (profile_map);
518 cpl_propertylist_append (profile_header, gain_header);
519 FREE (cpl_propertylist_delete, gain_header);
522 frame = cpl_frameset_get_position (flat_frameset, 0);
525 used_frameset, frame,
"gravity_p2vm",
526 NULL, GRAVI_FLAT_MAP);
528 CPLCHECK_CLEAN (
"Could not save the FLAT profile_map");
538 if (!cpl_frameset_is_empty (wavecalib_frameset)) {
539 cpl_msg_info (cpl_func,
" ***** Get wave map ***** ");
542 frame = cpl_frameset_get_position (wavecalib_frameset, 0);
545 else if (!cpl_frameset_is_empty (wave_frameset)) {
546 cpl_msg_info (cpl_func,
" ***** Process the WAVE_RAW ***** ");
549 if ( !badpix_map || !profile_map || !dark_map) {
550 ERROR_CLEAN (CPL_ERROR_ILLEGAL_INPUT,
"Missing DARK, FLAT, or BAD in frameset");
557 frame = cpl_frameset_get_position (wave_frameset, 0);
560 snprintf(ext_regexp, 499,
"^(%s|%s)$", GRAVI_IMAGING_DATA_SC_EXT, GRAVI_IMAGING_DETECTOR_SC_EXT);
565 cpl_msg_info (cpl_func,
"Extract SC SPECTRUM for WAVE_RAW");
567 badpix_map, NULL, parlist, GRAVI_DET_SC);
571 snprintf(ext_regexp, 499,
"^(%s|%s)$", GRAVI_IMAGING_DATA_FT_EXT, GRAVI_IMAGING_DETECTOR_FT_EXT);
575 cpl_msg_info (cpl_func,
"Extract FT SPECTRUM for WAVE_RAW");
577 badpix_map, NULL, parlist, GRAVI_DET_FT);
583 cpl_propertylist_copy_property_regexp(gravi_data_get_header(spectrum_data),
584 gravi_data_get_header(ft_spectrum_data),
592 cpl_msg_info (cpl_func,
"Compute the P2VM_MET from WAVE_RAW");
594 double lbd_met = gravi_pfits_get_met_wavelength_mean (gravi_data_get_header(wave_met_data), met_table);
600 CPLCHECK_CLEAN (
"Cannot compute P2VM_MET");
603 cpl_msg_info (cpl_func,
"Compute OPDs for WAVE_RAW");
609 CPLCHECK_CLEAN (
"Cannot compute OPDs");
612 if (gravi_param_get_bool (parlist,
"gravity.dfs.debug-file")) {
614 used_frameset, frame,
"gravity_p2vm",
621 CPLCHECK_CLEAN (
"Cannot compute wave for FT");
624 if (!cpl_frameset_is_empty (wavesc_frameset)) {
626 cpl_msg_info (cpl_func,
"Delete WAVE_RAW data");
629 cpl_msg_info (cpl_func,
" ***** Process the WAVESC_RAW ***** ");
632 frame = cpl_frameset_get_position (wavesc_frameset, 0);
635 snprintf(ext_regexp, 499,
"^(%s|%s)$", GRAVI_IMAGING_DATA_SC_EXT, GRAVI_IMAGING_DETECTOR_SC_EXT);
639 cpl_msg_info (cpl_func,
"Extract SC SPECTRUM for WAVESC_RAW");
641 badpix_map, NULL, parlist, GRAVI_DET_SC);
642 CPLCHECK_CLEAN (
"Cannot extract SC spectrum from WAVESC_RAW");
646 snprintf(ext_regexp, 499,
"^(%s|%s)$", GRAVI_IMAGING_DATA_FT_EXT, GRAVI_IMAGING_DETECTOR_FT_EXT);
649 cpl_msg_info (cpl_func,
"Extract FT SPECTRUM for WAVESC_RAW");
651 badpix_map, NULL, parlist, GRAVI_DET_FT);
652 CPLCHECK_CLEAN (
"Cannot extract FT spectrum from WAVESC_RAW");
658 cpl_propertylist_copy_property_regexp(gravi_data_get_header(spectrum_data),
659 gravi_data_get_header(ft_spectrum_data),
666 cpl_msg_info (cpl_func,
"Compute OPDs for WAVESC_RAW");
672 CPLCHECK_CLEAN (
"Cannot process the WAVESC_RAW");
675 if (gravi_param_get_bool (parlist,
"gravity.dfs.debug-file")) {
677 parlist, used_frameset, frame,
"gravity_p2vm",
682 cpl_msg_warning (cpl_func,
"No WAVESC_RAW in the SOF:" 683 " SC wavelength will be inaccurate");
689 CPLCHECK_CLEAN (
"Cannot compute wave for SC");
699 used_frameset, frame,
"gravity_p2vm",
700 NULL, GRAVI_WAVE_MAP);
702 CPLCHECK_CLEAN (
"Could not save the WAVE map");
710 if ( cpl_frameset_is_empty (p2vm_frameset) ) {
711 cpl_msg_info (cpl_func,
"All RAW data reduced... stop recipe");
716 if ( !badpix_map || !profile_map || !wave_map || !dark_map) {
717 ERROR_CLEAN (CPL_ERROR_ILLEGAL_INPUT,
"Missing DARK, FLAT, BAD, or WAVE in frameset");
721 if ( !cpl_frameset_is_empty (flat_frameset) )
722 cpl_frameset_join (p2vm_frameset, flat_frameset);
724 if ( !cpl_frameset_is_empty (wave_frameset) )
725 cpl_frameset_join (p2vm_frameset, wave_frameset);
728 nb_frame = cpl_frameset_get_size (p2vm_frameset);
731 if (nb_frame != 11) {
732 ERROR_CLEAN (CPL_ERROR_ILLEGAL_INPUT,
"Missing P2VM in frameset");
741 if (!cpl_frameset_is_empty (wave_param_frameset)) {
742 frame = cpl_frameset_get_position (wave_param_frameset, 0);
746 cpl_msg_error (cpl_func,
"There is no WAVE_PARAM in the frameset");
748 cpl_msg_info (cpl_func,
" ***** Create the P2VM ***** ");
750 CPLCHECK_CLEAN (
"Cannot create the P2VM data");
754 for (
int i = 0; i < nb_frame; i++) {
756 cpl_msg_info (cpl_func,
" ***** file %d over %d ***** ", i+1, nb_frame );
757 current_frameset = cpl_frameset_duplicate (used_frameset);
760 frame = cpl_frameset_get_position (p2vm_frameset, i);
761 cpl_frameset_insert (used_frameset, cpl_frame_duplicate (frame));
762 snprintf(ext_regexp, 499,
"^(%s|%s)$", GRAVI_ARRAY_GEOMETRY_EXT, GRAVI_OPTICAL_TRAIN_EXT);
764 CPLCHECK_CLEAN (
"Cannot load data");
767 cpl_msg_info (cpl_func,
"Shutters: %d-%d-%d-%d",
768 gravi_data_get_shutter (hdr_data, 0), gravi_data_get_shutter (hdr_data, 1),
769 gravi_data_get_shutter (hdr_data, 2), gravi_data_get_shutter (hdr_data, 3));
774 if ( frame_p2vm==NULL && gravi_data_check_shutter (hdr_data, 1,1,0,0) )
776 cpl_msg_info (cpl_func,
"Use this frame for the P2VM product");
783 if ( gravi_data_check_shutter (hdr_data, 1,1,1,1) ) {
786 cpl_msg_info (cpl_func,
"Nothing to be done with the file... yet.");
790 FREE (cpl_frameset_delete, current_frameset);
797 snprintf(ext_regexp, 499,
"^(%s|%s|%s|%s)$", GRAVI_ARRAY_GEOMETRY_EXT, GRAVI_OPTICAL_TRAIN_EXT, GRAVI_IMAGING_DATA_SC_EXT, GRAVI_IMAGING_DETECTOR_SC_EXT);
803 badpix_map, NULL, parlist, GRAVI_DET_SC);
804 CPLCHECK_CLEAN (
"Cannot extract spectrum");
809 CPLCHECK_CLEAN (
"Cannot re-interpolate spectrum");
813 CPLCHECK_CLEAN(
"Cannot compute the P2VM");
816 snprintf(ext_regexp, 499,
"^(%s|%s)$", GRAVI_IMAGING_DATA_FT_EXT, GRAVI_IMAGING_DETECTOR_FT_EXT);
821 badpix_map, NULL, parlist, GRAVI_DET_FT);
823 CPLCHECK_CLEAN (
"Cannot extract spectrum");
827 CPLCHECK_CLEAN (
"Cannot re-interpolate spectrum");
831 CPLCHECK_CLEAN(
"Cannot compute the P2VM");
839 if (gravi_param_get_bool (parlist,
"gravity.dfs.preproc-file")) {
842 current_frameset, frame,
"gravity_p2vm",
843 NULL, GRAVI_PREPROC);
849 cpl_msg_info(cpl_func,
"Execution time to delete preproc_data : %f s",
850 (clock() - start) / (
double)CLOCKS_PER_SEC);
853 FREE (cpl_frameset_delete, current_frameset);
862 CPLCHECK_CLEAN(
"Cannot normalise the p2vm_map");
870 cpl_msg_info (cpl_func,
" ***** Analyse the WAVE file to calibrate the internal closure and transmission ***** ");
873 frame = cpl_frameset_get_position (p2vm_frameset, i_wave);
876 snprintf(ext_regexp, 499,
"^(%s|%s|%s|%s)$", GRAVI_ARRAY_GEOMETRY_EXT, GRAVI_OPTICAL_TRAIN_EXT, GRAVI_IMAGING_DATA_SC_EXT, GRAVI_IMAGING_DETECTOR_SC_EXT);
882 badpix_map, NULL, parlist, GRAVI_DET_SC);
883 CPLCHECK_CLEAN (
"Cannot extract SC spectrum");
889 CPLCHECK_CLEAN (
"Cannot move ext");
893 CPLCHECK_CLEAN (
"Cannot re-interpolate SC spectrum");
897 parlist, GRAVI_DET_SC);
899 CPLCHECK_CLEAN (
"Cannot apply p2vm");
902 snprintf(ext_regexp, 499,
"^(%s|%s|%s|%s)$", GRAVI_ARRAY_GEOMETRY_EXT, GRAVI_OPTICAL_TRAIN_EXT, GRAVI_IMAGING_DATA_FT_EXT, GRAVI_IMAGING_DETECTOR_FT_EXT);
907 badpix_map, NULL, parlist, GRAVI_DET_FT);
908 CPLCHECK_CLEAN (
"Cannot extract FT spectrum");
914 CPLCHECK_CLEAN (
"Cannot move ext");
918 CPLCHECK_CLEAN (
"Cannot re-interpolate FT spectrum");
922 p2vm_map,
"gravi_single", parlist, GRAVI_DET_FT);
924 CPLCHECK_CLEAN (
"Cannot apply p2vm");
931 CPLCHECK_CLEAN (
"Cannot merge SC and FT extensions");
934 if (!strcmp (gravi_param_get_string (parlist,
"gravity.calib.phase-calibration"),
"CLOSURE")) {
937 else if (!strcmp (gravi_param_get_string (parlist,
"gravity.calib.phase-calibration"),
"DISP")) {
940 else if (!strcmp (gravi_param_get_string (parlist,
"gravity.calib.phase-calibration"),
"FULL")) {
944 cpl_msg_info (cpl_func,
"P2VM phases are kept to zero (option phase-calibration=NONE)");
946 CPLCHECK_CLEAN (
"Cannot recalibrate the P2VM phases");
952 CPLCHECK_CLEAN (
"Cannot compute the transmission");
961 used_frameset, frame_p2vm,
"gravity_p2vm",
962 NULL, GRAVI_P2VM_MAP);
964 CPLCHECK_CLEAN(
"Could not save the P2VM on the output file");
968 cpl_msg_info (cpl_func,
"Cleanup memory");
970 FREE (cpl_frameset_delete, dark_frameset);
971 FREE (cpl_frameset_delete, darkcalib_frameset);
972 FREE (cpl_frameset_delete, badcalib_frameset);
978 FREE (cpl_propertylist_delete, met_plist);
979 FREE (cpl_frameset_delete, wavecalib_frameset);
980 FREE (cpl_frameset_delete, flatcalib_frameset);
981 FREE (cpl_frameset_delete, flat_frameset);
982 FREE (cpl_frameset_delete, wave_frameset);
983 FREE (cpl_frameset_delete, wavesc_frameset);
984 FREE (cpl_frameset_delete, used_frameset);
990 FREELOOP (cpl_free, valid_CP, 2);
991 FREELOOP (cpl_free, valid_trans, 2);
993 FREE (cpl_frameset_delete, p2vm_frameset);
994 FREE (cpl_frameset_delete, current_frameset);
995 FREE (cpl_frameset_delete, wave_param_frameset);
999 CPLCHECK_INT (
"Could not cleanup memory");
1009 #if defined(__linux__) && defined(__GLIBC__) 1013 gravi_msg_function_exit(1);
1014 return (
int)cpl_error_get_code();
gravi_data * gravi_data_new(int nb_ext)
Create an empty gravi_data.
cpl_error_code gravi_wave_qc(gravi_data *wave_map, gravi_data *profile_map)
Compute the QC parameters of the WAVE product.
gravi_data * gravi_data_load_frame(cpl_frame *frame, cpl_frameset *used_frameset)
Load a FITS file and create a gravi_data.
cpl_parameter * gravi_parameter_add_badpix(cpl_parameterlist *self)
Add badpix parameters to the input parameter list.
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_p2vm_transmission(gravi_data *p2vm_map, gravi_data *p2vmred_data)
Compute the flux normalisation in the P2VM.
cpl_error_code gravi_compute_p2vm(gravi_data *p2vm_map, gravi_data *preproc_data, int **valid_trans, int **valid_pair, enum gravi_detector_type det_type)
The given output FITS file contain a p2vm table with the values of the transmission, phase and coherence extract using the p2vm matrix.
cpl_error_code gravi_wave_compute_opds(gravi_data *spectrum_data, cpl_table *met_table, enum gravi_detector_type det_type)
Recover the OPD modulation from a spectrum_data and vismet_table.
cpl_error_code gravi_p2vm_phase_correction(gravi_data *p2vm_map, gravi_data *p2vmred_data, int full_phase)
Correct the phase of the P2VM from internal closure-phases.
cpl_error_code gravi_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
cpl_table * gravi_data_get_table(gravi_data *self, const char *extname)
Return a pointer on a table extension by its EXTNAME.
cpl_propertylist * gravi_compute_gain(gravi_data **flats_data, int nrawgain, gravi_data *dark_map)
Compute mean detector gain.
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_wave(gravi_data *wave_map, gravi_data *spectrum_data, int type_data, const cpl_parameterlist *parlist)
Create the WAVE calibration map.
const char * gravi_get_license(void)
Get the pipeline copyright and license.
cpl_parameter * gravi_parameter_add_profile(cpl_parameterlist *self)
Add profile parameters to the input parameter list.
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_frameset * gravi_frameset_extract_p2vm_data(cpl_frameset *frameset)
Extract P2VM_RAW frame from the input frameset.
gravi_data * gravi_compute_badpix(gravi_data *dark_map, gravi_data **flats_data, int nflat, const cpl_parameterlist *params)
Identify the bad pixels in the DARK map and create the BAD map.
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_p2vm_normalisation(gravi_data *p2vm_map, int **valid_trans, int **valid_pair)
The given output FITS file contain a p2vm table with the values of the transmission, phase and coherence extract using the p2vm matrix so this function will normalise the p2vm map.
cpl_parameter * gravi_parameter_add_wave(cpl_parameterlist *self)
Add wavelength calibration parameters to the input parameter list.
gravi_data * gravi_data_load_rawframe_ext(cpl_frame *frame, cpl_frameset *used_frameset, char *extensions_regexp)
Load a RAW FITS file and create a gravi_data from specified extensions.
cpl_error_code gravi_data_add_table(gravi_data *self, cpl_propertylist *plist, const char *extname, cpl_table *table)
Add a BINTABLE extension in gravi_data.
gravi_data * gravi_create_p2vm(gravi_data *wave_map, gravi_data *wave_param)
Create a new P2VM map.
void gravi_data_delete(gravi_data *self)
Delete a gravi data.
cpl_table * gravi_metrology_compute_p2vm(cpl_table *metrology_table, double wave_met)
Calibrate the P2VM of the metrology.
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.
gravi_data * gravi_compute_dark(gravi_data *raw_data)
Compute the DARK calibration map.
gravi_data * gravi_compute_profile(gravi_data **flats_data, gravi_data *dark_map, gravi_data *bad_map, int nflat, const cpl_parameterlist *params)
Computes the spatial profile of each spectrum for optimal extraction purpose.