GRAVI Pipeline Reference Manual 1.9.0
Loading...
Searching...
No Matches
gravity_viscal.c
Go to the documentation of this file.
1/* $Id: gravity_viscal.c,v 1.29 2011/12/3 09:16:12 nazouaoui Exp $
2 *
3 * This file is part of the GRAVI Pipeline
4 * Copyright (C) 2002,2003 European Southern Observatory
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21/*
22 * $Author: nazouaoui $
23 * $Date: 2011/12/3 09:16:12 $
24 * $Revision: 1.29 $
25 * $Name: $
26 *
27 * History : EkW 27/11/2019 Add smoothing parameter
28 */
29
30#ifdef HAVE_CONFIG_H
31#include <config.h>
32#endif
33
34/*-----------------------------------------------------------------------------
35 Includes
36 -----------------------------------------------------------------------------*/
37
38#include <cpl.h>
39#include <stdio.h>
40#include <string.h>
41#include <math.h>
42#include <time.h>
43
44#include "gravi_utils.h"
45#include "gravi_pfits.h"
46#include "gravi_data.h"
47#include "gravi_dfs.h"
48#include "gravi_calib.h"
49#include "gravi_p2vmred.h"
50#include "gravi_vis.h"
51#include "gravi_tf.h"
52#include "gravi_idp.h"
53
54/*-----------------------------------------------------------------------------
55 Private function prototypes
56 -----------------------------------------------------------------------------*/
57
58static int gravity_viscal_create(cpl_plugin *);
59static int gravity_viscal_exec(cpl_plugin *);
60static int gravity_viscal_destroy(cpl_plugin *);
61static int gravity_viscal(cpl_frameset *, const cpl_parameterlist *);
62
63/*-----------------------------------------------------------------------------
64 Static variables
65 -----------------------------------------------------------------------------*/
66
67static char gravity_viscal_short[] = "Calibrate visibilities from the transfer function.";
69 "This recipe calibrates the visibilities acquired on science target using visibilities acquired on a calibrator target. If the DIAMETER_CAT is not provided, the recipe will use the diameter provided in the header to compute the transfer function QC parameters. The corresponding keywords are INS.SOBJ.DIAMETER and FT.ROBJ.DIAMETER. The OI_FLUX data are not yet calibrated."
70 "\n"
71 "The tag in the DO category can be SINGLE/DUAL and CAL/SCI. The tag in the PRO.CATG category will be SINGLE/DUAL and CAL/SCI depending on the input tag.\n"
73 "* Loop on all input CALIB files, compute the TF for each of them and write the corresponding product\n"
74 "* Loop on all input SCIENCE files, interpolate the TF at that time, calibrate, and write the corresponding product\n"
76 GRAVI_VIS_SINGLE_SCIENCE" (>=1) : visibilities on sciences\n"
77 GRAVI_VIS_SINGLE_CALIB" (>=1) : visibilities on calibrators\n"
78 GRAVI_DIAMETER_CAT" (opt) : catalog of stellar diameters\n"
80 GRAVI_VIS_SINGLE_CALIBRATED" : calibrated science visibilities\n"
81 GRAVI_TF_SINGLE_CALIB" : Transfer Function (TF) estimated on calibrators\n"
82 GRAVI_TF_SINGLE_SCIENCE" : TF interpolated at the time of sciences\n"
83 "";
84
85/*-----------------------------------------------------------------------------
86 Function code
87 -----------------------------------------------------------------------------*/
88
89/*----------------------------------------------------------------------------*/
99/*----------------------------------------------------------------------------*/
100int cpl_plugin_get_info(cpl_pluginlist * list)
101{
102 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe );
103 cpl_plugin * plugin = &recipe->interface;
104
105 if (cpl_plugin_init(plugin,
106 CPL_PLUGIN_API,
107 GRAVI_BINARY_VERSION,
108 CPL_PLUGIN_TYPE_RECIPE,
109 "gravity_viscal",
112 "Nabih Azouaoui, Vincent Lapeyrere, JB. Le Bouquin",
113 PACKAGE_BUGREPORT,
118 cpl_msg_error(cpl_func, "Plugin initialization failed");
119 (void)cpl_error_set_where(cpl_func);
120 return 1;
121 }
122
123 if (cpl_pluginlist_append(list, plugin)) {
124 cpl_msg_error(cpl_func, "Error adding plugin to list");
125 (void)cpl_error_set_where(cpl_func);
126 return 1;
127 }
128
129 return 0;
130}
131
132/*----------------------------------------------------------------------------*/
140/*----------------------------------------------------------------------------*/
141static int gravity_viscal_create(cpl_plugin * plugin)
142{
143 cpl_recipe * recipe;
144 cpl_parameter * p;
145
146 /* Do not create the recipe if an error code is already set */
147 if (cpl_error_get_code() != CPL_ERROR_NONE) {
148 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
149 cpl_func, __LINE__, cpl_error_get_where());
150 return (int)cpl_error_get_code();
151 }
152
153 if (plugin == NULL) {
154 cpl_msg_error(cpl_func, "Null plugin");
155 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
156 }
157
158 /* Verify plugin type */
159 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
160 cpl_msg_error(cpl_func, "Plugin is not a recipe");
161 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
162 }
163
164 /* Get the recipe */
165 recipe = (cpl_recipe *)plugin;
166
167 /* Create the parameters list in the cpl_recipe object */
168 recipe->parameters = cpl_parameterlist_new();
169 if (recipe->parameters == NULL) {
170 cpl_msg_error(cpl_func, "Parameter list allocation failed");
171 cpl_ensure_code(0, (int)CPL_ERROR_ILLEGAL_OUTPUT);
172 }
173
174 /* Fill the parameters list */
175 gravi_parameter_add_static_name (recipe->parameters);
176
177 /* delta-time */
178 p = cpl_parameter_new_value ("gravity.viscal.delta-time-calib", CPL_TYPE_DOUBLE,
179 "Delta time to interpolate the TF [s]",
180 "gravity.viscal", 3600.0);
181 cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "delta-time-calib");
182 cpl_parameter_disable (p, CPL_PARAMETER_MODE_ENV);
183 cpl_parameterlist_append (recipe->parameters, p);
184
185 /* force-calib */
186 p = cpl_parameter_new_value ("gravity.viscal.force-calib", CPL_TYPE_BOOL,
187 "Force the calibration, don't check setup",
188 "gravity.viscal", FALSE);
189 cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "force-calib");
190 cpl_parameter_disable (p, CPL_PARAMETER_MODE_ENV);
191 cpl_parameterlist_append (recipe->parameters, p);
192
193 /* smooth */
194 p = cpl_parameter_new_value ("gravity.viscal.nsmooth-tfvis-sc", CPL_TYPE_INT,
195 "Smooth the TF spectrally by this number of "
196 "spectral bin, to enhance SNR (only "
197 "apply to VIS2, VISPHI, VISAMP, T3PHI, T3AMP). "
198 "This parameter is ignored in spectral mode LOW.",
199 "gravity.viscal", 0);
200 cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "nsmooth-tfvis-sc");
201 cpl_parameter_disable (p, CPL_PARAMETER_MODE_ENV);
202 cpl_parameterlist_append (recipe->parameters, p);
203
204 p = cpl_parameter_new_value ("gravity.viscal.nsmooth-tfflux-sc", CPL_TYPE_INT,
205 "Smooth the TF spectrally by this number of "
206 "spectral bin, to enhance SNR (only "
207 "apply to FLUX, RVIS, IVIS). "
208 "This parameter is ignored in spectral mode LOW.",
209 "gravity.viscal", 0);
210 cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "nsmooth-tfflux-sc");
211 cpl_parameter_disable (p, CPL_PARAMETER_MODE_ENV);
212 cpl_parameterlist_append (recipe->parameters, p);
213
214 p = cpl_parameter_new_value ("gravity.viscal.maxdeg-tfvis-sc", CPL_TYPE_INT,
215 "Fit the TF spectrally by a polynomial to enhance SNR "
216 "(only apply to VIS2, VISPHI, VISAMP, T3PHI, T3AMP). "
217 "This parameter is ignored in spectral mode LOW.",
218 "gravity.viscal", 5);
219 cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "maxdeg-tfvis-sc");
220 cpl_parameter_disable (p, CPL_PARAMETER_MODE_ENV);
221 cpl_parameterlist_append (recipe->parameters, p);
222
223 p = cpl_parameter_new_value ("gravity.viscal.calib-flux", CPL_TYPE_BOOL,
224 "Normalize the FLUX by the calibrator.",
225 "gravity.viscal", FALSE);
226 cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "calib-flux");
227 cpl_parameter_disable (p, CPL_PARAMETER_MODE_ENV);
228 cpl_parameterlist_append (recipe->parameters, p);
229
230 /* EKW 27/11/2019 smoothing for e.g. IMAGING_PHASE/MEDIUM */
231 p = cpl_parameter_new_value ("gravity.viscal.smoothing", CPL_TYPE_BOOL,
232 "control smoothing of transfer function (TF)"
233 "TRUE do smoothing - FALSE Skip smoothing",
234 "gravity.viscal", TRUE);
235 cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "smoothing");
236 cpl_parameter_disable (p, CPL_PARAMETER_MODE_ENV);
237 cpl_parameterlist_append (recipe->parameters, p);
238
239 p = cpl_parameter_new_value ("gravity.viscal.separate-phase-calib", CPL_TYPE_BOOL,
240 "enable use of distinct calibrator for VISPHI",
241 "gravity.viscal", FALSE);
242 cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI, "separate-phase-calib");
243 cpl_parameter_disable (p, CPL_PARAMETER_MODE_ENV);
244 cpl_parameterlist_append (recipe->parameters, p);
245
246 return 0;
247}
248
249/*----------------------------------------------------------------------------*/
255/*----------------------------------------------------------------------------*/
256static int gravity_viscal_exec(cpl_plugin * plugin)
257{
258
259 cpl_recipe * recipe;
260 int recipe_status;
261 cpl_errorstate initial_errorstate = cpl_errorstate_get();
262
263 /* Return immediately if an error code is already set */
264 if (cpl_error_get_code() != CPL_ERROR_NONE) {
265 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
266 cpl_func, __LINE__, cpl_error_get_where());
267 return (int)cpl_error_get_code();
268 }
269
270 if (plugin == NULL) {
271 cpl_msg_error(cpl_func, "Null plugin");
272 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
273 }
274
275 /* Verify plugin type */
276 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
277 cpl_msg_error(cpl_func, "Plugin is not a recipe");
278 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
279 }
280
281 /* Get the recipe */
282 recipe = (cpl_recipe *)plugin;
283
284 /* Verify parameter and frame lists */
285 if (recipe->parameters == NULL) {
286 cpl_msg_error(cpl_func, "Recipe invoked with NULL parameter list");
287 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
288 }
289 if (recipe->frames == NULL) {
290 cpl_msg_error(cpl_func, "Recipe invoked with NULL frame set");
291 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
292 }
293
294 /* Invoke the recipe */
295 recipe_status = gravity_viscal(recipe->frames, recipe->parameters);
296
297 /* Ensure DFS-compliance of the products */
298
299 if (cpl_dfs_update_product_header(recipe->frames)) {
300 if (!recipe_status){
301 recipe_status = (int)cpl_error_get_code();
302 }
303 }
304
305 if (!cpl_errorstate_is_equal(initial_errorstate)) {
306 /* Dump the error history since recipe execution start.
307 At this point the recipe cannot recover from the error */
308 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
309 }
310
311 return recipe_status;
312}
313
314/*----------------------------------------------------------------------------*/
320/*----------------------------------------------------------------------------*/
321static int gravity_viscal_destroy(cpl_plugin * plugin)
322{
323 cpl_recipe * recipe;
324
325 if (plugin == NULL) {
326 cpl_msg_error(cpl_func, "Null plugin");
327 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
328 }
329
330 /* Verify plugin type */
331 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
332 cpl_msg_error(cpl_func, "Plugin is not a recipe");
333 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
334 }
335
336 /* Get the recipe */
337 recipe = (cpl_recipe *)plugin;
338
339 cpl_parameterlist_delete(recipe->parameters);
340
341 return 0;
342}
343
344
345/*----------------------------------------------------------------------------*/
353/*----------------------------------------------------------------------------*/
354static int gravity_viscal(cpl_frameset * frameset,
355 const cpl_parameterlist * parlist)
356{
357 cpl_frameset * vis_calib_frameset = NULL, * vis_sci_frameset = NULL, *current_frameset = NULL;
358 cpl_frameset * tf_calib_frameset = NULL, * used_frameset = NULL, * diamcat_frameset = NULL;
359 cpl_frame * frame = NULL;
360
361 cpl_propertylist * applist = NULL;
362
363 gravi_data ** vis_calibs = NULL, * vis_calib = NULL, * visphi_calib = NULL, * zero_data = NULL, * tf_science = NULL;
364 gravi_data * calibrated = NULL, * vis_data = NULL, * diamcat_data = NULL;
365
366 int data_mode, nb_frame_tf = 0, nb_frame_calib = 0, nb_frame_sci, i, j, nb_calib = 0;
367
368 /* Message */
371
372 /* Identify the RAW and CALIB frames in the input frameset */
373 cpl_ensure_code(gravi_dfs_set_groups(frameset) == CPL_ERROR_NONE,
374 cpl_error_get_code());
375
376 /* Extract a set of vis_calib and vis_sci data frameset */
377 vis_calib_frameset = gravi_frameset_extract_vis_calib (frameset);
378 vis_sci_frameset = gravi_frameset_extract_vis_science (frameset);
379 tf_calib_frameset = gravi_frameset_extract_tf_calib (frameset);
380 diamcat_frameset = gravi_frameset_extract_diamcat_map (frameset);
381
382 /* To use this recipe the frameset must contain
383 * at least one VIS_*_CAL frame or TF_*_CAL frame. */
384 if ( cpl_frameset_is_empty (vis_calib_frameset) &&
385 cpl_frameset_is_empty (tf_calib_frameset) ) {
386 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
387 "No VIS or TF file on the frameset") ;
388 goto cleanup;
389 }
390
391 /* Get the number of the frames contained in the frameset */
392 nb_frame_tf = cpl_frameset_get_size (tf_calib_frameset);
393 nb_frame_calib = cpl_frameset_get_size (vis_calib_frameset);
394 nb_frame_sci = cpl_frameset_get_size (vis_sci_frameset);
395
396 /* Init memory */
397 vis_calibs = cpl_malloc ( (nb_frame_calib + nb_frame_tf) * sizeof (gravi_data *));
398 for (j = 0; j < (nb_frame_calib + nb_frame_tf); j++) vis_calibs[j] = NULL;
399
400 /*
401 * Load or compute of the transfer function
402 */
403
404 /* Load the DIAMETER_CAT
405 * FIXME: how/when install in the used_frameset ? */
406 if ( !cpl_frameset_is_empty (diamcat_frameset) ) {
407 frame = cpl_frameset_get_position (diamcat_frameset, 0);
408 diamcat_data = gravi_data_load_frame (frame, NULL);
409 }
410
411 /* Init the frameset for all calibration (TF computed and loaded) */
412 used_frameset = cpl_frameset_new();
413
414 /* Loop on the TF to compute */
415 for (j = 0; j < nb_frame_calib; j++) {
416 cpl_msg_info (cpl_func, "*** Compute TF %i over %i ***", j+1, nb_frame_calib);
417
418 /* Load the VIS data and compute TF */
419 frame = cpl_frameset_get_position (vis_calib_frameset, j);
420 vis_data = gravi_data_load_frame (frame, NULL);
421 vis_calib = gravi_compute_tf (vis_data, diamcat_data);
422
423 /* EKW 27/11/2019 - we may decide to skip smoothing */
424 int smoothing = gravi_param_get_bool (parlist, "gravity.viscal.smoothing");
425
426 /* Smooth the TF if required */
427 if ( !strcmp (gravi_data_get_spec_res (vis_calib), "LOW")) {
428 cpl_msg_info (cpl_func,"LOW spectral resolution -> don't smooth the TF");
429 } else if (!smoothing) {
430 cpl_msg_info (cpl_func,"smoothing parameter == FALSE -> don't smooth the TF");
431 } else {
432 cpl_size smooth_vis_sc = gravi_param_get_int (parlist, "gravity.viscal.nsmooth-tfvis-sc");
433 cpl_size smooth_flx_sc = gravi_param_get_int (parlist, "gravity.viscal.nsmooth-tfflux-sc");
434 cpl_size maxdeg_sc = gravi_param_get_int (parlist, "gravity.viscal.maxdeg-tfvis-sc");
435 gravi_vis_smooth (vis_calib, smooth_vis_sc, smooth_flx_sc, maxdeg_sc);
436 }
437
438 /* Check the TF has been computed */
439 if (vis_calib == NULL) {
440 cpl_msg_error (cpl_func, "Cannot compute this TF... continue");
441 goto cleanup_rawtf;
442 }
443
444 CPLCHECK_GOTO ("Cannot compute the TF", cleanup_rawtf);
445
446 /* Save the TF file */
447 data_mode = gravi_data_frame_get_mode (frame);
448
449 /* Store this successfull TF */
450 if (!strcmp(cpl_frame_get_tag(frame), GRAVI_VISPHI_SINGLE_CALIB) ||
451 !strcmp(cpl_frame_get_tag(frame), GRAVI_VISPHI_DUAL_CALIB)) {
452 if (!gravi_param_get_bool (parlist, "gravity.viscal.separate-phase-calib")) {
453 cpl_msg_warning (cpl_func, "visphi calib provided but --separate-phase-calib not set, will be ignored");
454 } else if (visphi_calib) {
455 cpl_msg_warning (cpl_func, "multiple visphi calib provided, will be ignored");
456 } else {
457 cpl_msg_info (cpl_func, "*** TF %i over %i to be used for visphi ***", j+1, nb_frame_calib);
458
459 gravi_data_save_new (vis_calib, frameset, NULL, NULL, parlist,
460 NULL, frame, "gravity_vis",
461 NULL, GRAVI_VISPHI_TF_CALIB(data_mode));
462 CPLCHECK_GOTO ("Cannot save the TF", cleanup_rawtf);
463
464 visphi_calib = vis_calib;
465 vis_calib = NULL;
466 }
467 } else {
468 gravi_data_save_new (vis_calib, frameset, NULL, NULL, parlist,
469 NULL, frame, "gravity_vis",
470 NULL, GRAVI_TF_CALIB(data_mode));
471 CPLCHECK_GOTO ("Cannot save the TF", cleanup_rawtf);
472
473 vis_calibs[nb_calib] = vis_calib;
474 vis_calib = NULL;
475 nb_calib++;
476 }
477
478 /* Update the used_frameset -- now used as calibration */
479 frame = cpl_frame_duplicate (frame);
480 cpl_frame_set_group (frame, CPL_FRAME_GROUP_CALIB);
481 cpl_frameset_insert (used_frameset, frame);
482
483 /* Clean memory of the loop */
484 cleanup_rawtf:
485 FREE (gravi_data_delete, vis_data);
486 FREE (gravi_data_delete, vis_calib);
487 }
488 /* End loop on the TF to compute */
489
490 cpl_msg_info (cpl_func,"*** Load already computed TF ***");
491
492 /* Loop on the TF to load */
493 for (j = 0; j < nb_frame_tf; j++) {
494 cpl_msg_info (cpl_func," %i over %i", j+1, nb_frame_tf);
495
496 frame = cpl_frameset_get_position (tf_calib_frameset, j);
497 vis_calib = gravi_data_load_frame (frame, used_frameset);
498
499 CPLCHECK_GOTO("Cannot load the TF", cleanup_caltf);
500
501 /* Store this successfull TF */
502 if (!strcmp(cpl_frame_get_tag(frame), GRAVI_VISPHI_TF_SINGLE_CALIB) ||
503 !strcmp(cpl_frame_get_tag(frame), GRAVI_VISPHI_TF_DUAL_CALIB)) {
504 if (!gravi_param_get_bool (parlist, "gravity.viscal.separate-phase-calib")) {
505 cpl_msg_warning (cpl_func, "visphi calib provided but --separate-phase-calib not set, will be ignored");
506 } else if (visphi_calib) {
507 cpl_msg_warning (cpl_func, "multiple visphi calib provided, will be ignored");
508 } else {
509 cpl_msg_info (cpl_func, "*** TF %i over %i to be used for visphi ***", j+1, nb_frame_tf);
510 visphi_calib = vis_calib;
511 vis_calib = NULL;
512 }
513 } else {
514 vis_calibs[nb_calib] = vis_calib;
515 vis_calib = NULL;
516 nb_calib++;
517 }
518
519 cleanup_caltf:
520 FREE (gravi_data_delete,vis_calib);
521 }
522 /* End loop on TF to load */
523
524 cpl_msg_info (cpl_func,"*** All TF computed or loaded ***");
525
526 cpl_msg_info (cpl_func, "Load or create successfully %i TF over %i input CAL files", nb_calib, nb_frame_calib + nb_frame_tf);
527
528 /*
529 * Compute the zero of the metrology if several TF are availables
530 */
531
532 if ( nb_calib > 1 ) {
533 cpl_msg_info (cpl_func, "*** Compute the zero of the metrology -- FIXME: to be done ***");
534 zero_data = gravi_compute_zp (vis_calibs, nb_calib);
535
536 CPLCHECK_GOTO("Cannot compute ZP", cleanup_zp);
537
538 gravi_data_save_new (zero_data, frameset, "output.fits", NULL, parlist,
539 used_frameset, NULL, "gravity_vis",
540 NULL, GRAVI_ZP_CAL);
541
542 CPLCHECK_GOTO("Cannot save ZP", cleanup_zp);
543
544 cleanup_zp:
545 FREE (gravi_data_delete,zero_data);
546 }
547
548
549 /*
550 * Apply the TF to the SCIENCE files of the frameset
551 */
552
553 /* Loop on the SCI files to calibrate */
554 for (i = 0; i < nb_frame_sci; i++){
555 current_frameset = cpl_frameset_duplicate (used_frameset);
556
557 cpl_msg_info (cpl_func, "*** Calibration of file %i over %i ***", i+1, nb_frame_sci);
558
559 frame = cpl_frameset_get_position (vis_sci_frameset, i);
560 vis_data = gravi_data_load_frame (frame, current_frameset);
561 tf_science = gravi_data_duplicate (vis_data);
562
563 calibrated = gravi_calibrate_vis (vis_data, vis_calibs, nb_calib, visphi_calib, tf_science, parlist);
564 CPLCHECK_GOTO("Cannot calibrate the visibility", cleanup_calib);
565
566 /* Save calibrated visibilities */
567 data_mode = gravi_data_frame_get_mode (frame);
568
569 /* Compute QC parameters */
570 cpl_msg_info (cpl_func, "Computing QC parameters for calibrated visibilities");
571 cpl_propertylist * idp_hdr = gravi_idp_compute(calibrated, gravi_data_get_header (calibrated),
572 current_frameset);
573 cpl_propertylist * extra_header = gravi_data_get_extra_primary_header (calibrated);
574 cpl_propertylist_append(extra_header, idp_hdr);
575 cpl_propertylist_delete(idp_hdr);
576
577 gravi_data_save_new (calibrated, frameset, NULL, NULL, parlist,
578 current_frameset, frame, "gravity_vis",
579 NULL, GRAVI_VIS_CALIBRATED(data_mode));
580
581 CPLCHECK_GOTO("Cannot save the calibrated visibility", cleanup_calib);
582
583 /* Save TF interpolated at the science visibilities */
584 data_mode = gravi_data_frame_get_mode (frame);
585
586 gravi_data_save_new (tf_science, frameset, NULL, NULL, parlist,
587 current_frameset, frame, "gravity_vis", NULL,
588 GRAVI_TF_SCIENCE(data_mode));
589
590 CPLCHECK_GOTO("Cannot save the TF interpolated for this visibility", cleanup_calib);
591
592 cleanup_calib:
593 FREE (gravi_data_delete,vis_data);
594 FREE (gravi_data_delete,tf_science);
595 FREE (gravi_data_delete,calibrated);
596 FREE (cpl_propertylist_delete,applist);
597 FREE (cpl_frameset_delete,current_frameset);
598 }
599 /* End loop on VIS_*_SCI files to calibrate */
600
601 /* Terminate the function */
602 goto cleanup;
603
604cleanup:
605 /* Deallocation of all variables */
606 cpl_msg_info(cpl_func,"Memory cleanup");
607
608 FREE (gravi_data_delete,diamcat_data);
609 FREE (gravi_data_delete,zero_data);
610 FREE (cpl_frameset_delete,tf_calib_frameset);
611 FREE (cpl_frameset_delete,vis_calib_frameset);
612 FREE (cpl_frameset_delete,vis_sci_frameset);
613 FREE (cpl_frameset_delete,diamcat_frameset);
614 FREE (cpl_frameset_delete,current_frameset);
615 FREE (cpl_frameset_delete,used_frameset);
616 FREE (gravi_data_delete, visphi_calib);
617 FREELOOP (gravi_data_delete,vis_calibs,nb_frame_calib+nb_frame_tf);
618
620 return (int)cpl_error_get_code();
621}
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_data_get_spec_res(data)
Definition: gravi_data.h:80
#define GRAVI_TF_SCIENCE(data_mode)
Definition: gravi_dfs.h:108
#define GRAVI_RECIPE_OUTPUT
Definition: gravi_dfs.h:39
#define GRAVI_VISPHI_SINGLE_CALIB
Definition: gravi_dfs.h:115
#define GRAVI_TF_SINGLE_CALIB
Definition: gravi_dfs.h:106
#define GRAVI_RECIPE_FLOW
Definition: gravi_dfs.h:37
#define GRAVI_VIS_SINGLE_SCIENCE
Definition: gravi_dfs.h:96
#define GRAVI_ZP_CAL
Definition: gravi_dfs.h:128
#define GRAVI_TF_CALIB(data_mode)
Definition: gravi_dfs.h:112
#define GRAVI_DIAMETER_CAT
Definition: gravi_dfs.h:80
#define GRAVI_RECIPE_INPUT
Definition: gravi_dfs.h:38
#define GRAVI_VIS_SINGLE_CALIBRATED
Definition: gravi_dfs.h:101
#define GRAVI_VIS_SINGLE_CALIB
Definition: gravi_dfs.h:97
#define GRAVI_TF_SINGLE_SCIENCE
Definition: gravi_dfs.h:107
#define GRAVI_VISPHI_TF_CALIB(data_mode)
Definition: gravi_dfs.h:119
#define GRAVI_VISPHI_DUAL_CALIB
Definition: gravi_dfs.h:116
#define GRAVI_VISPHI_TF_DUAL_CALIB
Definition: gravi_dfs.h:118
#define GRAVI_VIS_CALIBRATED(data_mode)
Definition: gravi_dfs.h:103
#define GRAVI_VISPHI_TF_SINGLE_CALIB
Definition: gravi_dfs.h:117
cpl_propertylist * gravi_idp_compute(gravi_data *vis_data, cpl_propertylist *header, cpl_frameset *frameset)
Create IDP keywords to satisfy standard.
Definition: gravi_idp.c:47
cpl_msg_info(cpl_func, "Compute WAVE_SCAN for %s", GRAVI_TYPE(type_data))
#define CPLCHECK_GOTO(msg, tag)
Definition: gravi_utils.h:57
#define gravi_msg_function_exit(flag)
Definition: gravi_utils.h:85
#define FREE(function, variable)
Definition: gravi_utils.h:69
#define gravi_msg_function_start(flag)
Definition: gravi_utils.h:84
#define FREELOOP(function, variable, n)
Definition: gravi_utils.h:72
static int gravity_viscal_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static char gravity_viscal_description[]
static int gravity_viscal(cpl_frameset *, const cpl_parameterlist *)
Compute the visibilities, and cloture phase and create the io fits file.
static int gravity_viscal_create(cpl_plugin *)
Setup the recipe options
static char gravity_viscal_short[]
static int gravity_viscal_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
gravi_data * gravi_data_duplicate(const gravi_data *self)
Create a copy of the gravi data.
Definition: gravi_data.c:250
cpl_propertylist * gravi_data_get_extra_primary_header(gravi_data *self)
Get the propertylist for additional keywords to the primary header.
Definition: gravi_data.c:2074
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_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
void gravi_data_delete(gravi_data *self)
Delete a gravi data.
Definition: gravi_data.c:146
cpl_frameset * gravi_frameset_extract_vis_calib(cpl_frameset *frameset)
Definition: gravi_dfs.c:1373
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_frameset * gravi_frameset_extract_vis_science(cpl_frameset *frameset)
Definition: gravi_dfs.c:1378
cpl_frameset * gravi_frameset_extract_tf_calib(cpl_frameset *frameset)
Definition: gravi_dfs.c:1368
int gravi_param_get_int(const cpl_parameterlist *parlist, const char *name)
Definition: gravi_dfs.c:1524
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_frameset * gravi_frameset_extract_diamcat_map(cpl_frameset *frameset)
Definition: gravi_dfs.c:1319
void gravity_print_banner(void)
Definition: gravi_dfs.c:61
int gravi_data_frame_get_mode(const cpl_frame *frame)
Definition: gravi_pfits.c:177
gravi_data * gravi_calibrate_vis(gravi_data *vis_data, gravi_data **tf_data, int num_tf, gravi_data *phi_tf_data, gravi_data *tf_science, const cpl_parameterlist *parlist)
Computes the calibrated visibility from science a single data and several previously evaluated instru...
Definition: gravi_tf.c:521
gravi_data * gravi_compute_zp(gravi_data **vis_calib, int num_calib)
Compute the ZP data.
Definition: gravi_tf.c:1049
gravi_data * gravi_compute_tf(gravi_data *vis_data, gravi_data *diamcat_data)
This function evaluates the transfer function from the observation of a reference star whose diameter...
Definition: gravi_tf.c:778
const char * gravi_get_license(void)
Get the pipeline copyright and license.
Definition: gravi_utils.c:104
cpl_error_code gravi_vis_smooth(gravi_data *oi_data, cpl_size nsamp_vis, cpl_size nsamp_flx, cpl_size maxdeg)
Smooth the SC table by nsamp consecutive spectral bins.
Definition: gravi_vis.c:3363