From 88f1415950524515300528ae5c2df5bf244b922a Mon Sep 17 00:00:00 2001 From: Graeme Winter Date: Wed, 3 May 2023 15:34:53 +0100 Subject: [PATCH 1/4] Add bit_depth_image This appears to be a feature of the dectris file writer to say how many pixel bits are used - which can be different to those read from the hardware. This is part of a fix which will be incoming shortly Includes reference --- src/nxmx/__init__.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/nxmx/__init__.py b/src/nxmx/__init__.py index 1526d39..02d8b52 100644 --- a/src/nxmx/__init__.py +++ b/src/nxmx/__init__.py @@ -843,6 +843,14 @@ def bit_depth_readout(self) -> int | None: return int(self._handle["bit_depth_readout"][()]) return None + # https://www.dectris.com/support/downloads/header-docs/nexus/ + @cached_property + def bit_depth_image(self) -> int | None: + """How many bits are saved per pixel to file (nonstandard).""" + if "bit_depth_image" in self._handle: + return int(self._handle["bit_depth_image"][()]) + return None + @cached_property def sensor_material(self) -> str: """The name of the material a detector sensor is constructed from. From 755621fe3ba455758c93d992cdb351096669ee02 Mon Sep 17 00:00:00 2001 From: Richard Gildea Date: Thu, 4 May 2023 14:23:37 +0100 Subject: [PATCH 2/4] Add basic test for bit_depth_image --- tests/conftest.py | 1 + tests/test_nxmx.py | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 84d2b79..f3421bd 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -60,6 +60,7 @@ def nxmx_example(): detector["frame_time"] = 0.1 detector["frame_time"].attrs["units"] = "s" detector["bit_depth_readout"] = np.array(32) + detector["bit_depth_image"] = np.array(32) detector_transformations = detector.create_group("transformations") detector_transformations.attrs["NX_class"] = "NXtransformations" diff --git a/tests/test_nxmx.py b/tests/test_nxmx.py index 4554983..a85b5ef 100644 --- a/tests/test_nxmx.py +++ b/tests/test_nxmx.py @@ -92,6 +92,7 @@ def test_nxmx(nxmx_example): detector.depends_on.path == "/entry/instrument/detector/transformations/det_z" ) assert detector.bit_depth_readout == 32 + assert detector.bit_depth_image == 32 assert detector.beam_center_x == pint.Quantity(2079.79727597266, "pixel") assert detector.beam_center_y == pint.Quantity(2225.38773853771, "pixel") From 4aa6cc57a3d534d4b8069f1138519efb3b469c62 Mon Sep 17 00:00:00 2001 From: Richard Gildea Date: Thu, 4 May 2023 14:26:05 +0100 Subject: [PATCH 3/4] Tweak docstring --- src/nxmx/__init__.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/nxmx/__init__.py b/src/nxmx/__init__.py index 02d8b52..3174b74 100644 --- a/src/nxmx/__init__.py +++ b/src/nxmx/__init__.py @@ -843,10 +843,16 @@ def bit_depth_readout(self) -> int | None: return int(self._handle["bit_depth_readout"][()]) return None - # https://www.dectris.com/support/downloads/header-docs/nexus/ @cached_property def bit_depth_image(self) -> int | None: - """How many bits are saved per pixel to file (nonstandard).""" + """Bit depth of generated images. + + Note this is currently a non-standard item that is included in NeXus + files generated by DECTRIS. See + https://www.dectris.com/support/downloads/header-docs/nexus/ + + See also: https://github.com/nexusformat/definitions/issues/1258 + """ if "bit_depth_image" in self._handle: return int(self._handle["bit_depth_image"][()]) return None From d96502baf62d6c6cf6265c4aa545abe90182e6df Mon Sep 17 00:00:00 2001 From: Richard Gildea Date: Mon, 26 Jun 2023 14:51:26 +0100 Subject: [PATCH 4/4] Update docstring to match wording in nexusformat/definitions#1284 --- src/nxmx/__init__.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/nxmx/__init__.py b/src/nxmx/__init__.py index 3174b74..5057a31 100644 --- a/src/nxmx/__init__.py +++ b/src/nxmx/__init__.py @@ -845,14 +845,7 @@ def bit_depth_readout(self) -> int | None: @cached_property def bit_depth_image(self) -> int | None: - """Bit depth of generated images. - - Note this is currently a non-standard item that is included in NeXus - files generated by DECTRIS. See - https://www.dectris.com/support/downloads/header-docs/nexus/ - - See also: https://github.com/nexusformat/definitions/issues/1258 - """ + """The number of bits per pixel saved to the image data.""" if "bit_depth_image" in self._handle: return int(self._handle["bit_depth_image"][()]) return None