40 #include "irplib_utils.h"
41 #include "irplib_slitpos.h"
43 #include "isaac_utils.h"
44 #include "isaac_pfits.h"
45 #include "isaac_dfs.h"
51 static int isaac_img_slitpos_create(cpl_plugin *);
52 static int isaac_img_slitpos_exec(cpl_plugin *);
53 static int isaac_img_slitpos_destroy(cpl_plugin *);
54 static int isaac_img_slitpos(cpl_parameterlist *, cpl_frameset *);
55 static int isaac_img_slitpos_save(cpl_table *,
int, cpl_parameterlist *,
72 } isaac_img_slitpos_config;
74 static char isaac_img_slitpos_description[] =
75 "isaac_img_slitpos -- ISAAC imaging slit position recipe.\n"
76 "The files listed in the Set Of Frames (sof-file) must be tagged:\n"
77 "raw-file.fits " ISAAC_IMG_SLITPOS_RAW
" or"
78 "raw-file.fits " ISAAC_IMG_SLITPOS_CAL_RAW
"\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 ISAAC_BINARY_VERSION,
101 CPL_PLUGIN_TYPE_RECIPE,
103 "Slit position recipe",
104 isaac_img_slitpos_description,
108 isaac_img_slitpos_create,
109 isaac_img_slitpos_exec,
110 isaac_img_slitpos_destroy);
112 cpl_pluginlist_append(list, plugin);
127 static int isaac_img_slitpos_create(cpl_plugin * plugin)
133 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
134 recipe = (cpl_recipe *)plugin;
135 else return CPL_ERROR_UNSPECIFIED;
138 recipe->parameters = cpl_parameterlist_new();
142 p = cpl_parameter_new_value(
"isaac.isaac_img_slitpos.slit_width",
143 CPL_TYPE_DOUBLE,
"Slit width",
"isaac.isaac_img_slitpos",
145 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"slit_w");
146 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
147 cpl_parameterlist_append(recipe->parameters, p);
149 p = cpl_parameter_new_value(
"isaac.isaac_img_slitpos.products",
150 CPL_TYPE_BOOL,
"flag to create the products",
151 "isaac.isaac_img_slitpos", TRUE);
152 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"prod");
153 cpl_parameter_disable(p, CPL_PARAMETER_MODE_ENV);
154 cpl_parameterlist_append(recipe->parameters, p);
167 static int isaac_img_slitpos_exec(cpl_plugin * plugin)
172 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
173 recipe = (cpl_recipe *)plugin;
174 else return CPL_ERROR_UNSPECIFIED;
176 return isaac_img_slitpos(recipe->parameters, recipe->frames);
186 static int isaac_img_slitpos_destroy(cpl_plugin * plugin)
191 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
192 recipe = (cpl_recipe *)plugin;
193 else return CPL_ERROR_UNSPECIFIED;
195 cpl_parameterlist_delete(recipe->parameters);
207 static int isaac_img_slitpos(
208 cpl_parameterlist * parlist,
209 cpl_frameset * framelist)
212 cpl_imagelist * imlist;
213 cpl_propertylist * plist;
214 cpl_frame * cur_frame;
215 cpl_frameset * slitframes;
217 cpl_table * out_table;
223 cpl_boolean did_reduce = CPL_FALSE;
227 isaac_img_slitpos_config.angle = -1.0;
228 isaac_img_slitpos_config.slit_flux = 0.0;
229 isaac_img_slitpos_config.xpos = -1.0;
230 isaac_img_slitpos_config.ypos = -1.0;
231 loc_pi = 3.1415926535897932384626433;
234 par = cpl_parameterlist_find(parlist,
"isaac.isaac_img_slitpos.slit_width");
235 isaac_img_slitpos_config.slit_width = cpl_parameter_get_double(par);
236 par = cpl_parameterlist_find(parlist,
"isaac.isaac_img_slitpos.products");
237 isaac_img_slitpos_config.products_flag = cpl_parameter_get_bool(par);
241 cpl_msg_error(cpl_func,
"Cannot identify RAW and CALIB frames");
242 return CPL_ERROR_UNSPECIFIED;
246 if (slitframes == NULL)
248 ISAAC_IMG_SLITPOS_CAL_RAW);
249 cpl_ensure_code(slitframes != NULL, CPL_ERROR_DATA_NOT_FOUND);
252 imlist = cpl_imagelist_load_frameset(slitframes, CPL_TYPE_FLOAT, 1, 0);
253 cpl_frameset_delete(slitframes);
257 cur_frame = cpl_frameset_get_position(framelist, 0);
258 if ((plist=cpl_propertylist_load(cpl_frame_get_filename(cur_frame),
260 cpl_msg_error(cpl_func,
"getting header from first frame");
261 cpl_imagelist_delete(imlist);
262 return CPL_ERROR_UNSPECIFIED;
265 cpl_msg_error(cpl_func,
"getting the MODE");
266 cpl_propertylist_delete(plist);
267 cpl_imagelist_delete(imlist);
268 return CPL_ERROR_UNSPECIFIED;
271 if (!strcmp(sval,
"SW_DARK") || !strcmp(sval,
"LW_DARK")) {
272 dark = cpl_image_duplicate(cpl_imagelist_get(imlist, 0));
273 cpl_imagelist_subtract_image(imlist, dark);
274 cpl_image_delete(dark);
277 cpl_propertylist_delete(plist);
280 for (i=0; i<cpl_imagelist_get_size(imlist); i++) {
281 cpl_errorstate prestate = cpl_errorstate_get();
282 if(i==0 && with_dark)
continue;
283 if (with_dark) slit_ind = i-1;
286 cpl_msg_info(cpl_func,
"Analyse slit nb %d", slit_ind+1);
287 cpl_msg_indent_more();
288 if ((out_table = irplib_slitpos_analysis(
289 cpl_imagelist_get(imlist, i),
290 isaac_img_slitpos_config.slit_width,
291 &(isaac_img_slitpos_config.slit_flux))) == NULL) {
292 cpl_msg_error(cpl_func,
"Could not analyse the slit in image "
293 "%d/%d", i+1, (
int)cpl_imagelist_get_size(imlist));
294 cpl_errorstate_dump(prestate, CPL_FALSE, NULL);
295 cpl_errorstate_set(prestate);
296 cpl_msg_indent_less();
301 slit_length = cpl_table_get_nrow(out_table);
303 isaac_img_slitpos_config.angle = (double)atan(
304 (
double)(cpl_table_get_int(out_table,
"SLIT_Y",slit_length-1, NULL) -
305 cpl_table_get_int(out_table,
"SLIT_Y", 0, NULL)) /
306 (cpl_table_get_double(out_table,
"SLIT_CENTER",slit_length-1, NULL) -
307 cpl_table_get_double(out_table,
"SLIT_CENTER", 0, NULL)));
308 isaac_img_slitpos_config.angle *= 180.0/loc_pi;
309 if (isaac_img_slitpos_config.angle >= 0.00 &&
310 isaac_img_slitpos_config.angle < 90.0)
311 isaac_img_slitpos_config.angle += 180.0;
313 isaac_img_slitpos_config.slit_length = slit_length;
315 isaac_img_slitpos_config.xpos =
316 (cpl_table_get_double(out_table,
"SLIT_CENTER",0,NULL) +
317 cpl_table_get_double(out_table,
"SLIT_CENTER",slit_length-1,NULL))
319 isaac_img_slitpos_config.ypos =
320 (double)(cpl_table_get_int(out_table,
"SLIT_Y",0,NULL) +
321 cpl_table_get_int(out_table,
"SLIT_Y",slit_length-1,NULL))
325 cpl_msg_info(cpl_func,
"Slit flux : %g",
326 isaac_img_slitpos_config.slit_flux);
327 cpl_msg_info(cpl_func,
"Slit angle : %g",
328 isaac_img_slitpos_config.angle);
329 cpl_msg_info(cpl_func,
"Slit length : %d",
330 isaac_img_slitpos_config.slit_length);
331 cpl_msg_info(cpl_func,
"Slit center : %g %g",
332 isaac_img_slitpos_config.xpos,
333 isaac_img_slitpos_config.ypos);
334 cpl_msg_indent_less();
337 if (isaac_img_slitpos_config.products_flag) {
338 cpl_msg_info(cpl_func,
"Save the product");
339 cpl_msg_indent_more();
340 if (isaac_img_slitpos_save(out_table, slit_ind+1, parlist,
342 cpl_msg_error(cpl_func,
"Cannot save the products");
343 cpl_imagelist_delete(imlist);
344 cpl_table_delete(out_table);
345 cpl_msg_indent_less();
346 return CPL_ERROR_UNSPECIFIED;
348 cpl_msg_indent_less();
350 cpl_table_delete(out_table);
351 if (!cpl_error_get_code()) did_reduce = CPL_TRUE;
355 cpl_imagelist_delete(imlist);
357 cpl_ensure_code(did_reduce, CPL_ERROR_ILLEGAL_INPUT);
359 return cpl_error_set_where(cpl_func);
372 static int isaac_img_slitpos_save(
373 cpl_table * out_table,
375 cpl_parameterlist * parlist,
378 cpl_propertylist * plist;
379 cpl_propertylist * paflist;
380 cpl_propertylist * qclist;
382 const cpl_frame * ref_frame = cpl_frameset_get_position_const(set, file_nb-1);
386 qclist = cpl_propertylist_new();
387 cpl_propertylist_append_double(qclist,
"ESO QC SLIT FLUX",
388 isaac_img_slitpos_config.slit_flux);
389 cpl_propertylist_append_double(qclist,
"ESO QC SLIT POSANG",
390 isaac_img_slitpos_config.angle);
391 cpl_propertylist_append_double(qclist,
"ESO QC SLIT XPOS",
392 isaac_img_slitpos_config.xpos);
393 cpl_propertylist_append_double(qclist,
"ESO QC SLIT YPOS",
394 isaac_img_slitpos_config.ypos);
396 cpl_propertylist_append_string(qclist, CPL_DFS_PRO_CATG,
397 ISAAC_IMG_SLITPOS_RES);
400 filename = cpl_sprintf(
"isaac_img_slitpos_%02d.fits", file_nb);
402 cpl_dfs_save_table(set, NULL, parlist, set, ref_frame, out_table,
403 NULL,
"isaac_img_slitpos", qclist, NULL,
404 PACKAGE
"/" PACKAGE_VERSION, filename);
408 if ((plist=cpl_propertylist_load(cpl_frame_get_filename(ref_frame),
410 cpl_msg_error(cpl_func,
"getting header from reference frame");
411 cpl_propertylist_delete(qclist);
412 return CPL_ERROR_UNSPECIFIED;
416 paflist = cpl_propertylist_new();
417 cpl_propertylist_copy_property_regexp(paflist, plist,
418 "^(ARCFILE|ORIGFILE|MJD-OBS|INSTRUME|ESO TPL ID|ESO TPL NEXP|"
419 "ESO TPL EXPNO|ESO DPR CATG|ESO DPR TECH|ESO DPR TYPE|DATE-OBS|"
420 "ESO INS OPTI1 ID)$",0);
421 cpl_propertylist_delete(plist);
424 cpl_propertylist_copy_property_regexp(paflist, qclist,
".", 0);
425 cpl_propertylist_delete(qclist);
428 cpl_propertylist_update_string(paflist, CPL_DFS_PRO_CATG,
429 ISAAC_IMG_SLITPOS_RES);
432 filename = cpl_sprintf(
"isaac_img_slitpos_%02d.paf", file_nb);
433 cpl_dfs_save_paf(
"ISAAC",
438 cpl_propertylist_delete(paflist);
int isaac_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset.
const char * isaac_pfits_get_mode(const cpl_propertylist *plist)
find out the instrument mode
cpl_frameset * isaac_extract_frameset(const cpl_frameset *self, const char *tag)
Extract the frames with the given tag from a frameset.
const char * isaac_get_license(void)
Get the pipeline copyright and license.