39 #include <irplib_utils.h>
42 #include <sinfo_tpl_utils.h>
43 #include <sinfo_pfits.h>
44 #include <sinfo_tpl_dfs.h>
45 #include <sinfo_raw_types.h>
46 #include <sinfo_pro_types.h>
47 #include <sinfo_functions.h>
48 #include <sinfo_key_names.h>
49 #include <sinfo_msg.h>
50 #include <sinfo_error.h>
51 #include <sinfo_utils_wrappers.h>
56 static int sinfo_utl_skymap_create(cpl_plugin *) ;
57 static int sinfo_utl_skymap_exec(cpl_plugin *) ;
58 static int sinfo_utl_skymap_destroy(cpl_plugin *) ;
59 static int sinfo_utl_skymap(cpl_parameterlist *, cpl_frameset *) ;
64 static char sinfo_utl_skymap_description[] =
65 "This recipe flags as bad pixels sky lines.\n"
66 "Input are sky frames with tag SKY\n"
67 "Output image is called out_skymap.fits\n"
91 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe ) ;
92 cpl_plugin * plugin = &recipe->interface ;
94 cpl_plugin_init(plugin,
96 SINFONI_BINARY_VERSION,
97 CPL_PLUGIN_TYPE_RECIPE,
99 "Flags sky lines as bad pixels, with map generation",
100 sinfo_utl_skymap_description,
102 "Andrea.Modigliani@eso.org",
104 sinfo_utl_skymap_create,
105 sinfo_utl_skymap_exec,
106 sinfo_utl_skymap_destroy) ;
108 cpl_pluginlist_append(list, plugin) ;
123 static int sinfo_utl_skymap_create(cpl_plugin * plugin)
125 cpl_recipe * recipe ;
129 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
130 recipe = (cpl_recipe *)plugin ;
134 recipe->parameters = cpl_parameterlist_new() ;
140 p = cpl_parameter_new_range(
"sinfoni.sinfo_utl_skymap.xsize",
141 CPL_TYPE_INT,
"X box size",
"sinfoni.sinfo_utl_skymap", 1,1,2047) ;
142 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"xsize") ;
143 cpl_parameterlist_append(recipe->parameters, p) ;
146 p = cpl_parameter_new_range(
"sinfoni.sinfo_utl_skymap.ysize",
147 CPL_TYPE_INT,
"Y box size",
"sinfoni.sinfo_utl_skymap", 30,1,2047) ;
148 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"ysize") ;
149 cpl_parameterlist_append(recipe->parameters, p) ;
154 p = cpl_parameter_new_value(
"sinfoni.sinfo_utl_skymap.threshold",
155 CPL_TYPE_DOUBLE,
"Threshold",
"sinfoni.sinfo_utl_skymap", 30.) ;
156 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"thresh") ;
157 cpl_parameterlist_append(recipe->parameters, p) ;
170 static int sinfo_utl_skymap_exec(cpl_plugin * plugin)
172 cpl_recipe * recipe ;
174 cpl_errorstate initial_errorstate = cpl_errorstate_get();
177 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
178 recipe = (cpl_recipe *)plugin ;
182 check_nomsg(code = sinfo_utl_skymap(recipe->parameters, recipe->frames)) ;
183 if (!cpl_errorstate_is_equal(initial_errorstate)) {
186 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
199 static int sinfo_utl_skymap_destroy(cpl_plugin * plugin)
201 cpl_recipe * recipe ;
204 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
205 recipe = (cpl_recipe *)plugin ;
208 cpl_parameterlist_delete(recipe->parameters) ;
212 static int sinfo_utl_skymap(
213 cpl_parameterlist * parlist,
214 cpl_frameset * framelist)
216 cpl_parameter * param =NULL;
217 const char * name_i=NULL;
221 cpl_frame * sky_frm=NULL;
223 const char * name_o=NULL ;
224 cpl_propertylist * plist =NULL;
225 cpl_frame * product_frame=NULL;
226 cpl_frameset * sky_set=NULL;
227 cpl_image * sky_ima=NULL;
228 cpl_image * sky_map=NULL;
232 double sinfo_median=0;
233 float* sky_ima_pix=NULL;
234 float* sky_map_pix=NULL;
242 sinfo_msg(
"Welcome to SINFONI Pipeline release %d.%d.%d",
243 SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
245 param = cpl_parameterlist_find(parlist,
246 "sinfoni.sinfo_utl_skymap.out_filename");
247 name_o =
"out_skymap.fits";
250 param = cpl_parameterlist_find(parlist,
"sinfoni.sinfo_utl_skymap.xsize");
251 xsize = cpl_parameter_get_int(param) ;
254 param = cpl_parameterlist_find(parlist,
"sinfoni.sinfo_utl_skymap.ysize");
255 ysize = cpl_parameter_get_int(param) ;
257 param = cpl_parameterlist_find(parlist,
258 "sinfoni.sinfo_utl_skymap.threshold");
259 threshold = cpl_parameter_get_double(param) ;
262 if (sinfo_dfs_set_groups(framelist)) {
268 n=cpl_frameset_get_size(framelist);
273 sky_set=cpl_frameset_new();
274 sinfo_extract_frames_type(framelist,sky_set,RAW_SKY);
276 n=cpl_frameset_get_size(framelist);
279 sinfo_free_frameset(&sky_set);
284 check_nomsg(sky_frm = cpl_frameset_get_frame(sky_set,0));
286 if ((plist=cpl_propertylist_load(cpl_frame_get_filename(sky_frm),
293 name_i=cpl_frame_get_filename(sky_frm);
294 sky_ima = cpl_image_load(name_i,CPL_TYPE_FLOAT,0,0);
295 sky_map=cpl_image_duplicate(sky_ima);
296 sky_ima_pix=cpl_image_get_data(sky_ima);
297 sky_map_pix=cpl_image_get_data(sky_map);
298 nx = cpl_image_get_size_x(sky_ima);
299 ny = cpl_image_get_size_y(sky_ima);
300 if (nx != SIZEX || ny != SIZEY) {
301 sinfo_msg_error(
"nx=%d ny=%d, expected nx=%d ny=%d",nx,ny,SIZEX,SIZEY);
307 for(j=ysize+1;j<ny-ysize;j++) {
309 sinfo_median=cpl_image_get_median_window(sky_ima,i,j-ysize,i,j+xsize);
310 if(cpl_error_get_code() != CPL_ERROR_NONE) {
312 sinfo_free_image(&sky_ima);
313 sinfo_free_image(&sky_map);
314 sinfo_free_propertylist(&plist);
315 sinfo_free_frameset(&sky_set);
318 if(sky_ima_pix[i+j*nx] > sinfo_median+threshold) {
319 sky_map_pix[i+j*nx]=0.;
321 sky_map_pix[i+j*nx]=1.;
331 for(j=0;j<ysize+1;j++) {
333 sky_map_pix[i+j*nx]=0.;
337 for(j=ny-ysize+1;j<ny;j++) {
339 sky_map_pix[i+j*nx]=0.;
354 name_o =
"sky_map.fits" ;
357 product_frame = cpl_frame_new();
358 cpl_frame_set_filename(product_frame, name_o) ;
359 cpl_frame_set_tag(product_frame, PRO_SKY_DUMMY) ;
360 cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE) ;
361 cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT) ;
362 cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL) ;
364 if (cpl_error_get_code()) {
366 sinfo_free_propertylist(&plist) ;
367 sinfo_free_frame(&product_frame) ;
372 if (cpl_dfs_setup_product_header(plist, product_frame, framelist, parlist,
374 "SINFONI", KEY_VALUE_HPRO_DID,NULL)
377 sinfo_free_propertylist(&plist) ;
378 sinfo_free_frame(&product_frame) ;
379 sinfo_free_image(&sky_ima);
380 sinfo_free_image(&sky_map);
381 sinfo_free_frameset(&sky_set);
387 if (cpl_image_save(sky_map, name_o, CPL_BPP_IEEE_FLOAT, plist,
388 CPL_IO_DEFAULT) != CPL_ERROR_NONE) {
390 sinfo_free_propertylist(&plist) ;
391 sinfo_free_frame(&product_frame) ;
392 sinfo_free_image(&sky_map) ;
395 sinfo_free_propertylist(&plist) ;
396 sinfo_free_image(&sky_map) ;
397 sinfo_free_image(&sky_ima) ;
400 cpl_frameset_insert(framelist, product_frame) ;
401 sinfo_free_frameset(&sky_set);
406 sinfo_free_image(&sky_ima);
407 sinfo_free_image(&sky_map);
408 sinfo_free_propertylist(&plist);
409 sinfo_free_frameset(&sky_set);
411 if( cpl_error_get_code()!=CPL_ERROR_NONE) {