63#define XSH_UTL_IMA_ARITH_RECIPE_ID "xsh_util_ima_arith"
64#define XSH_UTL_IMA_ARITH_RECIPE_AUTHOR "A.Modigliani"
65#define XSH_UTL_IMA_ARITH_RECIPE_CONTACT "Andrea.Modigliani@eso.org"
66#define PRO_IMA "PRO_IMA_UVB"
67#define KEY_VALUE_HPRO_DID "PRO-1.15"
84"This recipe performs image computation.\n"
85"The input files are 2 images\n"
86"their associated tags should be IMA.\n"
87"The output is an image resulting from the IMA op IMA where op indicates\n"
88"the operation to be performed specified by the parameter \n"
89"xsh.xsh_util_ima_arith.op having alias 'op'\n"
90"Information on relevant parameters can be found with\n"
91"esorex --params xsh_util_ima_arith\n"
92"esorex --help xsh_util_ima_arith\n"
117 cpl_recipe * recipe = cpl_calloc(1,
sizeof *recipe ) ;
118 cpl_plugin * plugin = &recipe->interface ;
120 cpl_plugin_init(plugin,
123 CPL_PLUGIN_TYPE_RECIPE,
134 cpl_pluginlist_append(list, plugin) ;
151 cpl_recipe * recipe ;
158 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
159 recipe = (cpl_recipe *)plugin ;
165 recipe->parameters = cpl_parameterlist_new() ;
170 recipe->parameters ) ) ;
174 p = cpl_parameter_new_value(
"xsh.xsh_util_ima_arith.op",
176 "A possible operation",
177 "xsh.xsh_util_ima_arith",
"+");
178 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"op") ;
179 cpl_parameterlist_append(recipe->parameters, p) ;
182 p = cpl_parameter_new_value(
"xsh.xsh_util_ima_arith.value",
183 CPL_TYPE_DOUBLE,
"a value",
"xsh.xsh_util_ima_arith", 9999.) ;
184 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI,
"value") ;
185 cpl_parameterlist_append(recipe->parameters, p) ;
201 cpl_recipe * recipe ;
203 cpl_errorstate initial_errorstate = cpl_errorstate_get();
206 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
207 recipe = (cpl_recipe *)plugin ;
214 if (!cpl_errorstate_is_equal(initial_errorstate)) {
217 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
232 cpl_recipe * recipe ;
235 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
236 recipe = (cpl_recipe *)plugin ;
239 cpl_parameterlist_delete(recipe->parameters) ;
253 cpl_frameset * framelist)
256 int recipe_tags_size = 1;
257 cpl_parameter * param= NULL ;
258 const char * operation=NULL;
260 cpl_image * ima1=NULL ;
261 cpl_image * ima2=NULL ;
263 const char * name_o=NULL ;
264 cpl_propertylist * plist=NULL ;
265 cpl_image * image=NULL ;
266 cpl_frame * product_frame=NULL;
267 cpl_frameset * raw_set=NULL;
271 cpl_frameset* raws=NULL;
272 cpl_frameset* calib=NULL;
274 int pre_overscan_corr=0;
275 xsh_msg(
"Welcome to XSHOOTER Pipeline release %d.%d.%d",
276 XSH_MAJOR_VERSION,XSH_MINOR_VERSION,XSH_MICRO_VERSION);
280 check(param=cpl_parameterlist_find(parlist,
281 "xsh.xsh_util_ima_arith.op"));
282 check(operation=cpl_parameter_get_string(param));
285 check(param=cpl_parameterlist_find(parlist,
286 "xsh.xsh_util_ima_arith.value"));
287 check(value = cpl_parameter_get_double(param)) ;
295 recipe_tags, recipe_tags_size,
297 XSH_UTL_IMA_ARITH, XSH_BINARY_VERSION,
303 "Cannot identify RAW and CALIB frames") ;
306 n=cpl_frameset_get_size(framelist);
315 check(nraw=cpl_frameset_get_size(raw_set));
321 check(ima1=cpl_image_load(
"RAW_IMA_PRE_0.fits",CPL_TYPE_FLOAT,0,0));
323 check(ima2 = cpl_image_load(
"RAW_IMA_PRE_1.fits",CPL_TYPE_FLOAT,0,0));
325 }
else if (value == 9999.) {
330 xsh_msg(
"Perform image arithmetics on frame %s",
338 check_msg(plist=cpl_propertylist_load(
"RAW_IMA_PRE_0.fits",0),
339 "Cannot read the FITS header") ;
343 if (value == 9999.) {
345 if(ima1 != NULL && ima2 != NULL) {
346 xsh_msg(
"ima1 %s ima2",operation);
347 if (strcmp(operation,
"+") == 0 ) {
348 check_msg(image = cpl_image_add_create(ima1, ima2),
349 "Cannot generate the %s image",operation) ;
350 }
else if (strcmp(operation,
"-") == 0 ) {
351 check_msg(image = cpl_image_subtract_create(ima1, ima2),
352 "Cannot generate the %s image",operation) ;
353 }
else if (strcmp(operation,
"*") == 0 ) {
354 check_msg(image = cpl_image_multiply_create(ima1, ima2),
355 "Cannot generate the %s image",operation) ;
356 }
else if (strcmp(operation,
"/") == 0 ) {
357 check_msg(image = cpl_image_divide_create(ima1, ima2),
358 "Cannot generate the %s image",operation) ;
369 xsh_msg(
"ima1 %s %f",operation,value);
371 if(switch_ima2 == 1) {
375 if (strcmp(operation,
"+") == 0 ) {
376 check_msg(image = cpl_image_add_scalar_create(ima1, value),
377 "Cannot apply the %s operator",operation) ;
378 }
else if (strcmp(operation,
"-") == 0 ) {
379 check_msg(image = cpl_image_subtract_scalar_create(ima1, value),
380 "Cannot apply the %s operator",operation) ;
381 }
else if (strcmp(operation,
"*") == 0 ) {
382 check_msg(image = cpl_image_multiply_scalar_create(ima1, value),
383 "Cannot apply the %s operator",operation) ;
384 }
else if (strcmp(operation,
"/") == 0 ) {
385 check_msg(image = cpl_image_divide_scalar_create(ima1, value),
386 "Cannot apply the %s operator",operation) ;
399 name_o =
"ima_res.fits" ;
402 check(product_frame = cpl_frame_new());
403 check(cpl_frame_set_filename(product_frame, name_o)) ;
405 check(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE)) ;
406 check(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT)) ;
407 check_msg(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
408 "Error while initialising the product frame") ;
411 check(cpl_propertylist_erase_regexp(plist,
"^ESO PRO CATG",0));
412 check_msg(cpl_dfs_setup_product_header(plist,
416 "xsh_util_ima_arith",
419 "Problem in the product DFS-compliance") ;
426 "Could not save product");
428 check(plist=cpl_propertylist_new());
431 cpl_image_power(image,0.5);
437 "Could not save product");
439 check(plist=cpl_propertylist_new());
443 cpl_image_divide(image,image);
449 "Could not save product");
465 check(cpl_frameset_insert(framelist, product_frame)) ;
480 if (cpl_error_get_code()) {
static xsh_instrument * instrument
void xsh_pre_free(xsh_pre **pre)
Free a xsh_pre structure.
void xsh_prepare(cpl_frameset *frames, cpl_frame *bpmap, cpl_frame *mbias, const char *prefix, xsh_instrument *instr, const int pre_overscan_corr, const bool flag_neg_and_thresh_pix)
This function transform RAW frames dataset in PRE frames dataset attaching the default bad pixel map ...
#define check_msg(COMMAND,...)
#define xsh_msg_error(...)
Print an error message.
#define xsh_msg(...)
Print a message on info level.
void xsh_pfits_set_extname(cpl_propertylist *plist, const char *value)
Write the EXTNAME value.
int cpl_plugin_get_info(cpl_pluginlist *list)
Build the list of available plugins, for this module.
static int xsh_util_ima_arith(cpl_parameterlist *, cpl_frameset *)
Get the command line options and execute the data reduction.
static int xsh_util_ima_arith_create(cpl_plugin *)
Setup the recipe options
static int xsh_util_ima_arith_destroy(cpl_plugin *)
Destroy what has been created by the 'create' function.
static int xsh_util_ima_arith_exec(cpl_plugin *)
Execute the plugin instance given by the interface.
void xsh_free_image(cpl_image **i)
Deallocate an image and set the pointer to NULL.
void xsh_free_frameset(cpl_frameset **f)
Deallocate a frame set and set the pointer to NULL.
const char * xsh_get_license(void)
Get the pipeline copyright and license.
void xsh_init(void)
Reset library state.
cpl_error_code xsh_begin(cpl_frameset *frames, const cpl_parameterlist *parameters, xsh_instrument **instrument, cpl_frameset **raws, cpl_frameset **calib, const char *tag_list[], int tag_list_size, const char *recipe_id, unsigned int binary_version, const char *short_descr)
Recipe initialization.
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
xsh_instrument * xsh_dfs_set_groups(cpl_frameset *set)
Set the group as RAW or CALIB in a frameset and return the instrument detected.
cpl_frameset * xsh_frameset_extract(const cpl_frameset *frames, const char *tag)
Extract frames with given tag from frameset.
#define XSH_RAW_IMA_SLIT_UVB
cpl_error_code xsh_parameters_decode_bp(const char *recipe_id, cpl_parameterlist *plist, const int ival)
void xsh_parameters_generic(const char *recipe_id, cpl_parameterlist *plist)
#define XSH_UTL_IMA_ARITH_RECIPE_AUTHOR
static char xsh_util_ima_arith_description_short[]
#define XSH_UTL_IMA_ARITH_RECIPE_ID
#define XSH_UTL_IMA_ARITH_RECIPE_CONTACT
#define KEY_VALUE_HPRO_DID
static char xsh_util_ima_arith_description[]