Skip to content

Commit

Permalink
Refactor panel positions of FormatISISSXD (cctbx#762)
Browse files Browse the repository at this point in the history
* Refactor panel positions of FormatISISSXD to account for differences depending on the date of data collection.
  • Loading branch information
toastisme authored Oct 2, 2024
1 parent 9cbe8d5 commit 2bde8b8
Show file tree
Hide file tree
Showing 2 changed files with 159 additions and 54 deletions.
1 change: 1 addition & 0 deletions newsfragments/762.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Refactor panel positions of FormatISISSXD to account for differences in panel positions depending on the date of data collection.
212 changes: 158 additions & 54 deletions src/dxtbx/format/FormatISISSXD.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down Expand Up @@ -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

0 comments on commit 2bde8b8

Please sign in to comment.