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
00167 check(xsh_parameters_remove_crh_single_create(RECIPE_ID,recipe->parameters,
00168 crh_single )) ;
00169
00170
00171
00172
00173 cleanup:
00174
00175
00176 return 0;
00177 }
00178
00179
00185
00186 static int xsh_util_crh_single_exec(cpl_plugin * plugin)
00187 {
00188 cpl_recipe * recipe ;
00189 int code=0;
00190 cpl_errorstate initial_errorstate = cpl_errorstate_get();
00191
00192
00193 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00194 recipe = (cpl_recipe *)plugin ;
00195 else return -1 ;
00196 cpl_error_reset();
00197
00198 code = xsh_util_crh_single(recipe->parameters, recipe->frames) ;
00199
00200
00201 if (!cpl_errorstate_is_equal(initial_errorstate)) {
00202
00203
00204 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
00205 }
00206
00207 return code ;
00208 }
00209
00210
00216
00217 static int xsh_util_crh_single_destroy(cpl_plugin * plugin)
00218 {
00219 cpl_recipe * recipe ;
00220
00221
00222 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00223 recipe = (cpl_recipe *)plugin ;
00224 else return -1 ;
00225
00226 cpl_parameterlist_delete(recipe->parameters) ;
00227 return 0 ;
00228 }
00229
00230
00231
00232
00239
00240 static int
00241 xsh_util_crh_single( cpl_parameterlist * parameters,
00242 cpl_frameset * frameset)
00243 {
00244 int i=0;
00245 xsh_instrument* instrument=NULL;
00246 cpl_frameset* raws=NULL;
00247 cpl_frameset* calib=NULL;
00248 const char* recipe_tags[1] = {XSH_IMA};
00249 int recipe_tags_size = 1;
00250 xsh_remove_crh_single_param * crh_single_par = NULL ;
00251 int nraw=0;
00252 const char* name=NULL;
00253 char nocrh_tag[256];
00254 char nocrh_name[256];
00255
00256 cpl_frame* frame=NULL;
00257 cpl_frame* res_frame=NULL;
00258 const char* pro_catg=NULL;
00259 xsh_msg("Welcome to XSHOOTER Pipeline release %d.%d.%d",
00260 XSH_MAJOR_VERSION,XSH_MINOR_VERSION,XSH_MICRO_VERSION);
00261 check( crh_single_par = xsh_parameters_remove_crh_single_get(RECIPE_ID,
00262 parameters));
00263
00264
00265
00266
00267 check( xsh_begin( frameset, parameters, &instrument, &raws, &calib,
00268 recipe_tags, recipe_tags_size,
00269 RECIPE_ID, XSH_BINARY_VERSION,
00270 xsh_util_crh_single_description_short ) ) ;
00271
00272 check(nraw=cpl_frameset_get_size(raws));
00273
00274 if(nraw<1) {
00275 xsh_msg_error("Please, provide at least opne input frame. Exit");
00276 goto cleanup;
00277 }
00278
00279 for(i=0;i<nraw;i++) {
00280 frame=cpl_frameset_get_frame(raws,i);
00281 name=cpl_frame_get_filename(frame);
00282 sprintf(nocrh_tag,"NOCRH_%s_",
00283 xsh_instrument_arm_tostring(instrument));
00284 sprintf(nocrh_name,"%s%s",nocrh_tag,".fits");
00285
00286 check(res_frame=xsh_remove_crh_single(frame,NULL,instrument,crh_single_par,
00287 nocrh_tag ));
00288 xsh_free_frame(&frame);
00289 check(pro_catg=XSH_GET_TAG_FROM_ARM(XSH_IMA,instrument));
00290 check(frame=xsh_frame_product(nocrh_name,pro_catg,
00291 CPL_FRAME_TYPE_IMAGE,
00292 CPL_FRAME_GROUP_PRODUCT,
00293 CPL_FRAME_LEVEL_FINAL));
00294
00295 check(xsh_add_product_image(frame, frameset,parameters,
00296 RECIPE_ID, instrument, pro_catg ));
00297 }
00298
00299
00300 cleanup:
00301
00302 if (cpl_error_get_code()) {
00303 xsh_free_frame(&frame);
00304 return -1 ;
00305 } else {
00306 return 0 ;
00307 }
00308
00309 }