61static int gravity_viscal(cpl_frameset *,
const cpl_parameterlist *);
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."
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"
102 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe );
103 cpl_plugin * plugin = &recipe->interface;
105 if (cpl_plugin_init(plugin,
107 GRAVI_BINARY_VERSION,
108 CPL_PLUGIN_TYPE_RECIPE,
112 "Nabih Azouaoui, Vincent Lapeyrere, JB. Le Bouquin",
118 cpl_msg_error(cpl_func,
"Plugin initialization failed");
119 (void)cpl_error_set_where(cpl_func);
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);
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();
153 if (plugin == NULL) {
154 cpl_msg_error(cpl_func,
"Null plugin");
155 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
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);
165 recipe = (cpl_recipe *)plugin;
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);
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);
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);
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);
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);
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);
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);
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);
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);
261 cpl_errorstate initial_errorstate = cpl_errorstate_get();
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();
270 if (plugin == NULL) {
271 cpl_msg_error(cpl_func,
"Null plugin");
272 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
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);
282 recipe = (cpl_recipe *)plugin;
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);
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);
295 recipe_status =
gravity_viscal(recipe->frames, recipe->parameters);
299 if (cpl_dfs_update_product_header(recipe->frames)) {
301 recipe_status = (int)cpl_error_get_code();
305 if (!cpl_errorstate_is_equal(initial_errorstate)) {
308 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
311 return recipe_status;
325 if (plugin == NULL) {
326 cpl_msg_error(cpl_func,
"Null plugin");
327 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
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);
337 recipe = (cpl_recipe *)plugin;
339 cpl_parameterlist_delete(recipe->parameters);
355 const cpl_parameterlist * parlist)
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;
361 cpl_propertylist * applist = NULL;
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;
366 int data_mode, nb_frame_tf = 0, nb_frame_calib = 0, nb_frame_sci, i, j, nb_calib = 0;
374 cpl_error_get_code());
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") ;
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);
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;
406 if ( !cpl_frameset_is_empty (diamcat_frameset) ) {
407 frame = cpl_frameset_get_position (diamcat_frameset, 0);
412 used_frameset = cpl_frameset_new();
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);
419 frame = cpl_frameset_get_position (vis_calib_frameset, j);
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");
433 cpl_size smooth_flx_sc =
gravi_param_get_int (parlist,
"gravity.viscal.nsmooth-tfflux-sc");
439 if (vis_calib == NULL) {
440 cpl_msg_error (cpl_func,
"Cannot compute this TF... continue");
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");
457 cpl_msg_info (cpl_func,
"*** TF %i over %i to be used for visphi ***", j+1, nb_frame_calib);
460 NULL, frame,
"gravity_vis",
464 visphi_calib = vis_calib;
469 NULL, frame,
"gravity_vis",
473 vis_calibs[nb_calib] = vis_calib;
479 frame = cpl_frame_duplicate (frame);
480 cpl_frame_set_group (frame, CPL_FRAME_GROUP_CALIB);
481 cpl_frameset_insert (used_frameset, frame);
490 cpl_msg_info (cpl_func,
"*** Load already computed TF ***");
493 for (j = 0; j < nb_frame_tf; j++) {
494 cpl_msg_info (cpl_func,
" %i over %i", j+1, nb_frame_tf);
496 frame = cpl_frameset_get_position (tf_calib_frameset, j);
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");
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;
514 vis_calibs[nb_calib] = vis_calib;
524 cpl_msg_info (cpl_func,
"*** All TF computed or loaded ***");
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);
532 if ( nb_calib > 1 ) {
533 cpl_msg_info (cpl_func,
"*** Compute the zero of the metrology -- FIXME: to be done ***");
539 used_frameset, NULL,
"gravity_vis",
554 for (i = 0; i < nb_frame_sci; i++){
555 current_frameset = cpl_frameset_duplicate (used_frameset);
557 cpl_msg_info (cpl_func,
"*** Calibration of file %i over %i ***", i+1, nb_frame_sci);
559 frame = cpl_frameset_get_position (vis_sci_frameset, i);
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);
570 cpl_msg_info (cpl_func,
"Computing QC parameters for calibrated visibilities");
574 cpl_propertylist_append(extra_header, idp_hdr);
575 cpl_propertylist_delete(idp_hdr);
578 current_frameset, frame,
"gravity_vis",
581 CPLCHECK_GOTO(
"Cannot save the calibrated visibility", cleanup_calib);
587 current_frameset, frame,
"gravity_vis", NULL,
590 CPLCHECK_GOTO(
"Cannot save the TF interpolated for this visibility", cleanup_calib);
596 FREE (cpl_propertylist_delete,applist);
597 FREE (cpl_frameset_delete,current_frameset);
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);
620 return (
int)cpl_error_get_code();
typedefCPL_BEGIN_DECLS struct _gravi_data_ gravi_data
#define gravi_data_get_header(data)
#define gravi_data_get_spec_res(data)
#define GRAVI_TF_SCIENCE(data_mode)
#define GRAVI_RECIPE_OUTPUT
#define GRAVI_VISPHI_SINGLE_CALIB
#define GRAVI_TF_SINGLE_CALIB
#define GRAVI_RECIPE_FLOW
#define GRAVI_VIS_SINGLE_SCIENCE
#define GRAVI_TF_CALIB(data_mode)
#define GRAVI_DIAMETER_CAT
#define GRAVI_RECIPE_INPUT
#define GRAVI_VIS_SINGLE_CALIBRATED
#define GRAVI_VIS_SINGLE_CALIB
#define GRAVI_TF_SINGLE_SCIENCE
#define GRAVI_VISPHI_TF_CALIB(data_mode)
#define GRAVI_VISPHI_DUAL_CALIB
#define GRAVI_VISPHI_TF_DUAL_CALIB
#define GRAVI_VIS_CALIBRATED(data_mode)
#define GRAVI_VISPHI_TF_SINGLE_CALIB
cpl_propertylist * gravi_idp_compute(gravi_data *vis_data, cpl_propertylist *header, cpl_frameset *frameset)
Create IDP keywords to satisfy standard.
cpl_msg_info(cpl_func, "Compute WAVE_SCAN for %s", GRAVI_TYPE(type_data))
#define CPLCHECK_GOTO(msg, tag)
#define gravi_msg_function_exit(flag)
#define FREE(function, variable)
#define gravi_msg_function_start(flag)
#define FREELOOP(function, variable, n)
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.
cpl_propertylist * gravi_data_get_extra_primary_header(gravi_data *self)
Get the propertylist for additional keywords to the primary header.
gravi_data * gravi_data_load_frame(cpl_frame *frame, cpl_frameset *used_frameset)
Load a FITS file and create a gravi_data.
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.
void gravi_data_delete(gravi_data *self)
Delete a gravi data.
cpl_frameset * gravi_frameset_extract_vis_calib(cpl_frameset *frameset)
int gravi_param_get_bool(const cpl_parameterlist *parlist, const char *name)
cpl_parameter * gravi_parameter_add_static_name(cpl_parameterlist *self)
cpl_frameset * gravi_frameset_extract_vis_science(cpl_frameset *frameset)
cpl_frameset * gravi_frameset_extract_tf_calib(cpl_frameset *frameset)
int gravi_param_get_int(const cpl_parameterlist *parlist, const char *name)
cpl_error_code gravi_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
cpl_frameset * gravi_frameset_extract_diamcat_map(cpl_frameset *frameset)
void gravity_print_banner(void)
int gravi_data_frame_get_mode(const cpl_frame *frame)
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...
gravi_data * gravi_compute_zp(gravi_data **vis_calib, int num_calib)
Compute the ZP data.
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...
const char * gravi_get_license(void)
Get the pipeline copyright and license.
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.