From 6fdca14ff623a6991c15293ea16ff6b53297cda5 Mon Sep 17 00:00:00 2001 From: Richard Gildea Date: Tue, 8 Feb 2022 18:11:56 +0000 Subject: [PATCH] FormatNXmx: open NeXus HDF5 files in SWMR mode (#478) --- newsfragments/478.bugfix | 1 + src/dxtbx/format/FormatNXmx.py | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-) create mode 100644 newsfragments/478.bugfix diff --git a/newsfragments/478.bugfix b/newsfragments/478.bugfix new file mode 100644 index 000000000..a9cbae645 --- /dev/null +++ b/newsfragments/478.bugfix @@ -0,0 +1 @@ +FormatNXmx: Open nexus files in SWMR mode. diff --git a/src/dxtbx/format/FormatNXmx.py b/src/dxtbx/format/FormatNXmx.py index 5262e70cf..690cc19a9 100644 --- a/src/dxtbx/format/FormatNXmx.py +++ b/src/dxtbx/format/FormatNXmx.py @@ -12,7 +12,7 @@ class FormatNXmx(FormatNexus): @staticmethod def understand(image_file): - with h5py.File(image_file, "r") as handle: + with h5py.File(image_file, "r", swmr=True) as handle: name = dxtbx.nexus.nxmx.h5str(FormatNXmx.get_instrument_name(handle)) # Temporarily restrict this to I19-2 while developing if name and "I19-2" in name: @@ -26,7 +26,7 @@ def __init__(self, image_file, **kwargs): def _start(self): self._static_mask = None - with h5py.File(self._image_file, "r") as fh: + with h5py.File(self._image_file, "r", swmr=True) as fh: nxmx = dxtbx.nexus.nxmx.NXmx(fh) nxsample = nxmx.entries[0].samples[0] nxinstrument = nxmx.entries[0].instruments[0] @@ -61,7 +61,7 @@ def get_static_mask(self, index=None, goniometer=None): def get_raw_data(self, index): if self._cached_file_handle is None: - self._cached_file_handle = h5py.File(self._image_file, "r") + self._cached_file_handle = h5py.File(self._image_file, "r", swmr=True) nxmx = dxtbx.nexus.nxmx.NXmx(self._cached_file_handle) nxdata = nxmx.entries[0].data[0]