00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifdef HAVE_CONFIG_H
00029 #include <config.h>
00030 #endif
00031
00032
00033
00034
00035 #include <string.h>
00036 #include <math.h>
00037
00038
00039 #include <cpl.h>
00040
00041 #include <xsh_dfs.h>
00042 #include <xsh_data_pre.h>
00043 #include <xsh_parameters.h>
00044 #include <xsh_drl.h>
00045 #include <xsh_msg.h>
00046 #include <xsh_pfits.h>
00047 #include <xsh_pfits_qc.h>
00048 #include <xsh_error.h>
00049 #include <xsh_utils_image.h>
00050
00051
00052
00053
00054
00055
00056 #define RECIPE_ID "xsh_util_crh_single"
00057 #define RECIPE_AUTHOR "A.Modigliani"
00058 #define RECIPE_CONTACT "Andrea.Modigliani@eso.org"
00059 #define PRO_IMA "PRO_IMA_UVB"
00060 #define KEY_VALUE_HPRO_DID "PRO-1.15"
00061
00062
00063
00064
00065 static int xsh_util_crh_single_create(cpl_plugin *) ;
00066 static int xsh_util_crh_single_exec(cpl_plugin *) ;
00067 static int xsh_util_crh_single_destroy(cpl_plugin *) ;
00068 static int xsh_util_crh_single(cpl_parameterlist *, cpl_frameset *) ;
00069
00070
00071
00072
00073
00074 static char
00075 xsh_util_crh_single_description_short[] = "Remove cosmic ray hits from image";
00076 static char xsh_util_crh_single_description[] =
00077 "This recipe removes cosmic ray hits from an input image.\n"
00078 "The input files should be tagged as IMA_arm)\n"
00079 "Information on relevant parameters can be found with\n"
00080 "esorex --params xsh_util_crh_single\n"
00081 "esorex --help xsh_util_crh_single\n"
00082 "\n";
00083
00084
00085
00086
00087
00098
00099
00101
00109
00110 int cpl_plugin_get_info(cpl_pluginlist * list)
00111 {
00112 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
00113 cpl_plugin * plugin = &recipe->interface ;
00114
00115 cpl_plugin_init(plugin,
00116 CPL_PLUGIN_API,
00117 XSH_BINARY_VERSION,
00118 CPL_PLUGIN_TYPE_RECIPE,
00119 RECIPE_ID,
00120 xsh_util_crh_single_description_short,
00121 xsh_util_crh_single_description,
00122 RECIPE_AUTHOR,
00123 RECIPE_CONTACT,
00124 xsh_get_license(),
00125 xsh_util_crh_single_create,
00126 xsh_util_crh_single_exec,
00127 xsh_util_crh_single_destroy) ;
00128
00129 cpl_pluginlist_append(list, plugin) ;
00130
00131 return 0;
00132 }
00133
00134
00143
00144 static int xsh_util_crh_single_create(cpl_plugin * plugin)
00145 {
00146 cpl_recipe * recipe ;
00147 xsh_remove_crh_single_param crh_single = { 0.1, 5, 2.0, 4} ;
00148
00149
00150 xsh_init();
00151
00152
00153 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00154 recipe = (cpl_recipe *)plugin ;
00155 else return -1 ;
00156 cpl_error_reset();
00157
00158
00159
00160 recipe->parameters = cpl_parameterlist_new() ;
00161
00162
00163
00164 check( xsh_parameters_generic(RECIPE_ID,
00165 recipe->parameters ) ) ;
00166 xsh_parameters_decode_bp(RECIPE_ID,recipe->parameters,-1);
00167
00168 check(xsh_parameters_remove_crh_single_create(RECIPE_ID,recipe->parameters,
00169 crh_single )) ;
00170
00171
00172
00173
00174 cleanup:
00175
00176
00177 return 0;
00178 }
00179
00180
00186
00187 static int xsh_util_crh_single_exec(cpl_plugin * plugin)
00188 {
00189 cpl_recipe * recipe ;
00190 int code=0;
00191 cpl_errorstate initial_errorstate = cpl_errorstate_get();
00192
00193
00194 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00195 recipe = (cpl_recipe *)plugin ;
00196 else return -1 ;
00197 cpl_error_reset();
00198
00199 code = xsh_util_crh_single(recipe->parameters, recipe->frames) ;
00200
00201
00202 if (!cpl_errorstate_is_equal(initial_errorstate)) {
00203
00204
00205 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
00206 }
00207
00208 return code ;
00209 }
00210
00211
00217
00218 static int xsh_util_crh_single_destroy(cpl_plugin * plugin)
00219 {
00220 cpl_recipe * recipe ;
00221
00222
00223 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00224 recipe = (cpl_recipe *)plugin ;
00225 else return -1 ;
00226
00227 cpl_parameterlist_delete(recipe->parameters) ;
00228 return 0 ;
00229 }
00230
00231
00232
00233
00240
00241 static int
00242 xsh_util_crh_single( cpl_parameterlist * parameters,
00243 cpl_frameset * frameset)
00244 {
00245 int i=0;
00246 xsh_instrument* instrument=NULL;
00247 cpl_frameset* raws=NULL;
00248 cpl_frameset* calib=NULL;
00249 const char* recipe_tags[1] = {XSH_IMA};
00250 int recipe_tags_size = 1;
00251 xsh_remove_crh_single_param * crh_single_par = NULL ;
00252 int nraw=0;
00253 const char* name=NULL;
00254 char nocrh_tag[256];
00255 char nocrh_name[256];
00256
00257 cpl_frame* frame=NULL;
00258 cpl_frame* res_frame=NULL;
00259 const char* pro_catg=NULL;
00260 xsh_msg("Welcome to XSHOOTER Pipeline release %d.%d.%d",
00261 XSH_MAJOR_VERSION,XSH_MINOR_VERSION,XSH_MICRO_VERSION);
00262 check( crh_single_par = xsh_parameters_remove_crh_single_get(RECIPE_ID,
00263 parameters));
00264
00265
00266
00267
00268 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib,
00269 recipe_tags, recipe_tags_size,
00270 RECIPE_ID, XSH_BINARY_VERSION,
00271 xsh_util_crh_single_description_short ) ) ;
00272
00273 check(nraw=cpl_frameset_get_size(raws));
00274
00275 if(nraw<1) {
00276 xsh_msg_error("Please, provide at least opne input frame. Exit");
00277 goto cleanup;
00278 }
00279
00280 for(i=0;i<nraw;i++) {
00281 frame=cpl_frameset_get_frame(raws,i);
00282 name=cpl_frame_get_filename(frame);
00283 sprintf(nocrh_tag,"NOCRH_%s_",
00284 xsh_instrument_arm_tostring(instrument));
00285 sprintf(nocrh_name,"%s%s",nocrh_tag,".fits");
00286
00287 check(res_frame=xsh_remove_crh_single(frame,instrument,crh_single_par,
00288 nocrh_tag ));
00289 xsh_free_frame(&frame);
00290 check(pro_catg=XSH_GET_TAG_FROM_ARM(XSH_IMA,instrument));
00291 check(frame=xsh_frame_product(nocrh_name,pro_catg,
00292 CPL_FRAME_TYPE_IMAGE,
00293 CPL_FRAME_GROUP_PRODUCT,
00294 CPL_FRAME_LEVEL_FINAL));
00295
00296 check(xsh_add_product_image(frame, frameset,parameters,
00297 RECIPE_ID, instrument, pro_catg ));
00298 }
00299
00300
00301 cleanup:
00302
00303 if (cpl_error_get_code()) {
00304 xsh_free_frame(&frame);
00305 return -1 ;
00306 } else {
00307 return 0 ;
00308 }
00309
00310 }