41 #include <irplib_utils.h>
54 #include <uves_error.h>
55 #include <uves_utils_wrappers.h>
56 #include <uves_utils.h>
71 static char uves_utl_rcosmic_description[] =
72 "This recipe performs image computation.\n"
73 "The input files are two images\n"
74 "one (containing cosmic ray hits) with associated tag RAW_IMA.\n"
75 "[optional] a bias frame with tag BIAS_BLUE or BIAS_RED.\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_rcosmic\n"
79 "esorex --help uves_utl_rcosmic\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,
111 "Remove CRHs from an image",
112 uves_utl_rcosmic_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_rcosmic.sky_mean",
154 "Mean sky value [ADUs]",
155 "uves.uves_utl_rcosmic",10.);
156 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"sky_mean") ;
157 cpl_parameterlist_append(recipe->parameters, p) ;
160 p = cpl_parameter_new_value(
"uves.uves_utl_rcosmic.ron",
163 "uves.uves_utl_rcosmic", 3.) ;
164 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"ron") ;
165 cpl_parameterlist_append(recipe->parameters, p) ;
169 p = cpl_parameter_new_value(
"uves.uves_utl_rcosmic.gain",
172 "uves.uves_utl_rcosmic", 0.7) ;
173 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"gain") ;
174 cpl_parameterlist_append(recipe->parameters, p) ;
177 p = cpl_parameter_new_value(
"uves.uves_utl_rcosmic.kappa",
179 "Kappa value in kappa-sigma CRH clip",
180 "uves.uves_utl_rcosmic",5) ;
181 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"kappa") ;
182 cpl_parameterlist_append(recipe->parameters, p) ;
185 p = cpl_parameter_new_value(
"uves.uves_utl_rcosmic.nc",
187 " critical ratio for discrimination of objects and cosmic rays",
188 "uves.uves_utl_rcosmic",5) ;
189 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"nc") ;
190 cpl_parameterlist_append(recipe->parameters, p) ;
206 cpl_recipe * recipe ;
208 cpl_errorstate initial_errorstate = cpl_errorstate_get();
211 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
212 recipe = (cpl_recipe *)plugin ;
219 if (!cpl_errorstate_is_equal(initial_errorstate)) {
222 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
237 cpl_recipe * recipe ;
240 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
241 recipe = (cpl_recipe *)plugin ;
244 cpl_parameterlist_delete(recipe->parameters) ;
258 cpl_frameset * framelist)
260 cpl_parameter * param= NULL ;
261 cpl_frameset * raw_on=NULL;
262 cpl_frameset * raw_off=NULL;
271 cpl_image* ima_res=NULL;
272 cpl_image* ima_on=NULL;
273 cpl_image* ima_off=NULL;
276 cpl_image* ima_flt=NULL;
277 cpl_image* ima_msk=NULL;
280 const char* name1=NULL;
283 const char* name2=NULL;
287 cpl_propertylist* plist1=NULL;
288 cpl_propertylist* plist2=NULL;
289 cpl_propertylist* pliste=NULL;
290 const char* name_r=
"ima_res.fits";
291 cpl_frame* product_frame=NULL;
292 cpl_frame* frame_on=NULL;
293 cpl_frame* frame_off=NULL;
298 uves_msg(
"Welcome to UVES Pipeline release %d.%d.%d",
299 UVES_MAJOR_VERSION,UVES_MINOR_VERSION,UVES_MICRO_VERSION);
303 "uves.uves_utl_rcosmic.sky_mean"));
304 check_nomsg(sky_mean=cpl_parameter_get_double(param));
307 "uves.uves_utl_rcosmic.ron"));
308 check_nomsg(ron = cpl_parameter_get_double(param)) ;
311 "uves.uves_utl_rcosmic.gain"));
312 check_nomsg(gain = cpl_parameter_get_double(param)) ;
315 "uves.uves_utl_rcosmic.kappa"));
316 check_nomsg(kappa = cpl_parameter_get_int(param)) ;
319 "uves.uves_utl_rcosmic.nc"));
324 check(uves_dfs_set_groups(framelist),
325 "Cannot identify RAW and CALIB frames") ;
329 nfrm=cpl_frameset_get_size(framelist);
338 check(uves_contains_frames_kind(framelist,raw_on,
"RAW_IMA"),
339 "Found no input frames with tag %s",
"RAW_IMA");
348 check_nomsg(frame_on=cpl_frameset_get_first(raw_on));
349 check_nomsg(next1=cpl_frame_get_nextensions(frame_on));
350 check_nomsg(name1=cpl_frame_get_filename(frame_on));
351 check_nomsg(plist1=cpl_propertylist_load(name1,0));
352 uves_msg(
"CRH affected file name =%s",name1);
360 chips=cpl_propertylist_get_int(plist1,
"ESO DET CHIPS");
364 check(uves_contains_frames_kind(framelist,raw_off,
"BIAS_RED"),
365 "Found no input frames with tag %s",
"BIAS_RED");
367 check(uves_contains_frames_kind(framelist,raw_off,
"BIAS_BLUE"),
368 "Found no input frames with tag %s",
"BIAS_BLUE");
377 frame_off=cpl_frameset_get_first(raw_off);
378 next2=cpl_frame_get_nextensions(frame_off);
385 name2=cpl_frame_get_filename(frame_off);
386 uves_msg(
"Bias file name =%s",name2);
387 check_nomsg(cpl_image_save(NULL, name_r,CPL_BPP_IEEE_FLOAT,
388 plist1,CPL_IO_DEFAULT));
398 check_nomsg(ima_on=cpl_image_load(name1,CPL_TYPE_FLOAT,0,0));
399 check_nomsg(ima_off=cpl_image_load(name2,CPL_TYPE_FLOAT,0,0));
403 cpl_image_save(ima_on,
"image_with_crh.fits",CPL_BPP_IEEE_FLOAT,
404 NULL,CPL_IO_DEFAULT);
407 sky_mean,ron,gain,kappa,nc),
408 "fail to remove CRHs");
413 check_nomsg(cpl_image_save(ima_res, name_r,CPL_BPP_IEEE_FLOAT,
414 plist1,CPL_IO_DEFAULT));
425 for(i=1;i<=next1;i++) {
428 check_nomsg(ima_on=cpl_image_load(name1,CPL_TYPE_FLOAT,0,i));
431 check_nomsg(pliste=cpl_propertylist_load(name1,i));
434 check_nomsg(ima_off=cpl_image_load(name2,CPL_TYPE_FLOAT,0,0));
437 check_nomsg(ima_off=cpl_image_load(name2,CPL_TYPE_FLOAT,0,i));
440 uves_msg(
"ima_on=%p ima_off=%p",ima_on,ima_off);
443 cpl_image_save(ima_on,
"image_with_crh.fits",CPL_BPP_IEEE_FLOAT,
444 NULL,CPL_IO_DEFAULT);
448 sky_mean,ron,gain,kappa,nc),
449 "fail to remove CRHs");
454 check_nomsg(cpl_image_save(ima_res, name_r,CPL_BPP_IEEE_FLOAT,
455 pliste,CPL_IO_EXTEND));
457 uves_free_image(&ima_on);
458 uves_free_image(&ima_off);
459 uves_free_image(&ima_flt);
460 uves_free_image(&ima_res);
461 cpl_propertylist_delete(pliste); pliste=NULL;
470 uves_free_frameset(&raw_off);
471 uves_free_frameset(&raw_on);
475 uves_msg(
"Please, provide a bias frame. Exit.");
483 name_r =
"ima_res.fits" ;
487 check_nomsg(cpl_frame_set_filename(product_frame, name_r)) ;
488 check_nomsg(cpl_frame_set_tag(product_frame,
"PRODUCT")) ;
489 check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
490 check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
491 check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
492 "Error while initialising the product frame") ;
496 check_nomsg(cpl_propertylist_erase_regexp(plist1,
"^ESO PRO CATG",0));
515 cpl_propertylist_delete(plist1) ; plist1=NULL;
518 check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
522 uves_free_frameset(&raw_on);
523 uves_free_frameset(&raw_off);
524 uves_free_image(&ima_on);
525 uves_free_image(&ima_off);
529 uves_free_image(&ima_flt);
530 uves_free_image(&ima_res);
532 if(pliste!=NULL) cpl_propertylist_delete(pliste); pliste=NULL;
534 if (plist1!=NULL) cpl_propertylist_delete(plist1);plist1=NULL;
535 if (plist2!=NULL) cpl_propertylist_delete(plist2);plist2=NULL;
541 if (cpl_error_get_code()) {
#define uves_msg_error(...)
Print an error message.
static int uves_utl_rcosmic(cpl_parameterlist *, cpl_frameset *)
Get the command line options and execute the data reduction.
cpl_error_code uves_rcosmic(cpl_image *ima, cpl_image **flt, cpl_image **out, cpl_image **msk, const double sky, const double ron, const double gain, const int ns, const double rc)
Remove cosmic ray events on single ccd exposure and replace them by interpolation on neighbourhood pi...
void irplib_reset(void)
Reset IRPLIB state.
const char * uves_get_license(void)
Get the pipeline copyright and license.
static int uves_utl_rcosmic_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
static int uves_utl_rcosmic_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
#define uves_msg(...)
Print a message on 'info' or 'debug' level.
static int uves_utl_rcosmic_create(cpl_plugin *)
Setup the recipe options.
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.