From 2bde8b81548957c5d21457594a2b051eac9731e5 Mon Sep 17 00:00:00 2001 From: David McDonagh <60879630+toastisme@users.noreply.github.com> Date: Wed, 2 Oct 2024 23:11:44 +0100 Subject: [PATCH] Refactor panel positions of FormatISISSXD (#762) * Refactor panel positions of FormatISISSXD to account for differences depending on the date of data collection. --- newsfragments/762.bugfix | 1 + src/dxtbx/format/FormatISISSXD.py | 212 ++++++++++++++++++++++-------- 2 files changed, 159 insertions(+), 54 deletions(-) create mode 100644 newsfragments/762.bugfix diff --git a/newsfragments/762.bugfix b/newsfragments/762.bugfix new file mode 100644 index 000000000..f0030e44f --- /dev/null +++ b/newsfragments/762.bugfix @@ -0,0 +1 @@ +Refactor panel positions of FormatISISSXD to account for differences in panel positions depending on the date of data collection. diff --git a/src/dxtbx/format/FormatISISSXD.py b/src/dxtbx/format/FormatISISSXD.py index 549fe3064..e013e29d6 100644 --- a/src/dxtbx/format/FormatISISSXD.py +++ b/src/dxtbx/format/FormatISISSXD.py @@ -135,69 +135,163 @@ def _get_panel_trusted_range(self) -> Tuple[int, int]: def _get_panel_type(self) -> str: return "SENSOR_PAD" - def _panel_0_params(self): - if self._panel_0_flipped(): - return { - "slow_axis": (0.793, 0.0, 0.609), - "fast_axis": (0.0, -1.0, 0.0), - "origin": (60.81, 96.0, -236.946), - } - return { - "fast_axis": (-0.793, 0.0, -0.609), - "slow_axis": (0.0, 1.0, 0.0), - "origin": (213.099, -96.0, -120.041), - } - def _get_panel_origins(self) -> Tuple[Tuple[float, float, float]]: # (mm) - return ( - self._panel_0_params()["origin"], - (224.999, -96.0, 96.0), - (60.809, -96.0, 236.945), - (-214.172, -96.0, 118.198), - (-224.999, -96.0, -96.0), - (-60.809, -96.0, -236.945), - (127.534, -256.614, 96.0), - (-96.0, -256.614, 127.534), - (-123.036, -258.801, -96.0), - (96.0, -256.614, -127.534), - (96.0, -278.0, 96.0), - ) + + start_date = self.get_start_date() + assert start_date is not None + year, _, _ = start_date.split("-") + year = int(year) + if year < 2020: + return ( + (213.066, -96.0, -120.018), + (224.999, -96.0, 96.0), + (60.809, -96.0, 236.945), + (-214.172, -96.0, 118.198), + (-224.999, -96.0, -96.0), + (-60.809, -96.0, -236.945), + (127.534, -256.614, 96.0), + (-96.0, -256.614, 127.534), + (-123.036, -258.801, -96.0), + (96.0, -256.614, -127.534), + (96.0, -278.0, 96.0), + ) + + elif year < 2024: + return ( + (60.81, 96.0, -236.946), + (224.999, -96.0, 96.0), + (60.809, -96.0, 236.945), + (-214.172, -96.0, 118.198), + (-224.999, -96.0, -96.0), + (-60.809, -96.0, -236.945), + (127.534, -256.614, 96.0), + (-96.0, -256.614, 127.534), + (-123.036, -258.801, -96.0), + (96.0, -256.614, -127.534), + (96.0, -278.0, 96.0), + ) + else: + return ( + (60.81, 96.0, -236.946), + (224.999, 96.0, -96.0), + (213.065, 96.0, 120.017), + (-62.876000000000005, 96.0, 236.46999999999997), + (-224.999, 96.0, 96.0), + (-213.065, 96.0, -120.017), + (260.974, -118.56599999999997, -96.0), + (96.0, -118.56599999999997, 260.974), + (-258.78, -123.05699999999999, 96.0), + (-96.0, -118.56599999999997, -260.974), + (96.0, -278.0, 96.0), + ) def _panel_0_flipped(self) -> bool: - if self._nxs_file["raw_data_1"]["run_number"][0] > 30000: + start_date = self.get_start_date() + assert start_date is not None + year, _, _ = start_date.split("-") + if int(year) < 2024: return True return False def _get_panel_slow_axes(self) -> Tuple[Tuple[float, float, float]]: - return ( - self._panel_0_params()["slow_axis"], - (0.0, 1.0, 0.0), - (0.0, 1.0, 0.0), - (0.0, 1.0, 0.0), - (0.0, 1.0, 0.0), - (0.0, 1.0, 0.0), - (0.695, 0.719, -0.0), - (0.0, 0.719, 0.695), - (-0.707, 0.707, -0.0), - (0.0, 0.719, -0.695), - (-0.0, 0.0, -1.0), - ) + start_date = self.get_start_date() + assert start_date is not None + year, _, _ = start_date.split("-") + year = int(year) + if year < 2020: + return ( + (0.0, 1.0, 0.0), + (0.0, 1.0, 0.0), + (0.0, 1.0, 0.0), + (0.0, 1.0, 0.0), + (0.0, 1.0, 0.0), + (0.0, 1.0, 0.0), + (0.695, 0.719, -0.0), + (0.0, 0.719, 0.695), + (-0.707, 0.707, -0.0), + (0.0, 0.719, -0.695), + (-0.0, 0.0, -1.0), + ) + elif year < 2024: + return ( + (0.793, 0.0, 0.609), + (0.0, 1.0, 0.0), + (0.0, 1.0, 0.0), + (0.0, 1.0, 0.0), + (0.0, 1.0, 0.0), + (0.0, 1.0, 0.0), + (0.695, 0.719, -0.0), + (0.0, 0.719, 0.695), + (-0.707, 0.707, -0.0), + (0.0, 0.719, -0.695), + (-0.0, 0.0, -1.0), + ) + + else: + return ( + (0.0, -1.0, 0.0), + (0.0, -1.0, 0.0), + (0.0, -1.0, 0.0), + (0.0, -1.0, 0.0), + (0.0, -1.0, 0.0), + (0.0, -1.0, 0.0), + (-0.695, -0.719, 0.0), + (0.0, -0.719, -0.695), + (0.707, -0.707, 0.0), + (0.0, -0.719, 0.695), + (-0.0, 0.0, -1.0), + ) def _get_panel_fast_axes(self) -> Tuple[Tuple[float, float, float]]: - return ( - self._panel_0_params()["fast_axis"], - (-0.0, -0.0, -1.0), - (0.793, -0.0, -0.609), - (0.788, -0.0, 0.616), - (-0.0, -0.0, 1.0), - (-0.793, -0.0, 0.609), - (0.0, -0.0, -1.0), - (1.0, -0.0, -0.0), - (-0.0, -0.0, 1.0), - (-1.0, -0.0, -0.0), - (-1.0, -0.0, -0.0), - ) + start_date = self.get_start_date() + assert start_date is not None + year, _, _ = start_date.split("-") + year = int(year) + if year < 2020: + return ( + (-0.793, 0.0, -0.609), + (-0.0, -0.0, -1.0), + (0.793, -0.0, -0.609), + (0.788, -0.0, 0.616), + (-0.0, -0.0, 1.0), + (-0.793, -0.0, 0.609), + (0.0, -0.0, -1.0), + (1.0, -0.0, -0.0), + (-0.0, -0.0, 1.0), + (-1.0, -0.0, -0.0), + (-1.0, -0.0, -0.0), + ) + + elif year < 2024: + return ( + (0.0, -1.0, 0.0), + (-0.0, -0.0, -1.0), + (0.793, -0.0, -0.609), + (0.788, -0.0, 0.616), + (-0.0, -0.0, 1.0), + (-0.793, -0.0, 0.609), + (0.0, -0.0, -1.0), + (1.0, -0.0, -0.0), + (-0.0, -0.0, 1.0), + (-1.0, -0.0, -0.0), + (-1.0, -0.0, -0.0), + ) + + else: + return ( + (0.793, 0.0, 0.609), + (-0.0, -0.0, 1.0), + (-0.793, 0.0, 0.609), + (-0.788, 0.0, -0.616), + (0.0, 0.0, -1.0), + (0.793, 0.0, -0.609), + (0.0, 0.0, 1.0), + (-1.0, 0.0, 0.0), + (0.0, 0.0, -1.0), + (1.0, 0.0, 0.0), + (-1.0, 0.0, 0.0), + ) def _get_panel_projections_2d(self) -> dict: """ @@ -386,5 +480,15 @@ def get_flattened_pixel_data( tuple(self._nxs_file["raw_data_1/detector_1/counts"][0, idx, :].tolist()), ) - def get_proton_charge(self): + def get_proton_charge(self) -> float: return float(self._nxs_file["raw_data_1/proton_charge"][0]) + + def get_start_date(self) -> str: + """ + Date of experiment in YYYY-MM-DD format + """ + try: + raw_date = self._nxs_file["raw_data_1/start_time"][0].decode() + return raw_date.split("T")[0] + except IndexError: + return None