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
00037
00038 #include <cpl.h>
00039
00040
00041 #include <irplib_utils.h>
00042
00043 #include <sinfo_tpl_utils.h>
00044 #include <sinfo_pfits.h>
00045 #include <sinfo_tpl_dfs.h>
00046 #include <sinfo_key_names.h>
00047 #include <sinfo_pro_types.h>
00048 #include <sinfo_functions.h>
00049 #include <sinfo_image_ops.h>
00050 #include <sinfo_msg.h>
00051 #include <sinfo_error.h>
00052 #include <sinfo_utils_wrappers.h>
00053
00054
00055
00056
00057
00058 static int sinfo_utl_ima_line_corr_create(cpl_plugin *) ;
00059 static int sinfo_utl_ima_line_corr_exec(cpl_plugin *) ;
00060 static int sinfo_utl_ima_line_corr_destroy(cpl_plugin *) ;
00061 static int sinfo_utl_ima_line_corr(cpl_parameterlist *, cpl_frameset *) ;
00062
00063
00064
00065
00066
00067 static char sinfo_utl_ima_line_corr_description[] =
00068 "This recipe performs image computation.\n"
00069 "The input files are images\n"
00070 "their associated tags should be IMA.\n"
00071 "The output are the images cleaned by the defect introduced by SINFONI sw\n"
00072 "Information on relevant parameters can be found with\n"
00073 "esorex --params sinfo_utl_ima_line_corr\n"
00074 "esorex --help sinfo_utl_ima_line_corr\n"
00075 "\n";
00076
00077
00078
00079
00080
00084
00085
00087
00095
00096 int cpl_plugin_get_info(cpl_pluginlist * list)
00097 {
00098 cpl_recipe * recipe = cpl_calloc(1, sizeof *recipe ) ;
00099 cpl_plugin * plugin = &recipe->interface ;
00100
00101 cpl_plugin_init(plugin,
00102 CPL_PLUGIN_API,
00103 SINFONI_BINARY_VERSION,
00104 CPL_PLUGIN_TYPE_RECIPE,
00105 "sinfo_utl_ima_line_corr",
00106 "Computes result of ima1 op ima2",
00107 sinfo_utl_ima_line_corr_description,
00108 "Andrea Modigliani",
00109 "Andrea.Modigliani@eso.org",
00110 sinfo_get_license(),
00111 sinfo_utl_ima_line_corr_create,
00112 sinfo_utl_ima_line_corr_exec,
00113 sinfo_utl_ima_line_corr_destroy) ;
00114
00115 cpl_pluginlist_append(list, plugin) ;
00116
00117 return 0;
00118 }
00119
00120
00129
00130 static int sinfo_utl_ima_line_corr_create(cpl_plugin * plugin)
00131 {
00132 cpl_recipe * recipe ;
00133 cpl_parameter * p ;
00134
00135
00136 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00137 recipe = (cpl_recipe *)plugin ;
00138 else return -1 ;
00139 cpl_error_reset();
00140 irplib_reset();
00141
00142
00143 recipe->parameters = cpl_parameterlist_new() ;
00144
00145
00146 p = cpl_parameter_new_value("sinfoni.sinfo_utl_ima_line_corr.kappa",
00147 CPL_TYPE_INT,
00148 "Kappa sigma value",
00149 "sinfoni.sinfo_utl_ima_line_corr",18);
00150 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "kappa") ;
00151 cpl_parameterlist_append(recipe->parameters, p) ;
00152
00153 p = cpl_parameter_new_value("sinfoni.sinfo_utl_ima_line_corr.filt_rad",
00154 CPL_TYPE_INT,
00155 "Filtering radii applied during median filter."
00156 " Should be small",
00157 "sinfoni.sinfo_utl_ima_line_corr",3) ;;
00158 cpl_parameter_set_alias(p, CPL_PARAMETER_MODE_CLI, "filt_rad") ;
00159 cpl_parameterlist_append(recipe->parameters, p) ;
00160
00161
00162 return 0;
00163 }
00164
00165
00171
00172 static int sinfo_utl_ima_line_corr_exec(cpl_plugin * plugin)
00173 {
00174 cpl_recipe * recipe ;
00175 int code=0;
00176 cpl_errorstate initial_errorstate = cpl_errorstate_get();
00177
00178
00179 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00180 recipe = (cpl_recipe *)plugin ;
00181 else return -1 ;
00182 cpl_error_reset();
00183 irplib_reset();
00184 code = sinfo_utl_ima_line_corr(recipe->parameters, recipe->frames) ;
00185
00186
00187 if (!cpl_errorstate_is_equal(initial_errorstate)) {
00188
00189
00190 cpl_errorstate_dump(initial_errorstate, CPL_FALSE, NULL);
00191 }
00192
00193 return code ;
00194 }
00195
00196
00202
00203 static int sinfo_utl_ima_line_corr_destroy(cpl_plugin * plugin)
00204 {
00205 cpl_recipe * recipe ;
00206
00207
00208 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00209 recipe = (cpl_recipe *)plugin ;
00210 else return -1 ;
00211
00212 cpl_parameterlist_delete(recipe->parameters) ;
00213 return 0 ;
00214 }
00215
00216
00223
00224 static int
00225 sinfo_utl_ima_line_corr( cpl_parameterlist * parlist,
00226 cpl_frameset * framelist)
00227 {
00228 cpl_parameter * p= NULL ;
00229 int kappa=18;
00230 int filt_rad=3;
00231 int width=4;
00232
00233 cpl_image * ima=NULL ;
00234 cpl_image * ima_out=NULL ;
00235 cpl_propertylist * plist=NULL ;
00236 cpl_frame * product_frame=NULL;
00237 cpl_frameset * raw_set=NULL;
00238 int i=0;
00239 cpl_frame * frm=NULL;
00240 char name_o[MAX_NAME_SIZE];
00241 const char* name=NULL;
00242
00243 int n=0;
00244 sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
00245 SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
00246
00247
00248
00249 check_nomsg(p=cpl_parameterlist_find(parlist,
00250 "sinfoni.sinfo_utl_ima_line_corr.kappa"));
00251 check_nomsg(kappa=cpl_parameter_get_int(p));
00252
00253
00254 check_nomsg(p=cpl_parameterlist_find(parlist,
00255 "sinfoni.sinfo_utl_ima_line_corr.filt_rad"));
00256 check_nomsg(filt_rad = cpl_parameter_get_int(p)) ;
00257
00258
00259 check(sinfo_dfs_set_groups(framelist),
00260 "Cannot identify RAW and CALIB frames") ;
00261
00262
00263 n=cpl_frameset_get_size(framelist);
00264 if(n<1) {
00265 sinfo_msg_error("Empty input frame list!");
00266 goto cleanup ;
00267 }
00268 raw_set=cpl_frameset_new();
00269 ck0_nomsg(sinfo_extract_raw_frames(framelist, &raw_set));
00270 n=cpl_frameset_get_size(raw_set);
00271 if(n<1) {
00272 sinfo_msg_error("No raw data found in frame list!");
00273 goto cleanup ;
00274 }
00275
00276
00277 for(i=0;i<n;i++) {
00278 check_nomsg(frm=cpl_frameset_get_frame(raw_set,0));
00279 check_nomsg(name=cpl_frame_get_filename(frm));
00280 check_nomsg(ima=cpl_image_load(name,CPL_TYPE_FLOAT,0,0));
00281
00282 check_nomsg(sinfo_image_line_corr(width,filt_rad,kappa,ima,&ima_out));
00283
00284 sprintf(name_o,"%s%d%s","ima_cor",i,".fits") ;
00285
00286
00287 check_nomsg(product_frame = cpl_frame_new());
00288 check_nomsg(cpl_frame_set_filename(product_frame, name_o));
00289 check_nomsg(cpl_frame_set_tag(product_frame, "IMA_COR"));
00290 check_nomsg(cpl_frame_set_type(product_frame, CPL_FRAME_TYPE_IMAGE));
00291 check_nomsg(cpl_frame_set_group(product_frame, CPL_FRAME_GROUP_PRODUCT));
00292 check(cpl_frame_set_level(product_frame, CPL_FRAME_LEVEL_FINAL),
00293 "Error while initialising the product frame") ;
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308 check(cpl_image_save(ima_out,
00309 name_o,
00310 CPL_BPP_IEEE_FLOAT,
00311 plist,
00312 CPL_IO_DEFAULT),
00313 "Could not save product");
00314 sinfo_free_propertylist(&plist) ;
00315 sinfo_free_image(&ima_out);
00316 sinfo_free_image(&ima);
00317
00318
00319 check_nomsg(cpl_frameset_insert(framelist, product_frame)) ;
00320
00321 }
00322
00323 cleanup:
00324 sinfo_free_image(&ima);
00325 sinfo_free_image(&ima_out);
00326
00327
00328
00329
00330
00331
00332
00333
00334 if (cpl_error_get_code()) {
00335 return -1 ;
00336 } else {
00337 return 0 ;
00338 }
00339
00340 }