diff options
author | Thomas White <taw@physics.org> | 2016-01-15 12:50:53 -0800 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2016-01-15 12:50:53 -0800 |
commit | dab0992fd181f9dc969518883c514a8dbe4e4dca (patch) | |
tree | 5a2241b6a95777351ab6240b56d9cc4a309b3541 /libcrystfel/src/hdf5-file.c | |
parent | 552233f3cd960c1d6d707f9d49c3df9bb5ee8526 (diff) |
Use only the first two dimensions when using an external bad pixel mask or saturation map
Diffstat (limited to 'libcrystfel/src/hdf5-file.c')
-rw-r--r-- | libcrystfel/src/hdf5-file.c | 53 |
1 files changed, 47 insertions, 6 deletions
diff --git a/libcrystfel/src/hdf5-file.c b/libcrystfel/src/hdf5-file.c index a9518add..09eb4081 100644 --- a/libcrystfel/src/hdf5-file.c +++ b/libcrystfel/src/hdf5-file.c @@ -1485,12 +1485,30 @@ int hdf5_read(struct hdfile *f, struct image *image, const char *element, } +static hsize_t *first_two_dims(hsize_t *in, struct dim_structure *ds) +{ + int i, j; + hsize_t *out = malloc(2*sizeof(hsize_t)); + + if ( out == NULL ) return NULL; + + j = 0; + for ( i=0; i<ds->num_dims; i++ ) { + if ( (ds->dims[i] == HYSL_FS) || (ds->dims[i] == HYSL_SS) ) { + out[j++] = in[i]; + } + } + return out; +} + + static int load_mask(struct hdfile *f, struct event *ev, char *mask, const char *mask_file, const char *pname, struct image *image, size_t p_w, size_t sum_p_h, uint16_t *flags, - hsize_t *f_offset, hsize_t *f_count, - hsize_t *m_offset, hsize_t *m_count) + hsize_t *in_f_offset, hsize_t *in_f_count, + hsize_t *m_offset, hsize_t *m_count, + struct dim_structure *dim_struct) { hid_t mask_dataspace, mask_dh; int exists; @@ -1498,15 +1516,25 @@ static int load_mask(struct hdfile *f, struct event *ev, char *mask, hid_t memspace; hsize_t dimsm[2]; hid_t fh; + hsize_t *f_offset, *f_count; if ( mask_file != NULL ) { + fh = H5Fopen(mask_file, H5F_ACC_RDONLY, H5P_DEFAULT); if ( fh < 0 ) { ERROR("Couldn't open mask file '%s'\n", mask_file); return 1; } + + /* If we have an external map file, we assume it to be a simple + * 2D job */ + f_offset = first_two_dims(in_f_offset, dim_struct); + f_count = first_two_dims(in_f_count, dim_struct); + } else { fh = f->fh; + f_offset = in_f_offset; + f_count = in_f_count; } if ( ev != NULL ) { @@ -1567,8 +1595,9 @@ static int load_satmap(struct hdfile *f, struct event *ev, char *satmap, const char *satmap_file, const char *pname, struct image *image, size_t p_w, size_t sum_p_h, float *smap, - hsize_t *f_offset, hsize_t *f_count, - hsize_t *m_offset, hsize_t *m_count) + hsize_t *in_f_offset, hsize_t *in_f_count, + hsize_t *m_offset, hsize_t *m_count, + struct dim_structure *dim_struct) { hid_t satmap_dataspace, satmap_dh; int exists; @@ -1576,15 +1605,25 @@ static int load_satmap(struct hdfile *f, struct event *ev, char *satmap, hid_t memspace; hsize_t dimsm[2]; hid_t fh; + hsize_t *f_offset, *f_count; if ( satmap_file != NULL ) { + fh = H5Fopen(satmap_file, H5F_ACC_RDONLY, H5P_DEFAULT); if ( fh < 0 ) { ERROR("Couldn't open satmap file '%s'\n", satmap_file); return 1; } + + /* If we have an external map file, we assume it to be a simple + * 2D job */ + f_offset = first_two_dims(in_f_offset, dim_struct); + f_count = first_two_dims(in_f_count, dim_struct); + } else { fh = f->fh; + f_offset = in_f_offset; + f_count = in_f_count; } if ( ev != NULL ) { @@ -1835,7 +1874,8 @@ int hdf5_read2(struct hdfile *f, struct image *image, struct event *ev, if ( p->mask != NULL ) { if ( load_mask(f, ev, p->mask, p->mask_file, p->name, image, p_w, sum_p_h, flags, - f_offset, f_count, m_offset, m_count) ) { + f_offset, f_count, m_offset, m_count, + hsd) ) { ERROR("Error loading bad pixel mask!\n"); } } @@ -1843,7 +1883,8 @@ int hdf5_read2(struct hdfile *f, struct image *image, struct event *ev, if ( p->satmap != NULL ) { if ( load_satmap(f, ev, p->satmap, p->satmap_file, p->name, image, p_w, sum_p_h, smap, - f_offset, f_count, m_offset, m_count) ) + f_offset, f_count, m_offset, m_count, + hsd) ) { ERROR("Error loading saturation map!\n"); } |