From ff658e830db271e41c22c0ed71743f9286214fb5 Mon Sep 17 00:00:00 2001 From: David Waterman Date: Mon, 26 Feb 2024 14:53:25 +0000 Subject: [PATCH 1/3] The xia2 tests show that single panel detectors can have a hierarchy too! (why?!) In such cases it seems that hierarchy is useless, and has origin at 0,0,0. When we have a single panel, ensure that it is the panel itself that has its distance updated. Only change the hierarchy for multi-panel detectors, where it is assumed that it has a sensible origin. --- src/dxtbx/model/detector_helpers.py | 47 ++++++++++++++--------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/src/dxtbx/model/detector_helpers.py b/src/dxtbx/model/detector_helpers.py index 3240caf7e..5810638d7 100644 --- a/src/dxtbx/model/detector_helpers.py +++ b/src/dxtbx/model/detector_helpers.py @@ -303,34 +303,31 @@ def set_detector_distance(detector, distance): """ Set detector origin from distance along normal """ - # If the detector has a hierarchy, just update the root note - try: - h = detector.hierarchy() - normal = matrix.col(h.get_normal()) - origin = matrix.col(h.get_origin()) + panels = list(detector) + if len(panels) > 1: + # If a multi-panel detector has a hierarchy, we will just update the + # root note. Otherwise check that all panels are at the same distance + # and share the same normal vector + try: + panels = [ + detector.hierarchy(), + ] + except AttributeError: + dists = [p.get_distance() for p in panels] + norm_vecs = [p.get_normal() for p in panels] + assert all(v == norm_vecs[0] for v in norm_vecs[1:]) and all( + d == dists[0] for d in dists + ) + + for panel in panels: + normal = matrix.col(panel.get_normal()) + origin = matrix.col(panel.get_origin()) d = origin.dot(normal) x = origin - d * normal origin = distance * normal + x - fast_axis = h.get_fast_axis() - slow_axis = h.get_slow_axis() - h.set_frame(fast_axis, slow_axis, origin) - except AttributeError: - # Check all panels are at the same distance and share the same normal - dists = [p.get_distance() for p in detector] - norm_vecs = [p.get_normal() for p in detector] - assert all(v == norm_vecs[0] for v in norm_vecs[1:]) and all( - d == dists[0] for d in dists - ) - - for panel in detector: - normal = matrix.col(panel.get_normal()) - origin = matrix.col(panel.get_origin()) - d = origin.dot(normal) - x = origin - d * normal - origin = distance * normal + x - fast_axis = panel.get_fast_axis() - slow_axis = panel.get_slow_axis() - panel.set_frame(fast_axis, slow_axis, origin) + fast_axis = panel.get_fast_axis() + slow_axis = panel.get_slow_axis() + panel.set_frame(fast_axis, slow_axis, origin) def get_detector_projection_2d_axes( From 531dfd51623b6f323bef42af4cd41027c9d62907 Mon Sep 17 00:00:00 2001 From: David Waterman Date: Mon, 26 Feb 2024 14:57:57 +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..66e598963 --- /dev/null +++ b/newsfragments/xxx.bugfix @@ -0,0 +1 @@ +Fix bug when setting the distance for single panel detectors that have a hierarchy. From babbcc361da54c52da6943bb366aff4f531b6cec Mon Sep 17 00:00:00 2001 From: DiamondLightSource-build-server Date: Mon, 26 Feb 2024 14:59:31 +0000 Subject: [PATCH 3/3] Rename newsfragments/xxx.bugfix to newsfragments/699.bugfix --- newsfragments/{xxx.bugfix => 699.bugfix} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename newsfragments/{xxx.bugfix => 699.bugfix} (100%) diff --git a/newsfragments/xxx.bugfix b/newsfragments/699.bugfix similarity index 100% rename from newsfragments/xxx.bugfix rename to newsfragments/699.bugfix