41 #include <irplib_utils.h>
54 #include <uves_error.h>
55 #include <uves_utils_wrappers.h>
56 #include <uves_remove_crh_single.h>
57 #include <uves_cpl_size.h>
72 static char uves_utl_remove_crh_single_description[] =
73 "This recipe performs image computation.\n"
74 "The input files is one image\n"
75 "their associated tags should be IMA.\n"
76 "The output is the image cleaned from CRHs\n"
77 "Information on relevant parameters can be found with\n"
78 "esorex --params uves_utl_remove_crh_single\n"
79 "esorex --help uves_utl_remove_crh_single\n"
103 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe ) ;
104 cpl_plugin * plugin = &recipe->interface ;
106 cpl_plugin_init(plugin,
109 CPL_PLUGIN_TYPE_RECIPE,
110 "uves_utl_remove_crh_single",
111 "Remove CRHs from an image",
112 uves_utl_remove_crh_single_description,
114 "Andrea.Modigliani@eso.org",
120 cpl_pluginlist_append(list, plugin) ;
137 cpl_recipe * recipe ;
141 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
142 recipe = (cpl_recipe *)plugin ;
148 recipe->parameters = cpl_parameterlist_new() ;
152 p = cpl_parameter_new_value(
"uves.uves_utl_remove_crh_single.crh_frac_max",
154 "Maximum fraction of allowed CRHs",
155 "uves.uves_utl_remove_crh_single",0.7);
156 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"crh_frac_max") ;
157 cpl_parameterlist_append(recipe->parameters, p) ;
160 p = cpl_parameter_new_value(
"uves.uves_utl_remove_crh_single.sigma_lim",
162 "Maximum sigma in kappa-sigma clip",
163 "uves.uves_utl_remove_crh_single", 25.) ;
164 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"sigma_lim") ;
165 cpl_parameterlist_append(recipe->parameters, p) ;
169 p = cpl_parameter_new_value(
"uves.uves_utl_remove_crh_single.f_lim",
171 "Max fraction of bad pixels allowed",
172 "uves.uves_utl_remove_crh_single", 0.7) ;
173 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"f_lim") ;
174 cpl_parameterlist_append(recipe->parameters, p) ;
177 p = cpl_parameter_new_value(
"uves.uves_utl_remove_crh_single.max_iter",
179 "Max fraction of bad pixels allowed",
180 "uves.uves_utl_remove_crh_single",5) ;
181 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"max_iter") ;
182 cpl_parameterlist_append(recipe->parameters, p) ;
186 p = cpl_parameter_new_value(
"uves.uves_utl_remove_crh_single.gain",
189 "uves.uves_utl_remove_crh_single",2.42) ;
190 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"gain") ;
191 cpl_parameterlist_append(recipe->parameters, p) ;
194 p = cpl_parameter_new_value(
"uves.uves_utl_remove_crh_single.ron",
197 "uves.uves_utl_remove_crh_single",1.) ;
198 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"ron") ;
199 cpl_parameterlist_append(recipe->parameters, p) ;
217 cpl_recipe * recipe ;
219 cpl_errorstate initial_errorstate = cpl_errorstate_get();
222 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
223 recipe = (cpl_recipe *)plugin ;
230 if (!cpl_errorstate_is_equal(initial_errorstate)) {
233 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
248 cpl_recipe * recipe ;
251 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
252 recipe = (cpl_recipe *)plugin ;
255 cpl_parameterlist_delete(recipe->parameters) ;
269 cpl_frameset * framelist)
271 cpl_parameter * param= NULL ;
272 cpl_frameset * raw_on=NULL;
273 cpl_frameset * raw_off=NULL;
274 double crh_frac_max=0;
282 cpl_image* ima_res=NULL;
283 cpl_image* ima_on=NULL;
284 cpl_image* ima_off=NULL;
287 cpl_propertylist* plist1=NULL;
288 cpl_propertylist* plist2=NULL;
289 cpl_propertylist* pliste=NULL;
291 const char* name_r=
"ima_res.fits";
293 cpl_frame* product_frame=NULL;
294 cpl_frame* frame_on=NULL;
295 cpl_frame* frame_off=NULL;
297 const char* name1=NULL;
300 const char* name2=NULL;
308 uves_msg(
"Welcome to UVES Pipeline release %d.%d.%d",
309 UVES_MAJOR_VERSION,UVES_MINOR_VERSION,UVES_MICRO_VERSION);
313 "uves.uves_utl_remove_crh_single.crh_frac_max"));
314 check_nomsg(crh_frac_max=cpl_parameter_get_double(param));
317 "uves.uves_utl_remove_crh_single.sigma_lim"));
318 check_nomsg(sigma_lim = cpl_parameter_get_double(param)) ;
322 "uves.uves_utl_remove_crh_single.f_lim"));
323 check_nomsg(f_lim = cpl_parameter_get_double(param)) ;
326 "uves.uves_utl_remove_crh_single.max_iter"));
327 check_nomsg(max_iter = cpl_parameter_get_int(param)) ;
330 "uves.uves_utl_remove_crh_single.gain"));
331 check_nomsg(gain = cpl_parameter_get_double(param)) ;
335 "uves.uves_utl_remove_crh_single.ron"));
336 check_nomsg(ron = cpl_parameter_get_double(param)) ;
342 check(uves_dfs_set_groups(framelist),
343 "Cannot identify RAW and CALIB frames") ;
347 nfrm=cpl_frameset_get_size(framelist);
356 check(uves_contains_frames_kind(framelist,raw_on,
"RAW_IMA"),
357 "Found no input frames with tag %s",
"RAW_IMA");
366 check_nomsg(frame_on=cpl_frameset_get_first(raw_on));
367 check_nomsg(next1=cpl_frame_get_nextensions(frame_on));
368 check_nomsg(name1=cpl_frame_get_filename(frame_on));
369 check_nomsg(plist1=cpl_propertylist_load(name1,0));
370 uves_msg(
"CRH affected file name =%s",name1);
378 chips=cpl_propertylist_get_int(plist1,
"ESO DET CHIPS");
382 check(uves_contains_frames_kind(framelist,raw_off,
"BIAS_RED"),
383 "Found no input frames with tag %s",
"BIAS_RED");
385 check(uves_contains_frames_kind(framelist,raw_off,
"BIAS_BLUE"),
386 "Found no input frames with tag %s",
"BIAS_BLUE");
395 frame_off=cpl_frameset_get_first(raw_off);
396 next2=cpl_frame_get_nextensions(frame_off);
403 name2=cpl_frame_get_filename(frame_off);
404 uves_msg(
"Bias file name =%s",name2);
405 check_nomsg(cpl_image_save(NULL, name_r,CPL_BPP_IEEE_FLOAT,
406 plist1,CPL_IO_DEFAULT));
416 check_nomsg(ima_on=cpl_image_load(name1,CPL_TYPE_FLOAT,0,0));
417 check_nomsg(ima_off=cpl_image_load(name2,CPL_TYPE_FLOAT,0,0));
421 cpl_image_save(ima_on,
"image_with_crh.fits",CPL_BPP_IEEE_FLOAT,
422 NULL,CPL_IO_DEFAULT);
428 "fail to remove CRHs");
432 check_nomsg(cpl_image_save(ima_res, name_r,CPL_BPP_IEEE_FLOAT,
433 plist1,CPL_IO_DEFAULT));
435 uves_msg(
"next=%" CPL_SIZE_FORMAT
"",next1);
444 for(i=1;i<=next1;i++) {
447 check_nomsg(ima_on=cpl_image_load(name1,CPL_TYPE_FLOAT,0,i));
450 check_nomsg(pliste=cpl_propertylist_load(name1,i));
453 check_nomsg(ima_off=cpl_image_load(name2,CPL_TYPE_FLOAT,0,0));
456 check_nomsg(ima_off=cpl_image_load(name2,CPL_TYPE_FLOAT,0,i));
459 uves_msg(
"ima_on=%p ima_off=%p",ima_on,ima_off);
462 cpl_image_save(ima_on,
"image_with_crh.fits",CPL_BPP_IEEE_FLOAT,
463 NULL,CPL_IO_DEFAULT);
468 "fail to remove CRHs");
474 check_nomsg(cpl_image_save(ima_res, name_r,CPL_BPP_IEEE_FLOAT,
475 pliste,CPL_IO_EXTEND));
477 uves_free_image(&ima_on);
478 uves_free_image(&ima_off);
479 uves_free_image(&ima_res);
480 cpl_propertylist_delete(pliste); pliste=NULL;
489 uves_free_frameset(&raw_off);
490 uves_free_frameset(&raw_on);
494 uves_msg(
"Please, provide a bias frame. Exit.");
506 check_nomsg(cpl_frame_set_filename(product_frame, name_r)) ;
507 check_nomsg(cpl_frame_set_tag(product_frame,
"PRODUCT")) ;
508 check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
509 check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
510 check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
511 "Error while initialising the product frame") ;
514 check_nomsg(cpl_propertylist_erase_regexp(plist1,
"^ESO PRO CATG",0));
533 cpl_propertylist_delete(plist1) ; plist1=NULL;
536 check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
540 uves_free_frameset(&raw_off);
541 uves_free_image(&ima_on);
542 uves_free_image(&ima_off);
543 uves_free_image(&ima_res);
545 if(pliste!=NULL) cpl_propertylist_delete(pliste); pliste=NULL;
547 if (plist1!=NULL) cpl_propertylist_delete(plist1);plist1=NULL;
548 if (plist2!=NULL) cpl_propertylist_delete(plist2);plist2=NULL;
551 if (cpl_error_get_code()) {