GRAVI Pipeline Reference Manual 1.9.4
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 cpl_propertylist ** p2vm_qcs = NULL;
332
333 int nb_frame;
334
335 /* Message */
338
339
340 /* Identify the RAW and CALIB frames in the input frameset */
341 cpl_ensure_code(gravi_dfs_set_groups(frameset) == CPL_ERROR_NONE,
342 cpl_error_get_code()) ;
343
344 /* Check if a DISP_VIS is already existing */
345 dispvis_frameset = gravi_frameset_extract_dispvis_data (frameset);
346
347 /* Insert calibration frame into the used frameset */
348 used_frameset = cpl_frameset_new();
349
350 /* EKW 12/11/2018 START */
351 /* Extract static param frameset */
352 static_param_frameset = gravi_frameset_extract_static_param (frameset);
353
354 /* Load the STATIC_PARAM Parameter */
355 if (!cpl_frameset_is_empty (static_param_frameset)) {
356 frame = cpl_frameset_get_position (static_param_frameset, 0);
357 static_param_data = gravi_data_load_frame (frame, used_frameset);
358 }
359 else
360 cpl_msg_info (cpl_func, "There is no STATIC_PARAM in the frameset");
361 /* EKW 12/11/2018 END */
362
363 /* No DISP_VIS, reduce all data */
364 if (cpl_frameset_is_empty (dispvis_frameset)){
365
366 /* Identify the ARGON, P2VM, DISP, DARK, WAVE, FLAT, BADPIX frames */
367 wavelampcalib_frameset = gravi_frameset_extract_wavelamp_map (frameset);
368 p2vmcalib_frameset = gravi_frameset_extract_p2vm_map (frameset);
369 wavecalib_frameset = gravi_frameset_extract_wave_map (frameset);
370 flatcalib_frameset = gravi_frameset_extract_flat_map (frameset);
371 badcalib_frameset = gravi_frameset_extract_bad_map (frameset);
372
373 darkcalib_frameset = gravi_frameset_extract_dark_map (frameset);
374 dark_frameset = gravi_frameset_extract_dark_data (frameset);
375
376 disp_frameset = gravi_frameset_extract_disp_data (frameset);
377
378 /* Check inputs */
379 if ( cpl_frameset_is_empty(p2vmcalib_frameset) ||
380 cpl_frameset_is_empty(wavecalib_frameset) ||
381 cpl_frameset_is_empty(flatcalib_frameset) ||
382 cpl_frameset_is_empty(badcalib_frameset) ||
383 ( cpl_frameset_is_empty(dark_frameset) &&
384 cpl_frameset_is_empty(darkcalib_frameset) ) ||
385 cpl_frameset_is_empty(disp_frameset) ||
386 cpl_frameset_is_empty(wavelampcalib_frameset) ) {
387
388 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
389 "Missing P2VM, DARK, BAD, WAVE, WAVELAMP, FLAT or DISP frames") ;
390 goto cleanup;
391 }
392
393 /*
394 * Identify the DARK in the input frameset
395 */
396
397 if (!cpl_frameset_is_empty (dark_frameset)) {
398
399 frame = cpl_frameset_get_position (dark_frameset, 0);
400 data = gravi_data_load_rawframe (frame, used_frameset);
401 gravi_data_detector_cleanup (data, parlist);
402
403 /* Compute dark */
404 dark_map = gravi_compute_dark (data);
405 FREE (gravi_data_delete, data);
406
407 CPLCHECK_CLEAN ("Could not compute the DARK map");
408
409 /* Save the dark map */
410 gravi_data_save_new (dark_map, frameset, NULL, NULL, parlist,
411 NULL, frame, "gravi_single",
412 NULL, GRAVI_DARK_MAP);
413
414 CPLCHECK_CLEAN ("Could not save the DARK map");
415 }
416 else if (!cpl_frameset_is_empty (darkcalib_frameset)) {
417
418 frame = cpl_frameset_get_position (darkcalib_frameset, 0);
419 dark_map = gravi_data_load_frame (frame, used_frameset);
420
421 CPLCHECK_CLEAN ("Could not load the DARK map");
422 }
423 else
424 cpl_msg_error (cpl_func, "There is no DARK in the frame set");
425
426 /* Identify the BAD in the input frameset */
427 frame = cpl_frameset_get_position (badcalib_frameset, 0);
428 badpix_map = gravi_data_load_frame (frame, used_frameset);
429
430 /* Identify the FLAT in the input frameset */
431 frame = cpl_frameset_get_position (flatcalib_frameset, 0);
432 profile_map = gravi_data_load_frame (frame, used_frameset);
433
434 /* Identify the WAVE in the input frameset */
435 frame = cpl_frameset_get_position (wavecalib_frameset, 0);
436 wave_map = gravi_data_load_frame (frame, used_frameset);
437
438 /* Identify the P2VM in the input frameset */
439 frame = cpl_frameset_get_position (p2vmcalib_frameset, 0);
440 p2vm_map = gravi_data_load_frame (frame, used_frameset);
441
442 CPLCHECK_CLEAN ("Error while loading the calibration map");
443
444
445 /*
446 * Loop on input DISP files
447 */
448
449 nb_frame = cpl_frameset_get_size (disp_frameset);
450 p2vm_qcs = cpl_malloc(sizeof(cpl_propertylist*) * nb_frame);
451
452 for (int ivis = 0; ivis < nb_frame; ivis++) {
453 current_frameset = cpl_frameset_duplicate (used_frameset);
454 p2vm_qcs[ivis] = cpl_propertylist_new();
455
456 cpl_msg_info (cpl_func, "*** Processing file %d over %d *** ", ivis+1, nb_frame);
457
458 frame = cpl_frameset_get_position (disp_frameset, ivis);
459 data = gravi_data_load_rawframe (frame, current_frameset);
460 gravi_data_detector_cleanup (data, parlist);
461
462 /* Extract spectrum */
463 preproc_data = gravi_extract_spectrum (data, profile_map, dark_map,
464 badpix_map, NULL, parlist,
466 CPLCHECK_CLEAN ("Cannot extract spectrum");
467
468 /* Rescale to common wavelength */
469 gravi_align_spectrum (preproc_data, wave_map, p2vm_map, GRAVI_DET_ALL);
470 CPLCHECK_CLEAN ("Cannot re-interpolate spectrum");
471
472 /* Move extensions from raw_data */
473 gravi_data_move_ext (preproc_data, data, GRAVI_ARRAY_GEOMETRY_EXT);
474 gravi_data_move_ext (preproc_data, data, GRAVI_OPTICAL_TRAIN_EXT);
475 gravi_data_move_ext (preproc_data, data, GRAVI_OPDC_EXT);
476 gravi_data_move_ext (preproc_data, data, GRAVI_FDDL_EXT);
477 gravi_data_move_ext (preproc_data, data, GRAVI_METROLOGY_EXT);
478 CPLCHECK_CLEAN ("Cannot move ext");
479
480 FREE (gravi_data_delete,data);
481
482 /* Option save the proproc file */
483 if (gravi_param_get_bool (parlist,"gravity.dfs.preproc-file")) {
484
485 gravi_data_save_new (preproc_data, frameset, NULL, NULL, parlist,
486 current_frameset, frame, "gravity_disp",
487 NULL, GRAVI_PREPROC);
488
489 CPLCHECK_CLEAN ("Could not save the preproc data");
490 }
491
492 /* Compute the flux and visibilities for each telescope and
493 * per acquisition with the P2VM applied to preproc_data */
494 p2vmred_data = gravi_compute_p2vmred (preproc_data, p2vm_map,
495 "gravi_single", parlist);
496 CPLCHECK_CLEAN ("Cannot apply p2vm to the preproc data");
497
498 /* Move extensions and delete preproc */
499 gravi_data_move_ext (p2vmred_data, preproc_data, GRAVI_METROLOGY_EXT);
500 gravi_data_move_ext (p2vmred_data, preproc_data, GRAVI_FDDL_EXT);
501 gravi_data_move_ext (p2vmred_data, preproc_data, GRAVI_OPDC_EXT);
502 FREE (gravi_data_delete, preproc_data);
503 CPLCHECK_CLEAN ("Cannot delete preproc");
504
505 /* Reduce the OPDC table */
506 gravi_compute_opdc_state (p2vmred_data);
507 CPLCHECK_CLEAN ("Cannot reduce OPDC");
508
509 /* Reduce the metrology */
510 gravi_metrology_reduce (p2vmred_data, NULL, static_param_data, NULL, parlist);
511 CPLCHECK_CLEAN ("Cannot reduce metrology");
512
513 /* Find outliers */
514 gravi_compute_outliers (p2vmred_data, parlist);
515 CPLCHECK_MSG ("Cannot compute outliers");
516
517 /* Compute the SNR_SMT and GDELAY_SMT columns */
518 gravi_compute_snr (p2vmred_data, parlist);
519 CPLCHECK_MSG ("Cannot compute SNR");
520
521 /* Compute the additional signals for averaging */
522 gravi_compute_signals (p2vmred_data, disp_map, parlist);
523 CPLCHECK_MSG ("Cannot compute signals");
524
525 /* Compute rejection flags for averaging */
526 gravi_compute_rejection (p2vmred_data, parlist);
527 CPLCHECK_MSG ("Cannot rejection flags signals");
528
529 /* Temporary copy for averaging over all frames */
530 gravi_copy_p2vm_qcs(p2vmred_data, p2vm_qcs[ivis]);
531 CPLCHECK_MSG ("Cannot copy QC for averaging");
532
533 /* Save the P2VMREDUCED */
534 if (gravi_param_get_bool (parlist,"gravity.dfs.p2vmred-file")) {
535
536 gravi_data_save_new (p2vmred_data, frameset, NULL, NULL, parlist,
537 current_frameset, frame, "gravity_disp",
539
540 CPLCHECK_CLEAN ("Cannot save the P2VMREDUCED product");
541 }
542
543
544 /* Loop on the wanted sub-integration */
545 cpl_size current_frame = 0;
546 while (current_frame >= 0)
547 {
548
549 /* Visibility and flux are averaged and the followings
550 * are saved in Visibility data in tables VIS, VIS2 and T3 */
551 tmpvis_data = gravi_compute_vis (p2vmred_data, parlist, &current_frame);
552 CPLCHECK_CLEAN ("Cannot average the visibilities");
553
554 /* Compute QC parameters (for this frame individually) */
555 gravi_compute_vis_qc (tmpvis_data, NULL, NULL, 0);
556
557 /* Save the VIS */
558 if (gravi_param_get_bool (parlist,"gravity.dfs.vis-file")) {
559
560 gravi_data_save_new (tmpvis_data, frameset, NULL, NULL, parlist,
561 current_frameset, frame, "gravity_disp",
563
564 CPLCHECK_CLEAN ("Cannot save the VIS product");
565 }
566
567 /* Merge with already existing */
568 if (vis_data == NULL) {
569 vis_data = tmpvis_data; tmpvis_data = NULL;
570 }
571 else {
572 cpl_msg_info (cpl_func,"Merge with previous OI_VIS");
573 gravi_data_append (vis_data, tmpvis_data, 1);
574 FREE (gravi_data_delete, tmpvis_data);
575 }
576 CPLCHECK_CLEAN ("Cannot merge the visibilities");
577
578 }
579
580 /* Save the astro file, which is a lighter version of the p2vmreduced */
581 if (gravi_param_get_bool (parlist,"gravity.dfs.astro-file")) {
582
583 gravi_data_clean_for_astro (p2vmred_data);
584 gravi_data_save_new (p2vmred_data, frameset, NULL, NULL,
585 parlist, current_frameset, frame,
586 "gravity_vis", NULL, GRAVI_ASTROREDUCED);
587
588 CPLCHECK_CLEAN ("Cannot save the ASTROREDUCED product");
589 }
590
591 cpl_msg_info (cpl_func,"Free the p2vmreduced");
592 FREE (cpl_frameset_delete, current_frameset);
593 FREE (gravi_data_delete, p2vmred_data);
594 }
595 /* End loop on the input files to reduce */
596
597 /* Compute QC parameters (for all frames averaged) */
598 gravi_compute_vis_qc (tmpvis_data, used_frameset, p2vm_qcs, nb_frame);
599
600 /* Recompute the TIME column from the MJD column
601 * in all OIFITS tables to follow standard */
602 gravi_vis_mjd_to_time (vis_data);
603
604 /* Identify the WAVELAMP in the input frameset */
605 frame = cpl_frameset_get_position (wavelampcalib_frameset, 0);
606 argon_data = gravi_data_load_frame (frame, used_frameset);
607
608 /* Duplicate POS_ARGON into the VIS file */
609 gravi_data_copy_ext (vis_data, argon_data, "POS_ARGON");
610
611 /* Save the output data file based on the first frame of the frameset */
612 cpl_frameset_join (used_frameset, disp_frameset);
613 frame = cpl_frameset_get_position (disp_frameset, 0);
614
615 gravi_data_save_new (vis_data, frameset, NULL, NULL, parlist,
616 used_frameset, frame, "gravity_disp",
617 NULL, GRAVI_DISP_VIS);
618
619 CPLCHECK_CLEAN("Could not save the VIS_SINGLE product");
620
621 FREE (gravi_data_delete, profile_map);
622 FREE (gravi_data_delete, dark_map);
623 FREE (gravi_data_delete, wave_map);
624 FREE (gravi_data_delete, badpix_map);
625 FREE (gravi_data_delete, p2vm_map);
626 FREE (cpl_frameset_delete, darkcalib_frameset);
627 FREE (cpl_frameset_delete, wavecalib_frameset);
628 FREE (cpl_frameset_delete, dark_frameset);
629 FREE (cpl_frameset_delete, flatcalib_frameset);
630 FREE (cpl_frameset_delete, badcalib_frameset);
631 FREE (cpl_frameset_delete, p2vmcalib_frameset);
632 FREE (cpl_frameset_delete, wavelampcalib_frameset);
633 FREELOOP(cpl_propertylist_delete, p2vm_qcs, nb_frame);
634 }
635 else {
636
637 /* Load the DIS_VIS already computed */
638 frame = cpl_frameset_get_position (dispvis_frameset, 0);
639 vis_data = gravi_data_load_frame (frame, used_frameset);
640
641 CPLCHECK_CLEAN ("Cannot load the DISP_VIS file");
642
643 disp_frameset = cpl_frameset_duplicate (dispvis_frameset);
644 }
645
646 /*
647 * Compute the dispersion table of a set of disp frames
648 */
649
650 gravi_disp_cleanup (vis_data);
651
652 disp_map = gravi_compute_disp (vis_data);
653
654 CPLCHECK_CLEAN ("Error while computing the disp_map");
655
656 /* Create product frame */
657 frame = cpl_frameset_get_position (disp_frameset, 0);
658
659 /* Save the DISP_MODEL */
660 gravi_data_save_new (disp_map, frameset, NULL, NULL, parlist,
661 used_frameset, frame, "gravity_disp",
662 NULL, GRAVI_DISP_MODEL);
663
664 CPLCHECK_CLEAN("Could not save the DISP_MODEL product");
665
666 /* Deallocation of all variables */
667 goto cleanup;
668
669cleanup :
670 cpl_msg_info(cpl_func,"Memory cleanup");
671 FREE (gravi_data_delete, data);
672 FREE (gravi_data_delete, tmpvis_data);
673 FREE (gravi_data_delete, vis_data);
674 FREE (gravi_data_delete, disp_map);
675 FREE (gravi_data_delete, dark_map);
676 FREE (gravi_data_delete, wave_map);
677 FREE (gravi_data_delete, profile_map);
678 FREE (gravi_data_delete, badpix_map);
679 FREE (gravi_data_delete, p2vmred_data);
680 FREE (gravi_data_delete, p2vm_map);
681 FREE (gravi_data_delete, preproc_data);
682 FREE (cpl_frameset_delete, disp_frameset);
683 FREE (cpl_frameset_delete, dispvis_frameset);
684 FREE (cpl_frameset_delete, darkcalib_frameset);
685 FREE (cpl_frameset_delete, dark_frameset);
686 FREE (cpl_frameset_delete, wavecalib_frameset);
687 FREE (cpl_frameset_delete, badcalib_frameset);
688 FREE (cpl_frameset_delete, flatcalib_frameset);
689 FREE (cpl_frameset_delete, p2vmcalib_frameset);
690 FREE (cpl_frameset_delete, wavelampcalib_frameset);
691 FREE (cpl_frameset_delete, used_frameset);
692 FREE (cpl_frameset_delete, current_frameset);
693 FREELOOP(cpl_propertylist_delete, p2vm_qcs, nb_frame);
694
696 return (int)cpl_error_get_code();
697}
698
699
typedefCPL_BEGIN_DECLS struct _gravi_data_ gravi_data
Definition: gravi_data.h:39
#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
#define FREELOOP(function, variable, n)
Definition: gravi_utils.h:72
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:864
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:943
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.
cpl_error_code gravi_copy_p2vm_qcs(gravi_data *p2vmred_data, cpl_propertylist *plist)
Copy PFACTOR and VFACTOR QCs so that they may be aggregated over all frames.
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:1675
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:2688
cpl_error_code gravi_compute_vis_qc(gravi_data *vis_data, cpl_frameset *frameset, cpl_propertylist **frame_qcs, cpl_size nb_frame)
Compute the QC parameters for a VIS (averaged) data.
Definition: gravi_vis.c:2237