65 "This recipe averages the real-time data of P2VMRED files into a VIS product. It allows to run the reduction with different parameters (for instance for SNR thresholding) without having to re-reduce the files from scratch. Typically the reduction is 4x faster when started from this intermediate product.\n"
67 "The tag in the DO category can be SINGLE/DUAL and CAL/SCI. They should reflect the mode (SINGLE or DUAL) and the DPR.CATG of the observation (SCIENCE or CALIB). The tag in the PRO.CATG category will be SINGLE/DUAL and CAL/SCI depending on the input tag.\n"
69 "* Load the input file (loop on input files)\n"
70 "* Update the selection flag\n"
71 "* Average the real-time visibilities\n"
72 "* Write the product\n"
96 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe );
97 cpl_plugin * plugin = &recipe->interface;
99 if (cpl_plugin_init(plugin,
101 GRAVI_BINARY_VERSION,
102 CPL_PLUGIN_TYPE_RECIPE,
103 "gravity_vis_from_p2vmred",
106 "JB. Le Bouquin, Vincent Lapeyrere, ",
112 cpl_msg_error(cpl_func,
"Plugin initialization failed");
113 (void)cpl_error_set_where(cpl_func);
117 if (cpl_pluginlist_append(list, plugin)) {
118 cpl_msg_error(cpl_func,
"Error adding plugin to list");
119 (void)cpl_error_set_where(cpl_func);
141 if (cpl_error_get_code() != CPL_ERROR_NONE) {
142 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
143 cpl_func, __LINE__, cpl_error_get_where());
144 return (
int)cpl_error_get_code();
147 if (plugin == NULL) {
148 cpl_msg_error(cpl_func,
"Null plugin");
149 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
153 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
154 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
155 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
159 recipe = (cpl_recipe *)plugin;
162 recipe->parameters = cpl_parameterlist_new();
163 if (recipe->parameters == NULL) {
164 cpl_msg_error(cpl_func,
"Parameter list allocation failed");
165 cpl_ensure_code(0, (
int)CPL_ERROR_ILLEGAL_OUTPUT);
190 p = cpl_parameter_new_value (
"gravity.test.reduce-acq-cam", CPL_TYPE_BOOL,
191 "If TRUE, reduced ACQ_CAM images",
192 "gravity.test", FALSE);
193 cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI,
"reduce-acq-cam");
194 cpl_parameter_disable (p, CPL_PARAMETER_MODE_ENV);
195 cpl_parameterlist_append (recipe->parameters, p);
198 p = cpl_parameter_new_value (
"gravity.signal.use-existing-rejection", CPL_TYPE_BOOL,
199 "Use existing rejection flags (ignore related options)",
200 "gravity.signal", FALSE);
201 cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI,
"use-existing-rejection");
202 cpl_parameter_disable (p, CPL_PARAMETER_MODE_ENV);
203 cpl_parameterlist_append (recipe->parameters, p);
220 cpl_errorstate initial_errorstate = cpl_errorstate_get();
224 if (cpl_error_get_code() != CPL_ERROR_NONE) {
225 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
226 cpl_func, __LINE__, cpl_error_get_where());
227 return (
int)cpl_error_get_code();
230 if (plugin == NULL) {
231 cpl_msg_error(cpl_func,
"Null plugin");
232 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
236 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
237 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
238 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
242 recipe = (cpl_recipe *)plugin;
245 if (recipe->parameters == NULL) {
246 cpl_msg_error(cpl_func,
"Recipe invoked with NULL parameter list");
247 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
249 if (recipe->frames == NULL) {
250 cpl_msg_error(cpl_func,
"Recipe invoked with NULL frame set");
251 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
258 if (cpl_dfs_update_product_header(recipe->frames)) {
260 recipe_status = (int)cpl_error_get_code();
264 if (!cpl_errorstate_is_equal(initial_errorstate)) {
267 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
270 return recipe_status;
284 if (plugin == NULL) {
285 cpl_msg_error(cpl_func,
"Null plugin");
286 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
290 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
291 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
292 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
296 recipe = (cpl_recipe *)plugin;
298 cpl_parameterlist_delete(recipe->parameters);
314 cpl_parameterlist * parlist)
316 cpl_frameset * recipe_frameset=NULL, *pcacalib_frameset=NULL, *used_frameset=NULL;
318 cpl_frame * frame=NULL;
320 const char * frame_tag=NULL;
321 char * proCatg = NULL, * mode=NULL;
323 gravi_data * p2vmred_data=NULL, * vis_data=NULL, * tmpvis_data=NULL, * pca_calib_data=NULL;
324 cpl_propertylist ** p2vm_qcs = NULL;
333 cpl_error_get_code()) ;
340 if ( cpl_frameset_get_size (recipe_frameset) < 1 ) {
341 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
342 "Illegal number of P2VMREDUCED file on the frameset");
348 cpl_parameter *phase_ref = cpl_parameterlist_find (parlist,
"gravity.vis.phase-ref-sc");
349 cpl_parameter *output_phase = cpl_parameterlist_find (parlist,
"gravity.vis.output-phase-sc");
351 if (strcmp (cpl_parameter_get_string(phase_ref),
"SELF_REF") != 0) {
352 cpl_msg_warning (cpl_func,
"VISPHI flattening requires phase-ref-sc=SELF_REF, forcing");
353 cpl_parameter_set_string (phase_ref,
"SELF_REF");
356 if (strcmp (cpl_parameter_get_string(output_phase),
"SELF_VISPHI") != 0) {
357 cpl_msg_warning (cpl_func,
"VISPHI flattening requires output-phase-sc=SELF_VISPHI, forcing");
358 cpl_parameter_set_string (output_phase,
"SELF_VISPHI");
363 used_frameset = cpl_frameset_new();
365 if ( !cpl_frameset_is_empty (pcacalib_frameset)) {
366 frame = cpl_frameset_get_position (pcacalib_frameset, 0);
369 cpl_msg_info (cpl_func,
"There is no PHASE_PCA in the frameset");
375 frame_tag = cpl_frame_get_tag (cpl_frameset_get_position (recipe_frameset, 0));
379 mode = cpl_sprintf (
"gravi_dual");
383 mode = cpl_sprintf (
"gravi_dual");
387 mode = cpl_sprintf (
"gravi_single");
391 mode = cpl_sprintf (
"gravi_single");
394 proCatg = cpl_sprintf (
"UNKNOWN");
395 mode = cpl_sprintf (
"gravi_single");
398 cpl_msg_info (cpl_func,
"Mode of the first frame is: %s (will be used for all frames)", mode);
404 nb_frame = cpl_frameset_get_size (recipe_frameset);
405 p2vm_qcs = cpl_malloc(
sizeof(cpl_propertylist*) * nb_frame);
407 for (
int ivis = 0; ivis < nb_frame; ivis++){
409 cpl_msg_info (cpl_func,
" ***** P2VMREDUCED %d over %d ***** ", ivis+1, nb_frame);
411 frame = cpl_frameset_get_position (recipe_frameset, ivis);
413 p2vm_qcs[ivis] = cpl_propertylist_new();
417 cpl_msg_info (cpl_func,
"Don't recompute SNR and selection, use the existing one");
429 CPLCHECK_MSG (
"Cannot recompute rejection flags signals");
437 cpl_size current_frame = 0;
438 while (current_frame >= 0)
448 cpl_msg_info (cpl_func,
"Force same time for all quantities/baselines");
461 if (vis_data == NULL) {
462 vis_data = tmpvis_data; tmpvis_data = NULL;
492 cpl_msg_info (cpl_func,
"Align the SC visibilities on the FT");
496 cpl_msg_info (cpl_func,
"Don't align the SC visibilities on the FT");
502 cpl_msg_warning (cpl_func,
"Average the different observation (if any) = EXPERIMENTAL");
506 cpl_msg_info (cpl_func,
"Don't average the different observation (if any)");
514 frame = cpl_frameset_get_position (recipe_frameset, 0);
517 used_frameset, frame,
"gravity_vis_from_p2vmred",
533 FREE (cpl_frameset_delete,recipe_frameset);
534 FREE (cpl_frameset_delete,pcacalib_frameset);
535 FREE (cpl_frameset_delete,used_frameset);
536 FREE (cpl_free,proCatg);
537 FREE (cpl_free,mode);
538 FREELOOP(cpl_propertylist_delete, p2vm_qcs, nb_frame);
541 return (
int)cpl_error_get_code();
typedefCPL_BEGIN_DECLS struct _gravi_data_ gravi_data
#define GRAVI_RECIPE_OUTPUT
#define GRAVI_P2VMRED_SINGLE_CALIB
#define GRAVI_P2VMRED_DUAL_CALIB
#define GRAVI_RECIPE_FLOW
#define GRAVI_VIS_DUAL_SCIENCE
#define GRAVI_VIS_SINGLE_SCIENCE
#define GRAVI_P2VMRED_SINGLE_SCIENCE
#define GRAVI_RECIPE_INPUT
#define GRAVI_VIS_DUAL_CALIB
#define GRAVI_VIS_SINGLE_CALIB
#define GRAVI_P2VMRED_DUAL_SCIENCE
cpl_msg_info(cpl_func, "Compute WAVE_SCAN for %s", GRAVI_TYPE(type_data))
#define GRAVI_IMAGING_DATA_ACQ_EXT
#define CPLCHECK_CLEAN(msg)
#define gravi_msg_function_exit(flag)
#define FREE(function, variable)
#define gravi_msg_function_start(flag)
#define CPLCHECK_MSG(msg)
#define FREELOOP(function, variable, n)
static int gravity_vis_from_p2vmred_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static char gravity_vis_from_p2vmred_description[]
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static int gravity_vis_from_p2vmred_create(cpl_plugin *)
Setup the recipe options
static char gravity_vis_from_p2vmred_short[]
static int gravity_vis_from_p2vmred(cpl_frameset *, cpl_parameterlist *)
Compute the visibilities, and closure phase and create the io fits file.
static int gravity_vis_from_p2vmred_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
cpl_error_code gravi_flatten_vis(gravi_data *vis_data, gravi_data *calib_data)
Use PCA model to flatten observed visphi. The flattened data are added to the existing VIS table.
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_append(gravi_data *first, const gravi_data *second, int force)
Append a gravi_data into another existing one.
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.
cpl_error_code gravi_data_copy_ext_insname(gravi_data *output, gravi_data *input, const char *name, const char *insname)
Copy extensions from one data to another.
void gravi_data_delete(gravi_data *self)
Delete a gravi data.
int gravi_param_get_bool(const cpl_parameterlist *parlist, const char *name)
cpl_parameter * gravi_parameter_add_static_name(cpl_parameterlist *self)
cpl_error_code gravi_parameter_add_rejection(cpl_parameterlist *self, int isCalib)
Add rejection parameters to the input parameter list.
cpl_error_code gravi_parameter_add_compute_snr(cpl_parameterlist *self)
cpl_parameter * gravi_parameter_add_average_vis(cpl_parameterlist *self)
const char * gravi_param_get_string(const cpl_parameterlist *parlist, const char *name)
cpl_parameter * gravi_parameter_add_pca(cpl_parameterlist *self)
Add pca parameters to the input parameter list.
cpl_frameset * gravi_frameset_extract_pca_calib(cpl_frameset *frameset)
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_p2vmred_data(cpl_frameset *frameset)
cpl_error_code gravi_parameter_add_compute_vis(cpl_parameterlist *self, int isCalib)
void gravity_print_banner(void)
cpl_error_code gravi_compute_snr(gravi_data *p2vmred_data, const cpl_parameterlist *parlist)
Compute real-time SNR and Group-Delay of the observation.
cpl_error_code gravi_compute_outliers(gravi_data *p2vmred_data, const cpl_parameterlist *parlist)
Compute the outliers flags.
cpl_error_code gravi_compute_rejection(gravi_data *p2vmred_data, const cpl_parameterlist *parlist)
Create rejection flags P2VMREDUCED file.
cpl_error_code gravi_copy_p2vm_qcs(gravi_data *p2vmred_data, cpl_propertylist *plist)
Copy PFACTOR and VFACTOR QCs so that they may be aggregated over all frames.
const char * gravi_get_license(void)
Get the pipeline copyright and license.
cpl_error_code gravi_normalize_sc_to_ft(gravi_data *vis_data)
Align the SC visibilities on the FT visibilities.
gravi_data * gravi_compute_vis(gravi_data *p2vmred_data, const cpl_parameterlist *parlist, cpl_size *current_frame)
The function average the individual frames of a P2VMREDUCED file into a final, single observation per...
cpl_error_code gravi_vis_force_time(gravi_data *oi_data)
Force all data in OI_TABLE to have the same TIME and MJD.
cpl_error_code gravi_vis_mjd_to_time(gravi_data *vis_data)
Recompute the TIME column of all OIFITS extension from the MJD column, following the OIFITS standard ...
cpl_error_code gravi_compute_vis_qc(gravi_data *vis_data, cpl_frameset *frameset, cpl_propertylist **frame_qcs, cpl_size nb_frame)
Compute the QC parameters for a VIS (averaged) data.
cpl_error_code gravi_average_vis(gravi_data *oi_data)
Coadd the observations together.