37 #include <irplib_utils.h>
38 #include <sinfo_skycor.h>
39 #include <sinfo_skycor_config.h>
40 #include <sinfo_tpl_utils.h>
41 #include <sinfo_tpl_dfs.h>
42 #include <sinfo_pro_types.h>
43 #include <sinfo_utils_wrappers.h>
44 #include <sinfo_error.h>
45 #include <sinfo_msg.h>
46 #include <sinfo_pro_save.h>
47 #include <sinfo_globals.h>
55 static int sinfo_utl_skycor_create(cpl_plugin *) ;
56 static int sinfo_utl_skycor_exec(cpl_plugin *) ;
57 static int sinfo_utl_skycor_destroy(cpl_plugin *) ;
58 static int sinfo_utl_skycor(cpl_parameterlist * config, cpl_frameset* set);
63 static char sinfo_utl_skycor_description[] =
64 "This recipe perform a correction of possible sky line residuals in the \n"
65 "object cube after standard data reduction.\n"
66 "Input frames are cubes with target and sky observations.\n"
67 "Their tags can be respectively OBS_OBJ (or OBS_PSF or OBS_STD) and OBS_SKY.\n"
68 "The output is a cube with same tag as the corresponding input target frame.\n"
93 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe ) ;
94 cpl_plugin * plugin = &recipe->interface ;
96 cpl_plugin_init(plugin,
98 SINFONI_BINARY_VERSION,
99 CPL_PLUGIN_TYPE_RECIPE,
101 "Sky lines residuals correction",
102 sinfo_utl_skycor_description,
104 "Andrea.Modigliani@eso.org",
106 sinfo_utl_skycor_create,
107 sinfo_utl_skycor_exec,
108 sinfo_utl_skycor_destroy) ;
110 cpl_pluginlist_append(list, plugin) ;
124 static int sinfo_utl_skycor_create(cpl_plugin * plugin)
126 cpl_recipe * recipe ;
129 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
130 recipe = (cpl_recipe *)plugin ;
136 recipe->parameters = cpl_parameterlist_new() ;
137 sinfo_skycor_config_add(recipe->parameters);
150 static int sinfo_utl_skycor_exec(cpl_plugin * plugin)
152 cpl_recipe * recipe ;
155 cpl_errorstate initial_errorstate = cpl_errorstate_get();
157 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
158 recipe = (cpl_recipe *)plugin ;
162 code = sinfo_utl_skycor(recipe->parameters, recipe->frames) ;
164 if (!cpl_errorstate_is_equal(initial_errorstate)) {
167 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
179 static int sinfo_utl_skycor_destroy(cpl_plugin * plugin)
181 cpl_recipe * recipe ;
184 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
185 recipe = (cpl_recipe *)plugin ;
188 cpl_parameterlist_delete(recipe->parameters) ;
201 sinfo_utl_skycor(cpl_parameterlist * config, cpl_frameset* set)
204 cpl_frame* obj_frm=NULL;
205 cpl_frame* sky_frm=NULL;
206 cpl_imagelist* obj_cor=NULL;
207 const char * name_o=NULL ;
208 cpl_frame* product_frame=NULL;
210 cpl_propertylist* plist=NULL;
211 sinfo_skycor_qc* sqc=NULL;
212 char obj_tag[MAX_NAME_SIZE];
213 cpl_table* int_obj=NULL;
215 sinfo_msg(
"Welcome to SINFONI Pipeline release %d.%d.%d",
216 SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
219 ck0(sinfo_dfs_set_groups(set),
"Cannot indentify RAW and CALIB frames") ;
223 obj_frm=cpl_frameset_find(set,PRO_OBS_OBJ);
224 if(obj_frm == NULL) {
225 obj_frm=cpl_frameset_find(set,PRO_OBS_PSF);
226 strcpy(obj_tag,PRO_OBS_PSF);
228 strcpy(obj_tag,PRO_OBS_OBJ);
232 if(obj_frm == NULL) {
233 obj_frm=cpl_frameset_find(set,PRO_OBS_STD);
234 strcpy(obj_tag,PRO_OBS_STD);
236 cknull(obj_frm,
"No %s or %s or %s frame found",
237 PRO_OBS_OBJ,PRO_OBS_PSF,PRO_OBS_STD);
238 check(sky_frm=cpl_frameset_find(set,PRO_OBS_SKY),
239 "No %s found",PRO_OBS_SKY);
240 sqc=sinfo_skycor_qc_new();
242 check(plist=cpl_propertylist_load(cpl_frame_get_filename(obj_frm),0),
243 "Cannot read the FITS header") ;
245 ck0(sinfo_skycor(config, obj_frm,sky_frm,sqc,&obj_cor,&int_obj),
246 "determining sky residuals corrected object");
247 sinfo_msg(
"Write out adjusted cube");
250 cpl_frameset_erase(set,obj_tag);
251 cpl_frameset_erase(set,PRO_OBS_SKY);
252 name_o =
"out_obj_cor.fits" ;
256 check_nomsg(product_frame = cpl_frame_new());
257 check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
258 check_nomsg(cpl_frame_set_tag(product_frame, obj_tag)) ;
259 check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
260 check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
261 check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
262 "Error while initialising the product frame") ;
281 check(cpl_imagelist_save(obj_cor,
286 "Could not save product");
288 check_nomsg(cpl_frameset_insert(set,cpl_frame_duplicate(product_frame))) ;
289 sinfo_free_frame(&product_frame);
299 sinfo_free_imagelist(&obj_cor);
303 name_o =
"out_obj_int.fits" ;
306 check_nomsg(product_frame = cpl_frame_new());
307 check_nomsg(cpl_frame_set_filename(product_frame, name_o)) ;
308 check_nomsg(cpl_frame_set_tag(product_frame, PRO_SPECTRA_QC)) ;
309 check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_TABLE)) ;
310 check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
311 check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
312 "Error while initialising the product frame") ;
313 check_nomsg(cpl_propertylist_update_string(plist,
"ESO PRO CATG",
334 check(cpl_table_save(int_obj, plist, NULL, name_o,CPL_IO_DEFAULT),
335 "Could not save product");
336 sinfo_free_propertylist(&plist) ;
339 check_nomsg(cpl_frameset_insert(set, cpl_frame_duplicate(product_frame))) ;
340 sinfo_free_frame(&product_frame);
346 sinfo_free_imagelist(&obj_cor);
347 sinfo_free_table(&int_obj);
348 sinfo_skycor_qc_delete(&sqc);
349 sinfo_free_propertylist(&plist);
350 sinfo_free_frame(&product_frame);
351 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.