41 #include "gravi_data.h" 42 #include "gravi_pfits.h" 43 #include "gravi_dfs.h" 45 #include "gravi_utils.h" 47 #include "gravi_calib.h" 48 #include "gravi_p2vmred.h" 49 #include "gravi_eop.h" 50 #include "gravi_metrology.h" 52 #include "gravi_vis.h" 55 #include "gravi_preproc.h" 61 static int gravity_postprocess_create(cpl_plugin *);
62 static int gravity_postprocess_exec(cpl_plugin *);
63 static int gravity_postprocess_destroy(cpl_plugin *);
64 static int gravity_postprocess(cpl_frameset *,
const cpl_parameterlist *);
70 static char gravity_postprocess_short[] =
"Post-process the products, to fine-tune their content.";
71 static char gravity_postprocess_description[] =
72 "This recipe allows to manipulate the product of the GRAVITY pipeline, mostly the VIS. It permits to merge several files together into a single VIS file with all observations; to average the observations of one or several VIS file to increse the SNR; to remove some data (FT, SC); and to resample the SC observation with spectral binning.\n" 74 "The list of input files can be P2VMRED, VIS, VIS_CALIBRATED (or even RAW for some parameters). However they should all be compatible in term of setup and observed objets !! Note that the recipe performs only litle checks of the input file content and structure. Thus the user shall ensure the input files are conformable (same polarisation and spectral mode for instante)\n" 77 "* Execute request from user\n" 79 GRAVI_RECIPE_INPUT
"\n" 80 "Input files : see above\n" 81 GRAVI_RECIPE_OUTPUT
"\n" 82 "POSTPROCESSED : Output file\n" 100 int cpl_plugin_get_info(cpl_pluginlist * list)
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,
109 "gravity_postprocess",
110 gravity_postprocess_short,
111 gravity_postprocess_description,
112 "Nabih Azouaoui, Vincent Lapeyrere, JB. Le Bouquin",
115 gravity_postprocess_create,
116 gravity_postprocess_exec,
117 gravity_postprocess_destroy)) {
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);
141 static int gravity_postprocess_create(cpl_plugin * plugin)
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);
177 gravi_parameter_add_average_vis (recipe->parameters);
178 gravi_parameter_add_force_uncertainties (recipe->parameters);
181 p = cpl_parameter_new_value (
"gravity.postprocess.force-merge", CPL_TYPE_BOOL,
182 "Force merging even if inconsistent data",
183 "gravity.postprocess", FALSE);
184 cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI,
"force-merge");
185 cpl_parameter_disable (p, CPL_PARAMETER_MODE_ENV);
186 cpl_parameterlist_append (recipe->parameters, p);
189 p = cpl_parameter_new_value (
"gravity.postprocess.remove-ft", CPL_TYPE_BOOL,
190 "Remove FT extensions",
191 "gravity.postprocess", FALSE);
192 cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI,
"remove-ft");
193 cpl_parameter_disable (p, CPL_PARAMETER_MODE_ENV);
194 cpl_parameterlist_append (recipe->parameters, p);
197 p = cpl_parameter_new_value (
"gravity.postprocess.remove-sc", CPL_TYPE_BOOL,
198 "Remove SC extensions",
199 "gravity.postprocess", FALSE);
200 cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI,
"remove-sc");
201 cpl_parameter_disable (p, CPL_PARAMETER_MODE_ENV);
202 cpl_parameterlist_append (recipe->parameters, p);
205 p = cpl_parameter_new_value (
"gravity.postprocess.remove-opdc", CPL_TYPE_BOOL,
206 "Remove OPDC extensions",
207 "gravity.postprocess", FALSE);
208 cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI,
"remove-opdc");
209 cpl_parameter_disable (p, CPL_PARAMETER_MODE_ENV);
210 cpl_parameterlist_append (recipe->parameters, p);
213 p = cpl_parameter_new_value (
"gravity.postprocess.remove-met", CPL_TYPE_BOOL,
214 "Remove METROLOGY related extensions",
215 "gravity.postprocess", FALSE);
216 cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI,
"remove-met");
217 cpl_parameter_disable (p, CPL_PARAMETER_MODE_ENV);
218 cpl_parameterlist_append (recipe->parameters, p);
221 p = cpl_parameter_new_value (
"gravity.postprocess.nbin-lambda-sc", CPL_TYPE_INT,
222 "Bin SC extensions in spectral dimension",
223 "gravity.postprocess", 0);
224 cpl_parameter_set_alias (p, CPL_PARAMETER_MODE_CLI,
"nbin-lambda-sc");
225 cpl_parameter_disable (p, CPL_PARAMETER_MODE_ENV);
226 cpl_parameterlist_append (recipe->parameters, p);
238 static int gravity_postprocess_exec(cpl_plugin * plugin)
243 cpl_errorstate initial_errorstate = cpl_errorstate_get();
247 if (cpl_error_get_code() != CPL_ERROR_NONE) {
248 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
249 cpl_func, __LINE__, cpl_error_get_where());
250 return (
int)cpl_error_get_code();
253 if (plugin == NULL) {
254 cpl_msg_error(cpl_func,
"Null plugin");
255 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
259 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
260 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
261 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
265 recipe = (cpl_recipe *)plugin;
268 if (recipe->parameters == NULL) {
269 cpl_msg_error(cpl_func,
"Recipe invoked with NULL parameter list");
270 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
272 if (recipe->frames == NULL) {
273 cpl_msg_error(cpl_func,
"Recipe invoked with NULL frame set");
274 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
278 recipe_status = gravity_postprocess(recipe->frames, recipe->parameters);
281 if (cpl_dfs_update_product_header(recipe->frames)) {
283 recipe_status = (int)cpl_error_get_code();
287 if (!cpl_errorstate_is_equal(initial_errorstate)) {
290 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
293 return recipe_status;
303 static int gravity_postprocess_destroy(cpl_plugin * plugin)
307 if (plugin == NULL) {
308 cpl_msg_error(cpl_func,
"Null plugin");
309 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
313 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
314 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
315 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
319 recipe = (cpl_recipe *)plugin;
321 cpl_parameterlist_delete(recipe->parameters);
336 static int gravity_postprocess(cpl_frameset * frameset,
337 const cpl_parameterlist * parlist)
339 cpl_frameset *used_frameset=NULL;
340 cpl_frame * frame=NULL, *frame_merged=NULL;
342 gravi_data * data_merged=NULL, * data=NULL;
345 gravity_print_banner ();
346 cpl_msg_set_time_on();
347 cpl_msg_set_component_on();
348 gravi_msg_function_start(1);
351 cpl_error_get_code());
353 cpl_size nframe = cpl_frameset_get_size (frameset);
354 int force = gravi_param_get_bool (parlist,
"gravity.postprocess.force-merge");
359 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
360 "Not enough frames in the frameset");
368 used_frameset = cpl_frameset_new();
372 for (cpl_size f = 0; f < nframe ; f++ ) {
375 frame = cpl_frameset_get_position (frameset, f);
379 if (gravi_param_get_bool (parlist,
"gravity.postprocess.remove-ft")) {
380 cpl_msg_info (cpl_func,
"Erase FT");
382 CPLCHECK_CLEAN (
"Cannot delete FT");
385 if (gravi_param_get_bool (parlist,
"gravity.postprocess.remove-sc")) {
386 cpl_msg_info (cpl_func,
"Erase SC");
388 CPLCHECK_CLEAN (
"Cannot delete SC");
391 if (gravi_param_get_bool (parlist,
"gravity.postprocess.remove-opdc")) {
392 cpl_msg_info (cpl_func,
"Erase OPDC");
394 CPLCHECK_CLEAN (
"Cannot delete OPDC");
397 if (gravi_param_get_bool (parlist,
"gravity.postprocess.remove-met")) {
398 cpl_msg_info (cpl_func,
"Erase MET");
401 CPLCHECK_CLEAN (
"Cannot delete MET");
406 CPLCHECK_CLEAN (
"Cannot force uncertainties");
411 frame_merged = frame;
412 data_merged = data; data = NULL;
420 CPLCHECK_CLEAN (
"Cannot append frames");
425 if (gravi_param_get_bool (parlist,
"gravity.postprocess.average-vis")) {
427 gravi_msg_warning (
"FIXME",
"Average the different observations = EXPERIMENTAL");
430 CPLCHECK_CLEAN (
"Cannot average VIS");
434 cpl_size resamp_sc = gravi_param_get_int (parlist,
"gravity.postprocess.nbin-lambda-sc");
435 if ( resamp_sc > 1) {
437 gravi_msg_warning (
"FIXME",
"Resamp the SC data = EXPERIMENTAL");
440 CPLCHECK_CLEAN (
"Cannot resamp SC");
450 used_frameset, frame_merged,
"gravity_postprocess",
451 NULL,
"POSTPROCESSED");
453 CPLCHECK_CLEAN (
"Cannot save the POSTPROCESSED product");
460 cpl_msg_info(cpl_func,
"Memory cleanup");
464 FREE (cpl_frameset_delete,used_frameset);
466 gravi_msg_function_exit(1);
467 return (
int)cpl_error_get_code();
cpl_error_code gravi_vis_resamp(gravi_data *oi_data, cpl_size nsamp)
Re-bin the SC table by nsamp consecutive spectral bins.
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_erase_type(gravi_data *self, const char *type)
Erase all extension related to an instrument (SC, FT, MET...)
cpl_error_code gravi_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
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 ...
const char * gravi_get_license(void)
Get the pipeline copyright and license.
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_average_vis(gravi_data *oi_data)
Coadd the observations together.
void gravi_data_delete(gravi_data *self)
Delete a gravi data.
cpl_error_code gravi_force_uncertainties(gravi_data *oi_data, const cpl_parameterlist *parlist)
Force uncertainties.
cpl_error_code gravi_data_append(gravi_data *first, const gravi_data *second, int force)
Append a gravi_data into another existing one.