aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2011-03-29 15:29:33 +0200
committerThomas White <taw@physics.org>2012-02-22 15:27:22 +0100
commit0215205efb28d4ea24b93ce4005f4668a358cc32 (patch)
tree47b42b4c5b7b82a164a4513311ecd6948e8dfba7 /src
parentabb1edf5301c36a814e65b9851c0848e35f82173 (diff)
Improve bad pixel handling
Diffstat (limited to 'src')
-rw-r--r--src/detector.c31
-rw-r--r--src/detector.h4
-rw-r--r--src/hdf5-file.c30
-rw-r--r--src/peaks.c10
4 files changed, 61 insertions, 14 deletions
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];