39 #include "irplib_utils.h"
41 #include "hawki_utils.h"
42 #include "hawki_pfits.h"
43 #include "hawki_dfs.h"
44 #include "hawki_load.h"
53 int cpl_plugin_get_info(cpl_pluginlist * list);
55 static int hawki_step_stitch_create(cpl_plugin *) ;
56 static int hawki_step_stitch_exec(cpl_plugin *) ;
57 static int hawki_step_stitch_destroy(cpl_plugin *) ;
58 static int hawki_step_stitch(cpl_parameterlist *, cpl_frameset *) ;
59 static int hawki_step_stitch_save
62 cpl_parameterlist * parlist,
69 static char hawki_step_stitch_description[] =
70 "hawki_step_stitch -- Stitching utility\n"
71 "This recipe accepts 1 parameter:\n"
72 "First parameter: the HAWKI image to stitch "
73 " (PRO CATG = "HAWKI_CALPRO_COMBINED
")\n"
75 "This recipe produces 1 file:\n"
76 "First product: the stitch image.\n"
77 " (PRO CATG = "HAWKI_CALPRO_STITCHED
")\n" ;
93 int cpl_plugin_get_info(cpl_pluginlist * list)
95 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe ) ;
96 cpl_plugin * plugin = &recipe->interface ;
98 cpl_plugin_init(plugin,
100 HAWKI_BINARY_VERSION,
101 CPL_PLUGIN_TYPE_RECIPE,
104 hawki_step_stitch_description,
105 "Cesar Enrique Garcia",
108 hawki_step_stitch_create,
109 hawki_step_stitch_exec,
110 hawki_step_stitch_destroy) ;
112 cpl_pluginlist_append(list, plugin) ;
126 static int hawki_step_stitch_create(cpl_plugin * plugin)
128 cpl_recipe * recipe ;
131 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
132 recipe = (cpl_recipe *)plugin ;
136 recipe->parameters = cpl_parameterlist_new() ;
137 if (recipe->parameters == NULL)
151 static int hawki_step_stitch_exec(cpl_plugin * plugin)
153 cpl_recipe * recipe ;
156 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
157 recipe = (cpl_recipe *)plugin ;
163 return hawki_step_stitch(recipe->parameters, recipe->frames) ;
173 static int hawki_step_stitch_destroy(cpl_plugin * plugin)
175 cpl_recipe * recipe ;
178 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
179 recipe = (cpl_recipe *)plugin ;
182 cpl_parameterlist_delete(recipe->parameters) ;
194 static int hawki_step_stitch(
195 cpl_parameterlist * parlist,
196 cpl_frameset * frameset)
198 const char * comb_filename ;
199 cpl_frameset * combframes;
200 cpl_frame * combframe;
201 cpl_propertylist * plist ;
202 cpl_image * stitched ;
203 cpl_image * in[HAWKI_NB_DETECTORS] ;
204 double posx[HAWKI_NB_DETECTORS] ;
205 double posy[HAWKI_NB_DETECTORS] ;
207 cpl_errorstate error_prevstate;
214 cpl_msg_error(__func__,
"Cannot identify RAW and CALIB frames") ;
219 cpl_msg_info(__func__,
"Identifying the combined frame");
221 (frameset, HAWKI_CALPRO_COMBINED);
222 if (combframes == NULL)
224 cpl_msg_error(__func__,
"No combined images found (%s)",
225 HAWKI_CALPRO_COMBINED);
226 cpl_frameset_delete(combframes);
231 if (cpl_frameset_get_size(combframes) != 1) {
232 cpl_msg_error(__func__,
"Expects one single combined images") ;
233 cpl_frameset_delete(combframes);
238 cpl_msg_info(__func__,
"Loading combined frame");
239 for (i=0 ; i<HAWKI_NB_DETECTORS ; i++) {
241 CPL_TYPE_FLOAT)) == NULL) {
242 cpl_msg_error(__func__,
"Cannot load chip nb %d", i+1) ;
243 for (j=0 ; j<i ; i++) cpl_image_delete(in[j]) ;
244 cpl_frameset_delete(combframes);
250 combframe = cpl_frameset_get_first(combframes);
251 comb_filename = cpl_frame_get_filename(combframe);
254 error_prevstate = cpl_errorstate_get();
255 for (i=0 ; i<HAWKI_NB_DETECTORS ; i++) {
256 plist = cpl_propertylist_load_regexp(comb_filename, i+1,
"QC", 0) ;
259 cpl_propertylist_delete(plist) ;
260 if(!cpl_errorstate_is_equal(error_prevstate))
262 cpl_msg_error(__func__,
"Cannot get POS infos for chip %d", i+1) ;
268 cpl_msg_info(__func__,
"Computing the stiched image") ;
270 cpl_msg_error(__func__,
"Cannot stitch the images") ;
271 for (i=0 ; i<HAWKI_NB_DETECTORS ; i++) cpl_image_delete(in[i]) ;
274 for (i=0 ; i<HAWKI_NB_DETECTORS ; i++) cpl_image_delete(in[i]) ;
277 if (hawki_step_stitch_save(stitched, combframe, parlist, frameset) == -1)
278 cpl_msg_warning(__func__,
"Some data could not be saved. "
279 "Check permisions or disk space");
282 cpl_frameset_delete(combframes);
283 cpl_image_delete(stitched);
286 if (cpl_error_get_code())
288 cpl_msg_error(__func__,
289 "HAWK-I pipeline could not recover from previous errors");
304 static int hawki_step_stitch_save
306 cpl_frame * combined,
307 cpl_parameterlist * parlist,
310 cpl_propertylist * plist;
311 cpl_propertylist * wcslist;
312 const char * recipe_name =
"hawki_step_stitch" ;
314 cpl_errorstate error_prevstate = cpl_errorstate_get();
316 cpl_msg_indent_more();
319 plist = cpl_propertylist_new();
320 cpl_propertylist_append_string(plist, CPL_DFS_PRO_TYPE,
321 HAWKI_PROTYPE_STITCHED) ;
322 cpl_propertylist_append_string(plist, CPL_DFS_PRO_CATG,
323 HAWKI_CALPRO_STITCHED) ;
327 wcslist = cpl_propertylist_load_regexp(
328 cpl_frame_get_filename(combined), ext_chip_1, HAWKI_HEADER_WCS, 0);
329 cpl_propertylist_append(plist, wcslist);
332 if(cpl_dfs_save_image(
set,
342 PACKAGE
"/" PACKAGE_VERSION,
343 "hawki_step_stitch.fits") != CPL_ERROR_NONE)
344 cpl_msg_error(__func__,
"Could not save stitched image");
346 cpl_propertylist_delete(plist) ;
347 cpl_propertylist_delete(wcslist) ;
348 cpl_msg_indent_less();
349 if(!cpl_errorstate_is_equal(error_prevstate))
351 cpl_errorstate_set(CPL_ERROR_NONE);