GRAVI Pipeline Reference Manual  1.2.3
gravity_p2vm.c
1 /* $Id: gravity_p2vm.c,v 1.29 2009/02/10 09:16:12 llundin Exp $
2  *
3  * This file is part of the GRAVI Pipeline
4  * Copyright (C) 2002,2003 European Southern Observatory
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 
21 /*
22  * $Author: llundin $
23  * $Date: 2009/02/10 09:16:12 $
24  * $Revision: 1.29 $
25  * $Name: $
26  *
27  * History :
28  * 04/12/2018 use GRAVITY_WAVE.fits calibration file instead of hardcoded values
29  */
30 
31 #ifdef HAVE_CONFIG_H
32 #include <config.h>
33 #endif
34 
35 /*-----------------------------------------------------------------------------
36  Includes
37  -----------------------------------------------------------------------------*/
38 
39 #include <cpl.h>
40 #include <stdio.h>
41 #include <string.h>
42 #include <time.h>
43 #if defined(__linux__) && defined(__GLIBC__)
44 #include <malloc.h> //Needed for malloc_trim()
45 #endif
46 
47 #include "gravi_data.h"
48 #include "gravi_pfits.h"
49 #include "gravi_dfs.h"
50 
51 #include "gravi_utils.h"
52 
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"
58 
59 #include "gravi_p2vmred.h"
60 
61 
62 /*-----------------------------------------------------------------------------
63  Private function prototypes
64  -----------------------------------------------------------------------------*/
65 
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 *);
70 
71 /*-----------------------------------------------------------------------------
72  Static variables
73  -----------------------------------------------------------------------------*/
74 
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"
78  GRAVI_RECIPE_FLOW"\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"
96  "";
97 
98 /*-----------------------------------------------------------------------------
99  Function code
100  -----------------------------------------------------------------------------*/
101 
102 /*----------------------------------------------------------------------------*/
112 /*----------------------------------------------------------------------------*/
113 int cpl_plugin_get_info(cpl_pluginlist * list)
114 {
115  cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe );
116  cpl_plugin * plugin = &recipe->interface;
117 
118  if (cpl_plugin_init(plugin,
119  CPL_PLUGIN_API,
120  GRAVI_BINARY_VERSION,
121  CPL_PLUGIN_TYPE_RECIPE,
122  "gravity_p2vm",
123  gravity_p2vm_short,
124  gravity_p2vm_description,
125  "Nabih Azouaoui, Vincent Lapeyrere, JB. Le Bouquin",
126  PACKAGE_BUGREPORT,
128  gravity_p2vm_create,
129  gravity_p2vm_exec,
130  gravity_p2vm_destroy)) {
131  cpl_msg_error(cpl_func, "Plugin initialization failed");
132  (void)cpl_error_set_where(cpl_func);
133  return 1;
134  }
135 
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);
139  return 1;
140  }
141 
142  return 0;
143 }
144 
145 /*----------------------------------------------------------------------------*/
153 /*----------------------------------------------------------------------------*/
154 static int gravity_p2vm_create(cpl_plugin * plugin)
155 {
156  cpl_recipe * recipe;
157  cpl_parameter * p;
158 
159  /* Do not create the recipe if an error code is already set */
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();
164  }
165 
166  if (plugin == NULL) {
167  cpl_msg_error(cpl_func, "Null plugin");
168  cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
169  }
170 
171  /* Verify plugin type */
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);
175  }
176 
177  /* Get the recipe */
178  recipe = (cpl_recipe *)plugin;
179 
180  /* Create the parameters list in the cpl_recipe object */
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);
185  }
186 
187  /* Fill the parameters list */
188 
189  /* Use static names (output_procatg.fits) */
190  gravi_parameter_add_static_name (recipe->parameters);
191 
192  /* Debug file */
193  gravi_parameter_add_debug_file (recipe->parameters);
194  gravi_parameter_add_preproc_file (recipe->parameters);
195 
196  /* Bias-method */
197  gravi_parameter_add_biasmethod (recipe->parameters);
198 
199  /* Badpix and profile */
200  gravi_parameter_add_badpix (recipe->parameters);
201  gravi_parameter_add_profile (recipe->parameters);
202  //gravi_parameter_add_preproc (recipe->parameters);
203 
204  /* Wave option */
205  gravi_parameter_add_wave (recipe->parameters);
206 
207  /* Phase definition in P2VM */
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);
223 
224  return 0;
225 }
226 
227 /*----------------------------------------------------------------------------*/
233 /*----------------------------------------------------------------------------*/
234 static int gravity_p2vm_exec(cpl_plugin * plugin)
235 {
236 
237  cpl_recipe * recipe;
238  int recipe_status;
239  cpl_errorstate initial_errorstate = cpl_errorstate_get();
240 
241  /* Return immediately if an error code is already set */
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();
246  }
247 
248  if (plugin == NULL) {
249  cpl_msg_error(cpl_func, "Null plugin");
250  cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
251  }
252 
253  /* Verify plugin type */
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);
257  }
258 
259  /* Get the recipe */
260  recipe = (cpl_recipe *)plugin;
261 
262  /* Verify parameter and frame lists */
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);
266  }
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);
270  }
271 
272  /* Invoke the recipe */
273  recipe_status = gravity_p2vm(recipe->frames, recipe->parameters);
274 
275  /* Ensure DFS-compliance of the products */
276  if (cpl_dfs_update_product_header(recipe->frames)) {
277  if (!recipe_status) recipe_status = (int)cpl_error_get_code();
278  }
279 
280  if (!cpl_errorstate_is_equal(initial_errorstate)) {
281  /* Dump the error history since recipe execution start.
282  At this point the recipe cannot recover from the error */
283  cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
284  }
285 
286  return recipe_status;
287 }
288 
289 /*----------------------------------------------------------------------------*/
295 /*----------------------------------------------------------------------------*/
296 static int gravity_p2vm_destroy(cpl_plugin * plugin)
297 {
298  cpl_recipe * recipe;
299 
300  if (plugin == NULL) {
301  cpl_msg_error(cpl_func, "Null plugin");
302  cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
303  }
304 
305  /* Verify plugin type */
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);
309  }
310 
311  /* Get the recipe */
312  recipe = (cpl_recipe *)plugin;
313 
314  cpl_parameterlist_delete(recipe->parameters);
315 
316  return 0;
317 }
318 
319 /*----------------------------------------------------------------------------*/
327 /*----------------------------------------------------------------------------*/
328 static int gravity_p2vm(cpl_frameset * frameset,
329  const cpl_parameterlist * parlist)
330 {
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;
335 
336  cpl_frame * frame=NULL, * frame_p2vm=NULL;
337 
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;
344 
345  int nb_frame, nb_frame_gain = 0;
346 
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];
351  clock_t start;
352 
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));
356  }
357 
358  /* Message */
359  gravity_print_banner ();
360  cpl_msg_set_time_on();
361  cpl_msg_set_component_on();
362  gravi_msg_function_start(1);
363 
364 
365  /* Get the input frameset */
366  cpl_ensure_code(gravi_dfs_set_groups(frameset) == CPL_ERROR_NONE, cpl_error_get_code()) ;
367 
368  /* Init the used frameset */
369  used_frameset = cpl_frameset_new ();
370 
371  /* Extract DARK frameset */
372  dark_frameset = gravi_frameset_extract_dark_data (frameset);
373  darkcalib_frameset = gravi_frameset_extract_dark_map (frameset);
374 
375  /* Extract FLAT frameset */
376  flat_frameset = gravi_frameset_extract_flat_data (frameset);
377  flatcalib_frameset = gravi_frameset_extract_flat_map (frameset);
378 
379  /* Extract BAD frameset */
380  badcalib_frameset = gravi_frameset_extract_bad_map (frameset);
381 
382  /* Extract WAVE 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);
386 
387  /* Extract P2VM frameset */
388  p2vm_frameset = gravi_frameset_extract_p2vm_data (frameset);
389 
390  /* EKW 04/12/2018 Extract new calibration file wave_param frameset */
391  wave_param_frameset = gravi_frameset_extract_wave_param (frameset);
392 
393  /*
394  * (1) Identify and extract the dark file
395  */
396 
397  if (!cpl_frameset_is_empty (dark_frameset)) {
398  cpl_msg_info (cpl_func, " ***** Compute DARK map ***** ");
399 
400  /* Load this DARK_RAW */
401  frame = cpl_frameset_get_position (dark_frameset, 0);
402  data = gravi_data_load_rawframe (frame, used_frameset);
403  gravi_data_detector_cleanup (data, parlist);
404 
405  /* Compute the dark */
406  dark_map = gravi_compute_dark (data);
407  FREE (gravi_data_delete, data);
408 
409  CPLCHECK_CLEAN ("Cannot compute the DARK map");
410 
411  /* Save the dark map */
412  gravi_data_save_new (dark_map, frameset, NULL, NULL, parlist,
413  NULL, frame, "gravity_p2vm",
414  NULL, GRAVI_DARK_MAP);
415 
416  CPLCHECK_CLEAN ("Could not save the DARK map");
417  }
418  else if (!cpl_frameset_is_empty (darkcalib_frameset)) {
419  cpl_msg_info (cpl_func, " ***** Get DARK map ***** ");
420 
421  /* Load this DARK */
422  frame = cpl_frameset_get_position (darkcalib_frameset, 0);
423  dark_map = gravi_data_load_frame (frame, used_frameset);
424 
425  CPLCHECK_CLEAN ("Could not load the DARK map");
426 
427  /* This new DARK may be used latter for BADPIX */
428  cpl_frameset_insert (dark_frameset, cpl_frame_duplicate (frame));
429  }
430 
431 
432  /*
433  * (2) Identify and extract the BADPIX file
434  */
435 
436  if (!cpl_frameset_is_empty (badcalib_frameset)) {
437  cpl_msg_info (cpl_func, " ***** Get BAD pixel map ***** ");
438 
439  /* The BADPIX is already in the frameset */
440  frame = cpl_frameset_get_position (badcalib_frameset, 0);
441  badpix_map = gravi_data_load_frame (frame, used_frameset);
442  }
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 ***** ");
446 
447  /* Identify the flat files */
448  nb_frame_gain = cpl_frameset_get_size (flat_frameset);
449  raw_data = cpl_calloc (nb_frame_gain, sizeof(gravi_data *));
450 
451  /* Build the list of FLAT files and output file name */
452  for (int i = 0; i < nb_frame_gain; i++) {
453  frame = cpl_frameset_get_position (flat_frameset, i);
454  raw_data[i] = gravi_data_load_rawframe (frame, NULL);
455  gravi_data_detector_cleanup (raw_data[i], parlist);
456  }
457 
458  /* Compute it from the DARK and the FLAT_RAW */
459  badpix_map = gravi_compute_badpix (dark_map, raw_data,
460  nb_frame_gain, parlist);
461 
462  CPLCHECK_CLEAN("Cannot compute the BAD pixel from DARK and FLAT");
463 
464  /* Save the BADPIX */
465  frame = cpl_frameset_get_position (dark_frameset, 0);
466  gravi_data_save_new (badpix_map, frameset, NULL, NULL, parlist,
467  NULL, frame, "gravity_p2vm",
468  NULL, GRAVI_BAD_MAP);
469 
470  CPLCHECK_CLEAN ("Could not save the BAD pixel map");
471 
472  FREELOOP (gravi_data_delete, raw_data, nb_frame_gain);
473  }
474 
475  /*
476  * (3) Check that the FLAT map in the input frameset
477  */
478 
479  if (!cpl_frameset_is_empty(flatcalib_frameset)) {
480  cpl_msg_info (cpl_func, " ***** Get FLAT map ***** ");
481 
482  /* The FLAT is already in the frameset */
483  frame = cpl_frameset_get_position (flatcalib_frameset, 0);
484  profile_map = gravi_data_load_frame (frame, used_frameset);
485  }
486  else if (!cpl_frameset_is_empty (flat_frameset)) {
487  cpl_msg_info (cpl_func, " ***** Compute FLAT map ***** ");
488 
489 
490  /* Check calibs */
491  if (!badpix_map || !dark_map) {
492  ERROR_CLEAN (CPL_ERROR_ILLEGAL_INPUT, "Missing DARK or BAD in frameset");
493  }
494 
495  /* Identify the flat files */
496  nb_frame_gain = cpl_frameset_get_size (flat_frameset);
497  raw_data = cpl_malloc (nb_frame_gain * sizeof(gravi_data *));
498 
499  /* Build the list of FLAT files and output file name */
500  for (int i = 0; i < nb_frame_gain; i++) {
501  frame = cpl_frameset_get_position (flat_frameset, i);
502  raw_data[i] = gravi_data_load_rawframe (frame, used_frameset);
503  gravi_data_detector_cleanup (raw_data[i], parlist);
504  }
505 
506 
507  /* Compute the profile from the list of FLAT */
508  profile_map = gravi_compute_profile (raw_data, dark_map, badpix_map, nb_frame_gain, parlist);
509  CPLCHECK_CLEAN ("Cannot compute the FLAT profile");
510 
511  /* Compute the gain QC */
512  cpl_propertylist * gain_header;
513  gain_header = gravi_compute_gain (raw_data, nb_frame_gain, dark_map);
514  CPLCHECK_CLEAN ("Cannot compute the GAIN");
515 
516  /* Put the gain QC in profile_map */
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);
520 
521  /* Save the FLAT map */
522  frame = cpl_frameset_get_position (flat_frameset, 0);
523 
524  gravi_data_save_new (profile_map, frameset, NULL, NULL, parlist,
525  used_frameset, frame, "gravity_p2vm",
526  NULL, GRAVI_FLAT_MAP);
527 
528  CPLCHECK_CLEAN ("Could not save the FLAT profile_map");
529 
530  /* Free the list of files */
531  FREELOOP (gravi_data_delete, raw_data, nb_frame_gain);
532  }
533 
534  /*
535  * (4) Check and get the WAVE frame
536  */
537 
538  if (!cpl_frameset_is_empty (wavecalib_frameset)) {
539  cpl_msg_info (cpl_func, " ***** Get wave map ***** ");
540 
541  /* The WAVE in the frame_set is a calibrated wave */
542  frame = cpl_frameset_get_position (wavecalib_frameset, 0);
543  wave_map = gravi_data_load_frame (frame, used_frameset);
544  }
545  else if (!cpl_frameset_is_empty (wave_frameset)) {
546  cpl_msg_info (cpl_func, " ***** Process the WAVE_RAW ***** ");
547 
548  /* Check calibs */
549  if ( !badpix_map || !profile_map || !dark_map) {
550  ERROR_CLEAN (CPL_ERROR_ILLEGAL_INPUT, "Missing DARK, FLAT, or BAD in frameset");
551  }
552 
553  /* Create the WAVE product */
554  wave_map = gravi_data_new (0);
555 
556  /* Get the frame */
557  frame = cpl_frameset_get_position (wave_frameset, 0);
558 
559  /* Load WAVE_RAW SC */
560  snprintf(ext_regexp, 499, "^(%s|%s)$", GRAVI_IMAGING_DATA_SC_EXT, GRAVI_IMAGING_DETECTOR_SC_EXT);
561  gravi_data * wave_sc_data = gravi_data_load_rawframe_ext (frame, used_frameset, ext_regexp);
562  gravi_data_detector_cleanup (wave_sc_data, parlist);
563 
564  /* Reduce WAVE_RAW SC */
565  cpl_msg_info (cpl_func, "Extract SC SPECTRUM for WAVE_RAW");
566  spectrum_data = gravi_extract_spectrum (wave_sc_data, profile_map, dark_map,
567  badpix_map, NULL, parlist, GRAVI_DET_SC);
568  FREE (gravi_data_delete, wave_sc_data);
569 
570  /* Load WAVE_RAW FT */
571  snprintf(ext_regexp, 499, "^(%s|%s)$", GRAVI_IMAGING_DATA_FT_EXT, GRAVI_IMAGING_DETECTOR_FT_EXT);
572  gravi_data * wave_ft_data = gravi_data_load_rawframe_ext (frame, NULL, ext_regexp);
573 
574  /* Reduce WAVE_RAW FT */
575  cpl_msg_info (cpl_func, "Extract FT SPECTRUM for WAVE_RAW");
576  gravi_data * ft_spectrum_data = gravi_extract_spectrum (wave_ft_data, profile_map, dark_map,
577  badpix_map, NULL, parlist, GRAVI_DET_FT);
578  FREE (gravi_data_delete, wave_ft_data);
579 
580  /* Copy FT extensions to spectrum_data */
581  gravi_data_move_ext(spectrum_data, ft_spectrum_data, GRAVI_IMAGING_DETECTOR_FT_EXT);
582  gravi_data_move_ext(spectrum_data, ft_spectrum_data, GRAVI_SPECTRUM_DATA_FT_EXT);
583  cpl_propertylist_copy_property_regexp(gravi_data_get_header(spectrum_data),
584  gravi_data_get_header(ft_spectrum_data),
585  "^ESO QC ",0);
586  FREE (gravi_data_delete, ft_spectrum_data);
587 
588  /* Load WAVE_RAW metrology */
589  gravi_data * wave_met_data = gravi_data_load_rawframe_ext (frame, NULL, GRAVI_METROLOGY_EXT);
590 
591  /* Compute the P2VM of the MET from the WAVE_RAW */
592  cpl_msg_info (cpl_func, "Compute the P2VM_MET from WAVE_RAW");
593  cpl_table * met_table = gravi_data_get_table (wave_met_data, GRAVI_METROLOGY_EXT);
594  double lbd_met = gravi_pfits_get_met_wavelength_mean (gravi_data_get_header(wave_met_data), met_table);
595  cpl_table * p2vm_met = gravi_metrology_compute_p2vm (met_table, lbd_met);
596 
597  /* Set the P2VM_MET in WAVE */
598  gravi_data_add_table (wave_map, NULL, GRAVI_P2VM_MET_EXT, p2vm_met);
599 
600  CPLCHECK_CLEAN ("Cannot compute P2VM_MET");
601 
602  /* Computing OPDs */
603  cpl_msg_info (cpl_func, "Compute OPDs for WAVE_RAW");
604  gravi_wave_compute_opds (spectrum_data,
605  gravi_data_get_table (wave_met_data, GRAVI_METROLOGY_EXT),
606  GRAVI_DET_ALL);
607  FREE (gravi_data_delete, wave_met_data);
608 
609  CPLCHECK_CLEAN ("Cannot compute OPDs");
610 
611  /* Save the file with OPD_SC, OPD_FT, OI_VIS_MET */
612  if (gravi_param_get_bool (parlist,"gravity.dfs.debug-file")) {
613  gravi_data_save_new (spectrum_data, frameset, NULL, NULL, parlist,
614  used_frameset, frame, "gravity_p2vm",
615  NULL, "DEBUG");
616  }
617 
618  /* Compute wave calibration for FT */
619  gravi_compute_wave (wave_map, spectrum_data, GRAVI_FT, parlist);
620 
621  CPLCHECK_CLEAN ("Cannot compute wave for FT");
622 
623  /* Load and process the WAVESC_RAW (if any) */
624  if (!cpl_frameset_is_empty (wavesc_frameset)) {
625  /* Erase spectrum data */
626  cpl_msg_info (cpl_func, "Delete WAVE_RAW data");
627  FREE (gravi_data_delete, spectrum_data);
628 
629  cpl_msg_info (cpl_func, " ***** Process the WAVESC_RAW ***** ");
630 
631  /* Get the frame */
632  frame = cpl_frameset_get_position (wavesc_frameset, 0);
633 
634  /* Load WAVESC_RAW SC*/
635  snprintf(ext_regexp, 499, "^(%s|%s)$", GRAVI_IMAGING_DATA_SC_EXT, GRAVI_IMAGING_DETECTOR_SC_EXT);
636  gravi_data * wavesc_sc_data = gravi_data_load_rawframe_ext (frame, used_frameset, ext_regexp);
637  gravi_data_detector_cleanup (wavesc_sc_data, parlist);
638 
639  cpl_msg_info (cpl_func, "Extract SC SPECTRUM for WAVESC_RAW");
640  spectrum_data = gravi_extract_spectrum (wavesc_sc_data, profile_map, dark_map,
641  badpix_map, NULL, parlist, GRAVI_DET_SC);
642  CPLCHECK_CLEAN ("Cannot extract SC spectrum from WAVESC_RAW");
643  FREE (gravi_data_delete, wavesc_sc_data);
644 
645  /* Load WAVESC_RAW FT*/
646  snprintf(ext_regexp, 499, "^(%s|%s)$", GRAVI_IMAGING_DATA_FT_EXT, GRAVI_IMAGING_DETECTOR_FT_EXT);
647  gravi_data * wavesc_ft_data = gravi_data_load_rawframe_ext (frame, used_frameset, ext_regexp);
648 
649  cpl_msg_info (cpl_func, "Extract FT SPECTRUM for WAVESC_RAW");
650  gravi_data * ft_spectrum_data = gravi_extract_spectrum (wavesc_ft_data, profile_map, dark_map,
651  badpix_map, NULL, parlist, GRAVI_DET_FT);
652  CPLCHECK_CLEAN ("Cannot extract FT spectrum from WAVESC_RAW");
653  FREE (gravi_data_delete, wavesc_ft_data);
654 
655  /* Copy FT extensions to spectrum_data */
656  gravi_data_move_ext(spectrum_data, ft_spectrum_data, GRAVI_IMAGING_DETECTOR_FT_EXT);
657  gravi_data_move_ext(spectrum_data, ft_spectrum_data, GRAVI_SPECTRUM_DATA_FT_EXT);
658  cpl_propertylist_copy_property_regexp(gravi_data_get_header(spectrum_data),
659  gravi_data_get_header(ft_spectrum_data),
660  "^ESO QC ",0);
661  FREE (gravi_data_delete, ft_spectrum_data);
662 
663  /* Load WAVESC_RAW metrology */
664  gravi_data * wavesc_met_data = gravi_data_load_rawframe_ext (frame, NULL, GRAVI_METROLOGY_EXT);
665 
666  cpl_msg_info (cpl_func, "Compute OPDs for WAVESC_RAW");
667  gravi_wave_compute_opds (spectrum_data,
668  gravi_data_get_table (wavesc_met_data, GRAVI_METROLOGY_EXT),
669  GRAVI_DET_SC);
670  FREE (gravi_data_delete, wavesc_met_data);
671 
672  CPLCHECK_CLEAN ("Cannot process the WAVESC_RAW");
673 
674  /* Save the file with OPD_SC, OPD_FT, OI_VIS_MET */
675  if (gravi_param_get_bool (parlist,"gravity.dfs.debug-file")) {
676  gravi_data_save_new (spectrum_data, frameset, NULL, NULL,
677  parlist, used_frameset, frame, "gravity_p2vm",
678  NULL, "DEBUG");
679  }
680  }
681  else {
682  cpl_msg_warning (cpl_func, "No WAVESC_RAW in the SOF:"
683  " SC wavelength will be inaccurate");
684  }
685 
686  /* Compute wave calibration for SC */
687  gravi_compute_wave (wave_map, spectrum_data, GRAVI_SC, parlist);
688 
689  CPLCHECK_CLEAN ("Cannot compute wave for SC");
690 
691  /* Free the spectrum */
692  FREE (gravi_data_delete, spectrum_data);
693 
694  /* Compute the QC */
695  gravi_wave_qc (wave_map, profile_map);
696 
697  /* Save the WAVE map */
698  gravi_data_save_new (wave_map, frameset, NULL, NULL, parlist,
699  used_frameset, frame, "gravity_p2vm",
700  NULL, GRAVI_WAVE_MAP);
701 
702  CPLCHECK_CLEAN ("Could not save the WAVE map");
703  }
704 
705  /*
706  * Build the frameset for the P2VM
707  */
708 
709  /* Check if P2VM are provided */
710  if ( cpl_frameset_is_empty (p2vm_frameset) ) {
711  cpl_msg_info (cpl_func,"All RAW data reduced... stop recipe");
712  goto cleanup;
713  }
714 
715  /* Check calibs */
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");
718  }
719 
720  /* Add the FLAT_RAW and WAVE_RAW to the p2vm frameset */
721  if ( !cpl_frameset_is_empty (flat_frameset) )
722  cpl_frameset_join (p2vm_frameset, flat_frameset);
723 
724  if ( !cpl_frameset_is_empty (wave_frameset) )
725  cpl_frameset_join (p2vm_frameset, wave_frameset);
726 
727  /* Get the number of the p2vm frame contained in the frameset */
728  nb_frame = cpl_frameset_get_size (p2vm_frameset);
729 
730  /* Check if the 11 files are here */
731  if (nb_frame != 11) {
732  ERROR_CLEAN (CPL_ERROR_ILLEGAL_INPUT, "Missing P2VM in frameset");
733  }
734 
735  /*
736  * (6) Loop on files of the p2vm frameset
737  */
738 
739  /* Construction of the p2vm data. */
740  /* START EKW 04/12/2018 read wave parameter from calibration file - Load the WAVE_PARAM Parameter */
741  if (!cpl_frameset_is_empty (wave_param_frameset)) {
742  frame = cpl_frameset_get_position (wave_param_frameset, 0);
743  wave_param = gravi_data_load_frame (frame, used_frameset);
744  }
745  else
746  cpl_msg_error (cpl_func, "There is no WAVE_PARAM in the frameset");
747 
748  cpl_msg_info (cpl_func, " ***** Create the P2VM ***** ");
749  p2vm_map = gravi_create_p2vm (wave_map,wave_param);
750  CPLCHECK_CLEAN ("Cannot create the P2VM data");
751 
752  /* Loop on files */
753  int i_wave;
754  for (int i = 0; i < nb_frame; i++) {
755 
756  cpl_msg_info (cpl_func, " ***** file %d over %d ***** ", i+1, nb_frame );
757  current_frameset = cpl_frameset_duplicate (used_frameset);
758 
759  /* Load this frame */
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);
763  gravi_data * hdr_data = gravi_data_load_rawframe_ext (frame, current_frameset, ext_regexp);
764  CPLCHECK_CLEAN ("Cannot load data");
765 
766  /* Verbose the shutters */
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));
770 
771  /* Create the product filename as the first P2VM file (1-1-0-0).
772  * This is to ensure the run_gravi_reduce.py script check
773  * for the correct product */
774  if ( frame_p2vm==NULL && gravi_data_check_shutter (hdr_data, 1,1,0,0) )
775  {
776  cpl_msg_info (cpl_func,"Use this frame for the P2VM product");
777  frame_p2vm = frame;
778  }
779 
780  /*
781  * If all shutter open we just continue
782  */
783  if ( gravi_data_check_shutter (hdr_data, 1,1,1,1) ) {
784 
785  /* Here we go to next file */
786  cpl_msg_info (cpl_func, "Nothing to be done with the file... yet.");
787  i_wave = i;
788 
789  FREE (gravi_data_delete, hdr_data);
790  FREE (cpl_frameset_delete, current_frameset);
791  continue;
792  }
793  FREE (gravi_data_delete, hdr_data);
794  /* End if all shutters open */
795 
796  /* Load SC */
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);
798  gravi_data * sc_data = gravi_data_load_rawframe_ext (frame, current_frameset, ext_regexp);
799  gravi_data_detector_cleanup (sc_data, parlist);
800 
801  /* Extract SC spectrum */
802  preproc_data = gravi_extract_spectrum (sc_data, profile_map, dark_map,
803  badpix_map, NULL, parlist, GRAVI_DET_SC);
804  CPLCHECK_CLEAN ("Cannot extract spectrum");
805  FREE (gravi_data_delete, sc_data);
806 
807  /* Rescale SC to common wavelength */
808  gravi_align_spectrum (preproc_data, wave_map, p2vm_map, GRAVI_DET_SC, parlist);
809  CPLCHECK_CLEAN ("Cannot re-interpolate spectrum");
810 
811  /* Compute the part of the p2vm associated to this file */
812  gravi_compute_p2vm (p2vm_map, preproc_data, valid_trans, valid_CP, GRAVI_DET_SC);
813  CPLCHECK_CLEAN("Cannot compute the P2VM");
814 
815  /* Load FT */
816  snprintf(ext_regexp, 499, "^(%s|%s)$", GRAVI_IMAGING_DATA_FT_EXT, GRAVI_IMAGING_DETECTOR_FT_EXT);
817  gravi_data * ft_data = gravi_data_load_rawframe_ext (frame, NULL, ext_regexp);
818 
819  /* Extract FT spectrum */
820  gravi_data * ft_preproc_data = gravi_extract_spectrum (ft_data, profile_map, dark_map,
821  badpix_map, NULL, parlist, GRAVI_DET_FT);
822  FREE (gravi_data_delete, ft_data);
823  CPLCHECK_CLEAN ("Cannot extract spectrum");
824 
825  /* Rescale FT to common wavelength */
826  gravi_align_spectrum (ft_preproc_data, wave_map, p2vm_map, GRAVI_DET_FT, parlist);
827  CPLCHECK_CLEAN ("Cannot re-interpolate spectrum");
828 
829  /* Compute the part of the p2vm associated to this file */
830  gravi_compute_p2vm (p2vm_map, ft_preproc_data, valid_trans, valid_CP, GRAVI_DET_FT);
831  CPLCHECK_CLEAN("Cannot compute the P2VM");
832 
833  /* Copy FT extensions to spectrum_data */
834  gravi_data_move_ext(preproc_data, ft_preproc_data, GRAVI_IMAGING_DETECTOR_FT_EXT);
835  gravi_data_move_ext(preproc_data, ft_preproc_data, GRAVI_SPECTRUM_DATA_FT_EXT);
836  FREE (gravi_data_delete, ft_preproc_data);
837 
838  /* Option save the preproc file */
839  if (gravi_param_get_bool (parlist,"gravity.dfs.preproc-file")) {
840 
841  gravi_data_save_new (preproc_data, frameset, NULL, NULL, parlist,
842  current_frameset, frame, "gravity_p2vm",
843  NULL, GRAVI_PREPROC);
844  }
845 
846  /* Delete the preproc data */
847  start = clock();
848  FREE (gravi_data_delete,preproc_data);
849  cpl_msg_info(cpl_func, "Execution time to delete preproc_data : %f s",
850  (clock() - start) / (double)CLOCKS_PER_SEC);
851 
852  /* End loop on files to build the p2vm */
853  FREE (cpl_frameset_delete, current_frameset);
854  }
855 
856 
857  /*
858  * (7) P2VM normalization
859  */
860 
861  gravi_p2vm_normalisation (p2vm_map, valid_trans, valid_CP);
862  CPLCHECK_CLEAN("Cannot normalise the p2vm_map");
863 
864 
865  /*
866  * (8) Analyse the WAVE to get the phase correction
867  * and the internal spectrum to latter correct.
868  */
869 
870  cpl_msg_info (cpl_func, " ***** Analyse the WAVE file to calibrate the internal closure and transmission ***** ");
871 
872  /* Get the WAVE frame */
873  frame = cpl_frameset_get_position (p2vm_frameset, i_wave);
874 
875  /* Load SC 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);
877  gravi_data * wave_sc_data = gravi_data_load_rawframe_ext (frame, NULL, ext_regexp);
878  gravi_data_detector_cleanup (wave_sc_data, parlist);
879 
880  /* Extract SC spectrum */
881  preproc_data = gravi_extract_spectrum (wave_sc_data, profile_map, dark_map,
882  badpix_map, NULL, parlist, GRAVI_DET_SC);
883  CPLCHECK_CLEAN ("Cannot extract SC spectrum");
884 
885  /* Move extensions necessary to compute the p2vmred */
886  gravi_data_move_ext (preproc_data, wave_sc_data, GRAVI_ARRAY_GEOMETRY_EXT);
887  gravi_data_move_ext (preproc_data, wave_sc_data, GRAVI_OPTICAL_TRAIN_EXT);
888  FREE (gravi_data_delete, wave_sc_data);
889  CPLCHECK_CLEAN ("Cannot move ext");
890 
891  /* Rescale to common wavelength */
892  gravi_align_spectrum (preproc_data, wave_map, p2vm_map, GRAVI_DET_SC, parlist);
893  CPLCHECK_CLEAN ("Cannot re-interpolate SC spectrum");
894 
895  /* Compute P2VMRED */
896  p2vmred_data = gravi_compute_p2vmred(preproc_data, p2vm_map, "gravi_single",
897  parlist, GRAVI_DET_SC);
898  FREE (gravi_data_delete, preproc_data);
899  CPLCHECK_CLEAN ("Cannot apply p2vm");
900 
901  /* Load FT WAVE */
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);
903  gravi_data * wave_ft_data = gravi_data_load_rawframe_ext (frame, NULL, ext_regexp);
904 
905  /* Extract FT spectrum */
906  gravi_data * ft_preproc_data = gravi_extract_spectrum (wave_ft_data, profile_map, dark_map,
907  badpix_map, NULL, parlist, GRAVI_DET_FT);
908  CPLCHECK_CLEAN ("Cannot extract FT spectrum");
909 
910  /* Move extensions necessary to compute the p2vmred */
911  gravi_data_move_ext (ft_preproc_data, wave_ft_data, GRAVI_ARRAY_GEOMETRY_EXT);
912  gravi_data_move_ext (ft_preproc_data, wave_ft_data, GRAVI_OPTICAL_TRAIN_EXT);
913  FREE (gravi_data_delete, wave_ft_data);
914  CPLCHECK_CLEAN ("Cannot move ext");
915 
916  /* Rescale to common wavelength */
917  gravi_align_spectrum (ft_preproc_data, wave_map, p2vm_map, GRAVI_DET_FT, parlist);
918  CPLCHECK_CLEAN ("Cannot re-interpolate FT spectrum");
919 
920  /* Compute P2VMRED */
921  gravi_data * ft_p2vmred_data = gravi_compute_p2vmred(ft_preproc_data,
922  p2vm_map, "gravi_single", parlist, GRAVI_DET_FT);
923  FREE (gravi_data_delete, ft_preproc_data);
924  CPLCHECK_CLEAN ("Cannot apply p2vm");
925 
926  /* Merge extensions of SC and FT extracted spectra */
927  gravi_data_move_ext(p2vmred_data, ft_p2vmred_data, GRAVI_OI_WAVELENGTH_EXT);
928  gravi_data_move_ext(p2vmred_data, ft_p2vmred_data, GRAVI_OI_VIS_EXT);
929  gravi_data_move_ext(p2vmred_data, ft_p2vmred_data, GRAVI_OI_FLUX_EXT);
930  FREE (gravi_data_delete, ft_p2vmred_data);
931  CPLCHECK_CLEAN ("Cannot merge SC and FT extensions");
932 
933  /* Perform the phase correction */
934  if (!strcmp (gravi_param_get_string (parlist, "gravity.calib.phase-calibration"), "CLOSURE")) {
935  gravi_p2vm_phase_correction (p2vm_map, p2vmred_data, 0);
936  }
937  else if (!strcmp (gravi_param_get_string (parlist, "gravity.calib.phase-calibration"), "DISP")) {
938  gravi_p2vm_phase_correction (p2vm_map, p2vmred_data, 1);
939  }
940  else if (!strcmp (gravi_param_get_string (parlist, "gravity.calib.phase-calibration"), "FULL")) {
941  gravi_p2vm_phase_correction (p2vm_map, p2vmred_data, 2);
942  }
943  else {
944  cpl_msg_info (cpl_func, "P2VM phases are kept to zero (option phase-calibration=NONE)");
945  }
946  CPLCHECK_CLEAN ("Cannot recalibrate the P2VM phases");
947 
948  /* Add the OI_FLUX to further normalize the flux if needed */
949  gravi_p2vm_transmission (p2vm_map, p2vmred_data);
950  FREE (gravi_data_delete, p2vmred_data);
951 
952  CPLCHECK_CLEAN ("Cannot compute the transmission");
953 
954  /*
955  * (9) Create product frame, add DataFlow keywords, save the file, log the
956  * saved file in the input frameset. Note that the output filename
957  * is already created (from first P2VM file)
958  */
959 
960  gravi_data_save_new (p2vm_map, frameset, NULL, NULL, parlist,
961  used_frameset, frame_p2vm, "gravity_p2vm",
962  NULL, GRAVI_P2VM_MAP);
963 
964  CPLCHECK_CLEAN("Could not save the P2VM on the output file");
965 
966  /* Deallocation of all variables */
967  cleanup:
968  cpl_msg_info (cpl_func,"Cleanup memory");
969 
970  FREE (cpl_frameset_delete, dark_frameset);
971  FREE (cpl_frameset_delete, darkcalib_frameset);
972  FREE (cpl_frameset_delete, badcalib_frameset);
973  FREE (gravi_data_delete, spectrum_data);
974  FREE (gravi_data_delete, p2vmred_data);
975  FREE (gravi_data_delete, dark_map);
976  FREELOOP (gravi_data_delete, raw_data, nb_frame_gain);
977  FREE (gravi_data_delete, badpix_map);
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);
985  FREE (gravi_data_delete, data);
986  FREE (gravi_data_delete, preproc_data);
987  FREE (gravi_data_delete, dark_map);
988  FREE (gravi_data_delete, wave_map);
989  FREE (gravi_data_delete, profile_map);
990  FREELOOP (cpl_free, valid_CP, 2);
991  FREELOOP (cpl_free, valid_trans, 2);
992  FREE (gravi_data_delete, p2vm_map);
993  FREE (cpl_frameset_delete, p2vm_frameset);
994  FREE (cpl_frameset_delete, current_frameset);
995  FREE (cpl_frameset_delete, wave_param_frameset);
996  FREE (gravi_data_delete, wave_param);
997 
998  /* FIXME: check a *change* of cpl_state instead */
999  CPLCHECK_INT ("Could not cleanup memory");
1000 
1001  //This is a workaround to aliviate PIPE-6316. For some reason the allocation
1002  //pattern of the recipe causes malloc to keep many pages in the allocation
1003  //arena which are not returned to the OS (typically calling brk()).
1004  //This causes issues if there is a fork() call, since then the whole
1005  //address space of the parent is duplicated in the child. This is actually
1006  //the case with the system() call in esorex.
1007  //malloc_trim() is specific to GLIBC and will ask malloc() to return
1008  //as many pages as possible. The code is not portable, hence the guards
1009 #if defined(__linux__) && defined(__GLIBC__)
1010  malloc_trim(0);
1011 #endif
1012 
1013  gravi_msg_function_exit(1);
1014  return (int)cpl_error_get_code();
1015 }
1016 
1017 
gravi_data * gravi_data_new(int nb_ext)
Create an empty gravi_data.
Definition: gravi_data.c:102
cpl_error_code gravi_wave_qc(gravi_data *wave_map, gravi_data *profile_map)
Compute the QC parameters of the WAVE product.
Definition: gravi_wave.c:1891
gravi_data * gravi_data_load_frame(cpl_frame *frame, cpl_frameset *used_frameset)
Load a FITS file and create a gravi_data.
Definition: gravi_data.c:573
cpl_parameter * gravi_parameter_add_badpix(cpl_parameterlist *self)
Add badpix parameters to the input parameter list.
Definition: gravi_dfs.c:187
cpl_frameset * gravi_frameset_extract_dark_data(cpl_frameset *frameset)
Extract DARK_RAW frame from the input frameset.
Definition: gravi_dfs.c:913
gravi_data * gravi_data_load_rawframe(cpl_frame *frame, cpl_frameset *used_frameset)
Load a RAW FITS file and create a gravi_data.
Definition: gravi_data.c:690
cpl_error_code gravi_data_move_ext(gravi_data *output, gravi_data *input, const char *name)
Move extensions from one data to another.
Definition: gravi_data.c:1376
cpl_error_code gravi_p2vm_transmission(gravi_data *p2vm_map, gravi_data *p2vmred_data)
Compute the flux normalisation in the P2VM.
Definition: gravi_p2vm.c:1416
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.
Definition: gravi_p2vm.c:547
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.
Definition: gravi_wave.c:822
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.
Definition: gravi_p2vm.c:1195
cpl_error_code gravi_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
Definition: gravi_dfs.c:78
cpl_table * gravi_data_get_table(gravi_data *self, const char *extname)
Return a pointer on a table extension by its EXTNAME.
Definition: gravi_data.c:1716
cpl_propertylist * gravi_compute_gain(gravi_data **flats_data, int nrawgain, gravi_data *dark_map)
Compute mean detector gain.
Definition: gravi_calib.c:1505
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.
Definition: gravi_wave.c:2038
const char * gravi_get_license(void)
Get the pipeline copyright and license.
Definition: gravi_utils.c:104
cpl_parameter * gravi_parameter_add_profile(cpl_parameterlist *self)
Add profile parameters to the input parameter list.
Definition: gravi_dfs.c:212
cpl_error_code gravi_data_detector_cleanup(gravi_data *data, const cpl_parameterlist *parlist)
Perform self-bias correction to the SC raw data.
Definition: gravi_data.c:1086
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.
Definition: gravi_data.c:896
cpl_frameset * gravi_frameset_extract_p2vm_data(cpl_frameset *frameset)
Extract P2VM_RAW frame from the input frameset.
Definition: gravi_dfs.c:895
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.
Definition: gravi_calib.c:1760
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.
Definition: gravi_p2vm.c:836
cpl_parameter * gravi_parameter_add_wave(cpl_parameterlist *self)
Add wavelength calibration parameters to the input parameter list.
Definition: gravi_dfs.c:290
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.
Definition: gravi_data.c:734
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.
Definition: gravi_data.c:1909
gravi_data * gravi_create_p2vm(gravi_data *wave_map, gravi_data *wave_param)
Create a new P2VM map.
Definition: gravi_p2vm.c:414
void gravi_data_delete(gravi_data *self)
Delete a gravi data.
Definition: gravi_data.c:137
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.
Definition: gravi_calib.c:122
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.
Definition: gravi_calib.c:976