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

NXmx: read data_scale_factor #756

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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/756.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add support for reading the detector gain for nexus files
6 changes: 4 additions & 2 deletions src/dxtbx/format/FormatNXmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ def _start(self):
nxinstrument = nxentry.instruments[0]
nxdetector = nxinstrument.detectors[0]
nxbeam = nxinstrument.beams[0]
nxdata = nxmx_obj.entries[0].data[0]
self._goniometer_model = dxtbx.nexus.get_dxtbx_goniometer(nxsample)
self._beam_factory = dxtbx.nexus.CachedWavelengthBeamFactory(nxbeam)
wavelength = self._beam_factory.make_beam(index=0).get_wavelength()
self._detector_model = dxtbx.nexus.get_dxtbx_detector(nxdetector, wavelength)
self._detector_model = dxtbx.nexus.get_dxtbx_detector(
nxdetector, wavelength, nxdata
)

# if the detector is between the sample and the source, and perpendicular
# to the beam, then invert the distance vector, as this is probably wrong
Expand All @@ -86,7 +89,6 @@ def _start(self):
if self._scan_model:
self._num_images = len(self._scan_model)
else:
nxdata = nxmx_obj.entries[0].data[0]
if nxdata.signal:
data = nxdata[nxdata.signal]
else:
Expand Down
4 changes: 4 additions & 0 deletions src/dxtbx/nexus/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ def get_dxtbx_scan(
def get_dxtbx_detector(
nxdetector: nxmx.NXdetector,
wavelength: float,
nxdata: nxmx.NXdata,
) -> dxtbx.model.Detector:
"""Generate a dxtbx detector model from an NXdetector and NXbeam.
Expand Down Expand Up @@ -461,6 +462,9 @@ def equipment_component_key(dependency):
p.set_mu(mu)
p.set_px_mm_strategy(px_mm)

if nxdata.data_scale_factor and not nxdata.data_scale_factor.shape:
p.set_gain(1 / nxdata.data_scale_factor)

return detector


Expand Down
24 changes: 24 additions & 0 deletions tests/nexus/test_mpccd_nexus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from __future__ import annotations

import dxtbx


def test_mpccd_nexus_gain(dials_data):
"""
Tests SACLA MPCCD image from CXI.DB 221
Includs parameter data_scale_factor, which accounts for a gain of 10
"""

try:
h5path = (
dials_data("image_examples", pathlib=True)
/ "SACLA-MPCCD-run197287-0-nexus.h5"
)
except Exception as e:
print(type(e), str(e))
raise
img = dxtbx.load(h5path)

d = img.get_detector()

assert d[0].get_gain() == 10
Loading