GRAVI Pipeline Reference Manual 1.9.4
Loading...
Searching...
No Matches
gravity_piezo.c
Go to the documentation of this file.
1/* $Id: gravity_vis.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
28/*
29 * History :
30 * 16/01/2019 fix warning unused parameter isCalib
31 */
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35
36/*-----------------------------------------------------------------------------
37 Includes
38 -----------------------------------------------------------------------------*/
39
40#include <cpl.h>
41#include <stdio.h>
42#include <string.h>
43#include <time.h>
44
45#include "gravi_data.h"
46#include "gravi_pfits.h"
47#include "gravi_dfs.h"
48
49#include "gravi_utils.h"
50
51#include "gravi_calib.h"
52#include "gravi_p2vmred.h"
53#include "gravi_eop.h"
54#include "gravi_metrology.h"
55
56#include "gravi_signal.h"
57#include "gravi_vis.h"
58#include "gravi_tf.h"
59
60#include "gravi_preproc.h"
61// #include "gravi_p2vm.h"
62
63/*-----------------------------------------------------------------------------
64 Private function prototypes
65 -----------------------------------------------------------------------------*/
66
67static int gravity_piezo_create(cpl_plugin *);
68static int gravity_piezo_exec(cpl_plugin *);
69static int gravity_piezo_destroy(cpl_plugin *);
70static int gravity_piezo(cpl_frameset *, const cpl_parameterlist *);
71
72/*-----------------------------------------------------------------------------
73 Static variables
74 -----------------------------------------------------------------------------*/
75
76static char gravity_piezo_short[] = "Calibrate the response of the piezo actuators.";
77static char gravity_piezo_description[] = "This recipe compute the response (open loop transfer function) of the piezo actuators used to fringe-track in GRAVITY.\n"
79 "* Compute the piezo TF QC parameter"
80 "* Write product\n"
82 GRAVI_PIEZOTF_RAW" : dedicated observations (DPR.CATG=PIEZOTF)\n"
84 GRAVI_PIEZOTF_MAP" : Response of the piezo\n"
85 "";
86
87/*-----------------------------------------------------------------------------
88 Function code
89 -----------------------------------------------------------------------------*/
90
91/*----------------------------------------------------------------------------*/
101/*----------------------------------------------------------------------------*/
102int cpl_plugin_get_info(cpl_pluginlist * list)
103{
104 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe );
105 cpl_plugin * plugin = &recipe->interface;
106
107 if (cpl_plugin_init(plugin,
108 CPL_PLUGIN_API,
109 GRAVI_BINARY_VERSION,
110 CPL_PLUGIN_TYPE_RECIPE,
111 "gravity_piezo",
114 "Nabih Azouaoui, Vincent Lapeyrere, JB. Le Bouquin",
115 PACKAGE_BUGREPORT,
120 cpl_msg_error(cpl_func, "Plugin initialization failed");
121 (void)cpl_error_set_where(cpl_func);
122 return 1;
123 }
124
125 if (cpl_pluginlist_append(list, plugin)) {
126 cpl_msg_error(cpl_func, "Error adding plugin to list");
127 (void)cpl_error_set_where(cpl_func);
128 return 1;
129 }
130
131 return 0;
132}
133
134/*----------------------------------------------------------------------------*/
142/*----------------------------------------------------------------------------*/
143static int gravity_piezo_create(cpl_plugin * plugin)
144{
145 cpl_recipe * recipe;
146 // cpl_parameter * p;
147
148 /* Do not create the recipe if an error code is already set */
149 if (cpl_error_get_code() != CPL_ERROR_NONE) {
150 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
151 cpl_func, __LINE__, cpl_error_get_where());
152 return (int)cpl_error_get_code();
153 }
154
155 if (plugin == NULL) {
156 cpl_msg_error(cpl_func, "Null plugin");
157 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
158 }
159
160 /* Verify plugin type */
161 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
162 cpl_msg_error(cpl_func, "Plugin is not a recipe");
163 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
164 }
165
166 /* Get the recipe */
167 recipe = (cpl_recipe *)plugin;
168
169 /* Create the parameters list in the cpl_recipe object */
170 recipe->parameters = cpl_parameterlist_new();
171 if (recipe->parameters == NULL) {
172 cpl_msg_error(cpl_func, "Parameter list allocation failed");
173 cpl_ensure_code(0, (int)CPL_ERROR_ILLEGAL_OUTPUT);
174 }
175
176 /* Fill the parameters list */
177 /* int isCalib = 1; */
178
179 /* Use static names (output_procatg.fits) */
180 gravi_parameter_add_static_name (recipe->parameters);
181
182 return 0;
183}
184
185/*----------------------------------------------------------------------------*/
191/*----------------------------------------------------------------------------*/
192static int gravity_piezo_exec(cpl_plugin * plugin)
193{
194
195 cpl_recipe * recipe;
196 int recipe_status;
197 cpl_errorstate initial_errorstate = cpl_errorstate_get();
198
199
200 /* Return immediately if an error code is already set */
201 if (cpl_error_get_code() != CPL_ERROR_NONE) {
202 cpl_msg_error(cpl_func, "%s():%d: An error is already set: %s",
203 cpl_func, __LINE__, cpl_error_get_where());
204 return (int)cpl_error_get_code();
205 }
206
207 if (plugin == NULL) {
208 cpl_msg_error(cpl_func, "Null plugin");
209 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
210 }
211
212 /* Verify plugin type */
213 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
214 cpl_msg_error(cpl_func, "Plugin is not a recipe");
215 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
216 }
217
218 /* Get the recipe */
219 recipe = (cpl_recipe *)plugin;
220
221 /* Verify parameter and frame lists */
222 if (recipe->parameters == NULL) {
223 cpl_msg_error(cpl_func, "Recipe invoked with NULL parameter list");
224 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
225 }
226 if (recipe->frames == NULL) {
227 cpl_msg_error(cpl_func, "Recipe invoked with NULL frame set");
228 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
229 }
230
231 /* Invoke the recipe */
232 recipe_status = gravity_piezo(recipe->frames, recipe->parameters);
233
234 /* Ensure DFS-compliance of the products */
235 if (cpl_dfs_update_product_header(recipe->frames)) {
236 if (!recipe_status){
237 recipe_status = (int)cpl_error_get_code();
238 }
239 }
240
241 if (!cpl_errorstate_is_equal(initial_errorstate)) {
242 /* Dump the error history since recipe execution start.
243 At this point the recipe cannot recover from the error */
244 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
245 }
246
247 return recipe_status;
248}
249
250/*----------------------------------------------------------------------------*/
256/*----------------------------------------------------------------------------*/
257static int gravity_piezo_destroy(cpl_plugin * plugin)
258{
259 cpl_recipe * recipe;
260
261 if (plugin == NULL) {
262 cpl_msg_error(cpl_func, "Null plugin");
263 cpl_ensure_code(0, (int)CPL_ERROR_NULL_INPUT);
264 }
265
266 /* Verify plugin type */
267 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
268 cpl_msg_error(cpl_func, "Plugin is not a recipe");
269 cpl_ensure_code(0, (int)CPL_ERROR_TYPE_MISMATCH);
270 }
271
272 /* Get the recipe */
273 recipe = (cpl_recipe *)plugin;
274
275 cpl_parameterlist_delete(recipe->parameters);
276
277 return 0;
278}
279
280
281/*----------------------------------------------------------------------------*/
289/*----------------------------------------------------------------------------*/
290static int gravity_piezo(cpl_frameset * frameset,
291 const cpl_parameterlist * parlist)
292{
293 cpl_frameset * recipe_frameset=NULL, *used_frameset=NULL, * current_frameset=NULL;
294
295 cpl_frame * frame=NULL;
296
297 gravi_data * data=NULL, * piezo_data=NULL;
298
299 int nb_frame;
300
301 /* Message */
304
305 /* Identify the frames in the input frameset */
306 cpl_ensure_code(gravi_dfs_set_groups(frameset) == CPL_ERROR_NONE,
307 cpl_error_get_code()) ;
308
309 /* Dispatch the frameset */
310 recipe_frameset = gravi_frameset_extract_piezotf_data (frameset);
311
312 /* Check the frameset */
313 if (cpl_frameset_is_empty (recipe_frameset)) {
314 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
315 "No PIEZOTF file on the frameset") ;
316 goto cleanup;
317 }
318
319
320 /* Insert calibration frame into the used frameset */
321 used_frameset = cpl_frameset_new();
322
323 /*
324 * Loop on input RAW frames to be reduced
325 */
326
327
328 nb_frame = cpl_frameset_get_size (recipe_frameset);
329
330 for (int i_file = 0; i_file < nb_frame; i_file++){
331 current_frameset = cpl_frameset_duplicate (used_frameset);
332
333 cpl_msg_info (cpl_func, " ***** File %d over %d ***** ", i_file+1, nb_frame);
334
335 /*
336 * Reduce the File
337 */
338
339 frame = cpl_frameset_get_position (recipe_frameset, i_file);
340 data = gravi_data_load_rawframe (frame, current_frameset);
341 piezo_data = gravi_compute_piezotf (data, parlist);
342 CPLCHECK_CLEAN ("Cannot compute the piezo TF");
343
344 /* Save the PIEZOTF which is in fact a P2VMREDUCED */
345 gravi_data_save_new (piezo_data, frameset, NULL, NULL, parlist,
346 current_frameset, frame, "gravity_piezo",
347 NULL, GRAVI_PIEZOTF_MAP);
348
349 CPLCHECK_CLEAN ("Cannot save the PIEZOTF product");
350
351 cpl_msg_info (cpl_func,"Free the piezotf");
352 FREE (cpl_frameset_delete, current_frameset);
353 FREE (gravi_data_delete, piezo_data);
354 }
355 /* End loop on the input files to reduce */
356
357 /* Terminate the function */
358 goto cleanup;
359
360cleanup:
361 /* Deallocation of all variables */
362 cpl_msg_info(cpl_func,"Memory cleanup");
363
364 FREE (gravi_data_delete,data);
365 FREE (gravi_data_delete,piezo_data);
366 FREE (cpl_frameset_delete,recipe_frameset);
367 FREE (cpl_frameset_delete,current_frameset);
368 FREE (cpl_frameset_delete,used_frameset);
369
371 return (int)cpl_error_get_code();
372}
typedefCPL_BEGIN_DECLS struct _gravi_data_ gravi_data
Definition: gravi_data.h:39
#define GRAVI_RECIPE_OUTPUT
Definition: gravi_dfs.h:39
#define GRAVI_PIEZOTF_MAP
Definition: gravi_dfs.h:86
#define GRAVI_RECIPE_FLOW
Definition: gravi_dfs.h:37
#define GRAVI_PIEZOTF_RAW
Definition: gravi_dfs.h:43
#define GRAVI_RECIPE_INPUT
Definition: gravi_dfs.h:38
cpl_msg_info(cpl_func, "Compute WAVE_SCAN for %s", GRAVI_TYPE(type_data))
#define CPLCHECK_CLEAN(msg)
Definition: gravi_utils.h:54
#define gravi_msg_function_exit(flag)
Definition: gravi_utils.h:85
#define FREE(function, variable)
Definition: gravi_utils.h:69
#define gravi_msg_function_start(flag)
Definition: gravi_utils.h:84
static int gravity_piezo_create(cpl_plugin *)
Setup the recipe options
static char gravity_piezo_short[]
Definition: gravity_piezo.c:76
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static int gravity_piezo_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static int gravity_piezo(cpl_frameset *, const cpl_parameterlist *)
Compute the visibilities, and closure phase and create the io fits file.
static char gravity_piezo_description[]
Definition: gravity_piezo.c:77
static int gravity_piezo_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
gravi_data * gravi_compute_piezotf(gravi_data *data, const cpl_parameterlist *params)
Create piezo transfer function for Kalman Calibration & monitoring.
Definition: gravi_calib.c:2376
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_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_parameter * gravi_parameter_add_static_name(cpl_parameterlist *self)
Definition: gravi_dfs.c:464
cpl_frameset * gravi_frameset_extract_piezotf_data(cpl_frameset *frameset)
Definition: gravi_dfs.c:1332
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
void gravity_print_banner(void)
Definition: gravi_dfs.c:61
const char * gravi_get_license(void)
Get the pipeline copyright and license.
Definition: gravi_utils.c:104