Commit a630a0aa authored by Pierre Paleo's avatar Pierre Paleo

nxflatfield: fix h5py bytes/str when loading nabu_processes.h5

parent 50f232e1
......@@ -117,3 +117,14 @@ def get_h5_value(fname, h5_path, default_ret=None):
except KeyError:
val_ptr = default_ret
return val_ptr
def get_h5_str_value(dataset_ptr):
"""
Get a HDF5 field which can be bytes or str (depending on h5py version !).
"""
data = dataset_ptr[()]
if isinstance(data, str):
return data
else:
return bytes.decode(data)
......@@ -5,7 +5,7 @@ from tomoscan.io import HDF5File
from tomoscan.esrf.hdf5scan import ImageKey
from ..utils import check_supported
from ..io.writer import NXProcessWriter
from ..io.utils import get_first_hdf5_entry, hdf5_entry_exists
from ..io.utils import get_first_hdf5_entry, hdf5_entry_exists, get_h5_str_value
from .logger import LoggerOrPrint
val_to_nxkey = {
......@@ -30,8 +30,6 @@ def replace_h5_entry(data_url, new_entry):
)
class NXFlatField:
"""
A helper class to load flats and darks, or to compute the final ones.
......@@ -155,11 +153,12 @@ class NXFlatField:
res = True
try:
for key in ["flats_reduction_method", "darks_reduction_method"]:
res &= (my_config[key] == bytes.decode(cfg[key][()]))
res &= (my_config[key] == get_h5_str_value(cfg[key]))
res &= np.allclose(my_config["data_shape"], cfg["data_shape"][()])
res &= np.allclose(my_config["image_key"], cfg["image_key"][()])
du1 = DataUrl(path=my_config["input_file"])
du2 = DataUrl(path=bytes.decode(cfg["input_file"][()]))
du2 = DataUrl(path=get_h5_str_value(cfg["input_file"]))
if not(ignore_filenames):
res &= (
os.path.basename(du1.file_path()) == os.path.basename(du2.file_path())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment