Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormatNXmx: open files in SWMR mode #478

Merged
merged 3 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions newsfragments/478.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FormatNXmx: open 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