diff options
author | Thomas White <taw@physics.org> | 2011-03-29 15:29:33 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2012-02-22 15:27:22 +0100 |
commit | 0215205efb28d4ea24b93ce4005f4668a358cc32 (patch) | |
tree | 47b42b4c5b7b82a164a4513311ecd6948e8dfba7 | |
parent | abb1edf5301c36a814e65b9851c0848e35f82173 (diff) |
Improve bad pixel handling
-rw-r--r-- | doc/examples/lcls-dec.geom | 4 | ||||
-rw-r--r-- | doc/examples/lcls-june-r0013-r0128.geom | 4 | ||||
-rw-r--r-- | doc/examples/lcls-xpp-estimate.geom | 2 | ||||
-rw-r--r-- | doc/examples/simple.geom | 2 | ||||
-rw-r--r-- | src/detector.c | 31 | ||||
-rw-r--r-- | src/detector.h | 4 | ||||
-rw-r--r-- | src/hdf5-file.c | 30 | ||||
-rw-r--r-- | src/peaks.c | 10 |
8 files changed, 68 insertions, 19 deletions
diff --git a/doc/examples/lcls-dec.geom b/doc/examples/lcls-dec.geom index 8db61144..349d2b16 100644 --- a/doc/examples/lcls-dec.geom +++ b/doc/examples/lcls-dec.geom @@ -1,3 +1,7 @@ +mask = /processing/hitfinder/masks +mask_good = 0x07 +mask_bad = 0x00 + upper/min_fs = 0 upper/max_fs = 1023 upper/min_ss = 512 diff --git a/doc/examples/lcls-june-r0013-r0128.geom b/doc/examples/lcls-june-r0013-r0128.geom index 0184f852..8a31ada6 100644 --- a/doc/examples/lcls-june-r0013-r0128.geom +++ b/doc/examples/lcls-june-r0013-r0128.geom @@ -1,4 +1,6 @@ -n_panels = 2 +mask = /processing/hitfinder/masks +mask_good = 0x27 +mask_bad = 0x00 ; Upper panel (nearest the beam) 0/min_fs = 0 diff --git a/doc/examples/lcls-xpp-estimate.geom b/doc/examples/lcls-xpp-estimate.geom index 7e53d3d9..c64c985a 100644 --- a/doc/examples/lcls-xpp-estimate.geom +++ b/doc/examples/lcls-xpp-estimate.geom @@ -1,5 +1,3 @@ -n_panels = 1 - 0/min_fs = 0 0/max_fs = 1455 0/min_ss = 0 diff --git a/doc/examples/simple.geom b/doc/examples/simple.geom index aa762b47..62ee53db 100644 --- a/doc/examples/simple.geom +++ b/doc/examples/simple.geom @@ -1,5 +1,3 @@ -n_panels = 2 - ; Upper panel 0/min_fs = 0 0/max_fs = 1023 diff --git a/src/detector.c b/src/detector.c index 3a00607a..95cbc08a 100644 --- a/src/detector.c +++ b/src/detector.c @@ -464,6 +464,36 @@ static int parse_field_bad(struct badregion *panel, const char *key, } +static void parse_toplevel(struct detector *det, const char *key, + const char *val) +{ + if ( strcmp(key, "mask") == 0 ) { + + det->mask = strdup(val); + + } else if ( strcmp(key, "mask_bad") == 0 ) { + + char *end; + double v = strtod(val, &end); + + if ( end != val ) { + det->mask_bad = v; + } + + } else if ( strcmp(key, "mask_good") == 0 ) { + + char *end; + double v = strtod(val, &end); + + if ( end != val ) { + det->mask_good = v; + } + + } else { + ERROR("Unrecognised top level field '%s'\n", key); + } +} + struct detector *get_detector_geometry(const char *filename) { FILE *fh; @@ -516,6 +546,7 @@ struct detector *get_detector_geometry(const char *filename) n2 = assplode(bits[0], "/\\.", &path, ASSPLODE_NONE); if ( n2 < 2 ) { /* This was a top-level option, but not handled above. */ + parse_toplevel(det, bits[0], bits[2]); for ( i=0; i<n1; i++ ) free(bits[i]); free(bits); for ( i=0; i<n2; i++ ) free(path[i]); diff --git a/src/detector.h b/src/detector.h index 67b10870..42651ebd 100644 --- a/src/detector.h +++ b/src/detector.h @@ -72,6 +72,10 @@ struct detector struct badregion *bad; int n_bad; + + char *mask; + unsigned int mask_bad; + unsigned int mask_good; }; diff --git a/src/hdf5-file.c b/src/hdf5-file.c index be0b5444..83850afe 100644 --- a/src/hdf5-file.c +++ b/src/hdf5-file.c @@ -412,22 +412,26 @@ int hdf5_read(struct hdfile *f, struct image *image, int satcorr) } image->data = buf; - mask_dh = H5Dopen2(f->fh, "/processing/hitfinder/masks", H5P_DEFAULT); - if ( mask_dh <= 0 ) { - ERROR("Couldn't open flags\n"); - image->flags = NULL; - } else { - flags = malloc(sizeof(uint16_t)*f->nx*f->ny); - r = H5Dread(mask_dh, H5T_NATIVE_UINT16, H5S_ALL, H5S_ALL, - H5P_DEFAULT, flags); - if ( r < 0 ) { - ERROR("Couldn't read flags\n"); - free(flags); + if ( image->det->mask != NULL ) { + + mask_dh = H5Dopen2(f->fh, image->det->mask, H5P_DEFAULT); + if ( mask_dh <= 0 ) { + ERROR("Couldn't open flags\n"); image->flags = NULL; } else { - image->flags = flags; + flags = malloc(sizeof(uint16_t)*f->nx*f->ny); + r = H5Dread(mask_dh, H5T_NATIVE_UINT16, H5S_ALL, H5S_ALL, + H5P_DEFAULT, flags); + if ( r < 0 ) { + ERROR("Couldn't read flags\n"); + free(flags); + image->flags = NULL; + } else { + image->flags = flags; + } + H5Dclose(mask_dh); } - H5Dclose(mask_dh); + } /* Read wavelength from file */ diff --git a/src/peaks.c b/src/peaks.c index e5ba5337..453f46e9 100644 --- a/src/peaks.c +++ b/src/peaks.c @@ -186,8 +186,16 @@ int integrate_peak(struct image *image, int cfs, int css, /* Veto this peak if we tried to integrate in a bad region */ if ( image->flags != NULL ) { + flags = image->flags[idx]; - if ( !(flags & 0x01) ) return 1; + + /* It must have all the "good" bits to be valid */ + if ( !((flags & image->det->mask_good) + == image->det->mask_good) ) return 1; + + /* If it has any of the "bad" bits, reject */ + if ( flags & image->det->mask_bad ) return 1; + } val = image->data[idx]; |