From 0a068b56df0cc05cd5ea5e5ebe2f0c203e341e54 Mon Sep 17 00:00:00 2001 From: Nicholas Devenish Date: Thu, 27 Jul 2023 14:52:33 +0100 Subject: [PATCH 1/2] MNT: Update CMake modules path relative to script Without this, dxtbx did not work as a subdirectory in a larger CMakeLists project. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c286d39e2..96c6b76d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.20 FATAL_ERROR) project(dxtbx LANGUAGES C CXX) # Add the included modules -set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/") # General cmake environment configuration include(SetDefaultBuildRelWithDebInfo) # Default builds to release with debug info From 64bcb3240a3e300fe7c7fa2f0de7a7aa931d9ef3 Mon Sep 17 00:00:00 2001 From: Christian Becke Date: Mon, 31 Jul 2023 10:58:00 +0200 Subject: [PATCH 2/2] Fixes for EMBL beamlines at PETRA (#626) The E-32-0017 Eiger moved to P13 on 2021-5-22, where the goniometer axis no longer needs overriding. Check for that date in the MiniCBF, and check for the serial matching the date range. Co-authored-by: Christian Becke Co-authored-by: Nicholas Devenish --- newsfragments/626.feature | 1 + src/dxtbx/format/FormatCBFMini.py | 15 +++++++++++++++ src/dxtbx/format/FormatCBFMiniEigerPetraP14.py | 13 ++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 newsfragments/626.feature diff --git a/newsfragments/626.feature b/newsfragments/626.feature new file mode 100644 index 000000000..c28cc4293 --- /dev/null +++ b/newsfragments/626.feature @@ -0,0 +1 @@ +Update Format handling to reflect move of Eiger detector from PETRA P14 to P13. diff --git a/src/dxtbx/format/FormatCBFMini.py b/src/dxtbx/format/FormatCBFMini.py index 4561665fd..39060f84a 100644 --- a/src/dxtbx/format/FormatCBFMini.py +++ b/src/dxtbx/format/FormatCBFMini.py @@ -8,6 +8,7 @@ from __future__ import annotations import binascii +import datetime import os import pathlib import sys @@ -73,6 +74,20 @@ def __init__(self, image_file, **kwargs): self._raw_data = None super().__init__(image_file, **kwargs) + @staticmethod + def _get_timestamp_from_raw_header( + header: str | list[str], + ) -> datetime.datetime | None: + """Given a raw header, or lines from, attempt to extract the timestamp field""" + if isinstance(header, str): + header = header.splitlines() + timestamp = None + for record in header: + if len(record[1:].split()) <= 2 and record.count(":") == 2: + timestamp = datetime.datetime.fromisoformat(record[1:].strip()) + break + return timestamp + def _start(self): """Open the image file, read the image header, copy it into a dictionary for future reference.""" diff --git a/src/dxtbx/format/FormatCBFMiniEigerPetraP14.py b/src/dxtbx/format/FormatCBFMiniEigerPetraP14.py index 530948590..36b5cce91 100644 --- a/src/dxtbx/format/FormatCBFMiniEigerPetraP14.py +++ b/src/dxtbx/format/FormatCBFMiniEigerPetraP14.py @@ -3,6 +3,7 @@ from __future__ import annotations +import datetime import sys from dxtbx.format.FormatCBFMiniEiger import FormatCBFMiniEiger @@ -19,11 +20,21 @@ def understand(image_file): header = FormatCBFMiniEiger.get_cbf_header(image_file) + # Valid from 22nd May 2021 + expected_serial = "E-32-0129" + if timestamp := FormatCBFMiniEiger._get_timestamp_from_raw_header(header): + # We have a timestamp. Let's see what detector we should expect + + # Before 22nd May 2021 + if timestamp < datetime.datetime(2021, 5, 22): + expected_serial = "E-32-0107" + + # Find the line recording detector serial, and check for record in header.split("\n"): if ( "# detector" in record.lower() and "eiger" in record.lower() - and "E-32-0107" in record + and expected_serial in record ): return True