From f21250179c411c7d036b23de94527e513c3cf0b1 Mon Sep 17 00:00:00 2001 From: David Waterman Date: Thu, 11 Jan 2024 15:09:05 +0000 Subject: [PATCH 1/3] For mrcfile>=1.5.0 use the indexed_extended_header. Attempt to process the extended header only if its length is equal to the number of images. Ignore extended header values if the pixel size is set to zero. --- src/dxtbx/format/FormatMRC.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/dxtbx/format/FormatMRC.py b/src/dxtbx/format/FormatMRC.py index b7d9b30bb..ef47c8a3c 100644 --- a/src/dxtbx/format/FormatMRC.py +++ b/src/dxtbx/format/FormatMRC.py @@ -39,11 +39,19 @@ def _start(self): with mrcfile.open(self._image_file, header_only=True) as mrc: h = mrc.header - xh = mrc.extended_header + try: + xh = mrc.indexed_extended_header + except AttributeError: + # mrcfile<1.5.0 does not have indexed_extended_header + xh = mrc.extended_header self._header_dictionary = self._unpack_header(h) - if len(xh) > 0: - self._extend_header(xh) + if len(xh) == int(h["nz"]): + try: + self._extend_header(xh) + except ValueError: + # Ignore problematic extended headers + pass @staticmethod def _unpack_header(header): @@ -73,9 +81,11 @@ def _extend_header(self, xh): self._header_dictionary["tilt_axis"] = xh["Tilt axis angle"][0] self._header_dictionary["pixelSpacing"] = xh["Pixel size X"][0] assert self._header_dictionary["pixelSpacing"] == xh["Pixel size Y"][0] + if self._header_dictionary["pixelSpacing"] == 0: + raise ValueError("Incorrect extended header") self._header_dictionary["acceleratingVoltage"] = xh["HT"][0] self._header_dictionary["camera"] = xh["Camera name"][0] - self._header_dictionary["binning"] = xh["Binning Width"][0] + self._header_dictionary["binning"] = max(xh["Binning Width"][0], 1) self._header_dictionary["noiseReduction"] = xh["Ceta noise reduction"][0] if b"Ceta" in self._header_dictionary["camera"]: # Does this ever differ from the Binning Width from the header? From 60981be3659248ce89c723c6b4885ee91fbcbeee Mon Sep 17 00:00:00 2001 From: David Waterman Date: Thu, 11 Jan 2024 15:15:14 +0000 Subject: [PATCH 2/3] news --- newsfragments/xxx.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 newsfragments/xxx.bugfix diff --git a/newsfragments/xxx.bugfix b/newsfragments/xxx.bugfix new file mode 100644 index 000000000..c5bf1354a --- /dev/null +++ b/newsfragments/xxx.bugfix @@ -0,0 +1 @@ +``FormatMRC``: better handling of extended headers: padding is supported in mrcfile>=1.5.0 (https://github.com/ccpem/mrcfile/issues/50), and extended headers are ignored if they contain junk values. From 5caded79ed8badf5d3ec63f4e4a6c06d40f99ef8 Mon Sep 17 00:00:00 2001 From: DiamondLightSource-build-server Date: Thu, 11 Jan 2024 15:19:45 +0000 Subject: [PATCH 3/3] Rename newsfragments/xxx.bugfix to newsfragments/679.bugfix --- newsfragments/{xxx.bugfix => 679.bugfix} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename newsfragments/{xxx.bugfix => 679.bugfix} (100%) diff --git a/newsfragments/xxx.bugfix b/newsfragments/679.bugfix similarity index 100% rename from newsfragments/xxx.bugfix rename to newsfragments/679.bugfix