Skip to content

Commit

Permalink
FormatNXmx: open NeXus HDF5 files in SWMR mode (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
rjgildea authored Feb 8, 2022
1 parent 42b1945 commit 6fdca14
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions newsfragments/478.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FormatNXmx: Open nexus files in SWMR mode.
6 changes: 3 additions & 3 deletions src/dxtbx/format/FormatNXmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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]
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 6fdca14

Please sign in to comment.