GRAVI Pipeline Reference Manual 1.8.0
Loading...
Searching...
No Matches
gravity_disp.c
Go to the documentation of this file.
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
67static int gravity_disp_create(cpl_plugin *);
68static int gravity_disp_exec(cpl_plugin *);
69static int gravity_disp_destroy(cpl_plugin *);
70static int gravity_disp(cpl_frameset *, const cpl_parameterlist *);
71
72/*-----------------------------------------------------------------------------
73 Static variables
74 -----------------------------------------------------------------------------*/
75
76static char gravity_disp_short[] = "Calibrate the linearity and the dispersion of the differential delay lines.";
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"
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"
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"
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/*----------------------------------------------------------------------------*/
111int 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",
123 "Nabih Azouaoui, Vincent Lapeyrere, JB. Le Bouquin",
124 PACKAGE_BUGREPORT,
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/*----------------------------------------------------------------------------*/
152static 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_biassub_file (recipe->parameters);
193 gravi_parameter_add_spectrum_file (recipe->parameters);
194 gravi_parameter_add_preproc_file (recipe->parameters);
195 gravi_parameter_add_p2vmred_file (recipe->parameters);
196 gravi_parameter_add_astro_file (recipe->parameters);
197 gravi_parameter_add_vis_file (recipe->parameters);
198
199 /* Extraction */
200 gravi_parameter_add_extract (recipe->parameters);
201 gravi_parameter_add_metrology (recipe->parameters);
202
203 /* Snr, signal, rejection, vis */
204 gravi_parameter_add_compute_snr (recipe->parameters);
205 gravi_parameter_add_compute_signal (recipe->parameters);
206 gravi_parameter_add_rejection (recipe->parameters, isCalib);
207 gravi_parameter_add_compute_vis (recipe->parameters, isCalib);
208
209 return 0;
210}
211
212/*----------------------------------------------------------------------------*/
218/*----------------------------------------------------------------------------*/
219static int gravity_disp_exec(cpl_plugin * plugin)
220{
221
222 cpl_recipe * recipe;
223 int recipe_status;
224 cpl_errorstate initial_errorstate = cpl_errorstate_get();
225
226 /* Return immediately if an error code is already set */
227 if (cpl_error_get_code() != CPL_ERROR_NONE) {
228 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
229 cpl_func, __LINE__, cpl_error_get_where());
230 return (int)cpl_error_get_code();
231 }
232
233 if (plugin == NULL) {
234 cpl_msg_error(cpl_func, "Null plugin");
235 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
236 }
237
238 /* Verify plugin type */
239 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
240 cpl_msg_error(cpl_func, "Plugin is not a recipe");
241 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
242 }
243
244 /* Get the recipe */
245 recipe = (cpl_recipe *)plugin;
246
247 /* Verify parameter and frame lists */
248 if (recipe->parameters == NULL) {
249 cpl_msg_error(cpl_func, "Recipe invoked with NULL parameter list");
250 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
251 }
252 if (recipe->frames == NULL) {
253 cpl_msg_error(cpl_func, "Recipe invoked with NULL frame set");
254 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
255 }
256
257 /* Invoke the recipe */
258 recipe_status = gravity_disp(recipe->frames, recipe->parameters);
259
260 /* Ensure DFS-compliance of the products */
261
262 if (cpl_dfs_update_product_header(recipe->frames)) {
263 if (!recipe_status){
264 recipe_status = (int)cpl_error_get_code();
265 }
266 }
267
268 if (!cpl_errorstate_is_equal(initial_errorstate)) {
269 /* Dump the error history since recipe execution start.
270 At this point the recipe cannot recover from the error */
271 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
272 }
273
274 return recipe_status;
275}
276
277/*----------------------------------------------------------------------------*/
283/*----------------------------------------------------------------------------*/
284static int gravity_disp_destroy(cpl_plugin * plugin)
285{
286 cpl_recipe * recipe;
287
288 if (plugin == NULL) {
289 cpl_msg_error(cpl_func, "Null plugin");
290 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
291 }
292
293 /* Verify plugin type */
294 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
295 cpl_msg_error(cpl_func, "Plugin is not a recipe");
296 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
297 }
298
299 /* Get the recipe */
300 recipe = (cpl_recipe *)plugin;
301
302 cpl_parameterlist_delete(recipe->parameters);
303
304 return 0;
305}
306
307
308/*----------------------------------------------------------------------------*/
316/*----------------------------------------------------------------------------*/
317static int gravity_disp(cpl_frameset * frameset,
318 const cpl_parameterlist * parlist)
319{
320 cpl_frameset * disp_frameset=NULL, * darkcalib_frameset=NULL,
321 * dark_frameset=NULL, * wavecalib_frameset=NULL,
322 * badcalib_frameset=NULL, * flatcalib_frameset=NULL, * dispvis_frameset=NULL,
323 * p2vmcalib_frameset=NULL, * wavelampcalib_frameset=NULL, *used_frameset=NULL,
324 * current_frameset=NULL, *static_param_frameset=NULL;
325
326 cpl_frame * frame=NULL;
327
328 gravi_data * disp_map = NULL, * data = NULL, * dark_map = NULL, * wave_map = NULL,
329 * profile_map = NULL, * badpix_map = NULL, * p2vmred_data = NULL, * preproc_data = NULL,
330 * p2vm_map = NULL, * vis_data = NULL, * tmpvis_data=NULL, * argon_data=NULL, * static_param_data=NULL;
331
332 int nb_frame;
333
334 /* Message */
337
338
339 /* Identify the RAW and CALIB frames in the input frameset */
340 cpl_ensure_code(gravi_dfs_set_groups(frameset) == CPL_ERROR_NONE,
341 cpl_error_get_code()) ;
342
343 /* Check if a DISP_VIS is already existing */
344 dispvis_frameset = gravi_frameset_extract_dispvis_data (frameset);
345
346 /* Insert calibration frame into the used frameset */
347 used_frameset = cpl_frameset_new();
348
349 /* EKW 12/11/2018 START */
350 /* Extract static param frameset */
351 static_param_frameset = gravi_frameset_extract_static_param (frameset);
352
353 /* Load the STATIC_PARAM Parameter */
354 if (!cpl_frameset_is_empty (static_param_frameset)) {
355 frame = cpl_frameset_get_position (static_param_frameset, 0);
356 static_param_data = gravi_data_load_frame (frame, used_frameset);
357 }
358 else
359 cpl_msg_info (cpl_func, "There is no STATIC_PARAM in the frameset");
360 /* EKW 12/11/2018 END */
361
362 /* No DISP_VIS, reduce all data */
363 if (cpl_frameset_is_empty (dispvis_frameset)){
364
365 /* Identify the ARGON, P2VM, DISP, DARK, WAVE, FLAT, BADPIX frames */
366 wavelampcalib_frameset = gravi_frameset_extract_wavelamp_map (frameset);
367 p2vmcalib_frameset = gravi_frameset_extract_p2vm_map (frameset);
368 wavecalib_frameset = gravi_frameset_extract_wave_map (frameset);
369 flatcalib_frameset = gravi_frameset_extract_flat_map (frameset);
370 badcalib_frameset = gravi_frameset_extract_bad_map (frameset);
371
372 darkcalib_frameset = gravi_frameset_extract_dark_map (frameset);
373 dark_frameset = gravi_frameset_extract_dark_data (frameset);
374
375 disp_frameset = gravi_frameset_extract_disp_data (frameset);
376
377 /* Check inputs */
378 if ( cpl_frameset_is_empty(p2vmcalib_frameset) ||
379 cpl_frameset_is_empty(wavecalib_frameset) ||
380 cpl_frameset_is_empty(flatcalib_frameset) ||
381 cpl_frameset_is_empty(badcalib_frameset) ||
382 ( cpl_frameset_is_empty(dark_frameset) &&
383 cpl_frameset_is_empty(darkcalib_frameset) ) ||
384 cpl_frameset_is_empty(disp_frameset) ||
385 cpl_frameset_is_empty(wavelampcalib_frameset) ) {
386
387 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
388 "Missing P2VM, DARK, BAD, WAVE, WAVELAMP, FLAT or DISP frames") ;
389 goto cleanup;
390 }
391
392 /*
393 * Identify the DARK in the input frameset
394 */
395
396 if (!cpl_frameset_is_empty (dark_frameset)) {
397
398 frame = cpl_frameset_get_position (dark_frameset, 0);
399 data = gravi_data_load_rawframe (frame, used_frameset);
400 gravi_data_detector_cleanup (data, parlist);
401
402 /* Compute dark */
403 dark_map = gravi_compute_dark (data);
404 FREE (gravi_data_delete, data);
405
406 CPLCHECK_CLEAN ("Could not compute the DARK map");
407
408 /* Save the dark map */
409 gravi_data_save_new (dark_map, frameset, NULL, NULL, parlist,
410 NULL, frame, "gravi_single",
411 NULL, GRAVI_DARK_MAP);
412
413 CPLCHECK_CLEAN ("Could not save the DARK map");
414 }
415 else if (!cpl_frameset_is_empty (darkcalib_frameset)) {
416
417 frame = cpl_frameset_get_position (darkcalib_frameset, 0);
418 dark_map = gravi_data_load_frame (frame, used_frameset);
419
420 CPLCHECK_CLEAN ("Could not load the DARK map");
421 }
422 else
423 cpl_msg_error (cpl_func, "There is no DARK in the frame set");
424
425 /* Identify the BAD in the input frameset */
426 frame = cpl_frameset_get_position (badcalib_frameset, 0);
427 badpix_map = gravi_data_load_frame (frame, used_frameset);
428
429 /* Identify the FLAT in the input frameset */
430 frame = cpl_frameset_get_position (flatcalib_frameset, 0);
431 profile_map = gravi_data_load_frame (frame, used_frameset);
432
433 /* Identify the WAVE in the input frameset */
434 frame = cpl_frameset_get_position (wavecalib_frameset, 0);
435 wave_map = gravi_data_load_frame (frame, used_frameset);
436
437 /* Identify the P2VM in the input frameset */
438 frame = cpl_frameset_get_position (p2vmcalib_frameset, 0);
439 p2vm_map = gravi_data_load_frame (frame, used_frameset);
440
441 CPLCHECK_CLEAN ("Error while loading the calibration map");
442
443
444 /*
445 * Loop on input DISP files
446 */
447
448 nb_frame = cpl_frameset_get_size (disp_frameset);
449 for (int ivis = 0; ivis < nb_frame; ivis++) {
450 current_frameset = cpl_frameset_duplicate (used_frameset);
451
452 cpl_msg_info (cpl_func, "*** Processing file %d over %d *** ", ivis+1, nb_frame);
453
454 frame = cpl_frameset_get_position (disp_frameset, ivis);
455 data = gravi_data_load_rawframe (frame, current_frameset);
456 gravi_data_detector_cleanup (data, parlist);
457
458 /* Extract spectrum */
459 preproc_data = gravi_extract_spectrum (data, profile_map, dark_map,
460 badpix_map, NULL, parlist,
462 CPLCHECK_CLEAN ("Cannot extract spectrum");
463
464 /* Rescale to common wavelength */
465 gravi_align_spectrum (preproc_data, wave_map, p2vm_map, GRAVI_DET_ALL);
466 CPLCHECK_CLEAN ("Cannot re-interpolate spectrum");
467
468 /* Move extensions from raw_data */
469 gravi_data_move_ext (preproc_data, data, GRAVI_ARRAY_GEOMETRY_EXT);
470 gravi_data_move_ext (preproc_data, data, GRAVI_OPTICAL_TRAIN_EXT);
471 gravi_data_move_ext (preproc_data, data, GRAVI_OPDC_EXT);
472 gravi_data_move_ext (preproc_data, data, GRAVI_FDDL_EXT);
473 gravi_data_move_ext (preproc_data, data, GRAVI_METROLOGY_EXT);
474 CPLCHECK_CLEAN ("Cannot move ext");
475
476 FREE (gravi_data_delete,data);
477
478 /* Option save the proproc file */
479 if (gravi_param_get_bool (parlist,"gravity.dfs.preproc-file")) {
480
481 gravi_data_save_new (preproc_data, frameset, NULL, NULL, parlist,
482 current_frameset, frame, "gravity_disp",
483 NULL, GRAVI_PREPROC);
484
485 CPLCHECK_CLEAN ("Could not save the preproc data");
486 }
487
488 /* Compute the flux and visibilities for each telescope and
489 * per acquisition with the P2VM applied to preproc_data */
490 p2vmred_data = gravi_compute_p2vmred (preproc_data, p2vm_map,
491 "gravi_single", parlist);
492 CPLCHECK_CLEAN ("Cannot apply p2vm to the preproc data");
493
494 /* Move extensions and delete preproc */
495 gravi_data_move_ext (p2vmred_data, preproc_data, GRAVI_METROLOGY_EXT);
496 gravi_data_move_ext (p2vmred_data, preproc_data, GRAVI_FDDL_EXT);
497 gravi_data_move_ext (p2vmred_data, preproc_data, GRAVI_OPDC_EXT);
498 FREE (gravi_data_delete, preproc_data);
499 CPLCHECK_CLEAN ("Cannot delete preproc");
500
501 /* Reduce the OPDC table */
502 gravi_compute_opdc_state (p2vmred_data);
503 CPLCHECK_CLEAN ("Cannot reduce OPDC");
504
505 /* Reduce the metrology */
506 gravi_metrology_reduce (p2vmred_data, NULL, static_param_data, NULL, parlist);
507 CPLCHECK_CLEAN ("Cannot reduce metrology");
508
509 /* Find outliers */
510 gravi_compute_outliers (p2vmred_data, parlist);
511 CPLCHECK_MSG ("Cannot compute outliers");
512
513 /* Compute the SNR_SMT and GDELAY_SMT columns */
514 gravi_compute_snr (p2vmred_data, parlist);
515 CPLCHECK_MSG ("Cannot compute SNR");
516
517 /* Compute the additional signals for averaging */
518 gravi_compute_signals (p2vmred_data, disp_map, parlist);
519 CPLCHECK_MSG ("Cannot compute signals");
520
521 /* Compute rejection flags for averaging */
522 gravi_compute_rejection (p2vmred_data, parlist);
523 CPLCHECK_MSG ("Cannot rejection flags signals");
524
525 /* Save the P2VMREDUCED */
526 if (gravi_param_get_bool (parlist,"gravity.dfs.p2vmred-file")) {
527
528 gravi_data_save_new (p2vmred_data, frameset, NULL, NULL, parlist,
529 current_frameset, frame, "gravity_disp",
531
532 CPLCHECK_CLEAN ("Cannot save the P2VMREDUCED product");
533 }
534
535
536 /* Loop on the wanted sub-integration */
537 cpl_size current_frame = 0;
538 while (current_frame >= 0)
539 {
540
541 /* Visibility and flux are averaged and the followings
542 * are saved in Visibility data in tables VIS, VIS2 and T3 */
543 tmpvis_data = gravi_compute_vis (p2vmred_data, parlist, &current_frame);
544 CPLCHECK_CLEAN ("Cannot average the visibilities");
545
546 /* Compute QC parameters */
547 gravi_compute_vis_qc (tmpvis_data, 0);
548
549 /* Save the VIS */
550 if (gravi_param_get_bool (parlist,"gravity.dfs.vis-file")) {
551
552 gravi_data_save_new (tmpvis_data, frameset, NULL, NULL, parlist,
553 current_frameset, frame, "gravity_disp",
555
556 CPLCHECK_CLEAN ("Cannot save the VIS product");
557 }
558
559 /* Merge with already existing */
560 if (vis_data == NULL) {
561 vis_data = tmpvis_data; tmpvis_data = NULL;
562 }
563 else {
564 cpl_msg_info (cpl_func,"Merge with previous OI_VIS");
565 gravi_data_append (vis_data, tmpvis_data, 1);
566 FREE (gravi_data_delete, tmpvis_data);
567 }
568 CPLCHECK_CLEAN ("Cannot merge the visibilities");
569
570 }
571
572 /* Save the astro file, which is a lighter version of the p2vmreduced */
573 if (gravi_param_get_bool (parlist,"gravity.dfs.astro-file")) {
574
575 gravi_data_clean_for_astro (p2vmred_data);
576 gravi_data_save_new (p2vmred_data, frameset, NULL, NULL,
577 parlist, current_frameset, frame,
578 "gravity_vis", NULL, GRAVI_ASTROREDUCED);
579
580 CPLCHECK_CLEAN ("Cannot save the ASTROREDUCED product");
581 }
582
583 cpl_msg_info (cpl_func,"Free the p2vmreduced");
584 FREE (cpl_frameset_delete, current_frameset);
585 FREE (gravi_data_delete, p2vmred_data);
586 }
587 /* End loop on the input files to reduce */
588
589 /* Recompute the TIME column from the MJD column
590 * in all OIFITS tables to follow standard */
591 gravi_vis_mjd_to_time (vis_data);
592
593 /* Identify the WAVELAMP in the input frameset */
594 frame = cpl_frameset_get_position (wavelampcalib_frameset, 0);
595 argon_data = gravi_data_load_frame (frame, used_frameset);
596
597 /* Duplicate POS_ARGON into the VIS file */
598 gravi_data_copy_ext (vis_data, argon_data, "POS_ARGON");
599
600 /* Save the output data file based on the first frame of the frameset */
601 cpl_frameset_join (used_frameset, disp_frameset);
602 frame = cpl_frameset_get_position (disp_frameset, 0);
603
604 gravi_data_save_new (vis_data, frameset, NULL, NULL, parlist,
605 used_frameset, frame, "gravity_disp",
606 NULL, GRAVI_DISP_VIS);
607
608 CPLCHECK_CLEAN("Could not save the VIS_SINGLE product");
609
610 FREE (gravi_data_delete, profile_map);
611 FREE (gravi_data_delete, dark_map);
612 FREE (gravi_data_delete, wave_map);
613 FREE (gravi_data_delete, badpix_map);
614 FREE (gravi_data_delete, p2vm_map);
615 FREE (cpl_frameset_delete, darkcalib_frameset);
616 FREE (cpl_frameset_delete, wavecalib_frameset);
617 FREE (cpl_frameset_delete, dark_frameset);
618 FREE (cpl_frameset_delete, flatcalib_frameset);
619 FREE (cpl_frameset_delete, badcalib_frameset);
620 FREE (cpl_frameset_delete, p2vmcalib_frameset);
621 FREE (cpl_frameset_delete, wavelampcalib_frameset);
622 }
623 else {
624
625 /* Load the DIS_VIS already computed */
626 frame = cpl_frameset_get_position (dispvis_frameset, 0);
627 vis_data = gravi_data_load_frame (frame, used_frameset);
628
629 CPLCHECK_CLEAN ("Cannot load the DISP_VIS file");
630
631 disp_frameset = cpl_frameset_duplicate (dispvis_frameset);
632 }
633
634 /*
635 * Compute the dispersion table of a set of disp frames
636 */
637
638 gravi_disp_cleanup (vis_data);
639
640 disp_map = gravi_compute_disp (vis_data);
641
642 CPLCHECK_CLEAN ("Error while computing the disp_map");
643
644 /* Create product frame */
645 frame = cpl_frameset_get_position (disp_frameset, 0);
646
647 /* Save the DISP_MODEL */
648 gravi_data_save_new (disp_map, frameset, NULL, NULL, parlist,
649 used_frameset, frame, "gravity_disp",
650 NULL, GRAVI_DISP_MODEL);
651
652 CPLCHECK_CLEAN("Could not save the DISP_MODEL product");
653
654 /* Deallocation of all variables */
655 goto cleanup;
656
657cleanup :
658 cpl_msg_info(cpl_func,"Memory cleanup");
659 FREE (gravi_data_delete, data);
660 FREE (gravi_data_delete, tmpvis_data);
661 FREE (gravi_data_delete, vis_data);
662 FREE (gravi_data_delete, disp_map);
663 FREE (gravi_data_delete, dark_map);
664 FREE (gravi_data_delete, wave_map);
665 FREE (gravi_data_delete, profile_map);
666 FREE (gravi_data_delete, badpix_map);
667 FREE (gravi_data_delete, p2vmred_data);
668 FREE (gravi_data_delete, p2vm_map);
669 FREE (gravi_data_delete, preproc_data);
670 FREE (cpl_frameset_delete, disp_frameset);
671 FREE (cpl_frameset_delete, dispvis_frameset);
672 FREE (cpl_frameset_delete, darkcalib_frameset);
673 FREE (cpl_frameset_delete, dark_frameset);
674 FREE (cpl_frameset_delete, wavecalib_frameset);
675 FREE (cpl_frameset_delete, badcalib_frameset);
676 FREE (cpl_frameset_delete, flatcalib_frameset);
677 FREE (cpl_frameset_delete, p2vmcalib_frameset);
678 FREE (cpl_frameset_delete, wavelampcalib_frameset);
679 FREE (cpl_frameset_delete, used_frameset);
680 FREE (cpl_frameset_delete, current_frameset);
681
683 return (int)cpl_error_get_code();
684}
685
686
typedefCPL_BEGIN_DECLS struct _gravi_data_ gravi_data
Definition: gravi_data.h:38
#define GRAVI_RECIPE_OUTPUT
Definition: gravi_dfs.h:39
#define GRAVI_P2VMRED_SINGLE_CALIB
Definition: gravi_dfs.h:63
#define GRAVI_PREPROC
Definition: gravi_dfs.h:60
#define GRAVI_P2VM_MAP
Definition: gravi_dfs.h:76
#define GRAVI_RECIPE_FLOW
Definition: gravi_dfs.h:37
#define GRAVI_ASTROREDUCED
Definition: gravi_dfs.h:67
#define GRAVI_DISP_RAW
Definition: gravi_dfs.h:45
#define GRAVI_BAD_MAP
Definition: gravi_dfs.h:73
#define GRAVI_WAVE_MAP
Definition: gravi_dfs.h:75
#define GRAVI_DISP_MODEL
Definition: gravi_dfs.h:79
#define GRAVI_FLAT_MAP
Definition: gravi_dfs.h:74
#define GRAVI_WAVELAMP_MAP
Definition: gravi_dfs.h:85
#define GRAVI_DARK_MAP
Definition: gravi_dfs.h:77
#define GRAVI_RECIPE_INPUT
Definition: gravi_dfs.h:38
#define GRAVI_VIS_SINGLE_CALIB
Definition: gravi_dfs.h:97
#define GRAVI_DISP_VIS
Definition: gravi_dfs.h:59
cpl_msg_info(cpl_func, "Compute WAVE_SCAN for %s", GRAVI_TYPE(type_data))
#define GRAVI_OPDC_EXT
Definition: gravi_pfits.h:62
#define GRAVI_FDDL_EXT
Definition: gravi_pfits.h:75
@ GRAVI_DET_ALL
Definition: gravi_pfits.h:173
#define GRAVI_ARRAY_GEOMETRY_EXT
Definition: gravi_pfits.h:84
#define GRAVI_METROLOGY_EXT
Definition: gravi_pfits.h:60
#define GRAVI_OPTICAL_TRAIN_EXT
Definition: gravi_pfits.h:85
#define CPLCHECK_CLEAN(msg)
Definition: gravi_utils.h:54
#define gravi_msg_function_exit(flag)
Definition: gravi_utils.h:85
#define FREE(function, variable)
Definition: gravi_utils.h:69
#define gravi_msg_function_start(flag)
Definition: gravi_utils.h:84
#define CPLCHECK_MSG(msg)
Definition: gravi_utils.h:45
static char gravity_disp_description[]
Definition: gravity_disp.c:77
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
Definition: gravity_disp.c:111
static int gravity_disp_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
Definition: gravity_disp.c:219
static int gravity_disp_create(cpl_plugin *)
Setup the recipe options
Definition: gravity_disp.c:152
static int gravity_disp(cpl_frameset *, const cpl_parameterlist *)
The perpese of the recipe is to reduce the raw calibration file for dispersion calibration.
Definition: gravity_disp.c:317
static int gravity_disp_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
Definition: gravity_disp.c:284
static char gravity_disp_short[]
Definition: gravity_disp.c:76
gravi_data * gravi_compute_dark(gravi_data *raw_data)
Compute the DARK calibration map.
Definition: gravi_calib.c:125
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:2435
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:599
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:1232
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:716
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:1741
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:308
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:925
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:1690
void gravi_data_delete(gravi_data *self)
Delete a gravi data.
Definition: gravi_data.c:146
cpl_parameter * gravi_parameter_add_astro_file(cpl_parameterlist *self)
Definition: gravi_dfs.c:569
int gravi_param_get_bool(const cpl_parameterlist *parlist, const char *name)
Definition: gravi_dfs.c:1537
cpl_parameter * gravi_parameter_add_static_name(cpl_parameterlist *self)
Definition: gravi_dfs.c:464
cpl_parameter * gravi_parameter_add_p2vmred_file(cpl_parameterlist *self)
Definition: gravi_dfs.c:539
cpl_parameter * gravi_parameter_add_metrology(cpl_parameterlist *self)
Definition: gravi_dfs.c:615
cpl_error_code gravi_parameter_add_rejection(cpl_parameterlist *self, int isCalib)
Add rejection parameters to the input parameter list.
Definition: gravi_dfs.c:873
cpl_error_code gravi_parameter_add_compute_snr(cpl_parameterlist *self)
Definition: gravi_dfs.c:779
cpl_parameter * gravi_parameter_add_extract(cpl_parameterlist *self)
Definition: gravi_dfs.c:686
cpl_parameter * gravi_parameter_add_vis_file(cpl_parameterlist *self)
Definition: gravi_dfs.c:554
cpl_frameset * gravi_frameset_extract_wave_map(cpl_frameset *frameset)
Definition: gravi_dfs.c:1410
cpl_frameset * gravi_frameset_extract_disp_data(cpl_frameset *frameset)
Definition: gravi_dfs.c:1297
cpl_frameset * gravi_frameset_extract_dispvis_data(cpl_frameset *frameset)
Definition: gravi_dfs.c:1348
cpl_frameset * gravi_frameset_extract_bad_map(cpl_frameset *frameset)
Definition: gravi_dfs.c:1414
cpl_parameter * gravi_parameter_add_spectrum_file(cpl_parameterlist *self)
Definition: gravi_dfs.c:509
cpl_frameset * gravi_frameset_extract_dark_map(cpl_frameset *frameset)
Definition: gravi_dfs.c:1406
cpl_frameset * gravi_frameset_extract_wavelamp_map(cpl_frameset *frameset)
Definition: gravi_dfs.c:1360
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_parameter * gravi_parameter_add_preproc_file(cpl_parameterlist *self)
Definition: gravi_dfs.c:524
cpl_frameset * gravi_frameset_extract_p2vm_map(cpl_frameset *frameset)
Definition: gravi_dfs.c:1398
cpl_frameset * gravi_frameset_extract_static_param(cpl_frameset *frameset)
Definition: gravi_dfs.c:1430
cpl_error_code gravi_parameter_add_compute_vis(cpl_parameterlist *self, int isCalib)
Definition: gravi_dfs.c:952
cpl_parameter * gravi_parameter_add_biassub_file(cpl_parameterlist *self)
Definition: gravi_dfs.c:494
cpl_frameset * gravi_frameset_extract_flat_map(cpl_frameset *frameset)
Definition: gravi_dfs.c:1402
void gravity_print_banner(void)
Definition: gravi_dfs.c:61
cpl_frameset * gravi_frameset_extract_dark_data(cpl_frameset *frameset)
Extract DARK_RAW frame from the input frameset.
Definition: gravi_dfs.c:1311
cpl_error_code gravi_parameter_add_compute_signal(cpl_parameterlist *self)
Definition: gravi_dfs.c:818
gravi_data * gravi_compute_disp(gravi_data *vis_data)
Compute the DISP_MODEL calibration map.
Definition: gravi_disp.c:113
cpl_error_code gravi_disp_cleanup(gravi_data *vis_data)
Cleanup a VIS gravi_data before calibrating the dispersion.
Definition: gravi_disp.c:360
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_compute_opdc_state(gravi_data *p2vmred_data)
Compute the real-time tracking state from OPDC.
gravi_data * gravi_compute_p2vmred(gravi_data *preproc_data, gravi_data *p2vm_map, const char *mode, const cpl_parameterlist *parlist)
Converts preprocessed data into coherent fluxes using the P2VM.
cpl_error_code gravi_align_spectrum(gravi_data *spectrum_data, gravi_data *wave_map, gravi_data *p2vm_map, enum gravi_detector_type det_type)
Regrid the regions into a common wavelength (in-place)
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_compute_snr(gravi_data *p2vmred_data, const cpl_parameterlist *parlist)
Compute real-time SNR and Group-Delay of the observation.
Definition: gravi_signal.c:620
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.
cpl_error_code gravi_compute_outliers(gravi_data *p2vmred_data, const cpl_parameterlist *parlist)
Compute the outliers flags.
Definition: gravi_signal.c:536
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
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:1676
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:2651
cpl_error_code gravi_compute_vis_qc(gravi_data *vis_data, cpl_frameset *frameset)
The function compute the QC parameters for a VIS (averaged) data.
Definition: gravi_vis.c:2235