GRAVI Pipeline Reference Manual 1.9.2
Loading...
Searching...
No Matches
gravity_p2vm.c
Go to the documentation of this file.
1/* $Id: gravity_p2vm.c,v 1.29 2009/02/10 09:16:12 llundin Exp $
2 *
3 * This file is part of the GRAVI Pipeline
4 * Copyright (C) 2002,2003 European Southern Observatory
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/*
22 * $Author: llundin $
23 * $Date: 2009/02/10 09:16:12 $
24 * $Revision: 1.29 $
25 * $Name: $
26 *
27 * History :
28 * 04/12/2018 use GRAVITY_WAVE.fits calibration file instead of hardcoded values
29 */
30
31#ifdef HAVE_CONFIG_H
32#include <config.h>
33#endif
34
35/*-----------------------------------------------------------------------------
36 Includes
37 -----------------------------------------------------------------------------*/
38
39#include <cpl.h>
40#include <stdio.h>
41#include <string.h>
42#include <time.h>
43#if defined(__linux__) && defined(__GLIBC__)
44#include <malloc.h> //Needed for malloc_trim()
45#endif
46
47#include "gravi_data.h"
48#include "gravi_pfits.h"
49#include "gravi_dfs.h"
50
51#include "gravi_utils.h"
52
53#include "gravi_metrology.h"
54#include "gravi_calib.h"
55#include "gravi_preproc.h"
56#include "gravi_wave.h"
57#include "gravi_p2vm.h"
58
59#include "gravi_p2vmred.h"
60
61
62/*-----------------------------------------------------------------------------
63 Private function prototypes
64 -----------------------------------------------------------------------------*/
65
66static int gravity_p2vm_create(cpl_plugin *);
67static int gravity_p2vm_exec(cpl_plugin *);
68static int gravity_p2vm_destroy(cpl_plugin *);
69static int gravity_p2vm(cpl_frameset *, const cpl_parameterlist *);
70
71/*-----------------------------------------------------------------------------
72 Static variables
73 -----------------------------------------------------------------------------*/
74
75static char gravity_p2vm_short[] = "Calibrate the instrument bad pixels, wavelength table, interferometric contrast and phase.";
77"This recipe reduces the internal calibrations. As a special sequence of shutter opening is required, it is advised to always build the SOF with a complete sequence of files obtained within a single execution of the p2vm calibration template. However it is still possible to input a SOF with DARK_RAW only, or DARK_RAW and FLAT_RAW only. It is also possible to input a SOF with some already processed calibration (e.g WAVE).\n"
79 "* Compute the dark, write product\n"
80 "* Compute the flat, write product\n"
81 "* Compute the badpixels, write product\n"
82 "* Compute the spectral calibration, write product\n"
83 "* Compute the p2vm, write product\n"
85 GRAVI_DARK_RAW" : raw dark, all shutters closed (DPR.TYPE=DARK)\n"
86 GRAVI_FLAT_RAW" x4 : raw flats, one shutter open (DPR.TYPE=FLAT)\n"
87 GRAVI_P2VM_RAW" x6 : raw p2vms, two shutters open (DPR.TYPE=P2VM)\n"
88 GRAVI_WAVE_RAW" : raw wavelength calibration for FT (DPR.TYPE=WAVE)\n"
89 GRAVI_WAVESC_RAW" : raw wavelength calibration for SC (DPR.TYPE=WAVE,SC)\n"
91 GRAVI_DARK_MAP" : dark calibration\n"
92 GRAVI_FLAT_MAP" : flat calibration\n"
93 GRAVI_BAD_MAP" : badpixel calibration\n"
94 GRAVI_WAVE_MAP" : wave calibration\n"
95 GRAVI_P2VM_MAP" : p2vm calibration\n"
96 "";
97
98/*-----------------------------------------------------------------------------
99 Function code
100 -----------------------------------------------------------------------------*/
101
102/*----------------------------------------------------------------------------*/
112/*----------------------------------------------------------------------------*/
113int cpl_plugin_get_info(cpl_pluginlist * list)
114{
115 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe );
116 cpl_plugin * plugin = &recipe->interface;
117
118 if (cpl_plugin_init(plugin,
119 CPL_PLUGIN_API,
120 GRAVI_BINARY_VERSION,
121 CPL_PLUGIN_TYPE_RECIPE,
122 "gravity_p2vm",
125 "Nabih Azouaoui, Vincent Lapeyrere, JB. Le Bouquin",
126 PACKAGE_BUGREPORT,
131 cpl_msg_error(cpl_func, "Plugin initialization failed");
132 (void)cpl_error_set_where(cpl_func);
133 return 1;
134 }
135
136 if (cpl_pluginlist_append(list, plugin)) {
137 cpl_msg_error(cpl_func, "Error adding plugin to list");
138 (void)cpl_error_set_where(cpl_func);
139 return 1;
140 }
141
142 return 0;
143}
144
145/*----------------------------------------------------------------------------*/
153/*----------------------------------------------------------------------------*/
154static int gravity_p2vm_create(cpl_plugin * plugin)
155{
156 cpl_recipe * recipe;
157 cpl_parameter * p;
158
159 /* Do not create the recipe if an error code is already set */
160 if (cpl_error_get_code() != CPL_ERROR_NONE) {
161 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
162 cpl_func, __LINE__, cpl_error_get_where());
163 return (int)cpl_error_get_code();
164 }
165
166 if (plugin == NULL) {
167 cpl_msg_error(cpl_func, "Null plugin");
168 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
169 }
170
171 /* Verify plugin type */
172 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
173 cpl_msg_error(cpl_func, "Plugin is not a recipe");
174 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
175 }
176
177 /* Get the recipe */
178 recipe = (cpl_recipe *)plugin;
179
180 /* Create the parameters list in the cpl_recipe object */
181 recipe->parameters = cpl_parameterlist_new();
182 if (recipe->parameters == NULL) {
183 cpl_msg_error(cpl_func, "Parameter list allocation failed");
184 cpl_ensure_code(0, (int)CPL_ERROR_ILLEGAL_OUTPUT);
185 }
186
187 /* Fill the parameters list */
188
189 /* Use static names (output_procatg.fits) */
190 gravi_parameter_add_static_name (recipe->parameters);
191
192 /* Debug file */
193 gravi_parameter_add_debug_file (recipe->parameters);
194 gravi_parameter_add_preproc_file (recipe->parameters);
195
196 /* Bias-method */
197 gravi_parameter_add_biasmethod (recipe->parameters);
198
199 /* Metrology parameters */
200 gravi_parameter_add_metrology (recipe->parameters);
201
202 /* Badpix and profile */
203 gravi_parameter_add_badpix (recipe->parameters);
204 gravi_parameter_add_profile (recipe->parameters);
205 //gravi_parameter_add_preproc (recipe->parameters);
206
207 /* Wave option */
208 gravi_parameter_add_wave (recipe->parameters);
209
210 /* Extraction */
211 gravi_parameter_add_extract (recipe->parameters);
212
213 /* Phase definition in P2VM */
214 p = cpl_parameter_new_enum ("gravity.calib.phase-calibration", CPL_TYPE_STRING,
215 "This option changes the phase reference of the P2VM:\n "
216 "NONE defines phiA(lbd) at zero for all baselines "
217 "(P2VM calibrates only the internal phase-shift of the beam combiner);\n "
218 "CLOSURE defines phiA(lbd) at zero for baselines 01, 02 and 03 "
219 "(P2VM calibrates the phase-shift and the closure-phase of the beam combiner);\n "
220 "DISP defines phiA(lbd) to have zero mean and minimum GD for baselines (01,02,03); "
221 "(P2VM calibrates the phase-shift, the closure-phase and the "
222 "spectral-dispersion of the beam combiner);\n "
223 "FULL defines phiA(lbd) to have zero-GD for baselines (01,02,03)",
224 "(P2VM calibrates the full phase with respect to zero-astrometry);\n "
225 "gravi.p2vm", "FULL", 4, "NONE", "CLOSURE", "DISP", "FULL");
226 cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "phase-calibration");
227 cpl_parameter_disable (p, CPL_PARAMETER_MODE_ENV);
228 cpl_parameterlist_append (recipe->parameters, p);
229
230 return 0;
231}
232
233/*----------------------------------------------------------------------------*/
239/*----------------------------------------------------------------------------*/
240static int gravity_p2vm_exec(cpl_plugin * plugin)
241{
242
243 cpl_recipe * recipe;
244 int recipe_status;
245 cpl_errorstate initial_errorstate = cpl_errorstate_get();
246
247 /* Return immediately if an error code is already set */
248 if (cpl_error_get_code() != CPL_ERROR_NONE) {
249 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
250 cpl_func, __LINE__, cpl_error_get_where());
251 return (int)cpl_error_get_code();
252 }
253
254 if (plugin == NULL) {
255 cpl_msg_error(cpl_func, "Null plugin");
256 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
257 }
258
259 /* Verify plugin type */
260 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
261 cpl_msg_error(cpl_func, "Plugin is not a recipe");
262 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
263 }
264
265 /* Get the recipe */
266 recipe = (cpl_recipe *)plugin;
267
268 /* Verify parameter and frame lists */
269 if (recipe->parameters == NULL) {
270 cpl_msg_error(cpl_func, "Recipe invoked with NULL parameter list");
271 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
272 }
273 if (recipe->frames == NULL) {
274 cpl_msg_error(cpl_func, "Recipe invoked with NULL frame set");
275 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
276 }
277
278 /* Invoke the recipe */
279 recipe_status = gravity_p2vm(recipe->frames, recipe->parameters);
280
281 /* Ensure DFS-compliance of the products */
282 if (cpl_dfs_update_product_header(recipe->frames)) {
283 if (!recipe_status) recipe_status = (int)cpl_error_get_code();
284 }
285
286 if (!cpl_errorstate_is_equal(initial_errorstate)) {
287 /* Dump the error history since recipe execution start.
288 At this point the recipe cannot recover from the error */
289 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
290 }
291
292 return recipe_status;
293}
294
295/*----------------------------------------------------------------------------*/
301/*----------------------------------------------------------------------------*/
302static int gravity_p2vm_destroy(cpl_plugin * plugin)
303{
304 cpl_recipe * recipe;
305
306 if (plugin == NULL) {
307 cpl_msg_error(cpl_func, "Null plugin");
308 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
309 }
310
311 /* Verify plugin type */
312 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
313 cpl_msg_error(cpl_func, "Plugin is not a recipe");
314 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
315 }
316
317 /* Get the recipe */
318 recipe = (cpl_recipe *)plugin;
319
320 cpl_parameterlist_delete(recipe->parameters);
321
322 return 0;
323}
324
325/*----------------------------------------------------------------------------*/
333/*----------------------------------------------------------------------------*/
334static int gravity_p2vm(cpl_frameset * frameset,
335 const cpl_parameterlist * parlist)
336{
337 cpl_frameset * p2vm_frameset=NULL, * wavecalib_frameset=NULL, * darkcalib_frameset=NULL,
338 * flatcalib_frameset=NULL, * dark_frameset=NULL, * wave_frameset=NULL, * wavesc_frameset=NULL,
339 * badcalib_frameset=NULL, * flat_frameset=NULL, * used_frameset=NULL, * current_frameset=NULL,
340 * wave_param_frameset=NULL;
341
342 cpl_frame * frame=NULL, * frame_p2vm=NULL;
343
344 gravi_data * p2vm_map=NULL, * data=NULL, * dark_map=NULL, * wave_map=NULL,
345 * profile_map=NULL, * badpix_map=NULL, * wave_param=NULL;
346 gravi_data * spectrum_data=NULL;
347 gravi_data * preproc_data=NULL;
348 gravi_data ** raw_data=NULL;
349 gravi_data * p2vmred_data = NULL;
350
351 int nb_frame, nb_frame_gain = 0;
352
353 cpl_propertylist * met_plist=NULL;
354 int ** valid_trans = cpl_malloc (2 * sizeof (int*));
355 int ** valid_CP = cpl_malloc (2 * sizeof (int*));
356 char ext_regexp[500];
357 clock_t start;
358
359 for (int i = 0 ; i < 2; i++){
360 valid_trans[i] = cpl_calloc (4, sizeof (int));
361 valid_CP[i] = cpl_calloc (6, sizeof (int));
362 }
363
364 /* Message */
367
368
369 /* Get the input frameset */
370 cpl_ensure_code(gravi_dfs_set_groups(frameset) == CPL_ERROR_NONE, cpl_error_get_code()) ;
371
372 /* Init the used frameset */
373 used_frameset = cpl_frameset_new ();
374
375 /* Extract DARK frameset */
376 dark_frameset = gravi_frameset_extract_dark_data (frameset);
377 darkcalib_frameset = gravi_frameset_extract_dark_map (frameset);
378 if ( cpl_frameset_get_size (dark_frameset) +
379 cpl_frameset_get_size (darkcalib_frameset) !=1) {
380 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
381 "Either a single DARK or DARK_RAW needs to be in the frameset");
382 goto cleanup;
383 }
384
385 /* Extract BAD frameset */
386 badcalib_frameset = gravi_frameset_extract_bad_map (frameset);
387 if ( cpl_frameset_is_empty (badcalib_frameset) && cpl_frameset_is_empty (dark_frameset) &&
388 cpl_frameset_is_empty (darkcalib_frameset) ) {
389 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,"Missing DARK or BAD on the frameset");
390 goto cleanup;
391 }
392
393 /* Extract FLAT frameset */
394 flat_frameset = gravi_frameset_extract_flat_data (frameset);
395 flatcalib_frameset = gravi_frameset_extract_flat_map (frameset);
396 if ( cpl_frameset_is_empty (flat_frameset) &&
397 cpl_frameset_is_empty (flatcalib_frameset) ) {
398 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,"Missing FLAT on the frameset");
399 goto cleanup;
400 }
401
402 /* Extract WAVE frameset */
403 wave_frameset = gravi_frameset_extract_wave_data (frameset);
404 wavesc_frameset = gravi_frameset_extract_wavesc_data (frameset);
405 wavecalib_frameset = gravi_frameset_extract_wave_map (frameset);
406 if ( cpl_frameset_is_empty (wave_frameset) &&
407 cpl_frameset_is_empty (wavecalib_frameset) ) {
408 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,"Missing WAVE on the frameset");
409 goto cleanup;
410 }
411
412 /* Extract P2VM frameset */
413 p2vm_frameset = gravi_frameset_extract_p2vm_data (frameset);
414 if ( cpl_frameset_get_size (p2vm_frameset) !=6) {
415 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,"Illegal number of P2VM on the frameset");
416 goto cleanup;
417 }
418
419 /* Extract calibration file wave_param frameset */
420 wave_param_frameset = gravi_frameset_extract_wave_param (frameset);
421 if ( cpl_frameset_is_empty (wave_param_frameset) ) {
422 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,"Missing WAVE_PARAM static calibration file");
423 goto cleanup;
424 }
425
426 /*
427 * (1) Identify and extract the dark file
428 */
429
430 if (!cpl_frameset_is_empty (dark_frameset)) {
431 cpl_msg_info (cpl_func, " ***** Compute DARK map ***** ");
432
433 /* Load this DARK_RAW */
434 frame = cpl_frameset_get_position (dark_frameset, 0);
435 data = gravi_data_load_rawframe (frame, used_frameset);
436 gravi_data_detector_cleanup (data, parlist);
437
438 /* Compute the dark */
439 dark_map = gravi_compute_dark (data);
440 FREE (gravi_data_delete, data);
441
442 CPLCHECK_CLEAN ("Cannot compute the DARK map");
443
444 /* Save the dark map */
445 gravi_data_save_new (dark_map, frameset, NULL, NULL, parlist,
446 NULL, frame, "gravity_p2vm",
447 NULL, GRAVI_DARK_MAP);
448
449 CPLCHECK_CLEAN ("Could not save the DARK map");
450 }
451 else if (!cpl_frameset_is_empty (darkcalib_frameset)) {
452 cpl_msg_info (cpl_func, " ***** Get DARK map ***** ");
453
454 /* Load this DARK */
455 frame = cpl_frameset_get_position (darkcalib_frameset, 0);
456 dark_map = gravi_data_load_frame (frame, used_frameset);
457
458 CPLCHECK_CLEAN ("Could not load the DARK map");
459
460 /* This new DARK may be used latter for BADPIX */
461 cpl_frameset_insert (dark_frameset, cpl_frame_duplicate (frame));
462 }
463
464
465 /*
466 * (2) Identify and extract the BADPIX file
467 */
468
469 if (!cpl_frameset_is_empty (badcalib_frameset)) {
470 cpl_msg_info (cpl_func, " ***** Get BAD pixel map ***** ");
471
472 /* The BADPIX is already in the frameset */
473 frame = cpl_frameset_get_position (badcalib_frameset, 0);
474 badpix_map = gravi_data_load_frame (frame, used_frameset);
475 }
476 else if (!cpl_frameset_is_empty (dark_frameset) &&
477 !cpl_frameset_is_empty (flat_frameset)) {
478 cpl_msg_info (cpl_func, " ***** Compute BAD pixel map from DARK and FLAT_RAW ***** ");
479
480 /* Identify the flat files */
481 nb_frame_gain = cpl_frameset_get_size (flat_frameset);
482 raw_data = cpl_calloc (nb_frame_gain, sizeof(gravi_data *));
483
484 /* Build the list of FLAT files and output file name */
485 for (int i = 0; i < nb_frame_gain; i++) {
486 frame = cpl_frameset_get_position (flat_frameset, i);
487 raw_data[i] = gravi_data_load_rawframe (frame, NULL);
488 gravi_data_detector_cleanup (raw_data[i], parlist);
489 }
490
491 /* Compute it from the DARK and the FLAT_RAW */
492 badpix_map = gravi_compute_badpix (dark_map, raw_data,
493 nb_frame_gain, parlist);
494
495 CPLCHECK_CLEAN("Cannot compute the BAD pixel from DARK and FLAT");
496
497 /* Save the BADPIX */
498 frame = cpl_frameset_get_position (dark_frameset, 0);
499 gravi_data_save_new (badpix_map, frameset, NULL, NULL, parlist,
500 NULL, frame, "gravity_p2vm",
501 NULL, GRAVI_BAD_MAP);
502
503 CPLCHECK_CLEAN ("Could not save the BAD pixel map");
504
505 FREELOOP (gravi_data_delete, raw_data, nb_frame_gain);
506 }
507
508 /*
509 * (3) Check that the FLAT map in the input frameset
510 */
511
512 if (!cpl_frameset_is_empty(flatcalib_frameset)) {
513 cpl_msg_info (cpl_func, " ***** Get FLAT map ***** ");
514
515 /* The FLAT is already in the frameset */
516 frame = cpl_frameset_get_position (flatcalib_frameset, 0);
517 profile_map = gravi_data_load_frame (frame, used_frameset);
518 }
519 else if (!cpl_frameset_is_empty (flat_frameset)) {
520 cpl_msg_info (cpl_func, " ***** Compute FLAT map ***** ");
521
522
523 /* Check calibs */
524 if (!badpix_map || !dark_map) {
525 ERROR_CLEAN (CPL_ERROR_ILLEGAL_INPUT, "Missing DARK or BAD in frameset");
526 }
527
528 /* Identify the flat files */
529 nb_frame_gain = cpl_frameset_get_size (flat_frameset);
530 raw_data = cpl_malloc (nb_frame_gain * sizeof(gravi_data *));
531
532 /* Build the list of FLAT files and output file name */
533 for (int i = 0; i < nb_frame_gain; i++) {
534 frame = cpl_frameset_get_position (flat_frameset, i);
535 raw_data[i] = gravi_data_load_rawframe (frame, used_frameset);
536 gravi_data_detector_cleanup (raw_data[i], parlist);
537 }
538
539
540 /* Compute the profile from the list of FLAT */
541 profile_map = gravi_compute_profile (raw_data, dark_map, badpix_map, nb_frame_gain, parlist);
542 CPLCHECK_CLEAN ("Cannot compute the FLAT profile");
543
544 /* Compute the gain QC */
545 cpl_propertylist * gain_header;
546 gain_header = gravi_compute_gain (raw_data, nb_frame_gain, dark_map);
547 CPLCHECK_CLEAN ("Cannot compute the GAIN");
548
549 /* Put the gain QC in profile_map */
550 cpl_propertylist * profile_header = gravi_data_get_header (profile_map);
551 cpl_propertylist_append (profile_header, gain_header);
552 FREE (cpl_propertylist_delete, gain_header);
553
554 /* Save the FLAT map */
555 frame = cpl_frameset_get_position (flat_frameset, 0);
556
557 gravi_data_save_new (profile_map, frameset, NULL, NULL, parlist,
558 used_frameset, frame, "gravity_p2vm",
559 NULL, GRAVI_FLAT_MAP);
560
561 CPLCHECK_CLEAN ("Could not save the FLAT profile_map");
562
563 /* Free the list of files */
564 FREELOOP (gravi_data_delete, raw_data, nb_frame_gain);
565 }
566
567 /*
568 * (4) Check and get the WAVE frame
569 */
570
571 if (!cpl_frameset_is_empty (wave_param_frameset)) {
572 frame = cpl_frameset_get_position (wave_param_frameset, 0);
573 wave_param = gravi_data_load_frame (frame, used_frameset);
574 }
575 else
576 cpl_msg_error (cpl_func, "There is no WAVE_PARAM in the frameset (did you forget the static calibration files?)");
577
578 if (!cpl_frameset_is_empty (wavecalib_frameset)) {
579 cpl_msg_info (cpl_func, " ***** Get wave map ***** ");
580
581 /* The WAVE in the frame_set is a calibrated wave */
582 frame = cpl_frameset_get_position (wavecalib_frameset, 0);
583 wave_map = gravi_data_load_frame (frame, used_frameset);
584 }
585 else if (!cpl_frameset_is_empty (wave_frameset)) {
586 cpl_msg_info (cpl_func, " ***** Process the WAVE_RAW ***** ");
587
588 /* Check calibs */
589 if ( !badpix_map || !profile_map || !dark_map) {
590 ERROR_CLEAN (CPL_ERROR_ILLEGAL_INPUT, "Missing DARK, FLAT, or BAD in frameset");
591 }
592
593 /* Create the WAVE product */
594 wave_map = gravi_data_new (0);
595
596 /* Get the frame */
597 frame = cpl_frameset_get_position (wave_frameset, 0);
598
599 /* Load WAVE_RAW SC */
600 snprintf(ext_regexp, 499, "^(%s|%s)$", GRAVI_IMAGING_DATA_SC_EXT, GRAVI_IMAGING_DETECTOR_SC_EXT);
601 gravi_data * wave_sc_data = gravi_data_load_rawframe_ext (frame, used_frameset, ext_regexp);
602 gravi_data_detector_cleanup (wave_sc_data, parlist);
603
604 /* Reduce WAVE_RAW SC */
605 cpl_msg_info (cpl_func, "Extract SC SPECTRUM for WAVE_RAW");
606 spectrum_data = gravi_extract_spectrum (wave_sc_data, profile_map, dark_map,
607 badpix_map, NULL, parlist, GRAVI_DET_SC);
608 FREE (gravi_data_delete, wave_sc_data);
609
610 /* Load WAVE_RAW FT */
611 snprintf(ext_regexp, 499, "^(%s|%s)$", GRAVI_IMAGING_DATA_FT_EXT, GRAVI_IMAGING_DETECTOR_FT_EXT);
612 gravi_data * wave_ft_data = gravi_data_load_rawframe_ext (frame, NULL, ext_regexp);
613
614 /* Reduce WAVE_RAW FT */
615 cpl_msg_info (cpl_func, "Extract FT SPECTRUM for WAVE_RAW");
616 gravi_data * ft_spectrum_data = gravi_extract_spectrum (wave_ft_data, profile_map, dark_map,
617 badpix_map, NULL, parlist, GRAVI_DET_FT);
618 FREE (gravi_data_delete, wave_ft_data);
619
620 /* Copy FT extensions to spectrum_data */
621 gravi_data_move_ext(spectrum_data, ft_spectrum_data, GRAVI_IMAGING_DETECTOR_FT_EXT);
622 gravi_data_move_ext(spectrum_data, ft_spectrum_data, GRAVI_SPECTRUM_DATA_FT_EXT);
623 cpl_propertylist_copy_property_regexp(gravi_data_get_header(spectrum_data),
624 gravi_data_get_header(ft_spectrum_data),
625 "^ESO QC ",0);
626 FREE (gravi_data_delete, ft_spectrum_data);
627
628 /* Load WAVE_RAW metrology */
629 gravi_data * wave_met_data = gravi_data_load_rawframe_ext (frame, NULL, GRAVI_METROLOGY_EXT);
630
631 /* Compute the P2VM of the MET from the WAVE_RAW */
632 cpl_msg_info (cpl_func, "Compute the P2VM_MET from WAVE_RAW");
633 cpl_table * met_table = gravi_data_get_table (wave_met_data, GRAVI_METROLOGY_EXT);
634 double lbd_met = gravi_pfits_get_met_wavelength_mean (gravi_data_get_header(wave_met_data), met_table);
635 cpl_table * p2vm_met = gravi_metrology_compute_p2vm (met_table, lbd_met);
636
637 /* Set the P2VM_MET in WAVE */
638 gravi_data_add_table (wave_map, NULL, GRAVI_P2VM_MET_EXT, p2vm_met);
639
640 CPLCHECK_CLEAN ("Cannot compute P2VM_MET");
641
642 /* Computing OPDs */
643 cpl_msg_info (cpl_func, "Compute OPDs for WAVE_RAW");
644 gravi_wave_compute_opds (spectrum_data,
646 parlist);
647 FREE (gravi_data_delete, wave_met_data);
648
649 CPLCHECK_CLEAN ("Cannot compute OPDs");
650
651 /* Save the file with OPD_SC, OPD_FT, OI_VIS_MET */
652 if (gravi_param_get_bool (parlist,"gravity.dfs.debug-file")) {
653 gravi_data_save_new (spectrum_data, frameset, NULL, NULL, parlist,
654 used_frameset, frame, "gravity_p2vm",
655 NULL, "DEBUG");
656 }
657
658 /* Compute wave calibration for FT */
659 gravi_compute_wave (wave_map, spectrum_data, GRAVI_FT, parlist, wave_param);
660
661 CPLCHECK_CLEAN ("Cannot compute wave for FT");
662
663 /* Load and process the WAVESC_RAW (if any) */
664 if (!cpl_frameset_is_empty (wavesc_frameset)) {
665 /* Erase spectrum data */
666 cpl_msg_info (cpl_func, "Delete WAVE_RAW data");
667 FREE (gravi_data_delete, spectrum_data);
668
669 cpl_msg_info (cpl_func, " ***** Process the WAVESC_RAW ***** ");
670
671 /* Get the frame */
672 frame = cpl_frameset_get_position (wavesc_frameset, 0);
673
674 /* Load WAVESC_RAW SC*/
675 snprintf(ext_regexp, 499, "^(%s|%s)$", GRAVI_IMAGING_DATA_SC_EXT, GRAVI_IMAGING_DETECTOR_SC_EXT);
676 gravi_data * wavesc_sc_data = gravi_data_load_rawframe_ext (frame, used_frameset, ext_regexp);
677 gravi_data_detector_cleanup (wavesc_sc_data, parlist);
678
679 cpl_msg_info (cpl_func, "Extract SC SPECTRUM for WAVESC_RAW");
680 spectrum_data = gravi_extract_spectrum (wavesc_sc_data, profile_map, dark_map,
681 badpix_map, NULL, parlist, GRAVI_DET_SC);
682 CPLCHECK_CLEAN ("Cannot extract SC spectrum from WAVESC_RAW");
683 FREE (gravi_data_delete, wavesc_sc_data);
684
685 /* Load WAVESC_RAW FT*/
686 snprintf(ext_regexp, 499, "^(%s|%s)$", GRAVI_IMAGING_DATA_FT_EXT, GRAVI_IMAGING_DETECTOR_FT_EXT);
687 gravi_data * wavesc_ft_data = gravi_data_load_rawframe_ext (frame, used_frameset, ext_regexp);
688
689 cpl_msg_info (cpl_func, "Extract FT SPECTRUM for WAVESC_RAW");
690 ft_spectrum_data = gravi_extract_spectrum (wavesc_ft_data, profile_map, dark_map,
691 badpix_map, NULL, parlist, GRAVI_DET_FT);
692 CPLCHECK_CLEAN ("Cannot extract FT spectrum from WAVESC_RAW");
693 FREE (gravi_data_delete, wavesc_ft_data);
694
695 /* Copy FT extensions to spectrum_data */
696 gravi_data_move_ext(spectrum_data, ft_spectrum_data, GRAVI_IMAGING_DETECTOR_FT_EXT);
697 gravi_data_move_ext(spectrum_data, ft_spectrum_data, GRAVI_SPECTRUM_DATA_FT_EXT);
698 cpl_propertylist_copy_property_regexp(gravi_data_get_header(spectrum_data),
699 gravi_data_get_header(ft_spectrum_data),
700 "^ESO QC ",0);
701 FREE (gravi_data_delete, ft_spectrum_data);
702
703 /* Load WAVESC_RAW metrology */
704 gravi_data * wavesc_met_data = gravi_data_load_rawframe_ext (frame, NULL, GRAVI_METROLOGY_EXT);
705
706 cpl_msg_info (cpl_func, "Compute OPDs for WAVESC_RAW");
707 gravi_wave_compute_opds (spectrum_data,
708 gravi_data_get_table (wavesc_met_data, GRAVI_METROLOGY_EXT),
709 parlist);
710 FREE (gravi_data_delete, wavesc_met_data);
711
712 CPLCHECK_CLEAN ("Cannot process the WAVESC_RAW");
713
714 /* Save the file with OPD_SC, OPD_FT, OI_VIS_MET */
715 if (gravi_param_get_bool (parlist,"gravity.dfs.debug-file")) {
716 gravi_data_save_new (spectrum_data, frameset, NULL, NULL,
717 parlist, used_frameset, frame, "gravity_p2vm",
718 NULL, "DEBUG");
719 }
720 }
721 else {
722 cpl_msg_warning (cpl_func, "No WAVESC_RAW in the SOF:"
723 " SC wavelength will be inaccurate");
724 }
725
726 /* Compute wave calibration for SC */
727 gravi_compute_wave (wave_map, spectrum_data, GRAVI_SC, parlist, wave_param);
728
729 CPLCHECK_CLEAN ("Cannot compute wave for SC");
730
731 /* Free the spectrum */
732 FREE (gravi_data_delete, spectrum_data);
733
734 /* Compute the QC */
735 gravi_wave_qc (wave_map, profile_map);
736
737 /* Save the WAVE map */
738 gravi_data_save_new (wave_map, frameset, NULL, NULL, parlist,
739 used_frameset, frame, "gravity_p2vm",
740 NULL, GRAVI_WAVE_MAP);
741
742 CPLCHECK_CLEAN ("Could not save the WAVE map");
743 }
744
745 /*
746 * Build the frameset for the P2VM
747 */
748
749 /* Check if P2VM are provided */
750 if ( cpl_frameset_is_empty (p2vm_frameset) ) {
751 cpl_msg_info (cpl_func,"All RAW data reduced... stop recipe");
752 goto cleanup;
753 }
754
755 /* Check calibs */
756 if ( !badpix_map || !profile_map || !wave_map || !dark_map) {
757 ERROR_CLEAN (CPL_ERROR_ILLEGAL_INPUT, "Missing DARK, FLAT, BAD, or WAVE in frameset");
758 }
759
760 /* Add the FLAT_RAW and WAVE_RAW to the p2vm frameset */
761 if ( !cpl_frameset_is_empty (flat_frameset) )
762 cpl_frameset_join (p2vm_frameset, flat_frameset);
763
764 if ( !cpl_frameset_is_empty (wave_frameset) )
765 cpl_frameset_join (p2vm_frameset, wave_frameset);
766
767 /* Get the number of the p2vm frame contained in the frameset */
768 nb_frame = cpl_frameset_get_size (p2vm_frameset);
769
770 /* Check if the 11 files are here */
771 if (nb_frame != 11) {
772 ERROR_CLEAN (CPL_ERROR_ILLEGAL_INPUT, "Missing P2VM in frameset");
773 }
774
775 /*
776 * (6) Loop on files of the p2vm frameset
777 */
778
779 /* Construction of the p2vm data. */
780 /* START EKW 04/12/2018 read wave parameter from calibration file - Load the WAVE_PARAM Parameter */
781
782 cpl_msg_info (cpl_func, " ***** Create the P2VM ***** ");
783 p2vm_map = gravi_create_p2vm (wave_map,wave_param);
784 CPLCHECK_CLEAN ("Cannot create the P2VM data");
785
786 /* Loop on files */
787 for (int i = 0; i < nb_frame; i++) {
788
789 cpl_msg_info (cpl_func, " ***** file %d over %d ***** ", i+1, nb_frame );
790 current_frameset = cpl_frameset_duplicate (used_frameset);
791
792 /* Load this frame */
793 frame = cpl_frameset_get_position (p2vm_frameset, i);
794 cpl_frameset_insert (used_frameset, cpl_frame_duplicate (frame));
795 snprintf(ext_regexp, 499, "^(%s|%s)$", GRAVI_ARRAY_GEOMETRY_EXT, GRAVI_OPTICAL_TRAIN_EXT);
796 gravi_data * hdr_data = gravi_data_load_rawframe_ext (frame, current_frameset, ext_regexp);
797 CPLCHECK_CLEAN ("Cannot load data");
798
799 /* Verbose the shutters */
800 cpl_msg_info (cpl_func, "Shutters: %d-%d-%d-%d",
801 gravi_data_get_shutter (hdr_data, 0), gravi_data_get_shutter (hdr_data, 1),
802 gravi_data_get_shutter (hdr_data, 2), gravi_data_get_shutter (hdr_data, 3));
803
804 /* Create the product filename as the first P2VM file (1-1-0-0).
805 * This is to ensure the run_gravi_reduce.py script check
806 * for the correct product */
807 if ( frame_p2vm==NULL && gravi_data_check_shutter (hdr_data, 1,1,0,0) )
808 {
809 cpl_msg_info (cpl_func,"Use this frame for the P2VM product");
810 frame_p2vm = frame;
811 }
812
813 /*
814 * If all shutter open we just continue
815 */
816 if ( gravi_data_check_shutter (hdr_data, 1,1,1,1) ) {
817
818 /* Here we go to next file */
819 cpl_msg_info (cpl_func, "Nothing to be done with the file... yet.");
820
821 FREE (gravi_data_delete, hdr_data);
822 FREE (cpl_frameset_delete, current_frameset);
823 continue;
824 }
825 FREE (gravi_data_delete, hdr_data);
826 /* End if all shutters open */
827
828 /* Load SC */
830 gravi_data * sc_data = gravi_data_load_rawframe_ext (frame, current_frameset, ext_regexp);
831 gravi_data_detector_cleanup (sc_data, parlist);
832
833 /* Extract SC spectrum */
834 preproc_data = gravi_extract_spectrum (sc_data, profile_map, dark_map,
835 badpix_map, NULL, parlist, GRAVI_DET_SC);
836 CPLCHECK_CLEAN ("Cannot extract spectrum");
837 FREE (gravi_data_delete, sc_data);
838
839 /* Rescale SC to common wavelength */
840 gravi_align_spectrum (preproc_data, wave_map, p2vm_map, GRAVI_DET_SC);
841 CPLCHECK_CLEAN ("Cannot re-interpolate spectrum");
842
843 /* Compute the part of the p2vm associated to this file */
844 gravi_compute_p2vm (p2vm_map, preproc_data, valid_trans, valid_CP, GRAVI_DET_SC);
845 CPLCHECK_CLEAN("Cannot compute the P2VM");
846
847 /* Load FT */
848 snprintf(ext_regexp, 499, "^(%s|%s)$", GRAVI_IMAGING_DATA_FT_EXT, GRAVI_IMAGING_DETECTOR_FT_EXT);
849 gravi_data * ft_data = gravi_data_load_rawframe_ext (frame, NULL, ext_regexp);
850
851 /* Extract FT spectrum */
852 gravi_data * ft_preproc_data = gravi_extract_spectrum (ft_data, profile_map, dark_map,
853 badpix_map, NULL, parlist, GRAVI_DET_FT);
854 FREE (gravi_data_delete, ft_data);
855 CPLCHECK_CLEAN ("Cannot extract spectrum");
856
857 /* Rescale FT to common wavelength */
858 gravi_align_spectrum (ft_preproc_data, wave_map, p2vm_map, GRAVI_DET_FT);
859 CPLCHECK_CLEAN ("Cannot re-interpolate spectrum");
860
861 /* Compute the part of the p2vm associated to this file */
862 gravi_compute_p2vm (p2vm_map, ft_preproc_data, valid_trans, valid_CP, GRAVI_DET_FT);
863 CPLCHECK_CLEAN("Cannot compute the P2VM");
864
865 /* Copy FT extensions to spectrum_data */
866 gravi_data_move_ext(preproc_data, ft_preproc_data, GRAVI_IMAGING_DETECTOR_FT_EXT);
867 gravi_data_move_ext(preproc_data, ft_preproc_data, GRAVI_SPECTRUM_DATA_FT_EXT);
868 FREE (gravi_data_delete, ft_preproc_data);
869
870 /* Option save the preproc file */
871 if (gravi_param_get_bool (parlist,"gravity.dfs.preproc-file")) {
872
873 gravi_data_save_new (preproc_data, frameset, NULL, NULL, parlist,
874 current_frameset, frame, "gravity_p2vm",
875 NULL, GRAVI_PREPROC);
876 }
877
878 /* Delete the preproc data */
879 start = clock();
880 FREE (gravi_data_delete,preproc_data);
881 cpl_msg_info(cpl_func, "Execution time to delete preproc_data : %f s",
882 (clock() - start) / (double)CLOCKS_PER_SEC);
883
884 /* End loop on files to build the p2vm */
885 FREE (cpl_frameset_delete, current_frameset);
886 }
887
888
889 /*
890 * (7) P2VM normalization
891 */
892
893 gravi_p2vm_normalisation (p2vm_map, valid_trans, valid_CP);
894 CPLCHECK_CLEAN("Cannot normalise the p2vm_map");
895
896
897 /*
898 * (8) Analyse the WAVE to get the phase correction
899 * and the internal spectrum to latter correct.
900 */
901
902 cpl_msg_info (cpl_func, " ***** Analyse the WAVE file to calibrate the internal closure and transmission ***** ");
903
904 /* Get the WAVE_SC frame (or WAVE if WAVE_SC does not exist)*/
905 if (!cpl_frameset_is_empty (wavesc_frameset)) {
906 /* TODO: using wavesc instead of wave, but does not work for now (wrapping issue?) */
907 frame = cpl_frameset_get_position (wave_frameset, 0);
908 } else {
909 frame = cpl_frameset_get_position (wave_frameset, 0);
910 }
911
912 /* Load SC WAVE */
914 gravi_data * wave_sc_data = gravi_data_load_rawframe_ext (frame, NULL, ext_regexp);
915 gravi_data_detector_cleanup (wave_sc_data, parlist);
916
917 /* Extract SC spectrum */
918 preproc_data = gravi_extract_spectrum (wave_sc_data, profile_map, dark_map,
919 badpix_map, NULL, parlist, GRAVI_DET_SC);
920 CPLCHECK_CLEAN ("Cannot extract SC spectrum");
921
922 /* Move extensions necessary to compute the p2vmred */
923 gravi_data_move_ext (preproc_data, wave_sc_data, GRAVI_ARRAY_GEOMETRY_EXT);
924 gravi_data_move_ext (preproc_data, wave_sc_data, GRAVI_OPTICAL_TRAIN_EXT);
925 FREE (gravi_data_delete, wave_sc_data);
926 CPLCHECK_CLEAN ("Cannot move ext");
927
928 /* Rescale to common wavelength */
929 gravi_align_spectrum (preproc_data, wave_map, p2vm_map, GRAVI_DET_SC);
930 CPLCHECK_CLEAN ("Cannot re-interpolate SC spectrum");
931
932 /* Compute P2VMRED */
933 p2vmred_data = gravi_compute_p2vmred(preproc_data, p2vm_map, "gravi_single",
934 parlist);
935 FREE (gravi_data_delete, preproc_data);
936 CPLCHECK_CLEAN ("Cannot apply p2vm");
937
938 /* Load FT WAVE */
940 gravi_data * wave_ft_data = gravi_data_load_rawframe_ext (frame, NULL, ext_regexp);
941
942 /* Extract FT spectrum */
943 gravi_data * ft_preproc_data = gravi_extract_spectrum (wave_ft_data, profile_map, dark_map,
944 badpix_map, NULL, parlist, GRAVI_DET_FT);
945 CPLCHECK_CLEAN ("Cannot extract FT spectrum");
946
947 /* Move extensions necessary to compute the p2vmred */
948 gravi_data_move_ext (ft_preproc_data, wave_ft_data, GRAVI_ARRAY_GEOMETRY_EXT);
949 gravi_data_move_ext (ft_preproc_data, wave_ft_data, GRAVI_OPTICAL_TRAIN_EXT);
950 FREE (gravi_data_delete, wave_ft_data);
951 CPLCHECK_CLEAN ("Cannot move ext");
952
953 /* Rescale to common wavelength */
954 gravi_align_spectrum (ft_preproc_data, wave_map, p2vm_map, GRAVI_DET_FT);
955 CPLCHECK_CLEAN ("Cannot re-interpolate FT spectrum");
956
957 /* Compute P2VMRED */
958 gravi_data * ft_p2vmred_data = gravi_compute_p2vmred(ft_preproc_data,
959 p2vm_map, "gravi_single", parlist);
960 FREE (gravi_data_delete, ft_preproc_data);
961 CPLCHECK_CLEAN ("Cannot apply p2vm");
962
963 /* Merge extensions of SC and FT extracted spectra */
964 gravi_data_move_ext(p2vmred_data, ft_p2vmred_data, GRAVI_OI_WAVELENGTH_EXT);
965 gravi_data_move_ext(p2vmred_data, ft_p2vmred_data, GRAVI_OI_VIS_EXT);
966 gravi_data_move_ext(p2vmred_data, ft_p2vmred_data, GRAVI_OI_FLUX_EXT);
967 FREE (gravi_data_delete, ft_p2vmred_data);
968 CPLCHECK_CLEAN ("Cannot merge SC and FT extensions");
969
970 /* Perform the phase correction */
971 if (!strcmp (gravi_param_get_string (parlist, "gravity.calib.phase-calibration"), "CLOSURE")) {
972 gravi_p2vm_phase_correction (p2vm_map, p2vmred_data, 0);
973 }
974 else if (!strcmp (gravi_param_get_string (parlist, "gravity.calib.phase-calibration"), "DISP")) {
975 gravi_p2vm_phase_correction (p2vm_map, p2vmred_data, 1);
976 }
977 else if (!strcmp (gravi_param_get_string (parlist, "gravity.calib.phase-calibration"), "FULL")) {
978 gravi_p2vm_phase_correction (p2vm_map, p2vmred_data, 2);
979 }
980 else {
981 cpl_msg_info (cpl_func, "P2VM phases are kept to zero (option phase-calibration=NONE)");
982 }
983 CPLCHECK_CLEAN ("Cannot recalibrate the P2VM phases");
984
985 /* Add the OI_FLUX to further normalize the flux if needed */
986 gravi_p2vm_transmission (p2vm_map, p2vmred_data);
987 FREE (gravi_data_delete, p2vmred_data);
988
989 CPLCHECK_CLEAN ("Cannot compute the transmission");
990
991 /* Add the bad pixel masks to the P2VM if we are making the P2VM for TAC */
992 if (gravi_param_get_bool(parlist, "gravity.calib.force-wave-ft-equal"))
993 {
994 cpl_msg_info(cpl_func,"storing bad pixel mask for TAC");
995 gravi_data_copy_ext (p2vm_map, badpix_map, GRAVI_IMAGING_DATA_FT_EXT);
996 CPLCHECK_CLEAN ("Cannot append bad pixel mask");
997 }
998 /*
999 * (9) Create product frame, add DataFlow keywords, save the file, log the
1000 * saved file in the input frameset. Note that the output filename
1001 * is already created (from first P2VM file)
1002 */
1003
1004 gravi_data_save_new (p2vm_map, frameset, NULL, NULL, parlist,
1005 used_frameset, frame_p2vm, "gravity_p2vm",
1006 NULL, GRAVI_P2VM_MAP);
1007
1008 CPLCHECK_CLEAN("Could not save the P2VM on the output file");
1009
1010 /* Terminate the function */
1011 goto cleanup;
1012
1013cleanup:
1014 /* Deallocation of all variables */
1015 cpl_msg_info (cpl_func,"Cleanup memory");
1016
1017 FREE (cpl_frameset_delete, dark_frameset);
1018 FREE (cpl_frameset_delete, darkcalib_frameset);
1019 FREE (cpl_frameset_delete, badcalib_frameset);
1020 FREE (gravi_data_delete, spectrum_data);
1021 FREE (gravi_data_delete, p2vmred_data);
1022 FREE (gravi_data_delete, dark_map);
1023 FREELOOP (gravi_data_delete, raw_data, nb_frame_gain);
1024 FREE (gravi_data_delete, badpix_map);
1025 FREE (cpl_propertylist_delete, met_plist);
1026 FREE (cpl_frameset_delete, wavecalib_frameset);
1027 FREE (cpl_frameset_delete, flatcalib_frameset);
1028 FREE (cpl_frameset_delete, flat_frameset);
1029 FREE (cpl_frameset_delete, wave_frameset);
1030 FREE (cpl_frameset_delete, wavesc_frameset);
1031 FREE (cpl_frameset_delete, used_frameset);
1032 FREE (gravi_data_delete, data);
1033 FREE (gravi_data_delete, preproc_data);
1034 FREE (gravi_data_delete, dark_map);
1035 FREE (gravi_data_delete, wave_map);
1036 FREE (gravi_data_delete, profile_map);
1037 FREELOOP (cpl_free, valid_CP, 2);
1038 FREELOOP (cpl_free, valid_trans, 2);
1039 FREE (gravi_data_delete, p2vm_map);
1040 FREE (cpl_frameset_delete, p2vm_frameset);
1041 FREE (cpl_frameset_delete, current_frameset);
1042 FREE (cpl_frameset_delete, wave_param_frameset);
1043 FREE (gravi_data_delete, wave_param);
1044
1045 //This is a workaround to aliviate PIPE-6316. For some reason the allocation
1046 //pattern of the recipe causes malloc to keep many pages in the allocation
1047 //arena which are not returned to the OS (typically calling brk()).
1048 //This causes issues if there is a fork() call, since then the whole
1049 //address space of the parent is duplicated in the child. This is actually
1050 //the case with the system() call in esorex.
1051 //malloc_trim() is specific to GLIBC and will ask malloc() to return
1052 //as many pages as possible. The code is not portable, hence the guards
1053#if defined(__linux__) && defined(__GLIBC__)
1054 malloc_trim(0);
1055#endif
1056
1058 return (int)cpl_error_get_code();
1059}
1060
1061
typedefCPL_BEGIN_DECLS struct _gravi_data_ gravi_data
Definition: gravi_data.h:39
#define gravi_data_get_header(data)
Definition: gravi_data.h:75
#define GRAVI_RECIPE_OUTPUT
Definition: gravi_dfs.h:39
#define GRAVI_DARK_RAW
Definition: gravi_dfs.h:46
#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_BAD_MAP
Definition: gravi_dfs.h:73
#define GRAVI_WAVE_RAW
Definition: gravi_dfs.h:47
#define GRAVI_WAVE_MAP
Definition: gravi_dfs.h:75
#define GRAVI_FLAT_MAP
Definition: gravi_dfs.h:74
#define GRAVI_DARK_MAP
Definition: gravi_dfs.h:77
#define GRAVI_RECIPE_INPUT
Definition: gravi_dfs.h:38
#define GRAVI_P2VM_RAW
Definition: gravi_dfs.h:44
#define GRAVI_FLAT_RAW
Definition: gravi_dfs.h:50
#define GRAVI_WAVESC_RAW
Definition: gravi_dfs.h:48
cpl_msg_info(cpl_func, "Compute WAVE_SCAN for %s", GRAVI_TYPE(type_data))
#define GRAVI_IMAGING_DETECTOR_FT_EXT
Definition: gravi_pfits.h:82
#define GRAVI_SC
Definition: gravi_pfits.h:165
#define GRAVI_IMAGING_DATA_FT_EXT
Definition: gravi_pfits.h:43
#define GRAVI_OI_VIS_EXT
Definition: gravi_pfits.h:92
#define GRAVI_OI_FLUX_EXT
Definition: gravi_pfits.h:93
@ GRAVI_DET_FT
Definition: gravi_pfits.h:171
@ GRAVI_DET_SC
Definition: gravi_pfits.h:172
#define GRAVI_IMAGING_DATA_SC_EXT
Definition: gravi_pfits.h:44
#define GRAVI_SPECTRUM_DATA_FT_EXT
Definition: gravi_pfits.h:54
#define GRAVI_P2VM_MET_EXT
Definition: gravi_pfits.h:71
#define GRAVI_ARRAY_GEOMETRY_EXT
Definition: gravi_pfits.h:84
#define GRAVI_IMAGING_DETECTOR_SC_EXT
Definition: gravi_pfits.h:81
#define GRAVI_METROLOGY_EXT
Definition: gravi_pfits.h:60
#define GRAVI_FT
Definition: gravi_pfits.h:166
#define GRAVI_OI_WAVELENGTH_EXT
Definition: gravi_pfits.h:91
#define GRAVI_OPTICAL_TRAIN_EXT
Definition: gravi_pfits.h:85
#define gravi_data_check_shutter(data, t0, t1, t2, t3)
Definition: gravi_utils.h:89
#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 ERROR_CLEAN(code, msg)
Definition: gravi_utils.h:60
#define gravi_msg_function_start(flag)
Definition: gravi_utils.h:84
#define gravi_data_get_shutter(data, tel)
Definition: gravi_utils.h:88
#define FREELOOP(function, variable, n)
Definition: gravi_utils.h:72
static char gravity_p2vm_short[]
Definition: gravity_p2vm.c:75
static char gravity_p2vm_description[]
Definition: gravity_p2vm.c:76
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
Definition: gravity_p2vm.c:113
static int gravity_p2vm_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
Definition: gravity_p2vm.c:302
static int gravity_p2vm_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
Definition: gravity_p2vm.c:240
static int gravity_p2vm(cpl_frameset *, const cpl_parameterlist *)
Compute the DARK, BAD, FLAT, WAVE, P2VM from a list of calibration set.
Definition: gravity_p2vm.c:334
static int gravity_p2vm_create(cpl_plugin *)
Setup the recipe options
Definition: gravity_p2vm.c:154
cpl_propertylist * gravi_compute_gain(gravi_data **flats_data, int nrawgain, gravi_data *dark_map)
Compute mean detector gain.
Definition: gravi_calib.c:1551
gravi_data * gravi_compute_profile(gravi_data **flats_data, gravi_data *dark_map, gravi_data *bad_map, int nflat, const cpl_parameterlist *params)
Computes the spatial profile of each spectrum for optimal extraction purpose.
Definition: gravi_calib.c:994
gravi_data * gravi_compute_dark(gravi_data *raw_data)
Compute the DARK calibration map.
Definition: gravi_calib.c:125
gravi_data * gravi_compute_badpix(gravi_data *dark_map, gravi_data **flats_data, int nflat, const cpl_parameterlist *params)
Identify the bad pixels in the DARK map and create the BAD map.
Definition: gravi_calib.c:1806
gravi_data * gravi_data_new(int nb_ext)
Create an empty gravi_data.
Definition: gravi_data.c:110
cpl_error_code gravi_data_add_table(gravi_data *self, cpl_propertylist *plist, const char *extname, cpl_table *table)
Add a BINTABLE extension in gravi_data.
Definition: gravi_data.c:2289
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
cpl_table * gravi_data_get_table(gravi_data *self, const char *extname)
Return a pointer on a table extension by its EXTNAME.
Definition: gravi_data.c:2096
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_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
gravi_data * gravi_data_load_rawframe_ext(cpl_frame *frame, cpl_frameset *used_frameset, const char *extensions_regexp)
Load a RAW FITS file and create a gravi_data from specified extensions.
Definition: gravi_data.c:760
void gravi_data_delete(gravi_data *self)
Delete a gravi data.
Definition: gravi_data.c:146
cpl_parameter * gravi_parameter_add_debug_file(cpl_parameterlist *self)
Definition: gravi_dfs.c:479
cpl_frameset * gravi_frameset_extract_wavesc_data(cpl_frameset *frameset)
Definition: gravi_dfs.c:1344
cpl_parameter * gravi_parameter_add_profile(cpl_parameterlist *self)
Add profile parameters to the input parameter list.
Definition: gravi_dfs.c:346
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_metrology(cpl_parameterlist *self)
Definition: gravi_dfs.c:615
cpl_parameter * gravi_parameter_add_extract(cpl_parameterlist *self)
Definition: gravi_dfs.c:686
cpl_parameter * gravi_parameter_add_biasmethod(cpl_parameterlist *self)
Definition: gravi_dfs.c:584
cpl_frameset * gravi_frameset_extract_wave_map(cpl_frameset *frameset)
Definition: gravi_dfs.c:1410
const char * gravi_param_get_string(const cpl_parameterlist *parlist, const char *name)
Definition: gravi_dfs.c:1550
cpl_parameter * gravi_parameter_add_wave(cpl_parameterlist *self)
Add wavelength calibration parameters to the input parameter list.
Definition: gravi_dfs.c:423
cpl_frameset * gravi_frameset_extract_bad_map(cpl_frameset *frameset)
Definition: gravi_dfs.c:1414
cpl_frameset * gravi_frameset_extract_flat_data(cpl_frameset *frameset)
Definition: gravi_dfs.c:1315
cpl_frameset * gravi_frameset_extract_wave_data(cpl_frameset *frameset)
Definition: gravi_dfs.c:1340
cpl_frameset * gravi_frameset_extract_dark_map(cpl_frameset *frameset)
Definition: gravi_dfs.c:1406
cpl_frameset * gravi_frameset_extract_p2vm_data(cpl_frameset *frameset)
Extract P2VM_RAW frame from the input frameset.
Definition: gravi_dfs.c:1293
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_parameter * gravi_parameter_add_badpix(cpl_parameterlist *self)
Add badpix parameters to the input parameter list.
Definition: gravi_dfs.c:194
cpl_frameset * gravi_frameset_extract_wave_param(cpl_frameset *frameset)
Definition: gravi_dfs.c:1434
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_table * gravi_metrology_compute_p2vm(cpl_table *metrology_table, double wave_met)
Calibrate the P2VM of the metrology.
cpl_error_code gravi_p2vm_phase_correction(gravi_data *p2vm_map, gravi_data *p2vmred_data, int full_phase)
Correct the phase of the P2VM from internal closure-phases.
Definition: gravi_p2vm.c:1267
cpl_error_code gravi_p2vm_normalisation(gravi_data *p2vm_map, int **valid_trans, int **valid_pair)
The given output FITS file contain a p2vm table with the values of the transmission,...
Definition: gravi_p2vm.c:880
cpl_error_code gravi_compute_p2vm(gravi_data *p2vm_map, gravi_data *preproc_data, int **valid_trans, int **valid_pair, enum gravi_detector_type det_type)
The given output FITS file contain a p2vm table with the values of the transmission,...
Definition: gravi_p2vm.c:546
cpl_error_code gravi_p2vm_transmission(gravi_data *p2vm_map, gravi_data *p2vmred_data)
Compute the flux normalisation in the P2VM.
Definition: gravi_p2vm.c:1550
gravi_data * gravi_create_p2vm(gravi_data *wave_map, gravi_data *wave_param)
Create a new P2VM map.
Definition: gravi_p2vm.c:413
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.
double gravi_pfits_get_met_wavelength_mean(const cpl_propertylist *plist, cpl_table *met_table)
Definition: gravi_pfits.c:312
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.
const char * gravi_get_license(void)
Get the pipeline copyright and license.
Definition: gravi_utils.c:104
cpl_error_code gravi_wave_compute_opds(gravi_data *spectrum_data, cpl_table *met_table, const cpl_parameterlist *parlist)
Recover the OPD modulation from a spectrum_data and vismet_table.
Definition: gravi_wave.c:819
cpl_error_code gravi_compute_wave(gravi_data *wave_map, gravi_data *spectrum_data, int type_data, const cpl_parameterlist *parlist, gravi_data *wave_param)
Create the WAVE calibration map.
Definition: gravi_wave.c:2053
cpl_error_code gravi_wave_qc(gravi_data *wave_map, gravi_data *profile_map)
Compute the QC parameters of the WAVE product.
Definition: gravi_wave.c:1906