GRAVI Pipeline Reference Manual  1.2.3
gravity_disp.c
1 /* $Id: gravity_disp.c,v 1.29 2015/01/10 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: 2015/01/10 09:16:12 $
24  * $Revision: 1.29 $
25  * $Name: $
26  *
27  * History
28  * 12/11/2018 add static_param_frameset / static_param_data
29  *
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 
45 #include "gravi_data.h"
46 #include "gravi_pfits.h"
47 #include "gravi_dfs.h"
48 
49 #include "gravi_utils.h"
50 
51 #include "gravi_calib.h"
52 #include "gravi_preproc.h"
53 #include "gravi_p2vmred.h"
54 #include "gravi_signal.h"
55 #include "gravi_vis.h"
56 #include "gravi_metrology.h"
57 #include "gravi_disp.h"
58 
59 
60 
61 
62 
63 /*-----------------------------------------------------------------------------
64  Private function prototypes
65  -----------------------------------------------------------------------------*/
66 
67 static int gravity_disp_create(cpl_plugin *);
68 static int gravity_disp_exec(cpl_plugin *);
69 static int gravity_disp_destroy(cpl_plugin *);
70 static int gravity_disp(cpl_frameset *, const cpl_parameterlist *);
71 
72 /*-----------------------------------------------------------------------------
73  Static variables
74  -----------------------------------------------------------------------------*/
75 
76 static char gravity_disp_short[] = "Calibrate the linearity and the dispersion of the differential delay lines.";
77 static char gravity_disp_description[] =
78  "This recipe is associated to the template GRAVI_all_disp. It measures the phases obtained on the internal source at the position of the Argon lines and various positions (= fiber stretch) of the Fibered Differential Delay Lines (FDDL). It deduces the linearity model and the dispersion model of the differential delay lines. These models are stored as polynomials versus wavelength.\n"
79  GRAVI_RECIPE_FLOW"\n"
80  "* Reduce all the input DISP files (see gravity_vis), write each product\n"
81  "* Compute the dispersion parameters from this entire dataset\n"
82  "* Write product\n"
83  GRAVI_RECIPE_INPUT"\n"
84  GRAVI_FLAT_MAP" : flat calibration (PRO.CATG="GRAVI_FLAT_MAP")\n"
85  GRAVI_BAD_MAP" : badpixel calibration (PRO.CATG="GRAVI_BAD_MAP") \n"
86  GRAVI_WAVE_MAP" : wave calibration (PRO.CATG="GRAVI_WAVE_MAP")\n"
87  GRAVI_P2VM_MAP" : p2vm calibration (PRO.CATG="GRAVI_P2VM_MAP")\n"
88  GRAVI_DARK_MAP" : dark calibration (PRO.CATG="GRAVI_DARK_MAP")\n"
89  GRAVI_WAVELAMP_MAP" : spectrum of Argon, with position of lines\n"
90  GRAVI_DISP_RAW" (>50) : raw dispersion\n"
91  GRAVI_RECIPE_OUTPUT"\n"
92  GRAVI_DISP_VIS" : intermediate product\n"
93  GRAVI_DISP_MODEL" : dispersion model of FDDL\n"
94  "";
95 
96 /*-----------------------------------------------------------------------------
97  Function code
98  -----------------------------------------------------------------------------*/
99 
100 /*----------------------------------------------------------------------------*/
110 /*----------------------------------------------------------------------------*/
111 int cpl_plugin_get_info(cpl_pluginlist * list)
112 {
113  cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe );
114  cpl_plugin * plugin = &recipe->interface;
115 
116  if (cpl_plugin_init(plugin,
117  CPL_PLUGIN_API,
118  GRAVI_BINARY_VERSION,
119  CPL_PLUGIN_TYPE_RECIPE,
120  "gravity_disp",
121  gravity_disp_short,
122  gravity_disp_description,
123  "Nabih Azouaoui, Vincent Lapeyrere, JB. Le Bouquin",
124  PACKAGE_BUGREPORT,
126  gravity_disp_create,
127  gravity_disp_exec,
128  gravity_disp_destroy)) {
129  cpl_msg_error(cpl_func, "Plugin initialization failed");
130  (void)cpl_error_set_where(cpl_func);
131  return 1;
132  }
133 
134  if (cpl_pluginlist_append(list, plugin)) {
135  cpl_msg_error(cpl_func, "Error adding plugin to list");
136  (void)cpl_error_set_where(cpl_func);
137  return 1;
138  }
139 
140  return 0;
141 }
142 
143 /*----------------------------------------------------------------------------*/
151 /*----------------------------------------------------------------------------*/
152 static int gravity_disp_create(cpl_plugin * plugin)
153 {
154  cpl_recipe * recipe;
155  // cpl_parameter * p;
156 
157  /* Do not create the recipe if an error code is already set */
158  if (cpl_error_get_code() != CPL_ERROR_NONE) {
159  cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
160  cpl_func, __LINE__, cpl_error_get_where());
161  return (int)cpl_error_get_code();
162  }
163 
164  if (plugin == NULL) {
165  cpl_msg_error(cpl_func, "Null plugin");
166  cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
167  }
168 
169  /* Verify plugin type */
170  if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
171  cpl_msg_error(cpl_func, "Plugin is not a recipe");
172  cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
173  }
174 
175  /* Get the recipe */
176  recipe = (cpl_recipe *)plugin;
177 
178  /* Create the parameters list in the cpl_recipe object */
179  recipe->parameters = cpl_parameterlist_new();
180  if (recipe->parameters == NULL) {
181  cpl_msg_error(cpl_func, "Parameter list allocation failed");
182  cpl_ensure_code(0, (int)CPL_ERROR_ILLEGAL_OUTPUT);
183  }
184 
185  /* Fill the parameters list */
186  int isCalib = 1;
187 
188  /* Use static names (output_procatg.fits) */
189  gravi_parameter_add_static_name (recipe->parameters);
190 
191  /* Intermediate files */
192  gravi_parameter_add_preproc_file (recipe->parameters);
193  gravi_parameter_add_p2vmred_file (recipe->parameters);
194  gravi_parameter_add_vis_file (recipe->parameters);
195 
196  /* Snr, signal, rejection, vis */
197  gravi_parameter_add_compute_snr (recipe->parameters, isCalib);
198  gravi_parameter_add_compute_signal (recipe->parameters, isCalib);
199  gravi_parameter_add_rejection (recipe->parameters, isCalib);
200  gravi_parameter_add_compute_vis (recipe->parameters, isCalib);
201 
202  return 0;
203 }
204 
205 /*----------------------------------------------------------------------------*/
211 /*----------------------------------------------------------------------------*/
212 static int gravity_disp_exec(cpl_plugin * plugin)
213 {
214 
215  cpl_recipe * recipe;
216  int recipe_status;
217  cpl_errorstate initial_errorstate = cpl_errorstate_get();
218 
219  /* Return immediately if an error code is already set */
220  if (cpl_error_get_code() != CPL_ERROR_NONE) {
221  cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
222  cpl_func, __LINE__, cpl_error_get_where());
223  return (int)cpl_error_get_code();
224  }
225 
226  if (plugin == NULL) {
227  cpl_msg_error(cpl_func, "Null plugin");
228  cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
229  }
230 
231  /* Verify plugin type */
232  if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
233  cpl_msg_error(cpl_func, "Plugin is not a recipe");
234  cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
235  }
236 
237  /* Get the recipe */
238  recipe = (cpl_recipe *)plugin;
239 
240  /* Verify parameter and frame lists */
241  if (recipe->parameters == NULL) {
242  cpl_msg_error(cpl_func, "Recipe invoked with NULL parameter list");
243  cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
244  }
245  if (recipe->frames == NULL) {
246  cpl_msg_error(cpl_func, "Recipe invoked with NULL frame set");
247  cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
248  }
249 
250  /* Invoke the recipe */
251  recipe_status = gravity_disp(recipe->frames, recipe->parameters);
252 
253  /* Ensure DFS-compliance of the products */
254 
255  if (cpl_dfs_update_product_header(recipe->frames)) {
256  if (!recipe_status){
257  recipe_status = (int)cpl_error_get_code();
258  }
259  }
260 
261  if (!cpl_errorstate_is_equal(initial_errorstate)) {
262  /* Dump the error history since recipe execution start.
263  At this point the recipe cannot recover from the error */
264  cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
265  }
266 
267  return recipe_status;
268 }
269 
270 /*----------------------------------------------------------------------------*/
276 /*----------------------------------------------------------------------------*/
277 static int gravity_disp_destroy(cpl_plugin * plugin)
278 {
279  cpl_recipe * recipe;
280 
281  if (plugin == NULL) {
282  cpl_msg_error(cpl_func, "Null plugin");
283  cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
284  }
285 
286  /* Verify plugin type */
287  if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
288  cpl_msg_error(cpl_func, "Plugin is not a recipe");
289  cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
290  }
291 
292  /* Get the recipe */
293  recipe = (cpl_recipe *)plugin;
294 
295  cpl_parameterlist_delete(recipe->parameters);
296 
297  return 0;
298 }
299 
300 
301 /*----------------------------------------------------------------------------*/
309 /*----------------------------------------------------------------------------*/
310 static int gravity_disp(cpl_frameset * frameset,
311  const cpl_parameterlist * parlist)
312 {
313  cpl_frameset * disp_frameset=NULL, * darkcalib_frameset=NULL,
314  * dark_frameset=NULL, * wavecalib_frameset=NULL,
315  * badcalib_frameset=NULL, * flatcalib_frameset=NULL, * dispvis_frameset=NULL,
316  * p2vmcalib_frameset=NULL, * wavelampcalib_frameset=NULL, *used_frameset=NULL,
317  * current_frameset=NULL, *static_param_frameset=NULL;
318 
319  cpl_frame * frame=NULL;
320 
321  gravi_data * disp_map = NULL, * data = NULL, * dark_map = NULL, * wave_map = NULL,
322  * profile_map = NULL, * badpix_map = NULL, * p2vmred_data = NULL, * preproc_data = NULL,
323  * p2vm_map = NULL, * vis_data = NULL, * tmpvis_data=NULL, * argon_data=NULL, * static_param_data=NULL;
324 
325  int nb_frame;
326 
327  /* Message */
328  gravity_print_banner ();
329  cpl_msg_set_time_on();
330  cpl_msg_set_component_on();
331  gravi_msg_function_start(1);
332 
333 
334  /* Identify the RAW and CALIB frames in the input frameset */
335  cpl_ensure_code(gravi_dfs_set_groups(frameset) == CPL_ERROR_NONE,
336  cpl_error_get_code()) ;
337 
338  /* Check if a DISP_VIS is already existing */
339  dispvis_frameset = gravi_frameset_extract_dispvis_data (frameset);
340 
341  /* Insert calibration frame into the used frameset */
342  used_frameset = cpl_frameset_new();
343 
344  /* EKW 12/11/2018 START */
345  /* Extract static param frameset */
346  static_param_frameset = gravi_frameset_extract_static_param (frameset);
347 
348  /* Load the STATIC_PARAM Parameter */
349  if (!cpl_frameset_is_empty (static_param_frameset)) {
350  frame = cpl_frameset_get_position (static_param_frameset, 0);
351  static_param_data = gravi_data_load_frame (frame, used_frameset);
352  }
353  else
354  cpl_msg_info (cpl_func, "There is no STATIC_PARAM in the frameset");
355  /* EKW 12/11/2018 END */
356 
357  /* No DISP_VIS, reduce all data */
358  if (cpl_frameset_is_empty (dispvis_frameset)){
359 
360  /* Identify the ARGON, P2VM, DISP, DARK, WAVE, FLAT, BADPIX frames */
361  wavelampcalib_frameset = gravi_frameset_extract_wavelamp_map (frameset);
362  p2vmcalib_frameset = gravi_frameset_extract_p2vm_map (frameset);
363  wavecalib_frameset = gravi_frameset_extract_wave_map (frameset);
364  flatcalib_frameset = gravi_frameset_extract_flat_map (frameset);
365  badcalib_frameset = gravi_frameset_extract_bad_map (frameset);
366 
367  darkcalib_frameset = gravi_frameset_extract_dark_map (frameset);
368  dark_frameset = gravi_frameset_extract_dark_data (frameset);
369 
370  disp_frameset = gravi_frameset_extract_disp_data (frameset);
371 
372  /* Check inputs */
373  if ( cpl_frameset_is_empty(p2vmcalib_frameset) ||
374  cpl_frameset_is_empty(wavecalib_frameset) ||
375  cpl_frameset_is_empty(flatcalib_frameset) ||
376  cpl_frameset_is_empty(badcalib_frameset) ||
377  ( cpl_frameset_is_empty(dark_frameset) &&
378  cpl_frameset_is_empty(darkcalib_frameset) ) ||
379  cpl_frameset_is_empty(disp_frameset) ||
380  cpl_frameset_is_empty(wavelampcalib_frameset) ) {
381 
382  cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
383  "Missing P2VM, DARK, BAD, WAVE, WAVELAMP, FLAT or DISP frames") ;
384  goto cleanup;
385  }
386 
387  /*
388  * Identify the DARK in the input frameset
389  */
390 
391  if (!cpl_frameset_is_empty (dark_frameset)) {
392 
393  frame = cpl_frameset_get_position (dark_frameset, 0);
394  data = gravi_data_load_rawframe (frame, used_frameset);
395  gravi_data_detector_cleanup (data, parlist);
396 
397  /* Compute dark */
398  dark_map = gravi_compute_dark (data);
399  FREE (gravi_data_delete, data);
400 
401  CPLCHECK_CLEAN ("Could not compute the DARK map");
402 
403  /* Save the dark map */
404  gravi_data_save_new (dark_map, frameset, NULL, NULL, parlist,
405  NULL, frame, "gravi_single",
406  NULL, GRAVI_DARK_MAP);
407 
408  CPLCHECK_CLEAN ("Could not save the DARK map");
409  }
410  else if (!cpl_frameset_is_empty (darkcalib_frameset)) {
411 
412  frame = cpl_frameset_get_position (darkcalib_frameset, 0);
413  dark_map = gravi_data_load_frame (frame, used_frameset);
414 
415  CPLCHECK_CLEAN ("Could not load the DARK map");
416  }
417  else
418  cpl_msg_error (cpl_func, "There is no DARK in the frame set");
419 
420  /* Identify the BAD in the input frameset */
421  frame = cpl_frameset_get_position (badcalib_frameset, 0);
422  badpix_map = gravi_data_load_frame (frame, used_frameset);
423 
424  /* Identify the FLAT in the input frameset */
425  frame = cpl_frameset_get_position (flatcalib_frameset, 0);
426  profile_map = gravi_data_load_frame (frame, used_frameset);
427 
428  /* Identify the WAVE in the input frameset */
429  frame = cpl_frameset_get_position (wavecalib_frameset, 0);
430  wave_map = gravi_data_load_frame (frame, used_frameset);
431 
432  /* Identify the P2VM in the input frameset */
433  frame = cpl_frameset_get_position (p2vmcalib_frameset, 0);
434  p2vm_map = gravi_data_load_frame (frame, used_frameset);
435 
436  CPLCHECK_CLEAN ("Error while loading the calibration map");
437 
438 
439  /*
440  * Loop on input DISP files
441  */
442 
443  nb_frame = cpl_frameset_get_size (disp_frameset);
444  for (int ivis = 0; ivis < nb_frame; ivis++) {
445  current_frameset = cpl_frameset_duplicate (used_frameset);
446 
447  cpl_msg_info (cpl_func, "*** Processing file %d over %d *** ", ivis+1, nb_frame);
448 
449  frame = cpl_frameset_get_position (disp_frameset, ivis);
450  data = gravi_data_load_rawframe (frame, current_frameset);
451  gravi_data_detector_cleanup (data, parlist);
452 
453  /* Extract spectrum */
454  preproc_data = gravi_extract_spectrum (data, profile_map, dark_map,
455  badpix_map, NULL, parlist,
456  GRAVI_DET_ALL);
457  CPLCHECK_CLEAN ("Cannot extract spectrum");
458 
459  /* Rescale to common wavelength */
460  gravi_align_spectrum (preproc_data, wave_map, p2vm_map, GRAVI_DET_ALL, parlist);
461  CPLCHECK_CLEAN ("Cannot re-interpolate spectrum");
462 
463  /* Move extensions from raw_data */
464  gravi_data_move_ext (preproc_data, data, GRAVI_ARRAY_GEOMETRY_EXT);
465  gravi_data_move_ext (preproc_data, data, GRAVI_OPTICAL_TRAIN_EXT);
466  gravi_data_move_ext (preproc_data, data, GRAVI_OPDC_EXT);
467  gravi_data_move_ext (preproc_data, data, GRAVI_FDDL_EXT);
468  gravi_data_move_ext (preproc_data, data, GRAVI_METROLOGY_EXT);
469  CPLCHECK_CLEAN ("Cannot move ext");
470 
471  FREE (gravi_data_delete,data);
472 
473  /* Option save the proproc file */
474  if (gravi_param_get_bool (parlist,"gravity.dfs.preproc-file")) {
475 
476  gravi_data_save_new (preproc_data, frameset, NULL, NULL, parlist,
477  current_frameset, frame, "gravity_disp",
478  NULL, GRAVI_PREPROC);
479 
480  CPLCHECK_CLEAN ("Could not save the preproc data");
481  }
482 
483  /* Compute the flux and visibilities for each telescope and
484  * per acquisition with the P2VM applied to preproc_data */
485  p2vmred_data = gravi_compute_p2vmred (preproc_data, p2vm_map,
486  "gravi_single", parlist, GRAVI_DET_ALL);
487  CPLCHECK_CLEAN ("Cannot apply p2vm to the preproc data");
488 
489  /* Move extensions and delete preproc */
490  gravi_data_move_ext (p2vmred_data, preproc_data, GRAVI_METROLOGY_EXT);
491  gravi_data_move_ext (p2vmred_data, preproc_data, GRAVI_FDDL_EXT);
492  gravi_data_move_ext (p2vmred_data, preproc_data, GRAVI_OPDC_EXT);
493  FREE (gravi_data_delete, preproc_data);
494  CPLCHECK_CLEAN ("Cannot delete preproc");
495 
496  /* Reduce the OPDC table */
497  gravi_compute_opdc_state (p2vmred_data);
498  CPLCHECK_CLEAN ("Cannot reduce OPDC");
499 
500  /* Reduce the metrology */
501  gravi_metrology_reduce (p2vmred_data, NULL, static_param_data, NULL, parlist);
502  CPLCHECK_CLEAN ("Cannot reduce metrology");
503 
504  /* Compute the SNR_SMT and GDELAY_SMT columns */
505  gravi_compute_snr (p2vmred_data, parlist);
506  CPLCHECK_MSG ("Cannot compute SNR");
507 
508  /* Compute the additional signals for averaging */
509  gravi_compute_signals (p2vmred_data, disp_map, parlist);
510  CPLCHECK_MSG ("Cannot compute signals");
511 
512  /* Compute rejection flags for averaging */
513  gravi_compute_rejection (p2vmred_data, parlist);
514  CPLCHECK_MSG ("Cannot rejection flags signals");
515 
516  /* Save the P2VMREDUCED */
517  if (gravi_param_get_bool (parlist,"gravity.dfs.p2vmred-file")) {
518 
519  gravi_data_save_new (p2vmred_data, frameset, NULL, NULL, parlist,
520  current_frameset, frame, "gravity_disp",
521  NULL, GRAVI_P2VMRED_SINGLE_CALIB);
522 
523  CPLCHECK_CLEAN ("Cannot save the P2VMREDUCED product");
524  }
525 
526 
527  /* Loop on the wanted sub-integration */
528  cpl_size current_frame = 0;
529  while (current_frame >= 0)
530  {
531 
532  /* Visibility and flux are averaged and the followings
533  * are saved in Visibility data in tables VIS, VIS2 and T3 */
534  tmpvis_data = gravi_compute_vis (p2vmred_data, parlist, &current_frame);
535  CPLCHECK_CLEAN ("Cannot average the visibilities");
536 
537  /* Compute QC parameters */
538  gravi_compute_vis_qc (tmpvis_data);
539 
540  /* Save the VIS */
541  if (gravi_param_get_bool (parlist,"gravity.dfs.vis-file")) {
542 
543  gravi_data_save_new (tmpvis_data, frameset, NULL, NULL, parlist,
544  current_frameset, frame, "gravity_disp",
545  NULL, GRAVI_VIS_SINGLE_CALIB);
546 
547  CPLCHECK_CLEAN ("Cannot save the VIS product");
548  }
549 
550  /* Merge with already existing */
551  if (vis_data == NULL) {
552  vis_data = tmpvis_data; tmpvis_data = NULL;
553  }
554  else {
555  cpl_msg_info (cpl_func,"Merge with previous OI_VIS");
556  gravi_data_append (vis_data, tmpvis_data, 1);
557  FREE (gravi_data_delete, tmpvis_data);
558  }
559  CPLCHECK_CLEAN ("Cannot merge the visibilities");
560 
561  }
562 
563  cpl_msg_info (cpl_func,"Free the p2vmreduced");
564  FREE (cpl_frameset_delete, current_frameset);
565  FREE (gravi_data_delete, p2vmred_data);
566  }
567  /* End loop on the input files to reduce */
568 
569  /* Recompute the TIME column from the MJD column
570  * in all OIFITS tables to follow standard */
571  gravi_vis_mjd_to_time (vis_data);
572 
573  /* Identify the WAVELAMP in the input frameset */
574  frame = cpl_frameset_get_position (wavelampcalib_frameset, 0);
575  argon_data = gravi_data_load_frame (frame, used_frameset);
576 
577  /* Duplicate POS_ARGON into the VIS file */
578  gravi_data_copy_ext (vis_data, argon_data, "POS_ARGON");
579 
580  /* Save the output data file based on the first frame of the frameset */
581  cpl_frameset_join (used_frameset, disp_frameset);
582  frame = cpl_frameset_get_position (disp_frameset, 0);
583 
584  gravi_data_save_new (vis_data, frameset, NULL, NULL, parlist,
585  used_frameset, frame, "gravity_disp",
586  NULL, GRAVI_DISP_VIS);
587 
588  CPLCHECK_CLEAN("Could not save the VIS_SINGLE product");
589 
590  FREE (gravi_data_delete, profile_map);
591  FREE (gravi_data_delete, dark_map);
592  FREE (gravi_data_delete, wave_map);
593  FREE (gravi_data_delete, badpix_map);
594  FREE (gravi_data_delete, p2vm_map);
595  FREE (cpl_frameset_delete, darkcalib_frameset);
596  FREE (cpl_frameset_delete, wavecalib_frameset);
597  FREE (cpl_frameset_delete, dark_frameset);
598  FREE (cpl_frameset_delete, flatcalib_frameset);
599  FREE (cpl_frameset_delete, badcalib_frameset);
600  FREE (cpl_frameset_delete, p2vmcalib_frameset);
601  FREE (cpl_frameset_delete, wavelampcalib_frameset);
602  }
603  else {
604 
605  /* Load the DIS_VIS already computed */
606  frame = cpl_frameset_get_position (dispvis_frameset, 0);
607  vis_data = gravi_data_load_frame (frame, used_frameset);
608 
609  CPLCHECK_CLEAN ("Cannot load the DISP_VIS file");
610 
611  disp_frameset = cpl_frameset_duplicate (dispvis_frameset);
612  }
613 
614  /*
615  * Compute the dispersion table of a set of disp frames
616  */
617 
618  gravi_disp_cleanup (vis_data);
619 
620  disp_map = gravi_compute_disp (vis_data);
621 
622  CPLCHECK_CLEAN ("Error while computing the disp_map");
623 
624  /* Create product frame */
625  frame = cpl_frameset_get_position (disp_frameset, 0);
626 
627  /* Save the DISP_MODEL */
628  gravi_data_save_new (disp_map, frameset, NULL, NULL, parlist,
629  used_frameset, frame, "gravity_disp",
630  NULL, GRAVI_DISP_MODEL);
631 
632  CPLCHECK_CLEAN("Could not save the DISP_MODEL product");
633 
634  /* Deallocation of all variables */
635  goto cleanup;
636 
637 cleanup :
638  cpl_msg_info(cpl_func,"Memory cleanup");
639  FREE (gravi_data_delete, data);
640  FREE (gravi_data_delete, tmpvis_data);
641  FREE (gravi_data_delete, vis_data);
642  FREE (gravi_data_delete, disp_map);
643  FREE (gravi_data_delete, dark_map);
644  FREE (gravi_data_delete, wave_map);
645  FREE (gravi_data_delete, profile_map);
646  FREE (gravi_data_delete, badpix_map);
647  FREE (gravi_data_delete, p2vmred_data);
648  FREE (gravi_data_delete, p2vm_map);
649  FREE (gravi_data_delete, preproc_data);
650  FREE (cpl_frameset_delete, disp_frameset);
651  FREE (cpl_frameset_delete, dispvis_frameset);
652  FREE (cpl_frameset_delete, darkcalib_frameset);
653  FREE (cpl_frameset_delete, dark_frameset);
654  FREE (cpl_frameset_delete, wavecalib_frameset);
655  FREE (cpl_frameset_delete, badcalib_frameset);
656  FREE (cpl_frameset_delete, flatcalib_frameset);
657  FREE (cpl_frameset_delete, p2vmcalib_frameset);
658  FREE (cpl_frameset_delete, wavelampcalib_frameset);
659  FREE (cpl_frameset_delete, used_frameset);
660  FREE (cpl_frameset_delete, current_frameset);
661 
662  gravi_msg_function_exit(1);
663  return (int)cpl_error_get_code();
664 }
665 
666 
cpl_error_code gravi_compute_opdc_state(gravi_data *p2vmred_data)
Compute the real-time tracking state from OPDC.
gravi_data * gravi_compute_disp(gravi_data *vis_data)
Compute the DISP_MODEL calibration map.
Definition: gravi_disp.c:113
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_data_copy_ext(gravi_data *output, gravi_data *input, const char *name)
Copy extensions from one data to another.
Definition: gravi_data.c:1325
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_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
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.
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_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_disp_cleanup(gravi_data *vis_data)
Cleanup a VIS gravi_data before calibrating the dispersion.
Definition: gravi_disp.c:359
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)
void gravi_data_delete(gravi_data *self)
Delete a gravi data.
Definition: gravi_data.c:137
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
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