diff options
author | Thomas White <taw@physics.org> | 2022-09-20 14:38:05 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2022-09-21 14:10:36 +0200 |
commit | 1f53f659e757cc7d4704a885bab50f7060231d16 (patch) | |
tree | 2cedd6fa48fec8237a75b16e2e8192f9966fb571 | |
parent | 55188747562dfbfb95f5ec2b23d36aa91557324c (diff) |
Avoid nan/inf check unless data was given in float format
-rw-r--r-- | libcrystfel/src/image-hdf5.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/libcrystfel/src/image-hdf5.c b/libcrystfel/src/image-hdf5.c index 0da2898f..c38385ac 100644 --- a/libcrystfel/src/image-hdf5.c +++ b/libcrystfel/src/image-hdf5.c @@ -368,7 +368,8 @@ static int load_hdf5_hyperslab(struct panel_template *p, void *data, hid_t el_type, size_t el_size, int skip_placeholders_ok, - const char *path_spec) + const char *path_spec, + hid_t *orig_type) { int total_dt_dims; int plh_dt_dims; @@ -526,6 +527,10 @@ static int load_hdf5_hyperslab(struct panel_template *p, free(f_offset); free(f_count); + if ( orig_type != NULL ) { + *orig_type = H5Dget_type(dh); + } + H5Dclose(dh); return 0; @@ -599,12 +604,14 @@ int image_hdf5_read(struct image *image, for ( i=0; i<dtempl->n_panels; i++ ) { long int j; struct panel_template *p = &dtempl->panels[i]; + hid_t orig_type; profile_start("load-hdf5-hyperslab"); if ( load_hdf5_hyperslab(p, fh, image->ev, image->dp[i], H5T_NATIVE_FLOAT, sizeof(float), 0, - dtempl->panels[i].data) ) + dtempl->panels[i].data, + &orig_type) ) { ERROR("Failed to load panel data\n"); profile_end("load-hdf5-hyperslab"); @@ -612,13 +619,16 @@ int image_hdf5_read(struct image *image, return 1; } profile_end("load-hdf5-hyperslab"); - profile_start("nan-inf"); - for ( j=0; j<PANEL_WIDTH(p)*PANEL_HEIGHT(p); j++ ) { - if ( !isfinite(image->dp[i][j]) ) { - image->bad[i][j] = 1; + if ( H5Tget_class(orig_type) == H5T_FLOAT ) { + profile_start("nan-inf"); + for ( j=0; j<PANEL_WIDTH(p)*PANEL_HEIGHT(p); j++ ) { + if ( !isfinite(image->dp[i][j]) ) { + image->bad[i][j] = 1; + } } + profile_end("nan-inf"); } - profile_end("nan-inf"); + H5Tclose(orig_type); } close_hdf5(fh); @@ -639,7 +649,7 @@ int image_hdf5_read_satmap(struct panel_template *p, if ( load_hdf5_hyperslab(p, fh, event, map_data, H5T_NATIVE_FLOAT, - sizeof(float), 1, map_location) ) + sizeof(float), 1, map_location, NULL) ) { ERROR("Failed to load saturation map data\n"); return 1; @@ -676,7 +686,7 @@ int image_hdf5_read_mask(struct panel_template *p, if ( load_hdf5_hyperslab(p, fh, event, mask, H5T_NATIVE_INT, - sizeof(int), 1, mask_location) ) + sizeof(int), 1, mask_location, NULL) ) { ERROR("Failed to load mask data\n"); free(mask); |