Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a method to get the detector centre with sub-pixel accuracy #201

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions extra_geom/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,23 @@ def _snapped(self):
self._snapped_cache = SnappedGeometry(modules, self, centre)
return self._snapped_cache

def centre(self, snapped=False):
"""Return the centre of the detector in (y, x) pixel coordinates.

Parameters
----------
snapped: bool, optional
By default the center will be returned with sub-pixel accuracy, but if
this parameter is True then the approximate rounded coordinates will
be returned.
"""
if snapped:
return self._snapped().centre

tile_corners = [t.corner_pos[:2] for t in
chain.from_iterable(self.modules)]
return -np.min(tile_corners, axis=0)[::-1] / self.pixel_size

@staticmethod
def split_tiles(module_data):
"""Split data from a detector module into tiles.
Expand Down
19 changes: 19 additions & 0 deletions extra_geom/tests/test_agipd_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,3 +249,22 @@ def test_to_pyfai_detector():
)
agipd_pyfai = geom.to_pyfai_detector()
assert isinstance(agipd_pyfai, pyFAI.detectors.Detector)


def test_centre():
geom = AGIPD_1MGeometry.from_quad_positions(
quad_pos=[(-525, 625), (-550, -10), (520, -160), (542.5, 475)]
)

snapped_centre = geom._snapped().centre
np.testing.assert_equal(geom.centre(), snapped_centre)
np.testing.assert_equal(geom.centre(snapped=True), snapped_centre)

dx = 0.5
dy = 0.25
# A positive upwards shift of the modules means a negative downwards shift
# of the detector centre.
new_geom = geom.offset((dx * geom.pixel_size, dy * geom.pixel_size))
new_centre = snapped_centre - [dy, dx]
np.testing.assert_equal(new_geom.centre(), new_centre)
np.testing.assert_equal(new_geom.centre(snapped=True), snapped_centre)