70 const char * fname =
"noisy_pixels.dat" ;
73 fout = fopen( fname,
"w" ) ;
74 fprintf( fout,
"%d %d\n",
x,
y ) ;
75 if ( fout ) fclose( fout ) ;
99 cpl_image **pimg = NULL;
100 int nimg, nbad = 0, npix = 0;
101 double medStackv = 0.,
103 sumStackv = 0., errorStackv = 0.;
104 double *Stackv = NULL,
107 double *stack = NULL;
108 double *bisStackv = NULL,
110 double diff = 0.0, diff2 = 0.0;
111 double min = 999999.,
max = -9999999.;
112 double maxdelta = 0.0;
113 cpl_binary *bpmap_mask = NULL;
115 float ** pixdata = NULL;
116 cpl_binary **pixmask = NULL;
118 int totpix =
nx *
ny;
119 nimg = cpl_imagelist_get_size(raws);
124for( i = 0; i < nimg; i++) {
125 *(pimg + i) = cpl_imagelist_get (raws, i);
132 xsh_msg_dbg_low(
"Rejected in bpmap: %" CPL_SIZE_FORMAT
"", cpl_image_count_rejected( bpmap ));
138bpmap_mask = cpl_mask_get_data(cpl_image_get_bpm(bpmap));
139 assure( bpmap_mask != NULL, cpl_error_get_code(),
140 "Cant get bpmap Mask" );
151 for (j = 0; j < nimg; j++) {
152 *(pixdata + j) = cpl_image_get_data_float(*(pimg + j));
153 *(pixmask + j) = cpl_mask_get_data(cpl_image_get_bpm(*(pimg + j)));
158 for (iy = 1; iy <=
ny; iy++) {
159 for (ix = 1; ix <=
nx; ix++) {
164 if ((*(bpmap_mask + idpix) & inst->
decode_bp) > 0) {
169 for (j = 0; j < nimg; j++) {
171 double fval = *(*(pixdata + j) + idpix);
172 rej = (*(*(pixmask + j) + idpix ) & inst->
decode_bp);
181 *(stack + count) = fval;
188 double avg = sum / (double) count;
189 double dif, dif2 = 0.,
sigma = 0.;
193 " [%d,%d] Count=%d - sum = %lf, avg = %lf", ix, iy, count, sum, avg);
195 for (k = 0; k < count; k++) {
197 dif = *(stack + k) - avg;
200 sigma = sqrt(dif2 / (
double) (count - 1));
205 "++ dif2 = %lf, count= %d, sigma=%lf, Stackv=%lf, sum=%lf", dif2, count,
sigma, *pStackv, sumStackv);
206 if ((npix % 500) == 0)
208 "+++++ (%d,%d) sumStackv = %lf", ix, iy, sumStackv);
226 aveStackv = sumStackv / (double) npix;
228 "--- Npix=%d - sumStackv=%lf - aveStackv=%lf", npix, sumStackv, aveStackv);
232 for (pStackv = bisStackv, i = 0; i < npix; i++, pStackv++) {
233 diff = *pStackv - aveStackv;
238 diff2 += diff * diff;
244 errorStackv = sqrt(diff2 / (
double) (npix - 1));
248 maxdelta = noise_clipping->
sigma * errorStackv;
251 "Npix:%d/%d, sum: %lf, med:%lf, avg:%lf, err:%lf, delta: %lf", npix,
nx *
ny, sumStackv, medStackv, aveStackv, errorStackv, maxdelta);
256 for (iy = 1; iy <=
ny; iy++) {
257 for (ix = 1; ix <=
nx; ix++) {
258 if ( (*(bpmap_mask + idpix) & inst->
decode_bp) == 0 ) {
259 double delta = *pStackv - medStackv;
260 if (fabs(delta) > maxdelta) {
276 xsh_msg(
"Found %d Electronic Pickup Noise Hot Pixels", nhot );
308 cpl_frame * medFrame,
311 cpl_frame ** noisyFrame
314 int nx,
ny, nframes = 0;
315 cpl_image *resBpMap = NULL;
316 cpl_propertylist *bpmapHeader = NULL;
317 cpl_frame *resFrame = NULL;
319 const char *bpmapFile = cpl_frame_get_filename (medFrame);
321 int iter = 0,curnbad = 0;
322 char result_name[256] ;
324 char noisy_name[256];
325 cpl_image * noisyMap = NULL ;
326 cpl_propertylist * noisymapHeader = NULL ;
330 cpl_image* ima_aux=NULL;
338 cpl_msg_indent_more ();
339 xsh_msg (
"*** Removing Noisy Pixels (%s)",
343 xsh_msg (
"Bpmap file = \"%s\"", bpmapFile);
355 check( noisyMap = cpl_image_new(
nx,
ny, CPL_TYPE_INT ) ) ;
356 check( noisymapHeader = cpl_propertylist_duplicate( bpmapHeader ) ) ;
360 prevnbad = cpl_image_count_rejected (resBpMap);
362 nframes = cpl_imagelist_get_size (dataList);
363 xsh_msg (
"%d dark images in image list", nframes);
366 for (iter = 0; iter < noise_clipping->
niter; iter++) {
369 xsh_msg (
">>>> Iteration Nb %d/%d", iter+1, noise_clipping->
niter);
370 cpl_msg_indent_more ();
375 nx,
ny, noise_clipping,instr);
377 cpl_msg_indent_less ();
378 if ( nhot == 0 ) break ;
382 curnbad = cpl_image_count_rejected (resBpMap);
383 xsh_msg (
"End of noisy pixels, total bad pixels: %d", curnbad);
385 xsh_msg (
" Nb of noisy pixels: %d", curnbad - prevnbad);
392 strcpy(result_name,bpmapFile) ;
393 xsh_msg (
"save frame %s\n", result_name);
412 ima_aux=cpl_image_cast(medPre->
data,CPL_TYPE_FLOAT);
413 check(cpl_image_save (ima_aux,result_name, CPL_BPP_IEEE_FLOAT,
419 ima_aux=cpl_image_cast(medPre->
errs,CPL_TYPE_FLOAT);
420 check(cpl_image_save (ima_aux,result_name, CPL_BPP_IEEE_FLOAT,
431 CPL_FRAME_TYPE_IMAGE,
432 CPL_FRAME_GROUP_PRODUCT,
433 CPL_FRAME_LEVEL_FINAL));
445 CPL_FRAME_TYPE_IMAGE,
446 CPL_FRAME_GROUP_PRODUCT,
447 CPL_FRAME_LEVEL_TEMPORARY));
static xsh_instrument * instrument
void xsh_bpmap_set_bad_pixel(cpl_image *bpmap, int ix, int iy, int flag)
void xsh_set_image_cpl_bpmap(cpl_image *image, cpl_image *bpmap, const int decode_bp)
static int flag_noisy_pixels(cpl_imagelist *raws, cpl_image *bpmap, cpl_image *noisymap, int nx, int ny, xsh_clipping_param *noise_clipping, xsh_instrument *inst)
static void add_noisy_pixel_to_ascii_file(int x, int y)
cpl_frame * xsh_compute_noise_map(cpl_imagelist *dataList, cpl_frame *medFrame, xsh_clipping_param *noise_clipping, xsh_instrument *instr, cpl_frame **noisyFrame)
static void set_pickup_noise_pixels_qc(cpl_propertylist *header, int nbad, xsh_instrument *instrument)
xsh_pre * xsh_pre_load(cpl_frame *frame, xsh_instrument *instr)
Load a xsh_pre structure from a frame.
cpl_image * xsh_pre_get_qual(xsh_pre *pre)
Get qual.
void xsh_pre_free(xsh_pre **pre)
Free a xsh_pre structure.
#define assure(CONDITION, ERROR_CODE,...)
#define XSH_ASSURE_NOT_NULL(pointer)
const char * xsh_instrument_arm_tostring(xsh_instrument *i)
Get the string associated with an arm.
XSH_ARM xsh_instrument_get_arm(xsh_instrument *i)
Get an arm on instrument structure.
#define xsh_msg_dbg_medium(...)
#define xsh_msg(...)
Print a message on info level.
#define xsh_msg_dbg_low(...)
int xsh_pfits_get_binx(const cpl_propertylist *plist)
find out the BINX value
void xsh_pfits_set_extname(cpl_propertylist *plist, const char *value)
Write the EXTNAME value.
int xsh_pfits_get_biny(const cpl_propertylist *plist)
find out the BINY value
void xsh_pfits_set_qc_nhpix(cpl_propertylist *plist, int value)
Write the QC.NHPIX value.
void xsh_pfits_set_qc(cpl_propertylist *plist, void *value, const char *kw, xsh_instrument *instrument)
void xsh_free_image(cpl_image **i)
Deallocate an image and set the pointer to NULL.
int xsh_debug_level_get(void)
get debug level
double xsh_tools_get_median_double(double *array, int size)
Calculates the median value of an array of double.
void xsh_free_propertylist(cpl_propertylist **p)
Deallocate a property list and set the pointer to NULL.
void xsh_add_temporary_file(const char *name)
Add temporary file to temprary files list.
cpl_propertylist * qual_header
cpl_propertylist * errs_header
cpl_propertylist * data_header
#define QFLAG_ELECTRONIC_PICKUP
cpl_frame * xsh_frame_product(const char *fname, const char *tag, cpl_frame_type type, cpl_frame_group group, cpl_frame_level level)
Creates a frame with given characteristics.
#define XSH_GET_TAG_FROM_ARM(TAG, instr)
#define XSH_QC_BP_MAP_PICKUP_NOISE_PIX
#define XSH_FREE(POINTER)
#define XSH_MALLOC(POINTER, TYPE, SIZE)