50 #include <irplib_utils.h>
53 #include <sinfo_pro_types.h>
54 #include <sinfo_general_config.h>
55 #include <sinfo_utilities.h>
56 #include <sinfo_product_config.h>
57 #include <sinfo_prepare_stacked_frames_config.h>
58 #include <sinfo_wavecal_config.h>
59 #include <sinfo_raw_types.h>
60 #include <sinfo_tpl_utils.h>
61 #include <sinfo_tpl_dfs.h>
62 #include <sinfo_hidden.h>
63 #include <sinfo_globals.h>
64 #include <sinfo_functions.h>
65 #include <sinfo_msg.h>
66 #include <sinfo_new_prepare_stacked_frames.h>
67 #include <sinfo_new_wave_cal_slit2.h>
68 #include <sinfo_error.h>
69 #include <sinfo_utils_wrappers.h>
71 #include <sinfo_key_names.h>
76 static int sinfo_rec_wavecal_create(cpl_plugin *);
77 static int sinfo_rec_wavecal_exec(cpl_plugin *);
78 static int sinfo_rec_wavecal_destroy(cpl_plugin *);
79 static int sinfo_rec_wavecal(cpl_parameterlist *, cpl_frameset *);
85 static char sinfo_rec_wavecal_description1[] =
86 "This recipe performs wavelength calibration.\n"
87 "The input files are on/off arc lamp frames with tag WAVE_LAMP\n"
88 "Master calibration frame input is:\n"
89 "A corresponding (band) reference line table with tag REF_LINE_ARC\n"
90 "A corresponding (band) distortion table with tag DISTORTION\n"
91 "A corresponding (band,preoptic) master flat with tag MASTER_FLAT_LAMP\n"
92 "A corresponding (band,preoptics) master bad "
93 "pixel map with tag MASTER_BP_MAP\n";
96 static char sinfo_rec_wavecal_description2[] =
97 "If wcal-estimate_ind=TRUE, a corresponding (band,preoptics) slitlet position\n"
98 "guess table SLIT_POS_GUESS (for example a copy of the SLIT_POS product)\n"
99 "If wcal-calib_indicator=FALSE, a corresponding (band,preoptics) parabolic \n"
100 "fit coefficients table WAVE_COEF_SLIT\n"
101 "If sinfoni.wavecal.slitpos_boostrap_switch=FALSE \n"
102 "(wcal-calib-slitpos_bootstrap=0),\n"
103 "a corresponding (band,preoptics) slitlets position table with tag SLIT_POS\n";
107 static char sinfo_rec_wavecal_description3[] =
108 "The main products are:\n"
109 "The master flat field corrected for distortions \n"
110 "(PRO.CATG=MFLAT_STACKED_DIST)\n"
111 "The arc lamp frames stacked (PRO.CATG=WAVE_LAMP_STACKED)\n"
112 "The wavelength map (PRO.CATG=WAVE_MAP)\n"
113 "The slitlet position table (PRO.CATG=SLIT_POS)\n"
114 "A parabolic fit coefficients table (PRO.CATG=WAVE_COEF_SLIT)\n"
115 "Parameters relative to arc lamp line fit: (PRO.CATG=WAVE_FIT_PARAMS)\n"
119 static char sinfo_rec_wavecal_description[1500];
146 cpl_recipe *recipe = cpl_calloc(1,
sizeof *recipe);
147 cpl_plugin *plugin = &recipe->interface;
150 strcpy(sinfo_rec_wavecal_description,sinfo_rec_wavecal_description1);
151 strcat(sinfo_rec_wavecal_description,sinfo_rec_wavecal_description2);
152 strcat(sinfo_rec_wavecal_description,sinfo_rec_wavecal_description3);
154 cpl_plugin_init(plugin,
156 SINFONI_BINARY_VERSION,
157 CPL_PLUGIN_TYPE_RECIPE,
159 "Wavelength calibration and slitpos determination",
160 sinfo_rec_wavecal_description,
162 "Andrea.Modigliani@eso.org",
164 sinfo_rec_wavecal_create,
165 sinfo_rec_wavecal_exec,
166 sinfo_rec_wavecal_destroy);
168 cpl_pluginlist_append(list, plugin);
184 static int sinfo_rec_wavecal_create(cpl_plugin *plugin)
186 cpl_recipe * recipe ;
189 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
190 recipe = (cpl_recipe *)plugin ;
196 recipe->parameters = cpl_parameterlist_new() ;
204 sinfo_general_config_add(recipe->parameters);
205 sinfo_product_config_add(recipe->parameters);
206 sinfo_prepare_stacked_frames_config_add(recipe->parameters);
207 sinfo_wavecal_config_add(recipe->parameters);
221 static int sinfo_rec_wavecal_exec(cpl_plugin *plugin)
224 cpl_recipe *recipe = (cpl_recipe *) plugin;
227 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
228 recipe = (cpl_recipe *)plugin ;
231 return sinfo_rec_wavecal(recipe->parameters, recipe->frames);
242 static int sinfo_rec_wavecal_destroy(cpl_plugin *plugin)
244 cpl_recipe * recipe ;
246 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
247 recipe = (cpl_recipe *)plugin ;
250 cpl_parameterlist_delete(recipe->parameters);
268 static int sinfo_rec_wavecal(cpl_parameterlist *config, cpl_frameset *set)
273 cpl_parameter* p=NULL;
274 cpl_frameset* wrk_set=NULL;
275 cpl_frame* frame=NULL;
277 cpl_frameset* ref_set=NULL;
283 sinfo_msg(
"Welcome to SINFONI Pipeline release %d.%d.%d",
284 SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
288 ck0(sinfo_dfs_set_groups(set),
"Cannot indentify RAW and CALIB frames") ;
289 check_nomsg(p=cpl_parameterlist_find(config,
"sinfoni.general.lc_sw"));
290 check_nomsg(line_cor=cpl_parameter_get_bool(p));
292 check_nomsg(sinfo_ima_line_cor(config,set));
296 check_nomsg(ref_set=cpl_frameset_duplicate(set));
299 check_nomsg(p=cpl_parameterlist_find(config,
"sinfoni.product.density"));
300 check_nomsg(pdensity=cpl_parameter_get_int(p));
303 check_nomsg(p=cpl_parameterlist_find(config,
304 "sinfoni.wavecal.slitpos_boostrap"));
305 check_nomsg(sw=cpl_parameter_get_bool(p));
307 check_nomsg(wrk_set=cpl_frameset_duplicate(set));
309 check_nomsg(p=cpl_parameterlist_find(config,
"sinfoni.stacked.ind_index"));
310 check_nomsg(ind_index=cpl_parameter_get_bool(p));
311 check_nomsg(cpl_parameter_set_bool(p,TRUE));
313 sinfo_msg(
"---------------------------------------");
314 sinfo_msg(
"%s FRAME DETERMINATION", PRO_WAVE_LAMP_STACKED);
315 sinfo_msg(
"---------------------------------------");
316 ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, wrk_set, NULL,
317 PRO_WAVE_LAMP_STACKED,0,fk),
318 "FAILED STACKING FRAME %s",PRO_WAVE_LAMP_STACKED);
320 sinfo_msg(
"%s FRAME DETERMINATION SUCCESS", PRO_WAVE_LAMP_STACKED);
322 ck0(sinfo_new_wave_cal_slit2(cpl_func,config, wrk_set,ref_set),
323 "FIRST PART OF WAVELENGTH CALIBRATION FAILED") ;
324 sinfo_msg(
"FIRST PART OF WAVELENGTH CALIBRATION") ;
326 check_nomsg(frame = cpl_frameset_find(wrk_set,PRO_SLIT_POS_GUESS));
327 check_nomsg(cpl_frameset_insert(set,cpl_frame_duplicate(frame)));
328 check_nomsg(p=cpl_parameterlist_find(config,
"sinfoni.stacked.ind_index"));
330 check_nomsg(cpl_parameter_set_bool(p,TRUE));
331 check_nomsg(p=cpl_parameterlist_find(config,
332 "sinfoni.wavecal.slitpos_boostrap"));
333 check_nomsg(cpl_parameter_set_bool(p,TRUE));
334 sinfo_msg(
"Set ind_index to TRUE");
336 check_nomsg(cpl_parameter_set_bool(p,FALSE));
337 check_nomsg(p=cpl_parameterlist_find(config,
338 "sinfoni.wavecal.slitpos_boostrap"));
339 check_nomsg(cpl_parameter_set_bool(p,FALSE));
340 sinfo_msg(
"Set ind_index to FALSE");
342 sinfo_free_frameset(&wrk_set);
346 sinfo_msg(
"---------------------------------------------");
347 sinfo_msg(
"%s FRAME DETERMINATION", PRO_WAVE_LAMP_STACKED);
348 sinfo_msg(
"---------------------------------------------");
354 int nsky, ndark, nwave;
361 nsky = cpl_frameset_count_tags (set, RAW_SKY_NODDING);
362 nwave = cpl_frameset_count_tags (set, RAW_WAVE_LAMP);
363 ndark = cpl_frameset_count_tags (set, PRO_MASTER_DARK);
365 if ( (nwave == 0) & (nsky>0) ) {
366 sinfo_msg (
"No arc lamp frames found, using sky frames instead");
368 sinfo_msg (
"Including Master dark is recommended when running wavecal on sky frames");
372 while (i < cpl_frameset_get_size(set)) {
373 cpl_frame* fr = cpl_frameset_get_frame(set,i);
374 const char* tag = cpl_frame_get_tag (fr);
376 if (strcmp(tag, RAW_SKY_NODDING)==0)
378 cpl_frame * frnew = 0;
380 const char* fname = cpl_frame_get_filename(fr);
381 sprintf (&name[0],
"fakelamp_%d.fits", non++);
382 cpl_image* im = cpl_image_load(fname, CPL_TYPE_FLOAT, 0, 0);
383 cpl_propertylist* plist = cpl_propertylist_load(fname,0);
390 cpl_propertylist_set_bool (plist, KEY_NAME_LAMP_XE, 1);
391 cpl_propertylist_set_string (plist, KEY_NAME_DPR_TYPE,
"WAVE,LAMP");
393 cpl_image_save (im, name, CPL_BPP_IEEE_FLOAT, plist, CPL_IO_DEFAULT);
394 cpl_image_delete (im);
395 cpl_propertylist_delete(plist);
399 frnew = cpl_frame_duplicate (fr);
400 cpl_frame_set_filename(frnew, name);
401 cpl_frame_set_tag (frnew, RAW_WAVE_LAMP);
402 cpl_frameset_erase_frame (set, fr);
403 cpl_frameset_insert (set, frnew);
414 ck0(sinfo_new_prepare_stacked_frames(cpl_func,config, set, NULL,
415 PRO_WAVE_LAMP_STACKED,0,fk),
416 "%s FRAME DETERMINATION FAILED",PRO_WAVE_LAMP_STACKED);
417 sinfo_msg(
"%s FRAME DETERMINATION SUCCESS", PRO_WAVE_LAMP_STACKED);
419 sinfo_msg(
"---------------------------------------------");
420 sinfo_msg(
"WAVELENGTH CALIBRATION");
421 sinfo_msg(
"---------------------------------------------");
424 ck0(sinfo_new_wave_cal_slit2(cpl_func,config, set,ref_set),
425 "FAILED WAVELENGTH CALIBRATION");
426 sinfo_msg(
"SUCCESS WAVELENGTH CALIBRATION");
428 sinfo_fake_delete(&fk);
430 check_nomsg(cpl_frameset_erase(set,PRO_STACK_MFLAT_DIST));
431 check_nomsg(cpl_frameset_erase(set,PRO_WAVE_LAMP_STACKED));
436 sinfo_free_frameset(&ref_set);
437 sinfo_free_frameset(&wrk_set);
438 sinfo_fake_delete(&fk);
441 if (cpl_error_get_code() != CPL_ERROR_NONE) {
void irplib_reset(void)
Reset IRPLIB state.
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.