diff options
author | Thomas White <taw@physics.org> | 2013-05-23 14:12:52 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2013-05-27 17:33:15 +0200 |
commit | bc6e617c339fdd4e1be6042cb8b70fe9a704c863 (patch) | |
tree | d83c779d4917a559ded079f99117b53ede59ca9f /libcrystfel/src | |
parent | 4fd346391387f740c29561257a5af3fdfdd56700 (diff) |
Individual panel arrays
Diffstat (limited to 'libcrystfel/src')
-rw-r--r-- | libcrystfel/src/detector.c | 7 | ||||
-rw-r--r-- | libcrystfel/src/detector.h | 3 | ||||
-rw-r--r-- | libcrystfel/src/hdf5-file.c | 93 | ||||
-rw-r--r-- | libcrystfel/src/image.h | 4 |
4 files changed, 107 insertions, 0 deletions
diff --git a/libcrystfel/src/detector.c b/libcrystfel/src/detector.c index 37328e5f..09f33d5d 100644 --- a/libcrystfel/src/detector.c +++ b/libcrystfel/src/detector.c @@ -1003,8 +1003,12 @@ out: p->xss = -p->fsy / d; p->yss = p->fsx / d; + p->w = p->max_fs - p->min_fs + 1; + p->h = p->max_ss - p->min_ss + 1; + } + find_min_max_d(det); if ( reject ) return NULL; @@ -1129,6 +1133,9 @@ struct detector *simple_geometry(const struct image *image) geom->panels[0].yfs = 0; geom->panels[0].yss = 1; + geom->panels[0].w = image->width; + geom->panels[0].h = image->height; + find_min_max_d(geom); return geom; diff --git a/libcrystfel/src/detector.h b/libcrystfel/src/detector.h index 43bdc42d..c8d36396 100644 --- a/libcrystfel/src/detector.h +++ b/libcrystfel/src/detector.h @@ -75,6 +75,9 @@ struct panel double yfs; double xss; double yss; + + int w; /* Width, calculated as max_fs-min_fs+1 */ + int h; /* Height, calculated as max_ss-min_ss+1 */ }; diff --git a/libcrystfel/src/hdf5-file.c b/libcrystfel/src/hdf5-file.c index bb11adac..3c4066be 100644 --- a/libcrystfel/src/hdf5-file.c +++ b/libcrystfel/src/hdf5-file.c @@ -501,6 +501,73 @@ static void debodge_saturation(struct hdfile *f, struct image *image) } +static int unpack_panels(struct image *image, struct detector *det) +{ + int pi; + + image->dp = malloc(det->n_panels * sizeof(float *)); + image->bad = malloc(det->n_panels * sizeof(int *)); + if ( (image->dp == NULL) || (image->bad == NULL) ) { + ERROR("Failed to allocate panels.\n"); + return 1; + } + + for ( pi=0; pi<det->n_panels; pi++ ) { + + struct panel *p; + int fs, ss; + + p = &det->panels[pi]; + image->dp[pi] = malloc(p->w*p->h*sizeof(float)); + image->bad[pi] = calloc(p->w*p->h, sizeof(int)); + if ( (image->dp[pi] == NULL) || (image->bad[pi] == NULL) ) { + ERROR("Failed to allocate panel\n"); + return 1; + } + + for ( fs=0; fs<p->w; fs++ ) { + for ( ss=0; ss<p->h; ss++ ) { + + int idx; + int cfs, css; + int bad = 0; + + cfs = fs+p->min_fs; + css = ss+p->min_ss; + idx = cfs + css*image->width; + + image->dp[pi][fs+p->w*ss] = image->data[idx]; + + if ( in_bad_region(det, cfs, css) ) { + bad = 1; + } + + if ( image->flags != NULL ) { + + int flags; + + flags = image->flags[idx]; + + /* Bad if it's missing any of the "good" bits */ + if ( !((flags & image->det->mask_good) + == image->det->mask_good) ) bad = 1; + + /* Bad if it has any of the "bad" bits. */ + if ( flags & image->det->mask_bad ) bad = 1; + + } + + image->bad[pi][fs+p->w*ss] = bad; + + } + } + + } + + return 0; +} + + int hdf5_read(struct hdfile *f, struct image *image, int satcorr) { herr_t r; @@ -551,6 +618,32 @@ int hdf5_read(struct hdfile *f, struct image *image, int satcorr) if ( satcorr ) debodge_saturation(f, image); + if ( (image->width != image->det->max_fs + 1 ) + || (image->height != image->det->max_ss + 1)) + { + ERROR("Image size doesn't match geometry size" + " - rejecting image.\n"); + ERROR("Image size: %i,%i. Geometry size: %i,%i\n", + image->width, image->height, + image->det->max_fs + 1, image->det->max_ss + 1); + return 1; + } + + fill_in_values(image->det, f); + fill_in_beam_parameters(image->beam, f); + image->lambda = ph_en_to_lambda(eV_to_J(image->beam->photon_energy)); + + if ( (image->beam->photon_energy < 0.0) || (image->lambda > 1000) ) { + /* Error message covers a silly value in the beam file or in + * the HDF5 file. */ + ERROR("Nonsensical wavelength (%e m or %e eV) value for %s.\n", + image->lambda, image->beam->photon_energy, + image->filename); + return 1; + } + + unpack_panels(image, image->det); + return 0; } diff --git a/libcrystfel/src/image.h b/libcrystfel/src/image.h index 0d131451..a1ac75a3 100644 --- a/libcrystfel/src/image.h +++ b/libcrystfel/src/image.h @@ -124,10 +124,14 @@ struct image; struct image { + /* The following three fields will be going away in the future */ float *data; uint16_t *flags; double *twotheta; + float **dp; /* Data in panel */ + int **bad; /* Bad pixels by panel */ + Crystal **crystals; int n_crystals; IndexingMethod indexed_by; |