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 "sinfo_bp_noise.h"
00036 #include "sinfo_detnoise_ini_by_cpl.h"
00037 #include "sinfo_pro_save.h"
00038 #include "sinfo_pro_types.h"
00039 #include "sinfo_raw_types.h"
00040 #include "sinfo_functions.h"
00041 #include "sinfo_detlin.h"
00042 #include "sinfo_error.h"
00043 #include "sinfo_utils_wrappers.h"
00044
00050
00051
00052
00053
00054
00055
00056
00074 int
00075 sinfo_new_bp_search_noise (const char* plugin_id,
00076 cpl_parameterlist* config,
00077 cpl_frameset* sof,
00078 const char* out_name )
00079 {
00080
00081 detnoise_config * cfg =NULL;
00082
00083 cpl_imagelist * image_list=NULL ;
00084 cpl_image * img_tmp=NULL ;
00085 cpl_image * mask=NULL ;
00086 cpl_parameter *p=NULL;
00087 cpl_frameset* raw=NULL;
00088 cpl_table* qclog_tbl=NULL;
00089 char key_value[FILE_NAME_SZ];
00090 int i=0;
00091 int n_bad =0;
00092
00093
00094
00095 check_nomsg(raw=cpl_frameset_new());
00096 ck0(sinfo_extract_raw_frames_type1(sof,raw,RAW_DARK),
00097 "Error extracting %s frames",RAW_DARK);
00098 cknull(cfg = sinfo_parse_cpl_input_detnoise(config,sof,&raw),
00099 " could not parse .ini file!") ;
00100 check_nomsg(image_list = cpl_imagelist_new());
00101 for ( i = 0 ; i < cfg->nframes ; i++ )
00102 {
00103 if(sinfo_is_fits_file (cfg->framelist[i]) != 1) {
00104 sinfo_msg_error("Input file %s is not FITS",cfg->framelist[i] );
00105 goto cleanup;
00106 }
00107 check_nomsg(img_tmp=cpl_image_load(cfg->framelist[i],
00108 CPL_TYPE_FLOAT,0,0));
00109
00110 check_nomsg(cpl_imagelist_set(image_list,img_tmp,i));
00111 }
00112
00113
00114
00115
00116 sinfo_msg("Noise Search for bad pixels");
00117
00118 cknull(mask=sinfo_new_search_bad_pixels_via_noise (image_list,
00119 cfg->threshSigmaFactor,
00120 cfg->loReject,
00121 cfg->hiReject),
00122 " could not create bad pixel mask!") ;
00123
00124 n_bad = sinfo_new_count_bad_pixels(mask) ;
00125 sinfo_msg ("number of bad pixels: %d\n", n_bad) ;
00126
00127
00128 cknull_nomsg(qclog_tbl = sinfo_qclog_init());
00129 check_nomsg(p = cpl_parameterlist_find(config, "sinfoni.bp.method"));
00130 snprintf(key_value, MAX_NAME_SIZE-1,"%s",cpl_parameter_get_string(p));
00131 ck0_nomsg(sinfo_qclog_add_string(qclog_tbl,"QC BP-MAP METHOD",key_value,
00132 "BP search method","%s"));
00133 ck0_nomsg(sinfo_qclog_add_int(qclog_tbl,"QC BP-MAP NBADPIX",n_bad,
00134 "No of bad pixels","%d"));
00135
00136 ck0(sinfo_pro_save_ima(mask,raw,sof,(char *) out_name,
00137 PRO_BP_MAP_HP,qclog_tbl,plugin_id,config),
00138 "cannot save ima %s", out_name);
00139
00140 sinfo_free_image(&mask);
00141 sinfo_free_table(&qclog_tbl);
00142 sinfo_free_imagelist(&image_list) ;
00143 sinfo_detnoise_free(cfg);
00144 sinfo_free_frameset(&raw);
00145
00146 return 0 ;
00147
00148 cleanup:
00149
00150 sinfo_free_table(&qclog_tbl);
00151 sinfo_free_imagelist(&image_list) ;
00152 sinfo_free_image(&mask) ;
00153 sinfo_detnoise_free(cfg);
00154 sinfo_free_frameset(&raw);
00155 return -1 ;
00156
00157 }