aboutsummaryrefslogtreecommitdiff
path: root/libcrystfel/src
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2020-05-15 16:52:29 +0200
committerThomas White <taw@physics.org>2020-07-29 18:42:57 +0200
commit5f434be3c57e341b2c2a27622462f7c90646e91c (patch)
treefdccf65d16f5f4d0be7bba1c0bdd63b133ca3bd8 /libcrystfel/src
parentaf6d7f70863f96faf92ca53dabf4e6a3aa3216c8 (diff)
Allow skipping placeholders when loading from HDF5
This allows a static mask as a multi-dimensional array in a multi-event file, for example: data: { 148, 124, 1000, 16 } = { fs, ss, eventnum, panelnum } mask: { 148, 124, 16 } = { fs, ss, panelnum }
Diffstat (limited to 'libcrystfel/src')
-rw-r--r--libcrystfel/src/image.c47
1 files changed, 39 insertions, 8 deletions
diff --git a/libcrystfel/src/image.c b/libcrystfel/src/image.c
index de77a8a2..4bee2683 100644
--- a/libcrystfel/src/image.c
+++ b/libcrystfel/src/image.c
@@ -1359,7 +1359,8 @@ static int load_hdf5_hyperslab(struct panel_template *p,
const char *filename,
const char *event,
void **pdata,
- hid_t el_type, size_t el_size)
+ hid_t el_type, size_t el_size,
+ int skip_placeholders_ok)
{
struct event *ev;
hid_t fh;
@@ -1372,6 +1373,8 @@ static int load_hdf5_hyperslab(struct panel_template *p,
hsize_t dims[2];
char *panel_full_path;
void *data;
+ int ndims;
+ int skip_placeholders = 0;
if ( access(filename, R_OK) == -1 ) {
ERROR("File does not exist or cannot be read: %s\n",
@@ -1414,7 +1417,35 @@ static int load_hdf5_hyperslab(struct panel_template *p,
free(panel_full_path);
- /* Determine where to read the data from in the file */
+ /* Set up dataspace for file
+ * (determine where to read the data from) */
+ dataspace = H5Dget_space(dh);
+ ndims = H5Sget_simple_extent_ndims(dataspace);
+ if ( ndims < 0 ) {
+ ERROR("Failed to get number of dimensions for panel %s\n",
+ p->name);
+ free_event(ev);
+ H5Fclose(fh);
+ return 1;
+ }
+
+ if ( ndims != p->dim_structure->num_dims ) {
+ /* Dimensionality doesn't match */
+ int n_nonplaceholder = 0;
+ for ( hsi=0; hsi<p->dim_structure->num_dims; hsi++ ) {
+ if ( p->dim_structure->dims[hsi] != HYSL_PLACEHOLDER ) {
+ n_nonplaceholder++;
+ }
+ }
+
+ /* If the dimensions match after excluding
+ * placeholders, it's OK - probably a static mask
+ * in a multi-event file. */
+ if ( ndims == n_nonplaceholder ) {
+ skip_placeholders = 1;
+ }
+ }
+
f_offset = malloc(p->dim_structure->num_dims*sizeof(hsize_t));
f_count = malloc(p->dim_structure->num_dims*sizeof(hsize_t));
if ( (f_offset == NULL) || (f_count == NULL ) ) {
@@ -1432,8 +1463,10 @@ static int load_hdf5_hyperslab(struct panel_template *p,
f_offset[hsi] = p->orig_min_ss;
f_count[hsi] = p->orig_max_ss - p->orig_min_ss+1;
} else if (p->dim_structure->dims[hsi] == HYSL_PLACEHOLDER ) {
- f_offset[hsi] = ev->dim_entries[0];
- f_count[hsi] = 1;
+ if ( !skip_placeholders ) {
+ f_offset[hsi] = ev->dim_entries[0];
+ f_count[hsi] = 1;
+ }
} else {
f_offset[hsi] = p->dim_structure->dims[hsi];
f_count[hsi] = 1;
@@ -1441,8 +1474,6 @@ static int load_hdf5_hyperslab(struct panel_template *p,
}
- /* Set up dataspace for file */
- dataspace = H5Dget_space(dh);
check = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET,
f_offset, NULL, f_count, NULL);
if ( check < 0 ) {
@@ -1521,7 +1552,7 @@ static struct image *image_read_hdf5(DataTemplate *dtempl,
if ( load_hdf5_hyperslab(&dtempl->panels[i], filename,
event, (void *)&image->dp[i],
H5T_NATIVE_FLOAT,
- sizeof(float)) )
+ sizeof(float), 0) )
{
ERROR("Failed to load panel data\n");
image_free(image);
@@ -1560,7 +1591,7 @@ static int load_mask_hdf5(struct panel_template *p,
if ( load_hdf5_hyperslab(p, filename, event,
(void *)&mask, H5T_NATIVE_INT,
- sizeof(int)) )
+ sizeof(int), 1) )
{
ERROR("Failed to load mask data\n");
free(mask);