45 #include "gravi_data.h" 46 #include "gravi_pfits.h" 47 #include "gravi_dfs.h" 49 #include "gravi_utils.h" 51 #include "gravi_calib.h" 52 #include "gravi_preproc.h" 53 #include "gravi_p2vmred.h" 54 #include "gravi_signal.h" 55 #include "gravi_vis.h" 56 #include "gravi_metrology.h" 57 #include "gravi_disp.h" 67 static int gravity_disp_create(cpl_plugin *);
68 static int gravity_disp_exec(cpl_plugin *);
69 static int gravity_disp_destroy(cpl_plugin *);
70 static int gravity_disp(cpl_frameset *,
const cpl_parameterlist *);
76 static char gravity_disp_short[] =
"Calibrate the linearity and the dispersion of the differential delay lines.";
77 static char gravity_disp_description[] =
78 "This recipe is associated to the template GRAVI_all_disp. It measures the phases obtained on the internal source at the position of the Argon lines and various positions (= fiber stretch) of the Fibered Differential Delay Lines (FDDL). It deduces the linearity model and the dispersion model of the differential delay lines. These models are stored as polynomials versus wavelength.\n" 80 "* Reduce all the input DISP files (see gravity_vis), write each product\n" 81 "* Compute the dispersion parameters from this entire dataset\n" 83 GRAVI_RECIPE_INPUT
"\n" 84 GRAVI_FLAT_MAP
" : flat calibration (PRO.CATG="GRAVI_FLAT_MAP
")\n" 85 GRAVI_BAD_MAP
" : badpixel calibration (PRO.CATG="GRAVI_BAD_MAP
") \n" 86 GRAVI_WAVE_MAP
" : wave calibration (PRO.CATG="GRAVI_WAVE_MAP
")\n" 87 GRAVI_P2VM_MAP
" : p2vm calibration (PRO.CATG="GRAVI_P2VM_MAP
")\n" 88 GRAVI_DARK_MAP
" : dark calibration (PRO.CATG="GRAVI_DARK_MAP
")\n" 89 GRAVI_WAVELAMP_MAP
" : spectrum of Argon, with position of lines\n" 90 GRAVI_DISP_RAW
" (>50) : raw dispersion\n" 91 GRAVI_RECIPE_OUTPUT
"\n" 92 GRAVI_DISP_VIS
" : intermediate product\n" 93 GRAVI_DISP_MODEL
" : dispersion model of FDDL\n" 111 int cpl_plugin_get_info(cpl_pluginlist * list)
113 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe );
114 cpl_plugin * plugin = &recipe->interface;
116 if (cpl_plugin_init(plugin,
118 GRAVI_BINARY_VERSION,
119 CPL_PLUGIN_TYPE_RECIPE,
122 gravity_disp_description,
123 "Nabih Azouaoui, Vincent Lapeyrere, JB. Le Bouquin",
128 gravity_disp_destroy)) {
129 cpl_msg_error(cpl_func,
"Plugin initialization failed");
130 (void)cpl_error_set_where(cpl_func);
134 if (cpl_pluginlist_append(list, plugin)) {
135 cpl_msg_error(cpl_func,
"Error adding plugin to list");
136 (void)cpl_error_set_where(cpl_func);
152 static int gravity_disp_create(cpl_plugin * plugin)
158 if (cpl_error_get_code() != CPL_ERROR_NONE) {
159 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
160 cpl_func, __LINE__, cpl_error_get_where());
161 return (
int)cpl_error_get_code();
164 if (plugin == NULL) {
165 cpl_msg_error(cpl_func,
"Null plugin");
166 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
170 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
171 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
172 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
176 recipe = (cpl_recipe *)plugin;
179 recipe->parameters = cpl_parameterlist_new();
180 if (recipe->parameters == NULL) {
181 cpl_msg_error(cpl_func,
"Parameter list allocation failed");
182 cpl_ensure_code(0, (
int)CPL_ERROR_ILLEGAL_OUTPUT);
189 gravi_parameter_add_static_name (recipe->parameters);
192 gravi_parameter_add_preproc_file (recipe->parameters);
193 gravi_parameter_add_p2vmred_file (recipe->parameters);
194 gravi_parameter_add_vis_file (recipe->parameters);
197 gravi_parameter_add_compute_snr (recipe->parameters, isCalib);
198 gravi_parameter_add_compute_signal (recipe->parameters, isCalib);
200 gravi_parameter_add_compute_vis (recipe->parameters, isCalib);
212 static int gravity_disp_exec(cpl_plugin * plugin)
217 cpl_errorstate initial_errorstate = cpl_errorstate_get();
220 if (cpl_error_get_code() != CPL_ERROR_NONE) {
221 cpl_msg_error(cpl_func,
"%s():%d: An error is already set: %s",
222 cpl_func, __LINE__, cpl_error_get_where());
223 return (
int)cpl_error_get_code();
226 if (plugin == NULL) {
227 cpl_msg_error(cpl_func,
"Null plugin");
228 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
232 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
233 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
234 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
238 recipe = (cpl_recipe *)plugin;
241 if (recipe->parameters == NULL) {
242 cpl_msg_error(cpl_func,
"Recipe invoked with NULL parameter list");
243 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
245 if (recipe->frames == NULL) {
246 cpl_msg_error(cpl_func,
"Recipe invoked with NULL frame set");
247 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
251 recipe_status = gravity_disp(recipe->frames, recipe->parameters);
255 if (cpl_dfs_update_product_header(recipe->frames)) {
257 recipe_status = (int)cpl_error_get_code();
261 if (!cpl_errorstate_is_equal(initial_errorstate)) {
264 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
267 return recipe_status;
277 static int gravity_disp_destroy(cpl_plugin * plugin)
281 if (plugin == NULL) {
282 cpl_msg_error(cpl_func,
"Null plugin");
283 cpl_ensure_code(0, (
int)CPL_ERROR_NULL_INPUT);
287 if (cpl_plugin_get_type(plugin) != CPL_PLUGIN_TYPE_RECIPE) {
288 cpl_msg_error(cpl_func,
"Plugin is not a recipe");
289 cpl_ensure_code(0, (
int)CPL_ERROR_TYPE_MISMATCH);
293 recipe = (cpl_recipe *)plugin;
295 cpl_parameterlist_delete(recipe->parameters);
310 static int gravity_disp(cpl_frameset * frameset,
311 const cpl_parameterlist * parlist)
313 cpl_frameset * disp_frameset=NULL, * darkcalib_frameset=NULL,
314 * dark_frameset=NULL, * wavecalib_frameset=NULL,
315 * badcalib_frameset=NULL, * flatcalib_frameset=NULL, * dispvis_frameset=NULL,
316 * p2vmcalib_frameset=NULL, * wavelampcalib_frameset=NULL, *used_frameset=NULL,
317 * current_frameset=NULL, *static_param_frameset=NULL;
319 cpl_frame * frame=NULL;
321 gravi_data * disp_map = NULL, * data = NULL, * dark_map = NULL, * wave_map = NULL,
322 * profile_map = NULL, * badpix_map = NULL, * p2vmred_data = NULL, * preproc_data = NULL,
323 * p2vm_map = NULL, * vis_data = NULL, * tmpvis_data=NULL, * argon_data=NULL, * static_param_data=NULL;
328 gravity_print_banner ();
329 cpl_msg_set_time_on();
330 cpl_msg_set_component_on();
331 gravi_msg_function_start(1);
336 cpl_error_get_code()) ;
339 dispvis_frameset = gravi_frameset_extract_dispvis_data (frameset);
342 used_frameset = cpl_frameset_new();
346 static_param_frameset = gravi_frameset_extract_static_param (frameset);
349 if (!cpl_frameset_is_empty (static_param_frameset)) {
350 frame = cpl_frameset_get_position (static_param_frameset, 0);
354 cpl_msg_info (cpl_func,
"There is no STATIC_PARAM in the frameset");
358 if (cpl_frameset_is_empty (dispvis_frameset)){
361 wavelampcalib_frameset = gravi_frameset_extract_wavelamp_map (frameset);
362 p2vmcalib_frameset = gravi_frameset_extract_p2vm_map (frameset);
363 wavecalib_frameset = gravi_frameset_extract_wave_map (frameset);
364 flatcalib_frameset = gravi_frameset_extract_flat_map (frameset);
365 badcalib_frameset = gravi_frameset_extract_bad_map (frameset);
367 darkcalib_frameset = gravi_frameset_extract_dark_map (frameset);
370 disp_frameset = gravi_frameset_extract_disp_data (frameset);
373 if ( cpl_frameset_is_empty(p2vmcalib_frameset) ||
374 cpl_frameset_is_empty(wavecalib_frameset) ||
375 cpl_frameset_is_empty(flatcalib_frameset) ||
376 cpl_frameset_is_empty(badcalib_frameset) ||
377 ( cpl_frameset_is_empty(dark_frameset) &&
378 cpl_frameset_is_empty(darkcalib_frameset) ) ||
379 cpl_frameset_is_empty(disp_frameset) ||
380 cpl_frameset_is_empty(wavelampcalib_frameset) ) {
382 cpl_error_set_message (cpl_func, CPL_ERROR_ILLEGAL_INPUT,
383 "Missing P2VM, DARK, BAD, WAVE, WAVELAMP, FLAT or DISP frames") ;
391 if (!cpl_frameset_is_empty (dark_frameset)) {
393 frame = cpl_frameset_get_position (dark_frameset, 0);
401 CPLCHECK_CLEAN (
"Could not compute the DARK map");
405 NULL, frame,
"gravi_single",
406 NULL, GRAVI_DARK_MAP);
408 CPLCHECK_CLEAN (
"Could not save the DARK map");
410 else if (!cpl_frameset_is_empty (darkcalib_frameset)) {
412 frame = cpl_frameset_get_position (darkcalib_frameset, 0);
415 CPLCHECK_CLEAN (
"Could not load the DARK map");
418 cpl_msg_error (cpl_func,
"There is no DARK in the frame set");
421 frame = cpl_frameset_get_position (badcalib_frameset, 0);
425 frame = cpl_frameset_get_position (flatcalib_frameset, 0);
429 frame = cpl_frameset_get_position (wavecalib_frameset, 0);
433 frame = cpl_frameset_get_position (p2vmcalib_frameset, 0);
436 CPLCHECK_CLEAN (
"Error while loading the calibration map");
443 nb_frame = cpl_frameset_get_size (disp_frameset);
444 for (
int ivis = 0; ivis < nb_frame; ivis++) {
445 current_frameset = cpl_frameset_duplicate (used_frameset);
447 cpl_msg_info (cpl_func,
"*** Processing file %d over %d *** ", ivis+1, nb_frame);
449 frame = cpl_frameset_get_position (disp_frameset, ivis);
455 badpix_map, NULL, parlist,
457 CPLCHECK_CLEAN (
"Cannot extract spectrum");
461 CPLCHECK_CLEAN (
"Cannot re-interpolate spectrum");
469 CPLCHECK_CLEAN (
"Cannot move ext");
474 if (gravi_param_get_bool (parlist,
"gravity.dfs.preproc-file")) {
477 current_frameset, frame,
"gravity_disp",
478 NULL, GRAVI_PREPROC);
480 CPLCHECK_CLEAN (
"Could not save the preproc data");
486 "gravi_single", parlist, GRAVI_DET_ALL);
487 CPLCHECK_CLEAN (
"Cannot apply p2vm to the preproc data");
494 CPLCHECK_CLEAN (
"Cannot delete preproc");
498 CPLCHECK_CLEAN (
"Cannot reduce OPDC");
502 CPLCHECK_CLEAN (
"Cannot reduce metrology");
506 CPLCHECK_MSG (
"Cannot compute SNR");
510 CPLCHECK_MSG (
"Cannot compute signals");
514 CPLCHECK_MSG (
"Cannot rejection flags signals");
517 if (gravi_param_get_bool (parlist,
"gravity.dfs.p2vmred-file")) {
520 current_frameset, frame,
"gravity_disp",
521 NULL, GRAVI_P2VMRED_SINGLE_CALIB);
523 CPLCHECK_CLEAN (
"Cannot save the P2VMREDUCED product");
528 cpl_size current_frame = 0;
529 while (current_frame >= 0)
535 CPLCHECK_CLEAN (
"Cannot average the visibilities");
541 if (gravi_param_get_bool (parlist,
"gravity.dfs.vis-file")) {
544 current_frameset, frame,
"gravity_disp",
545 NULL, GRAVI_VIS_SINGLE_CALIB);
547 CPLCHECK_CLEAN (
"Cannot save the VIS product");
551 if (vis_data == NULL) {
552 vis_data = tmpvis_data; tmpvis_data = NULL;
555 cpl_msg_info (cpl_func,
"Merge with previous OI_VIS");
559 CPLCHECK_CLEAN (
"Cannot merge the visibilities");
563 cpl_msg_info (cpl_func,
"Free the p2vmreduced");
564 FREE (cpl_frameset_delete, current_frameset);
574 frame = cpl_frameset_get_position (wavelampcalib_frameset, 0);
581 cpl_frameset_join (used_frameset, disp_frameset);
582 frame = cpl_frameset_get_position (disp_frameset, 0);
585 used_frameset, frame,
"gravity_disp",
586 NULL, GRAVI_DISP_VIS);
588 CPLCHECK_CLEAN(
"Could not save the VIS_SINGLE product");
595 FREE (cpl_frameset_delete, darkcalib_frameset);
596 FREE (cpl_frameset_delete, wavecalib_frameset);
597 FREE (cpl_frameset_delete, dark_frameset);
598 FREE (cpl_frameset_delete, flatcalib_frameset);
599 FREE (cpl_frameset_delete, badcalib_frameset);
600 FREE (cpl_frameset_delete, p2vmcalib_frameset);
601 FREE (cpl_frameset_delete, wavelampcalib_frameset);
606 frame = cpl_frameset_get_position (dispvis_frameset, 0);
609 CPLCHECK_CLEAN (
"Cannot load the DISP_VIS file");
611 disp_frameset = cpl_frameset_duplicate (dispvis_frameset);
622 CPLCHECK_CLEAN (
"Error while computing the disp_map");
625 frame = cpl_frameset_get_position (disp_frameset, 0);
629 used_frameset, frame,
"gravity_disp",
630 NULL, GRAVI_DISP_MODEL);
632 CPLCHECK_CLEAN(
"Could not save the DISP_MODEL product");
638 cpl_msg_info(cpl_func,
"Memory cleanup");
650 FREE (cpl_frameset_delete, disp_frameset);
651 FREE (cpl_frameset_delete, dispvis_frameset);
652 FREE (cpl_frameset_delete, darkcalib_frameset);
653 FREE (cpl_frameset_delete, dark_frameset);
654 FREE (cpl_frameset_delete, wavecalib_frameset);
655 FREE (cpl_frameset_delete, badcalib_frameset);
656 FREE (cpl_frameset_delete, flatcalib_frameset);
657 FREE (cpl_frameset_delete, p2vmcalib_frameset);
658 FREE (cpl_frameset_delete, wavelampcalib_frameset);
659 FREE (cpl_frameset_delete, used_frameset);
660 FREE (cpl_frameset_delete, current_frameset);
662 gravi_msg_function_exit(1);
663 return (
int)cpl_error_get_code();
cpl_error_code gravi_compute_opdc_state(gravi_data *p2vmred_data)
Compute the real-time tracking state from OPDC.
gravi_data * gravi_compute_disp(gravi_data *vis_data)
Compute the DISP_MODEL calibration map.
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_copy_ext(gravi_data *output, gravi_data *input, const char *name)
Copy extensions from one data to another.
cpl_frameset * gravi_frameset_extract_dark_data(cpl_frameset *frameset)
Extract DARK_RAW frame from the input frameset.
gravi_data * gravi_data_load_rawframe(cpl_frame *frame, cpl_frameset *used_frameset)
Load a RAW FITS file and create a gravi_data.
cpl_error_code gravi_data_move_ext(gravi_data *output, gravi_data *input, const char *name)
Move extensions from one data to another.
cpl_error_code gravi_compute_vis_qc(gravi_data *vis_data)
The function compute the QC parameters for a VIS (averaged) data.
cpl_error_code gravi_compute_snr(gravi_data *p2vmred_data, const cpl_parameterlist *parlist)
Compute real-time SNR and Group-Delay of the observation.
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_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 ...
cpl_error_code gravi_compute_signals(gravi_data *p2vmred_data, gravi_data *disp_data, const cpl_parameterlist *parlist)
Create intermediate signal in the P2VMREDUCED file.
gravi_data * gravi_compute_p2vmred(gravi_data *preproc_data, gravi_data *p2vm_map, const char *mode, const cpl_parameterlist *parlist, enum gravi_detector_type det_type)
Converts preprocessed data into coherent fluxes using the P2VM.
cpl_error_code gravi_compute_rejection(gravi_data *p2vmred_data, const cpl_parameterlist *parlist)
Create rejection flags P2VMREDUCED file.
const char * gravi_get_license(void)
Get the pipeline copyright and license.
cpl_error_code gravi_parameter_add_rejection(cpl_parameterlist *self, int isCalib)
Add rejection parameters to the input parameter list.
cpl_error_code gravi_data_detector_cleanup(gravi_data *data, const cpl_parameterlist *parlist)
Perform self-bias correction to the SC raw 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.
cpl_error_code gravi_disp_cleanup(gravi_data *vis_data)
Cleanup a VIS gravi_data before calibrating the dispersion.
cpl_error_code gravi_align_spectrum(gravi_data *spectrum_data, gravi_data *wave_map, gravi_data *p2vm_map, enum gravi_detector_type det_type, const cpl_parameterlist *parlist)
Regrid the regions into a common wavelength (in-place)
void gravi_data_delete(gravi_data *self)
Delete a gravi data.
cpl_error_code gravi_metrology_reduce(gravi_data *data, gravi_data *eop_data, gravi_data *static_param_data, gravi_data *met_pos, const cpl_parameterlist *parlist)
Reduce the metrology.
cpl_error_code gravi_data_append(gravi_data *first, const gravi_data *second, int force)
Append a gravi_data into another existing one.
gravi_data * gravi_extract_spectrum(gravi_data *raw_data, gravi_data *profile_map, gravi_data *dark_map, gravi_data *bad_map, gravi_data *sky_map, const cpl_parameterlist *parlist, enum gravi_detector_type det_type)
Create the SPECTRUM gravi_data with extracted spectrum per region.
gravi_data * gravi_compute_dark(gravi_data *raw_data)
Compute the DARK calibration map.