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