Ensure single read and no copy for hdf5 data

This commit is contained in:
2025-07-11 14:47:20 +02:00
parent 7169ce5acb
commit 4eb4bb76dc
2 changed files with 5 additions and 5 deletions

View File

@@ -18,14 +18,14 @@ def calc_apply_additional_mask_from_file(results, pixel_mask_pf):
# Support for hdf5 and npy
if mask_file.endswith(".npy"):
try:
mask = np.load(mask_file)
mask = np.load(mask_file).astype(np.bool)
except Exception as error:
results["mask_error"] = f"Error loading mask data from NumPy file {mask_file}:\n{error}"
return
else:
try:
with h5py.File(mask_file, "r") as h5f:
mask = np.asarray(h5f[mask_dataset], dtype=np.bool)
mask = h5f[mask_dataset][:].astype(np.bool)
except Exception as error:
results["mask_error"] = f"Error loading mask from hdf5 file {mask_file}:\n{error}"
return

View File

@@ -79,13 +79,13 @@ def _generate_cryst_data(results, data, pf_pixel_mask) -> CrystData:
num_threads = results.get("num_threads", DEFAULT_NUM_THREADS)
with h5py.File(whitefield_data_file, "r") as hf:
whitefield = np.asarray(hf[whitefield_dataset])
whitefield = hf[whitefield_dataset][:]
with h5py.File(mask_data_file, "r") as hf:
mask = np.asarray(hf[mask_dataset], dtype=np.bool)
mask = hf[mask_dataset][:].astype(np.bool)
with h5py.File(std_data_file, "r") as hf:
std = np.asarray(hf[std_dataset])
std = hf[std_dataset][:]
data = CrystData(
data=data[np.newaxis, :],