GRAVI Pipeline Reference Manual  1.2.3
gravity_vis.c
1 /* $Id: gravity_vis.c,v 1.29 2011/12/3 09:16:12 nazouaoui 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: nazouaoui $
23  * $Date: 2011/12/3 09:16:12 $
24  * $Revision: 1.29 $
25  * $Name: $
26  *
27  * History
28  * 12/11/2018 add static_param_frameset
29  * 26/11/2018 add static_param_frameset to call of gravi_reduce_acqcam
30  */
31 
32 #ifdef HAVE_CONFIG_H
33 #include <config.h>
34 #endif
35 
36 /*-----------------------------------------------------------------------------
37  Includes
38  -----------------------------------------------------------------------------*/
39 
40 #include <cpl.h>
41 #include <stdio.h>
42 #include <string.h>
43 #include <time.h>
44 #if defined(__linux__) && defined(__GLIBC__)
45 #include <malloc.h> //Needed for malloc_trim()
46 #endif
47 
48 #include "gravi_data.h"
49 #include "gravi_pfits.h"
50 #include "gravi_dfs.h"
51 
52 #include "gravi_utils.h"
53 
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"
60 
61 #include "gravi_signal.h"
62 #include "gravi_vis.h"
63 #include "gravi_tf.h"
64 
65 #include "gravi_preproc.h"
66 
67 /*-----------------------------------------------------------------------------
68  Private function prototypes
69  -----------------------------------------------------------------------------*/
70 
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 *);
75 
76 /*-----------------------------------------------------------------------------
77  Static variables
78  -----------------------------------------------------------------------------*/
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."
82  "\n"
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"
84  GRAVI_RECIPE_FLOW"\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"
110  "";
111 
112 /*-----------------------------------------------------------------------------
113  Function code
114  -----------------------------------------------------------------------------*/
115 
116 /*----------------------------------------------------------------------------*/
126 /*----------------------------------------------------------------------------*/
127 int cpl_plugin_get_info(cpl_pluginlist * list)
128 {
129  cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe );
130  cpl_plugin * plugin = &recipe->interface;
131 
132  if (cpl_plugin_init(plugin,
133  CPL_PLUGIN_API,
134  GRAVI_BINARY_VERSION,
135  CPL_PLUGIN_TYPE_RECIPE,
136  "gravity_vis",
137  gravity_vis_short,
138  gravity_vis_description,
139  "Nabih Azouaoui, Vincent Lapeyrere, JB. Le Bouquin",
140  PACKAGE_BUGREPORT,
142  gravity_vis_create,
143  gravity_vis_exec,
144  gravity_vis_destroy)) {
145  cpl_msg_error(cpl_func, "Plugin initialization failed");
146  (void)cpl_error_set_where(cpl_func);
147  return 1;
148  }
149 
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);
153  return 1;
154  }
155 
156  return 0;
157 }
158 
159 /*----------------------------------------------------------------------------*/
167 /*----------------------------------------------------------------------------*/
168 static int gravity_vis_create(cpl_plugin * plugin)
169 {
170  cpl_recipe * recipe;
171  cpl_parameter * p;
172 
173  /* Do not create the recipe if an error code is already set */
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();
178  }
179 
180  if (plugin == NULL) {
181  cpl_msg_error(cpl_func, "Null plugin");
182  cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
183  }
184 
185  /* Verify plugin type */
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);
189  }
190 
191  /* Get the recipe */
192  recipe = (cpl_recipe *)plugin;
193 
194  /* Create the parameters list in the cpl_recipe object */
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);
199  }
200 
201  /* Fill the parameters list */
202  int isCalib = 0;
203 
204  /* Use static names (output_procatg.fits) */
205  gravi_parameter_add_static_name (recipe->parameters);
206 
207  /* Intermediate files */
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);
213 
214  /* Averaging */
215  gravi_parameter_add_average_vis (recipe->parameters);
216 
217  /* Bias-method */
218  gravi_parameter_add_biasmethod (recipe->parameters);
219 
220  /* Extraction */
221  gravi_parameter_add_extract (recipe->parameters);
222  gravi_parameter_add_metrology (recipe->parameters);
223  // gravi_parameter_add_preproc (recipe->parameters); // now automatically handled in the preproc
224 
225  /* Snr, signal, rejectio flags, vis */
226  gravi_parameter_add_compute_snr (recipe->parameters, isCalib);
227  gravi_parameter_add_compute_signal (recipe->parameters, isCalib);
228  gravi_parameter_add_rejection (recipe->parameters, isCalib);
229  gravi_parameter_add_compute_vis (recipe->parameters, isCalib);
230 
231  /* Correct from internal transmission */
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);
243 
244  /* Average sky */
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);
252 
253  /* Reduce ACQ_CAM */
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);
260 
261  /* Wave color correction */
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);
268 
269  return 0;
270 }
271 
272 /*----------------------------------------------------------------------------*/
278 /*----------------------------------------------------------------------------*/
279 static int gravity_vis_exec(cpl_plugin * plugin)
280 {
281 
282  cpl_recipe * recipe;
283  int recipe_status;
284  cpl_errorstate initial_errorstate = cpl_errorstate_get();
285 
286 
287  /* Return immediately if an error code is already set */
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();
292  }
293 
294  if (plugin == NULL) {
295  cpl_msg_error(cpl_func, "Null plugin");
296  cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
297  }
298 
299  /* Verify plugin type */
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);
303  }
304 
305  /* Get the recipe */
306  recipe = (cpl_recipe *)plugin;
307 
308  /* Verify parameter and frame lists */
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);
312  }
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);
316  }
317 
318  /* Invoke the recipe */
319  recipe_status = gravity_vis(recipe->frames, recipe->parameters);
320 
321  /* Ensure DFS-compliance of the products */
322  if (cpl_dfs_update_product_header(recipe->frames)) {
323  if (!recipe_status){
324  recipe_status = (int)cpl_error_get_code();
325  }
326  }
327 
328  if (!cpl_errorstate_is_equal(initial_errorstate)) {
329  /* Dump the error history since recipe execution start.
330  At this point the recipe cannot recover from the error */
331  cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
332  }
333 
334  return recipe_status;
335 }
336 
337 /*----------------------------------------------------------------------------*/
343 /*----------------------------------------------------------------------------*/
344 static int gravity_vis_destroy(cpl_plugin * plugin)
345 {
346  cpl_recipe * recipe;
347 
348  if (plugin == NULL) {
349  cpl_msg_error(cpl_func, "Null plugin");
350  cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
351  }
352 
353  /* Verify plugin type */
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);
357  }
358 
359  /* Get the recipe */
360  recipe = (cpl_recipe *)plugin;
361 
362  cpl_parameterlist_delete(recipe->parameters);
363 
364  return 0;
365 }
366 
367 
368 /*----------------------------------------------------------------------------*/
376 /*----------------------------------------------------------------------------*/
377 static int gravity_vis(cpl_frameset * frameset,
378  const cpl_parameterlist * parlist)
379 {
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;
385 
386  cpl_frame * frame=NULL;
387 
388  const char * frame_tag=NULL;
389  char * proCatg = NULL, * mode=NULL, * redCatg = NULL, * skyCatg = NULL;
390 
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;
395 
396  int nb_frame, nb_sky;
397 
398  /* Message */
399  gravity_print_banner ();
400  cpl_msg_set_time_on();
401  cpl_msg_set_component_on();
402  gravi_msg_function_start(1);
403 
404  cpl_ensure_code(gravi_dfs_set_groups(frameset) == CPL_ERROR_NONE,
405  cpl_error_get_code()) ;
406 
407  /* Dispatch the frameset */
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);
411  dark_frameset = gravi_frameset_extract_dark_data (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);
420 
421  recipe_frameset = gravi_frameset_extract_fringe_data (frameset);
422  sky_frameset = gravi_frameset_extract_sky_data (frameset);
423 
424  /* To use this recipe the frameset must contain the p2vm, wave and
425  * gain calibration file. */
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");
438  goto cleanup;
439  }
440 
441  /* Insert calibration frame into the used frameset */
442  used_frameset = cpl_frameset_new();
443 
444  /*
445  * Identify the DARK in the input frameset
446  */
447 
448  if (!cpl_frameset_is_empty (dark_frameset)) {
449 
450  frame = cpl_frameset_get_position (dark_frameset, 0);
451  data = gravi_data_load_rawframe (frame, used_frameset);
452  gravi_data_patch (data, patch_frameset);
453  gravi_data_detector_cleanup (data, parlist);
454 
455  /* Compute dark */
456  dark_map = gravi_compute_dark (data);
457  FREE (gravi_data_delete, data);
458 
459  CPLCHECK_CLEAN ("Could not compute the DARK map");
460 
461  /* Save the dark map */
462  gravi_data_save_new (dark_map, frameset, NULL, NULL, parlist,
463  NULL, frame, "gravity_vis",
464  NULL, GRAVI_DARK_MAP);
465 
466  CPLCHECK_CLEAN ("Could not save the DARK map");
467  }
468  else if (!cpl_frameset_is_empty (darkcalib_frameset)) {
469 
470  frame = cpl_frameset_get_position (darkcalib_frameset, 0);
471  dark_map = gravi_data_load_frame (frame, used_frameset);
472 
473  CPLCHECK_CLEAN ("Could not load the DARK map");
474  }
475  else
476  cpl_msg_info (cpl_func, "There is no DARK in the frame set");
477 
478  /* Identify the BAD in the input frameset */
479  frame = cpl_frameset_get_position (badcalib_frameset, 0);
480  badpix_map = gravi_data_load_frame (frame, used_frameset);
481 
482  /* Identify the FLAT in the input frameset */
483  frame = cpl_frameset_get_position (flatcalib_frameset, 0);
484  profile_map = gravi_data_load_frame (frame, used_frameset);
485 
486  /* Identify the WAVE in the input frameset */
487  frame = cpl_frameset_get_position (wavecalib_frameset, 0);
488  wave_map = gravi_data_load_frame (frame, used_frameset);
489 
490  /* Identify the P2VM in the input frameset */
491  frame = cpl_frameset_get_position (p2vmcalib_frameset, 0);
492  p2vm_map = gravi_data_load_frame (frame, used_frameset);
493 
494  /* Load the DISP_MODEL in the input frameset */
495  if (!cpl_frameset_is_empty (dispcalib_frameset)) {
496  frame = cpl_frameset_get_position (dispcalib_frameset, 0);
497  disp_map = gravi_data_load_frame (frame, used_frameset);
498  }
499  else
500  cpl_msg_info (cpl_func, "There is no DISP_MODEL in the frameset");
501 
502  /* Load the DIODE_POSITION in the input frameset */
503  if (!cpl_frameset_is_empty (metpos_frameset)) {
504  frame = cpl_frameset_get_position (metpos_frameset, 0);
505  diodepos_data = gravi_data_load_frame (frame, used_frameset);
506  }
507  else
508  cpl_msg_info (cpl_func, "There is no DIODE_POSITION in the frameset");
509 
510  /* Load the EOP_PARAM */
511  if ( !cpl_frameset_is_empty (eop_frameset) ) {
512  frame = cpl_frameset_get_position (eop_frameset, 0);
513  eop_map = gravi_data_load_frame (frame, used_frameset);
514  }
515  else
516  cpl_msg_info (cpl_func, "There is no EOP_PARAM in the frameset");
517 
518  /* START EKW 12/11/2018 read constant parameter from calibration file */
519  /* Load the STATIC_PARAM Parameter */
520  if (!cpl_frameset_is_empty (static_param_frameset)) {
521  frame = cpl_frameset_get_position (static_param_frameset, 0);
522  static_param_data = gravi_data_load_frame (frame, used_frameset);
523  }
524  else
525  cpl_msg_info (cpl_func, "There is no STATIC_PARAM in the frameset");
526 
527  /* Load the DIAMETER_CAT */
528  if ( !cpl_frameset_is_empty (diamcat_frameset) ) {
529  frame = cpl_frameset_get_position (diamcat_frameset, 0);
530  diamcat_data = gravi_data_load_frame (frame, used_frameset);
531  }
532  else
533  cpl_msg_info (cpl_func, "There is no DIAMETER_CAT in the frameset");
534 
535 
536  CPLCHECK_CLEAN ("Error while loading the calibration maps");
537 
538  /*
539  * Select the PRO CATG (based on first frame)
540  */
541 
542  frame_tag = cpl_frame_get_tag (cpl_frameset_get_position (recipe_frameset, 0));
543 
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");
549  }
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");
555  }
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");
561  }
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");
567  }
568  else {
569  cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
570  "Cannot recognize the input DO.CATG");
571  goto cleanup;
572  }
573 
574  cpl_msg_info (cpl_func,"Mode of the first frame is: %s (will be used for all frames)", mode);
575 
576  /*
577  * Mode for the SKY
578  */
579  int averageSky = gravi_param_get_bool (parlist,"gravity.preproc.average-sky");
580 
581  /*
582  * Loop on input SKY frames to be reduced
583  */
584  nb_sky = cpl_frameset_get_size (sky_frameset);
585  sky_maps = cpl_calloc (CPL_MAX(nb_sky,1), sizeof(gravi_data*));
586 
587  for (int isky = 0; isky < nb_sky; isky++){
588 
589  /* Load the raw SKY */
590  cpl_msg_info (cpl_func, " ***** SKY %d over %d ***** ", isky+1, nb_sky);
591  frame = cpl_frameset_get_position (sky_frameset, isky);
592  data = gravi_data_load_rawframe (frame, used_frameset);
593  gravi_data_patch (data, patch_frameset);
594  gravi_data_detector_cleanup (data, parlist);
595 
596  /* Compute the SKY map */
597  sky_maps[isky] = gravi_compute_dark (data);
598  FREE (gravi_data_delete, data);
599 
600  CPLCHECK_CLEAN ("Error while computing the sky_map");
601 
602  /* Save the SKY map */
603  if (averageSky == 0) {
604  char filename_suffix[10];
605  snprintf(filename_suffix, 10, "%d", isky);
606  gravi_data_save_new (sky_maps[isky], frameset, NULL, filename_suffix,
607  parlist, NULL, frame, "gravity_vis",
608  NULL, skyCatg);
609  CPLCHECK_CLEAN ("Could not save the sky");
610  }
611  }
612 
613  /*
614  * Average the sky if requested
615  */
616 
617  if (averageSky == 1) {
618  cpl_msg_info (cpl_func, "Do a MASTER SKY from the %d skys", nb_sky);
619 
620  gravi_data * msky_map;
621  msky_map = gravi_average_dark (sky_maps, nb_sky);
622  CPLCHECK_CLEAN ("Cannot do master sky");
623 
624  gravi_data_save_new (msky_map, frameset, NULL, NULL,
625  parlist, sky_frameset,
626  cpl_frameset_get_position (sky_frameset, 0),
627  "gravity_vis", NULL, skyCatg);
628  CPLCHECK_CLEAN ("Cannot save master sky");
629 
630  /* Add all sky to used_frameset, and move pointers */
631  cpl_frameset_join (used_frameset, sky_frameset);
632  for (int isky = 0; isky < nb_sky; isky++)
633  FREE (gravi_data_delete, sky_maps[isky]);
634  sky_maps[0] = msky_map;
635  nb_sky = 1;
636  }
637 
638  /*
639  * Loop on input RAW frames to be reduced
640  */
641 
642  nb_frame = cpl_frameset_get_size (recipe_frameset);
643 
644  for (int ivis = 0; ivis < nb_frame; ivis++){
645  int isky;
646  char filename_suffix[10];
647  snprintf(filename_suffix, 10, "%d", ivis);
648  current_frameset = cpl_frameset_duplicate (used_frameset);
649 
650  cpl_msg_info (cpl_func, " ***** OBJECT %d over %d ***** ", ivis+1, nb_frame);
651 
652  /*
653  * Identify the SKY for this OBJECT
654  */
655  isky = nb_sky>0 ? ivis % nb_sky : 0;
656 
657  if (nb_sky == 0) {
658  /* No SKY */
659  cpl_msg_info (cpl_func, "There is no SKY in the frameset");
660  }
661  else if (averageSky) {
662  /* Use master SKY already computed, already in frameset */
663  cpl_msg_info (cpl_func, "Use MASTER SKY (already reduced)");
664  }
665  else {
666  /* SKY already computed, add in the used_frameset */
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);
669 
670  /* Add this frame to the current_frameset as well */
671  cpl_frameset_insert (current_frameset, cpl_frame_duplicate (frame));
672  }
673 
674  /*
675  * Reduce the OBJECT
676  */
677 
678  frame = cpl_frameset_get_position (recipe_frameset, ivis);
679  data = gravi_data_load_rawframe (frame, current_frameset);
680  gravi_data_patch (data, patch_frameset);
681  gravi_data_detector_cleanup (data, parlist);
682 
683  /* Option save the preproc file */
684  if (gravi_param_get_bool (parlist,"gravity.dfs.bias-subtracted-file")) {
685 
686  gravi_data_save_new (data, frameset, NULL, filename_suffix, parlist,
687  current_frameset, frame, "gravity_vis",
688  NULL, "BIAS_SUBTRACTED");
689 
690  CPLCHECK_CLEAN ("Cannot save the BIAS_SUBTRACTED product");
691  }
692 
693  /* Check the shutters */
694  if ( !gravi_data_check_shutter_open (data) ) {
695  cpl_msg_warning (cpl_func, "Shutter problem in the OBJECT");
696  }
697 
698  /* Extract spectrum */
699  preproc_data = gravi_extract_spectrum (data, profile_map, dark_map,
700  badpix_map, sky_maps[isky],
701  parlist, GRAVI_DET_ALL);
702  CPLCHECK_CLEAN ("Cannot extract spectrum");
703 
704  /* Option save the spectrum file */
705  if (gravi_param_get_bool (parlist,"gravity.dfs.spectrum-file")) {
706  gravi_data_save_new (preproc_data, frameset, NULL, filename_suffix,
707  parlist, current_frameset, frame,
708  "gravity_vis", NULL, GRAVI_SPECTRUM);
709  CPLCHECK_CLEAN ("Cannot save the SPECTRUM product");
710  }
711 
712  /* Rescale to common wavelength */
713  gravi_align_spectrum (preproc_data, wave_map, p2vm_map, GRAVI_DET_ALL, parlist);
714  CPLCHECK_CLEAN ("Cannot re-interpolate spectrum");
715 
716  /* Preproc the Acquisition Camera */
717  if (gravi_param_get_bool (parlist,"gravity.test.reduce-acq-cam")) {
718  gravi_preproc_acqcam (preproc_data, data, badpix_map);
719  CPLCHECK_CLEAN ("Cannot preproc ACQ");
720  }
721 
722  /* Option save the preproc file */
723  if (gravi_param_get_bool (parlist,"gravity.dfs.preproc-file")) {
724  gravi_data_save_new (preproc_data, frameset, NULL, filename_suffix,
725  parlist, current_frameset, frame,
726  "gravity_vis", NULL, GRAVI_PREPROC);
727  CPLCHECK_CLEAN ("Cannot save the PREPROC product");
728  }
729 
730  /* Copy metrology and subtract background to preproc */
731  gravi_data_move_ext (preproc_data, data, GRAVI_METROLOGY_EXT);
732  if (dark_map != NULL)
733  gravi_subtract_met_dark (preproc_data, dark_map);
734 
735  /* Move extensions from raw_data and delete it */
736  gravi_data_move_ext (preproc_data, data, GRAVI_ARRAY_GEOMETRY_EXT);
737  gravi_data_move_ext (preproc_data, data, GRAVI_OPTICAL_TRAIN_EXT);
738  gravi_data_move_ext (preproc_data, data, GRAVI_OPDC_EXT);
739  gravi_data_move_ext (preproc_data, data, GRAVI_FDDL_EXT);
740  FREE (gravi_data_delete, data);
741  CPLCHECK_CLEAN ("Cannot move ext");
742 
743  /* Compute the flux and visibilities for each telescope and
744  * per acquisition with the P2VM applied to preproc_data */
745  p2vmred_data = gravi_compute_p2vmred(preproc_data, p2vm_map, mode,
746  parlist, GRAVI_DET_ALL);
747  CPLCHECK_CLEAN ("Cannot apply p2vm to the preproc data");
748 
749  /* Reduce the Acquisition Camera and delete data */
750  if (gravi_param_get_bool (parlist,"gravity.test.reduce-acq-cam")) {
751  gravi_reduce_acqcam (p2vmred_data, preproc_data, static_param_data);
752  }
753 
754  /* Move extensions and delete preproc */
755  gravi_data_move_ext (p2vmred_data, preproc_data, GRAVI_IMAGING_DATA_ACQ_EXT);
756  gravi_data_move_ext (p2vmred_data, preproc_data, GRAVI_METROLOGY_EXT);
757  gravi_data_move_ext (p2vmred_data, preproc_data, GRAVI_FDDL_EXT);
758  gravi_data_move_ext (p2vmred_data, preproc_data, GRAVI_OPDC_EXT);
759  FREE (gravi_data_delete, preproc_data);
760  CPLCHECK_CLEAN ("Cannot delete preproc");
761 
762  /* Reduce the OPDC table */
763  gravi_compute_opdc_state (p2vmred_data);
764  CPLCHECK_CLEAN ("Cannot reduce OPDC");
765 
766  /* Reduce the metrology into OI_VIS_MET */
767  gravi_metrology_reduce (p2vmred_data, eop_map, static_param_data, diodepos_data, parlist);
768  CPLCHECK_CLEAN ("Cannot reduce metrology");
769 
770  /* Compute the uv and pointing directions with ERFA */
771  gravi_compute_pointing_uv (p2vmred_data, eop_map);
772  CPLCHECK_CLEAN ("Cannot compute pointing");
773 
774  /* Compute the QC0 about tau0 from piezo signals */
775  gravi_compute_tau0 (p2vmred_data);
776  CPLCHECK_CLEAN ("Cannot compute QC for tau0");
777 
778  /* Compute QC for the Fringe Tracker injection */
779  gravi_compute_qc_injection (p2vmred_data);
780  CPLCHECK_CLEAN ("Cannot compute QC for FT injection");
781 
782  /* Compute QC for the Fringe Tracker OPD calculation */
783  gravi_compute_qc_ft_opd_estimator (p2vmred_data);
784  CPLCHECK_CLEAN ("Cannot compute QC for FT OPD estimator");
785 
786  /* Compute the SNR_BOOT and GDELAY_BOOT */
787  gravi_compute_snr (p2vmred_data, parlist);
788  CPLCHECK_MSG ("Cannot compute SNR");
789 
790  /* Compute the signals for averaging */
791  gravi_compute_signals (p2vmred_data, disp_map, parlist);
792  CPLCHECK_MSG ("Cannot compute signals");
793 
794  /* Compute rejection flags for averaging */
795  gravi_compute_rejection (p2vmred_data, parlist);
796  CPLCHECK_MSG ("Cannot compute rejection flags signals");
797 
798  /* Save the p2vmreduced file */
799  if (gravi_param_get_bool (parlist,"gravity.dfs.p2vmred-file")) {
800 
801  gravi_data_save_new (p2vmred_data, frameset, NULL, filename_suffix,
802  parlist, current_frameset, frame,
803  "gravity_vis", NULL, redCatg);
804 
805  CPLCHECK_CLEAN ("Cannot save the P2VMREDUCED product");
806  }
807 
808  /* Loop on the wanted sub-integration */
809  cpl_size current_frame = 0;
810  while (current_frame >= 0)
811  {
812 
813  /* Visibility and flux are averaged and the followings
814  * are saved in tables VIS, VIS2 and T3 */
815  tmpvis_data = gravi_compute_vis (p2vmred_data, parlist, &current_frame);
816  CPLCHECK_CLEAN ("Cannot average the P2VMRED frames into VIS");
817 
818  /* Set the mean TIME and mean MJD if required */
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");
821  gravi_vis_force_time (tmpvis_data);
822  CPLCHECK_CLEAN ("Cannot average the TIME in OI_VIS");
823  }
824 
825  /* Merge with already existing */
826  if (vis_data == NULL) {
827  vis_data = tmpvis_data; tmpvis_data = NULL;
828  }
829  else {
830  cpl_msg_info (cpl_func,"Merge with previous OI_VIS");
831  gravi_data_append (vis_data, tmpvis_data, 1);
832  FREE (gravi_data_delete, tmpvis_data);
833  }
834 
835  }
836 
837 
838  /* Save the astro file, which is a lighter version of the p2vmreduced */
839  if (gravi_param_get_bool (parlist,"gravity.dfs.astro-file")) {
840 
841  gravi_data_clean_for_astro (p2vmred_data);
842  gravi_data_save_new (p2vmred_data, frameset, NULL, filename_suffix,
843  parlist, current_frameset, frame,
844  "gravity_vis", NULL, GRAVI_ASTROREDUCED);
845 
846  CPLCHECK_CLEAN ("Cannot save the ASTROREDUCED product");
847  }
848 
849  cpl_msg_info (cpl_func,"Free the p2vmreduced");
850  FREE (cpl_frameset_delete, current_frameset);
851  FREE (gravi_data_delete, p2vmred_data);
852 
853  }
854  /* End loop on the input files to reduce */
855 
856  /* Compute QC parameters */
857  gravi_compute_vis_qc (vis_data);
858 
859  /* Compute the QC parameters of the TF
860  * FIXME: compute QC TF only for CALIB star */
861  gravi_compute_tf_qc (vis_data, diamcat_data);
862 
863  /* Eventually flatten the OI_FLUX */
864  if (gravi_param_get_bool (parlist, "gravity.vis.flat-flux")) {
865 
866  cpl_msg_info (cpl_func, "Flatten the FLUX with the internal P2VM spectrum");
867  gravi_flat_flux (vis_data, p2vm_map);
868  CPLCHECK_CLEAN ("Cannot flat the OI_FLUX");
869 
870  } else {
871  cpl_msg_info (cpl_func, "Don't flatten the FLUX with the internal P2VM spectrum");
872  }
873 
874  /* Perform the normalisation of the SC vis2 and visamp
875  * to match those of the FT */
876  if (!strcmp (gravi_param_get_string (parlist, "gravity.vis.vis-correction-sc"), "FORCE")) {
877 
878  cpl_msg_info (cpl_func, "Align the SC visibilities on the FT");
879  gravi_normalize_sc_to_ft (vis_data);
880 
881  } else {
882  cpl_msg_info (cpl_func, "Don't align the SC visibilities on the FT");
883  }
884 
885  /* Correct the wavelength due to target color shifting */
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");
888  gravi_wave_correct_color (vis_data);
889  CPLCHECK_CLEAN ("Cannot compute the wavelength in OI_VIS");
890  } else {
891  cpl_msg_info (cpl_func, "Don't compute the wavelength shift due to target color");
892  }
893 
894  /* Co-add the observations if requested */
895  if (gravi_param_get_bool (parlist, "gravity.postprocess.average-vis")) {
896  gravi_average_vis (vis_data);
897 
898  } else {
899  cpl_msg_info (cpl_func, "Don't average the different observation (if any)");
900  }
901 
902  /* Recompute the TIME column from the MJD column
903  * in all OIFITS tables to follow standard */
904  gravi_vis_mjd_to_time (vis_data);
905 
906  /* Save the output data file based on the first frame of the frameset */
907  cpl_frameset_join (used_frameset, recipe_frameset);
908  frame = cpl_frameset_get_position (recipe_frameset, 0);
909 
910  gravi_data_save_new (vis_data, frameset, NULL, NULL, parlist,
911  used_frameset, frame, "gravity_vis", NULL, proCatg);
912 
913  CPLCHECK_CLEAN ("Cannot save the VIS product");
914 
915  /* Terminate the function */
916  goto cleanup;
917 
918 cleanup:
919  /* Deallocation of all variables */
920  cpl_msg_info(cpl_func,"Memory cleanup");
921 
922  FREELOOP (gravi_data_delete,sky_maps,nb_sky);
923  FREE (gravi_data_delete,dark_map);
924  FREE (gravi_data_delete,data);
925  FREE (gravi_data_delete,preproc_data);
926  FREE (gravi_data_delete,profile_map);
927  FREE (gravi_data_delete,disp_map);
928  FREE (gravi_data_delete,wave_map);
929  FREE (gravi_data_delete,badpix_map);
930  FREE (gravi_data_delete,p2vm_map);
931  FREE (gravi_data_delete,p2vmred_data);
932  FREE (gravi_data_delete,vis_data);
933  FREE (gravi_data_delete,tmpvis_data);
934  FREE (gravi_data_delete,diamcat_data);
935  FREE (gravi_data_delete,diodepos_data);
936  FREE (gravi_data_delete,eop_map);
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);
956  //This is a workaround to aliviate PIPE-6316. For some reason the allocation
957  //pattern of the recipe causes malloc to keep many pages in the allocation
958  //arena which are not returned to the OS (typically calling brk()).
959  //This causes issues if there is a fork() call, since then the whole
960  //address space of the parent is duplicated in the child. This is actually
961  //the case with the system() call in esorex.
962  //malloc_trim() is specific to GLIBC and will ask malloc() to return
963  //as many pages as possible. The code is not portable, hence the guards
964 #if defined(__linux__) && defined(__GLIBC__)
965  malloc_trim(0);
966 #endif
967 
968 
969  gravi_msg_function_exit(1);
970  return (int)cpl_error_get_code();
971 }
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.
Definition: gravi_data.c:573
cpl_error_code gravi_wave_correct_color(gravi_data *vis_data)
Create a OI_WAVELENGTH_CORR table with color corrected wavelength.
Definition: gravi_wave.c:1733
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_compute_vis_qc(gravi_data *vis_data)
The function compute the QC parameters for a VIS (averaged) data.
Definition: gravi_vis.c:2048
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.
Definition: gravi_acqcam.c:154
cpl_error_code gravi_compute_tf_qc(gravi_data *oi_vis, gravi_data *diamcat_data)
Fill QC parameters related to transfer function.
Definition: gravi_tf.c:992
cpl_error_code gravi_compute_snr(gravi_data *p2vmred_data, const cpl_parameterlist *parlist)
Compute real-time SNR and Group-Delay of the observation.
Definition: gravi_signal.c:511
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...
Definition: gravi_vis.c:1509
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_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 ...
Definition: gravi_vis.c:2403
gravi_data * gravi_average_dark(gravi_data **data, cpl_size ndata)
Average several DARK calibration map.
Definition: gravi_calib.c:440
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.
Definition: gravi_utils.c:104
cpl_error_code gravi_parameter_add_rejection(cpl_parameterlist *self, int isCalib)
Add rejection parameters to the input parameter list.
Definition: gravi_dfs.c:593
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.
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_error_code gravi_average_vis(gravi_data *oi_data)
Coadd the observations together.
Definition: gravi_vis.c:2750
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.
Definition: gravi_eop.c:480
cpl_error_code gravi_data_clean_for_astro(gravi_data *data)
Clean the data to keep only OIFITS extensions related to SC.
Definition: gravi_data.c:2054
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.
Definition: gravi_vis.c:3761
cpl_error_code gravi_normalize_sc_to_ft(gravi_data *vis_data)
Align the SC visibilities on the FT visibilities.
Definition: gravi_vis.c:2317
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...)
Definition: gravi_vis.c:2457
void gravi_data_delete(gravi_data *self)
Delete a gravi data.
Definition: gravi_data.c:137
int gravi_data_patch(gravi_data *file_to_patch, cpl_frameset *patch_frameset)
Load a RAW FITS file and create a gravi_data.
Definition: gravi_data.c:609
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.
Definition: gravi_data.c:290
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.
Definition: gravi_calib.c:122