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
00029
00030
00031
00032 #ifdef HAVE_CONFIG_H
00033 #include <config.h>
00034 #endif
00035
00036
00037
00038
00039
00040
00041 #include <strings.h>
00042 #include <string.h>
00043 #include <stdio.h>
00044
00045
00046 #include <cpl.h>
00047
00048
00049 #include <irplib_utils.h>
00050
00051
00052 #include <sinfo_bp_noise.h>
00053 #include <sinfo_new_dark.h>
00054 #include <sinfo_bp_config.h>
00055 #include <sinfo_bp_noise_config.h>
00056 #include <sinfo_dark_config.h>
00057 #include <sinfo_tpl_utils.h>
00058 #include <sinfo_tpl_dfs.h>
00059 #include <sinfo_pfits.h>
00060 #include <sinfo_functions.h>
00061 #include <sinfo_pfits.h>
00062 #include <sinfo_msg.h>
00063 #include <sinfo_error.h>
00064 #include <sinfo_utils_wrappers.h>
00065
00066
00067
00068
00069 static int sinfo_rec_mdark_create(cpl_plugin *plugin);
00070 static int sinfo_rec_mdark_exec(cpl_plugin *plugin);
00071 static int sinfo_rec_mdark_destroy(cpl_plugin *plugin);
00072 static int sinfo_rec_mdark(cpl_parameterlist *config, cpl_frameset *set);
00073 static int count_diff_ndit(cpl_frameset *set, cpl_vector** dit_val);
00074
00075
00076
00077
00078
00079 static char sinfo_rec_mdark_description[] =
00080 "This recipe perform raw sinfo_dark data reduction.\n"
00081 "The input files are raw sinfo_dark images\n"
00082 "Their associated tags should be DARK.\n"
00083 "The output are a master sinfo_dark (PRO.CATG=MASTER_DARK) and\n"
00084 "a hot pixels bad pixel map (PRO.CATG=BP_MAP_HP)\n"
00085 "Information on relevant parameters may be found with\n"
00086 "esorex --params sinfo_rec_mdark\n"
00087 "esorex --help sinfo_rec_mdark\n"
00088 "\n";
00089
00090
00091
00092
00093
00094
00098
00100
00109
00110 int
00111 cpl_plugin_get_info(cpl_pluginlist *list)
00112 {
00113
00114 cpl_recipe *recipe = cpl_calloc(1, sizeof *recipe);
00115 cpl_plugin *plugin = &recipe->interface;
00116
00117
00118 cpl_plugin_init(plugin,
00119 CPL_PLUGIN_API,
00120 SINFONI_BINARY_VERSION,
00121 CPL_PLUGIN_TYPE_RECIPE,
00122 "sinfo_rec_mdark",
00123 "Master sinfo_dark and hot pixels mask generation.",
00124 sinfo_rec_mdark_description,
00125 "Andrea Modigliani",
00126 "Andrea.Modigliani@eso.org",
00127 sinfo_get_license(),
00128 sinfo_rec_mdark_create,
00129 sinfo_rec_mdark_exec,
00130 sinfo_rec_mdark_destroy);
00131
00132 cpl_pluginlist_append(list, plugin);
00133
00134 return 0;
00135
00136 }
00137
00138
00146
00147 static int sinfo_rec_mdark_create(cpl_plugin *plugin)
00148 {
00149 cpl_recipe * recipe ;
00150
00151
00152 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00153 recipe = (cpl_recipe *)plugin ;
00154 else return -1 ;
00155 cpl_error_reset();
00156 irplib_reset();
00157
00158
00159 recipe->parameters = cpl_parameterlist_new() ;
00160
00161
00162
00163
00164
00165 sinfo_bp_noise_config_add(recipe->parameters);
00166 sinfo_dark_config_add(recipe->parameters);
00167 return 0;
00168
00169 }
00170
00176
00177 static int sinfo_rec_mdark_exec(cpl_plugin *plugin)
00178 {
00179 cpl_recipe * recipe ;
00180
00181
00182 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00183 recipe = (cpl_recipe *)plugin ;
00184 else return -1 ;
00185
00186 return sinfo_rec_mdark(recipe->parameters, recipe->frames);
00187
00188 }
00189
00195
00196 static int sinfo_rec_mdark_destroy(cpl_plugin *plugin)
00197 {
00198 cpl_recipe * recipe ;
00199
00200
00201 if (cpl_plugin_get_type(plugin) == CPL_PLUGIN_TYPE_RECIPE)
00202 recipe = (cpl_recipe *)plugin ;
00203 else return -1 ;
00204
00205 cpl_parameterlist_delete(recipe->parameters) ;
00206 return 0 ;
00207
00208 }
00209
00210
00211
00218
00219
00220
00221
00222
00223 static int
00224 sinfo_rec_mdark(cpl_parameterlist *config, cpl_frameset *set)
00225 {
00226
00227 cpl_parameter* p=NULL;
00228 int nset=0;
00229 cpl_frameset * wrk_set=NULL;
00230 cpl_frameset * cdb_set=NULL;
00231 cpl_frameset * tot_set=NULL;
00232
00233 cpl_frame* tmp_frm=NULL;
00234 cpl_frame* dup_frm=NULL;
00235 cpl_frame* cdb_frm=NULL;
00236
00237 char tmp_name[FILE_NAME_SZ];
00238 char out_bpmap_name[FILE_NAME_SZ];
00239 char out_dark_name[FILE_NAME_SZ];
00240 double tmp_dit=0;
00241 double ref_dit=0;
00242
00243 cpl_vector* dit_val=NULL;
00244 cpl_propertylist* plist=NULL;
00245
00246 int i=0;
00247 int j=0;
00248
00249
00250 int nraw=0;
00251 int ncdb=0;
00252 int nred=0;
00253 int ntot=0;
00254 sinfo_msg("Welcome to SINFONI Pipeline release %d.%d.%d",
00255 SINFONI_MAJOR_VERSION,SINFONI_MINOR_VERSION,SINFONI_MICRO_VERSION);
00256 ck0(sinfo_dfs_set_groups(set),"Cannot indentify RAW and CALIB frames");
00257 check_nomsg(cdb_set=cpl_frameset_new());
00258 check_nomsg(tot_set=cpl_frameset_new());
00259
00260
00261 sinfo_extract_mst_frames(set,cdb_set);
00262 sinfo_bp_config_add(config);
00263 nset=count_diff_ndit(set,&dit_val);
00264
00265 check_nomsg(nraw=cpl_frameset_get_size(set));
00266 check_nomsg(ncdb=cpl_frameset_get_size(cdb_set));
00267
00268 for(i=0;i<nset;i++) {
00269 check_nomsg(wrk_set=cpl_frameset_new());
00270 check_nomsg(ref_dit=cpl_vector_get(dit_val,i));
00271
00272
00273 for(j=0;j<nraw;j++) {
00274 check_nomsg(tmp_frm=cpl_frameset_get_frame(set,j));
00275 check_nomsg(strcpy(tmp_name,cpl_frame_get_filename(tmp_frm)));
00276 plist=cpl_propertylist_load(tmp_name,0);
00277 tmp_dit=sinfo_pfits_get_dit(plist);
00278 sinfo_free_propertylist(&plist);
00279
00280 if(tmp_dit==ref_dit) {
00281 check_nomsg(cpl_frameset_insert(wrk_set,cpl_frame_duplicate(tmp_frm)));
00282 }
00283 }
00284
00285 for(j=0;j<ncdb;j++) {
00286 check_nomsg(cdb_frm=cpl_frameset_get_frame(cdb_set,j));
00287 check_nomsg(cpl_frameset_insert(wrk_set,cpl_frame_duplicate(cdb_frm)));
00288 }
00289
00290
00291 ck0(sinfo_dfs_set_groups(wrk_set),"Cannot indentify RAW and CALIB frames");
00292
00293
00294 check_nomsg(p = cpl_parameterlist_find(config,"sinfoni.bp.method"));
00295 check_nomsg(cpl_parameter_set_string(p,"Noise"));
00296 ck0(sinfo_dfs_set_groups(set),"Cannot indentify RAW and CALIB frames") ;
00297
00298 if (nset>1) {
00299 sprintf(out_bpmap_name,"%s%d%s","out_bp_noise",i,".fits");
00300 } else {
00301 strcpy(out_bpmap_name,"out_bp_noise.fits");
00302 }
00303
00304 sinfo_msg("-----------------------------------------------");
00305 sinfo_msg("BP_MAP_HP BAD PIXEL MAP DETERMINATION ");
00306 sinfo_msg("-----------------------------------------------");
00307
00308 ck0(sinfo_new_bp_search_noise(cpl_func,config,wrk_set,out_bpmap_name),
00309 "computing BP_MAP_HP") ;
00310 sinfo_msg("BP_MAP_HP BAD PIXEL MAP DETERMINATION SUCCESS") ;
00311
00312 sinfo_msg("-----------------------------------------------");
00313 sinfo_msg("MASTER DARK DETERMINATION ");
00314 sinfo_msg("-----------------------------------------------");
00315
00316 if (nset>1) {
00317 sprintf(out_dark_name,"%s%d%s","out_dark",i,".fits");
00318 } else {
00319 strcpy(out_dark_name,"out_dark.fits");
00320 }
00321
00322 ck0(sinfo_new_dark(cpl_func,config, wrk_set, out_dark_name),
00323 "Computing master dark") ;
00324 sinfo_msg("MASTER DARK DETERMINATION SUCCESS") ;
00325
00326 nred=cpl_frameset_get_size(wrk_set);
00327 for(j=0;j<nred;j++) {
00328 check_nomsg(tmp_frm=cpl_frameset_get_frame(wrk_set,j));
00329 check_nomsg(cpl_frameset_insert(tot_set,cpl_frame_duplicate(tmp_frm)));
00330 }
00331 sinfo_free_frameset(&wrk_set);
00332
00333 }
00334
00335 check_nomsg(ntot=cpl_frameset_get_size(tot_set));
00336 for(j=0;j<ntot;j++) {
00337 check_nomsg(tmp_frm=cpl_frameset_get_frame(tot_set,j));
00338 check_nomsg(cpl_frameset_insert(set,cpl_frame_duplicate(tmp_frm)));
00339 }
00340
00341 sinfo_free_frameset(&tot_set);
00342 sinfoni_free_vector(&dit_val);
00343 sinfo_free_frameset(&cdb_set);
00344
00345 return 0 ;
00346
00347 cleanup:
00348
00349 sinfo_free_propertylist(&plist);
00350 sinfo_free_frame(&dup_frm);
00351 sinfo_free_frameset(&wrk_set);
00352 sinfo_free_frameset(&tot_set);
00353 sinfoni_free_vector(&dit_val);
00354 sinfo_free_frameset(&cdb_set);
00355 irplib_error_dump(CPL_MSG_ERROR,CPL_MSG_ERROR);
00356 return -1 ;
00357
00358
00359 }
00360
00361 static int count_diff_ndit(cpl_frameset *set, cpl_vector** dit_val)
00362 {
00363 cpl_frame* tmp_frm=NULL;
00364 cpl_frame* dup_frm=NULL;
00365
00366
00367 char tmp_name[FILE_NAME_SZ];
00368 int nraw=0;
00369 int i=0;
00370 int ndit=1;
00371 double ref_dit=0;
00372 cpl_vector* dit=NULL;
00373 cpl_propertylist* plist=NULL;
00374
00375 nraw=cpl_frameset_get_size(set);
00376 dit=cpl_vector_new(nraw);
00377 for(i=0;i<nraw;i++) {
00378 tmp_frm = cpl_frameset_get_frame(set, i);
00379 strcpy(tmp_name,cpl_frame_get_filename(tmp_frm));
00380 plist= cpl_propertylist_load(tmp_name,0);
00381 cpl_vector_set(dit,i,sinfo_pfits_get_dit(plist));
00382 sinfo_free_propertylist(&plist);
00383 }
00384
00385
00386 cpl_vector_sort(dit,1);
00387 ref_dit=cpl_vector_get(dit,0);
00388
00389
00390 for(i=1;i<nraw;i++) {
00391 if(ref_dit != cpl_vector_get(dit,i)) {
00392 ref_dit=cpl_vector_get(dit,i);
00393 ndit++;
00394 }
00395 }
00396 *dit_val=cpl_vector_new(ndit);
00397 ref_dit=cpl_vector_get(dit,0);
00398 cpl_vector_set(*dit_val,0,cpl_vector_get(dit,0));
00399 ndit=1;
00400
00401 for(i=1;i<nraw;i++) {
00402 if(ref_dit != cpl_vector_get(dit,i)) {
00403 cpl_vector_set(*dit_val,ndit,cpl_vector_get(dit,i));
00404 ref_dit=cpl_vector_get(dit,i);
00405 ndit++;
00406 }
00407 }
00408
00409 cpl_vector_delete(dit);
00410 cpl_frame_delete(dup_frm);
00411
00412 return ndit;
00413 }
00414