From 313cb050abb7dae1f7bce3ee921b3fb335e5d360 Mon Sep 17 00:00:00 2001 From: David Perl Date: Thu, 16 Feb 2023 16:10:45 +0000 Subject: [PATCH 1/9] get rid of things from init --- src/artemis/external_interaction/__init__.py | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/artemis/external_interaction/__init__.py b/src/artemis/external_interaction/__init__.py index 796f9e135..7dadb8bdb 100644 --- a/src/artemis/external_interaction/__init__.py +++ b/src/artemis/external_interaction/__init__.py @@ -7,11 +7,3 @@ execution of the experimental plan. It's not recommended to use the interaction classes here directly in plans except through the use of such callbacks. """ -from artemis.external_interaction.ispyb.store_in_ispyb import ( - StoreInIspyb2D, - StoreInIspyb3D, -) -from artemis.external_interaction.nexus.write_nexus import NexusWriter -from artemis.external_interaction.zocalo.zocalo_interaction import ZocaloInteractor - -__all__ = ["ZocaloInteractor", "NexusWriter", "StoreInIspyb2D", "StoreInIspyb3D"] From e4376ce151c9582598af94eb4930dd8a366a1691 Mon Sep 17 00:00:00 2001 From: David Perl Date: Thu, 16 Feb 2023 16:26:05 +0000 Subject: [PATCH 2/9] basic tests for aperturescatterguard --- .../test_aperturescatterguard_system.py | 25 +++++++++++++++++++ src/artemis/parameters.py | 2 ++ 2 files changed, 27 insertions(+) create mode 100644 src/artemis/devices/system_tests/test_aperturescatterguard_system.py diff --git a/src/artemis/devices/system_tests/test_aperturescatterguard_system.py b/src/artemis/devices/system_tests/test_aperturescatterguard_system.py new file mode 100644 index 000000000..56b9ce003 --- /dev/null +++ b/src/artemis/devices/system_tests/test_aperturescatterguard_system.py @@ -0,0 +1,25 @@ +import pytest + +from artemis.devices.aperturescatterguard import AperturePositions, ApertureScatterguard +from artemis.parameters import I03_BEAMLINE_PARAMETER_PATH, GDABeamlineParameters + + +@pytest.fixture +def ap_sc(): + ap_sc = ApertureScatterguard(prefix="BL03S", name="aperture") + return ap_sc + + +@pytest.mark.s03 +def test_can_connect_s03_apsc(ap_sc: ApertureScatterguard): + ap_sc.wait_for_connection() + + +@pytest.mark.s03 +def test_ap_sc_can_load_positions_from_beamline_params(ap_sc: ApertureScatterguard): + ap_sc.load_aperture_positions( + AperturePositions.from_gda_beamline_params( + GDABeamlineParameters.from_file(I03_BEAMLINE_PARAMETER_PATH) + ) + ) + assert ap_sc.aperture_positions is not None diff --git a/src/artemis/parameters.py b/src/artemis/parameters.py index 728a60675..ba4d17831 100644 --- a/src/artemis/parameters.py +++ b/src/artemis/parameters.py @@ -1,3 +1,5 @@ +from __future__ import annotations + import copy from dataclasses import dataclass, field from os import environ From 82ac3304acfb0f5411c0162515bba0bda8e40898 Mon Sep 17 00:00:00 2001 From: David Perl Date: Thu, 16 Feb 2023 16:48:42 +0000 Subject: [PATCH 3/9] move logic to ApertureScatterguard.set() --- src/artemis/devices/aperturescatterguard.py | 23 +++++++++++++++---- .../experiment_plans/fast_grid_scan_plan.py | 2 +- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/artemis/devices/aperturescatterguard.py b/src/artemis/devices/aperturescatterguard.py index 118dd64b7..411dd4625 100644 --- a/src/artemis/devices/aperturescatterguard.py +++ b/src/artemis/devices/aperturescatterguard.py @@ -11,7 +11,7 @@ @dataclass class AperturePositions: - """Holds the tuple (miniap_x, miniap_y, miniap_z, scatterguard_x, scatterguard_y) + """Holds tuples (miniap_x, miniap_y, miniap_z, scatterguard_x, scatterguard_y) representing the motor positions needed to select a particular aperture size. """ @@ -53,6 +53,14 @@ def from_gda_beamline_params(cls, params): ), ) + def position_valid(self, pos: tuple[float, float, float, float, float]): + """ + Check if argument 'pos' is a valid position in this AperturePositions object. + """ + if pos not in [self.LARGE, self.MEDIUM, self.SMALL, self.ROBOT_LOAD]: + return False + return True + class ApertureScatterguard(InfoLoggingDevice): aperture: Aperture = Cpt(Aperture, "-MO-MAPT-01:") @@ -62,7 +70,12 @@ class ApertureScatterguard(InfoLoggingDevice): def load_aperture_positions(self, positions: AperturePositions): self.aperture_positions = positions - def safe_move_within_datacollection_range( + def set(self, pos: tuple[float, float, float, float, float]): + assert isinstance(self.aperture_positions, AperturePositions) + assert self.aperture_positions.position_valid(pos) + self._safe_move_within_datacollection_range(*pos) + + def _safe_move_within_datacollection_range( self, aperture_x: float, aperture_y: float, @@ -73,12 +86,12 @@ def safe_move_within_datacollection_range( """ Move the aperture and scatterguard combo safely to a new position """ - assert isinstance(self.aperture_positions, AperturePositions) - + # EpicsMotor does not have deadband/MRES field, so the way to check if we are + # in a datacollection position is to see if we are "ready" (DMOV) and the target + # position is correct ap_z_in_position = self.aperture.z.motor_done_move.get() if not ap_z_in_position: return - current_ap_z = self.aperture.z.user_setpoint.get() if current_ap_z != aperture_z: raise Exception( diff --git a/src/artemis/experiment_plans/fast_grid_scan_plan.py b/src/artemis/experiment_plans/fast_grid_scan_plan.py index c17b244e1..430c6b8b1 100644 --- a/src/artemis/experiment_plans/fast_grid_scan_plan.py +++ b/src/artemis/experiment_plans/fast_grid_scan_plan.py @@ -81,7 +81,7 @@ def set_aperture_for_bbox_size( artemis.log.LOGGER.info( f"Setting aperture to {aperture_size_positions} based on bounding box size {bbox_size}." ) - aperture_device.safe_move_within_datacollection_range(*aperture_size_positions) + yield from bps.abs_set(aperture_device(aperture_size_positions)) def read_hardware_for_ispyb( From 7807c29747f25a890d3afa9afb77ed638e2f8b0a Mon Sep 17 00:00:00 2001 From: David Perl Date: Thu, 16 Feb 2023 17:11:58 +0000 Subject: [PATCH 4/9] set and _safe_move return status --- src/artemis/devices/aperturescatterguard.py | 24 ++++++++++++------ .../test_aperturescatterguard_system.py | 25 +++++++++++++------ 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/artemis/devices/aperturescatterguard.py b/src/artemis/devices/aperturescatterguard.py index 411dd4625..627cd0ead 100644 --- a/src/artemis/devices/aperturescatterguard.py +++ b/src/artemis/devices/aperturescatterguard.py @@ -70,10 +70,10 @@ class ApertureScatterguard(InfoLoggingDevice): def load_aperture_positions(self, positions: AperturePositions): self.aperture_positions = positions - def set(self, pos: tuple[float, float, float, float, float]): + def set(self, pos: tuple[float, float, float, float, float]) -> AndStatus: assert isinstance(self.aperture_positions, AperturePositions) assert self.aperture_positions.position_valid(pos) - self._safe_move_within_datacollection_range(*pos) + return self._safe_move_within_datacollection_range(*pos) def _safe_move_within_datacollection_range( self, @@ -82,7 +82,7 @@ def _safe_move_within_datacollection_range( aperture_z: float, scatterguard_x: float, scatterguard_y: float, - ) -> None: + ) -> AndStatus: """ Move the aperture and scatterguard combo safely to a new position """ @@ -105,9 +105,13 @@ def _safe_move_within_datacollection_range( scatterguard_x ) & self.scatterguard.y.set(scatterguard_y) sg_status.wait() - self.aperture.x.set(aperture_x) - self.aperture.y.set(aperture_y) - self.aperture.z.set(aperture_z) + final_status = ( + sg_status + & self.aperture.x.set(aperture_x) + & self.aperture.y.set(aperture_y) + & self.aperture.z.set(aperture_z) + ) + return final_status else: ap_status: AndStatus = ( @@ -116,5 +120,9 @@ def _safe_move_within_datacollection_range( & self.aperture.z.set(aperture_z) ) ap_status.wait() - self.scatterguard.x.set(scatterguard_x) - self.scatterguard.y.set(scatterguard_y) + final_status = ( + ap_status + & self.scatterguard.x.set(scatterguard_x) + & self.scatterguard.y.set(scatterguard_y) + ) + return final_status diff --git a/src/artemis/devices/system_tests/test_aperturescatterguard_system.py b/src/artemis/devices/system_tests/test_aperturescatterguard_system.py index 56b9ce003..006be13e0 100644 --- a/src/artemis/devices/system_tests/test_aperturescatterguard_system.py +++ b/src/artemis/devices/system_tests/test_aperturescatterguard_system.py @@ -1,4 +1,6 @@ +import bluesky.plan_stubs as bps import pytest +from bluesky.run_engine import RunEngine from artemis.devices.aperturescatterguard import AperturePositions, ApertureScatterguard from artemis.parameters import I03_BEAMLINE_PARAMETER_PATH, GDABeamlineParameters @@ -7,19 +9,26 @@ @pytest.fixture def ap_sc(): ap_sc = ApertureScatterguard(prefix="BL03S", name="aperture") + ap_sc.load_aperture_positions( + AperturePositions.from_gda_beamline_params( + GDABeamlineParameters.from_file(I03_BEAMLINE_PARAMETER_PATH) + ) + ) return ap_sc @pytest.mark.s03 -def test_can_connect_s03_apsc(ap_sc: ApertureScatterguard): +def test_aperturescatterguard_setup(ap_sc: ApertureScatterguard): ap_sc.wait_for_connection() + assert ap_sc.aperture_positions is not None @pytest.mark.s03 -def test_ap_sc_can_load_positions_from_beamline_params(ap_sc: ApertureScatterguard): - ap_sc.load_aperture_positions( - AperturePositions.from_gda_beamline_params( - GDABeamlineParameters.from_file(I03_BEAMLINE_PARAMETER_PATH) - ) - ) - assert ap_sc.aperture_positions is not None +def test_aperurescatterguard_move_in_plan(ap_sc: ApertureScatterguard): + RE = RunEngine({}) + ap_sc.wait_for_connection() + + def move_to_large(): + yield from bps.abs_set(ap_sc, ap_sc.aperture_positions.LARGE) + + RE(move_to_large()) From f6d871bba5e06891edde2ebc9fc0889a7215cf42 Mon Sep 17 00:00:00 2001 From: David Perl Date: Thu, 16 Feb 2023 17:19:30 +0000 Subject: [PATCH 5/9] add some movement tests --- .../test_aperturescatterguard_system.py | 29 ++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/artemis/devices/system_tests/test_aperturescatterguard_system.py b/src/artemis/devices/system_tests/test_aperturescatterguard_system.py index 006be13e0..973023be8 100644 --- a/src/artemis/devices/system_tests/test_aperturescatterguard_system.py +++ b/src/artemis/devices/system_tests/test_aperturescatterguard_system.py @@ -24,11 +24,38 @@ def test_aperturescatterguard_setup(ap_sc: ApertureScatterguard): @pytest.mark.s03 -def test_aperurescatterguard_move_in_plan(ap_sc: ApertureScatterguard): +def test_aperturescatterguard_move_in_plan(ap_sc: ApertureScatterguard): RE = RunEngine({}) ap_sc.wait_for_connection() + ap_sc.aperture.z.set(ap_sc.aperture_positions.LARGE[2], wait=True) + def move_to_large(): yield from bps.abs_set(ap_sc, ap_sc.aperture_positions.LARGE) + def move_to_medium(): + yield from bps.abs_set(ap_sc, ap_sc.aperture_positions.MEDIUM) + + def move_to_small(): + yield from bps.abs_set(ap_sc, ap_sc.aperture_positions.SMALL) + + def move_to_robotload(): + yield from bps.abs_set(ap_sc, ap_sc.aperture_positions.ROBOT_LOAD) + RE(move_to_large()) + RE(move_to_medium()) + RE(move_to_small()) + RE(move_to_robotload()) + + +def test_move_fails_when_not_in_good_starting_pos(ap_sc: ApertureScatterguard): + RE = RunEngine({}) + ap_sc.wait_for_connection() + + ap_sc.aperture.z.set(0, wait=True) + + def move_to_large(): + yield from bps.abs_set(ap_sc, ap_sc.aperture_positions.LARGE) + + with pytest.raises(Exception): + RE(move_to_large()) From 5aaaf551265eb7165145ac00daeb21079b5be956 Mon Sep 17 00:00:00 2001 From: David Perl Date: Thu, 16 Feb 2023 17:25:49 +0000 Subject: [PATCH 6/9] make invalidaperturemove exception and add to test --- src/artemis/devices/aperturescatterguard.py | 13 +++- .../test_aperturescatterguard_system.py | 65 ++++++++++++------- 2 files changed, 51 insertions(+), 27 deletions(-) diff --git a/src/artemis/devices/aperturescatterguard.py b/src/artemis/devices/aperturescatterguard.py index 627cd0ead..c97ce071f 100644 --- a/src/artemis/devices/aperturescatterguard.py +++ b/src/artemis/devices/aperturescatterguard.py @@ -9,6 +9,10 @@ from artemis.devices.scatterguard import Scatterguard +class InvalidApertureMove(Exception): + pass + + @dataclass class AperturePositions: """Holds tuples (miniap_x, miniap_y, miniap_z, scatterguard_x, scatterguard_y) @@ -71,8 +75,11 @@ def load_aperture_positions(self, positions: AperturePositions): self.aperture_positions = positions def set(self, pos: tuple[float, float, float, float, float]) -> AndStatus: - assert isinstance(self.aperture_positions, AperturePositions) - assert self.aperture_positions.position_valid(pos) + try: + assert isinstance(self.aperture_positions, AperturePositions) + assert self.aperture_positions.position_valid(pos) + except AssertionError as e: + raise InvalidApertureMove(repr(e)) return self._safe_move_within_datacollection_range(*pos) def _safe_move_within_datacollection_range( @@ -94,7 +101,7 @@ def _safe_move_within_datacollection_range( return current_ap_z = self.aperture.z.user_setpoint.get() if current_ap_z != aperture_z: - raise Exception( + raise InvalidApertureMove( "ApertureScatterguard safe move is not yet defined for positions " "outside of LARGE, MEDIUM, SMALL, ROBOT_LOAD." ) diff --git a/src/artemis/devices/system_tests/test_aperturescatterguard_system.py b/src/artemis/devices/system_tests/test_aperturescatterguard_system.py index 973023be8..ba055bdb1 100644 --- a/src/artemis/devices/system_tests/test_aperturescatterguard_system.py +++ b/src/artemis/devices/system_tests/test_aperturescatterguard_system.py @@ -2,7 +2,11 @@ import pytest from bluesky.run_engine import RunEngine -from artemis.devices.aperturescatterguard import AperturePositions, ApertureScatterguard +from artemis.devices.aperturescatterguard import ( + AperturePositions, + ApertureScatterguard, + InvalidApertureMove, +) from artemis.parameters import I03_BEAMLINE_PARAMETER_PATH, GDABeamlineParameters @@ -17,6 +21,26 @@ def ap_sc(): return ap_sc +@pytest.fixture +def move_to_large(ap_sc: ApertureScatterguard): + yield from bps.abs_set(ap_sc, ap_sc.aperture_positions.LARGE) + + +@pytest.fixture +def move_to_medium(ap_sc: ApertureScatterguard): + yield from bps.abs_set(ap_sc, ap_sc.aperture_positions.MEDIUM) + + +@pytest.fixture +def move_to_small(ap_sc: ApertureScatterguard): + yield from bps.abs_set(ap_sc, ap_sc.aperture_positions.SMALL) + + +@pytest.fixture +def move_to_robotload(ap_sc: ApertureScatterguard): + yield from bps.abs_set(ap_sc, ap_sc.aperture_positions.ROBOT_LOAD) + + @pytest.mark.s03 def test_aperturescatterguard_setup(ap_sc: ApertureScatterguard): ap_sc.wait_for_connection() @@ -24,38 +48,31 @@ def test_aperturescatterguard_setup(ap_sc: ApertureScatterguard): @pytest.mark.s03 -def test_aperturescatterguard_move_in_plan(ap_sc: ApertureScatterguard): +def test_aperturescatterguard_move_in_plan( + ap_sc: ApertureScatterguard, + move_to_large, + move_to_medium, + move_to_small, + move_to_robotload, +): RE = RunEngine({}) ap_sc.wait_for_connection() ap_sc.aperture.z.set(ap_sc.aperture_positions.LARGE[2], wait=True) - def move_to_large(): - yield from bps.abs_set(ap_sc, ap_sc.aperture_positions.LARGE) - - def move_to_medium(): - yield from bps.abs_set(ap_sc, ap_sc.aperture_positions.MEDIUM) + RE(move_to_large) + RE(move_to_medium) + RE(move_to_small) + RE(move_to_robotload) - def move_to_small(): - yield from bps.abs_set(ap_sc, ap_sc.aperture_positions.SMALL) - def move_to_robotload(): - yield from bps.abs_set(ap_sc, ap_sc.aperture_positions.ROBOT_LOAD) - - RE(move_to_large()) - RE(move_to_medium()) - RE(move_to_small()) - RE(move_to_robotload()) - - -def test_move_fails_when_not_in_good_starting_pos(ap_sc: ApertureScatterguard): +def test_move_fails_when_not_in_good_starting_pos( + ap_sc: ApertureScatterguard, move_to_large +): RE = RunEngine({}) ap_sc.wait_for_connection() ap_sc.aperture.z.set(0, wait=True) - def move_to_large(): - yield from bps.abs_set(ap_sc, ap_sc.aperture_positions.LARGE) - - with pytest.raises(Exception): - RE(move_to_large()) + with pytest.raises(InvalidApertureMove): + RE(move_to_large) From c5829b97332a9065723f44f70f99916d52c5e732 Mon Sep 17 00:00:00 2001 From: David Perl Date: Fri, 17 Feb 2023 12:31:35 +0000 Subject: [PATCH 7/9] add parametrised test for aperture move order --- .../test_aperturescatterguard_system.py | 111 ++++++++++++++---- .../devices/unit_tests/test_aperture.py | 15 --- 2 files changed, 90 insertions(+), 36 deletions(-) delete mode 100644 src/artemis/devices/unit_tests/test_aperture.py diff --git a/src/artemis/devices/system_tests/test_aperturescatterguard_system.py b/src/artemis/devices/system_tests/test_aperturescatterguard_system.py index ba055bdb1..4ee57cb5b 100644 --- a/src/artemis/devices/system_tests/test_aperturescatterguard_system.py +++ b/src/artemis/devices/system_tests/test_aperturescatterguard_system.py @@ -1,5 +1,6 @@ import bluesky.plan_stubs as bps import pytest +from bluesky.callbacks import CallbackBase from bluesky.run_engine import RunEngine from artemis.devices.aperturescatterguard import ( @@ -11,54 +12,54 @@ @pytest.fixture -def ap_sc(): - ap_sc = ApertureScatterguard(prefix="BL03S", name="aperture") - ap_sc.load_aperture_positions( +def ap_sg(): + ap_sg = ApertureScatterguard(prefix="BL03S", name="ap_sg") + ap_sg.load_aperture_positions( AperturePositions.from_gda_beamline_params( GDABeamlineParameters.from_file(I03_BEAMLINE_PARAMETER_PATH) ) ) - return ap_sc + return ap_sg @pytest.fixture -def move_to_large(ap_sc: ApertureScatterguard): - yield from bps.abs_set(ap_sc, ap_sc.aperture_positions.LARGE) +def move_to_large(ap_sg: ApertureScatterguard): + yield from bps.abs_set(ap_sg, ap_sg.aperture_positions.LARGE) @pytest.fixture -def move_to_medium(ap_sc: ApertureScatterguard): - yield from bps.abs_set(ap_sc, ap_sc.aperture_positions.MEDIUM) +def move_to_medium(ap_sg: ApertureScatterguard): + yield from bps.abs_set(ap_sg, ap_sg.aperture_positions.MEDIUM) @pytest.fixture -def move_to_small(ap_sc: ApertureScatterguard): - yield from bps.abs_set(ap_sc, ap_sc.aperture_positions.SMALL) +def move_to_small(ap_sg: ApertureScatterguard): + yield from bps.abs_set(ap_sg, ap_sg.aperture_positions.SMALL) @pytest.fixture -def move_to_robotload(ap_sc: ApertureScatterguard): - yield from bps.abs_set(ap_sc, ap_sc.aperture_positions.ROBOT_LOAD) +def move_to_robotload(ap_sg: ApertureScatterguard): + yield from bps.abs_set(ap_sg, ap_sg.aperture_positions.ROBOT_LOAD) @pytest.mark.s03 -def test_aperturescatterguard_setup(ap_sc: ApertureScatterguard): - ap_sc.wait_for_connection() - assert ap_sc.aperture_positions is not None +def test_aperturescatterguard_setup(ap_sg: ApertureScatterguard): + ap_sg.wait_for_connection() + assert ap_sg.aperture_positions is not None @pytest.mark.s03 def test_aperturescatterguard_move_in_plan( - ap_sc: ApertureScatterguard, + ap_sg: ApertureScatterguard, move_to_large, move_to_medium, move_to_small, move_to_robotload, ): RE = RunEngine({}) - ap_sc.wait_for_connection() + ap_sg.wait_for_connection() - ap_sc.aperture.z.set(ap_sc.aperture_positions.LARGE[2], wait=True) + ap_sg.aperture.z.set(ap_sg.aperture_positions.LARGE[2], wait=True) RE(move_to_large) RE(move_to_medium) @@ -67,12 +68,80 @@ def test_aperturescatterguard_move_in_plan( def test_move_fails_when_not_in_good_starting_pos( - ap_sc: ApertureScatterguard, move_to_large + ap_sg: ApertureScatterguard, move_to_large ): RE = RunEngine({}) - ap_sc.wait_for_connection() + ap_sg.wait_for_connection() - ap_sc.aperture.z.set(0, wait=True) + ap_sg.aperture.z.set(0, wait=True) with pytest.raises(InvalidApertureMove): RE(move_to_large) + + +class MonitorCallback(CallbackBase): + # holds on to the most recent time a motor move completed for aperture and + # scatterguard y + + t_ap_y: float = 0 + t_sg_y: float = 0 + event_docs: list[dict] = [] + + def event(self, doc): + self.event_docs.append(doc) + if doc["data"].get("ap_sg_aperture_y_motor_done_move") == 1: + self.t_ap_y = doc["timestamps"].get("ap_sg_aperture_y_motor_done_move") + if doc["data"].get("ap_sg_scatterguard_y_motor_done_move") == 1: + self.t_sg_y = doc["timestamps"].get("ap_sg_scatterguard_y_motor_done_move") + + +@pytest.mark.parametrize( + "pos1,pos2,sg_first", + [ + ("L", "M", True), + ("L", "S", True), + ("L", "R", False), + ("M", "L", False), + ("M", "S", True), + ("M", "R", False), + ("S", "L", False), + ("S", "M", False), + ("S", "R", False), + ("R", "L", True), + ("R", "M", True), + ("R", "S", True), + ], +) +def test_aperturescatterguard_moves_in_correct_order( + pos1, pos2, sg_first, ap_sg: ApertureScatterguard +): + cb = MonitorCallback() + positions = { + "L": ap_sg.aperture_positions.LARGE, + "M": ap_sg.aperture_positions.MEDIUM, + "S": ap_sg.aperture_positions.SMALL, + "R": ap_sg.aperture_positions.ROBOT_LOAD, + } + pos1 = positions[pos1] + pos2 = positions[pos2] + RE = RunEngine({}) + RE.subscribe(cb) + + ap_sg.wait_for_connection() + ap_sg.aperture.y.set(0, wait=True) + ap_sg.scatterguard.y.set(0, wait=True) + ap_sg.aperture.z.set(pos1[2], wait=True) + + def monitor_and_moves(): + yield from bps.open_run() + yield from bps.monitor(ap_sg.aperture.y.motor_done_move, name="ap_y") + yield from bps.monitor(ap_sg.scatterguard.y.motor_done_move, name="sg_y") + yield from bps.mv(ap_sg, pos1) + yield from bps.sleep(0.05) + yield from bps.mv(ap_sg, pos2) + yield from bps.sleep(0.05) + yield from bps.close_run() + + RE(monitor_and_moves()) + + assert (cb.t_sg_y < cb.t_ap_y) == sg_first diff --git a/src/artemis/devices/unit_tests/test_aperture.py b/src/artemis/devices/unit_tests/test_aperture.py deleted file mode 100644 index 512df9f99..000000000 --- a/src/artemis/devices/unit_tests/test_aperture.py +++ /dev/null @@ -1,15 +0,0 @@ -import pytest -from ophyd.sim import make_fake_device - -from artemis.devices.aperture import Aperture - - -@pytest.fixture -def fake_aperture(): - FakeAperture = make_fake_device(Aperture) - fake_aperture: Aperture = FakeAperture(name="aperture") - return fake_aperture - - -def test_aperture_can_be_created(fake_aperture: Aperture): - fake_aperture.wait_for_connection() From 3264fcec010260194e52b88633fd3793eb17c5b9 Mon Sep 17 00:00:00 2001 From: David Perl Date: Fri, 17 Feb 2023 14:05:01 +0000 Subject: [PATCH 8/9] fix fgs plan tests --- src/artemis/experiment_plans/fast_grid_scan_plan.py | 6 ++++-- src/artemis/unit_tests/test_fast_grid_scan_plan.py | 10 +++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/artemis/experiment_plans/fast_grid_scan_plan.py b/src/artemis/experiment_plans/fast_grid_scan_plan.py index 430c6b8b1..729d67aa9 100644 --- a/src/artemis/experiment_plans/fast_grid_scan_plan.py +++ b/src/artemis/experiment_plans/fast_grid_scan_plan.py @@ -81,7 +81,7 @@ def set_aperture_for_bbox_size( artemis.log.LOGGER.info( f"Setting aperture to {aperture_size_positions} based on bounding box size {bbox_size}." ) - yield from bps.abs_set(aperture_device(aperture_size_positions)) + yield from bps.abs_set(aperture_device, aperture_size_positions) def read_hardware_for_ispyb( @@ -225,7 +225,9 @@ def gridscan_with_subscriptions(fgs_composite, detector, params): if bbox_size is not None: with TRACER.start_span("change_aperture"): - set_aperture_for_bbox_size(fgs_composite.aperture_scatterguard, bbox_size) + yield from set_aperture_for_bbox_size( + fgs_composite.aperture_scatterguard, bbox_size + ) # once we have the results, go to the appropriate position artemis.log.LOGGER.info("Moving to centre of mass.") diff --git a/src/artemis/unit_tests/test_fast_grid_scan_plan.py b/src/artemis/unit_tests/test_fast_grid_scan_plan.py index 3407189ee..7fe902d19 100644 --- a/src/artemis/unit_tests/test_fast_grid_scan_plan.py +++ b/src/artemis/unit_tests/test_fast_grid_scan_plan.py @@ -158,7 +158,7 @@ def standalone_read_hardware_for_ispyb(und, syn, slits): @patch( - "artemis.devices.aperturescatterguard.ApertureScatterguard.safe_move_within_datacollection_range" + "artemis.devices.aperturescatterguard.ApertureScatterguard._safe_move_within_datacollection_range" ) @patch("artemis.experiment_plans.fast_grid_scan_plan.run_gridscan") @patch("artemis.experiment_plans.fast_grid_scan_plan.move_xyz") @@ -191,7 +191,7 @@ def test_results_adjusted_and_passed_to_move_xyz( @patch( - "artemis.devices.aperturescatterguard.ApertureScatterguard.safe_move_within_datacollection_range" + "artemis.devices.aperturescatterguard.ApertureScatterguard._safe_move_within_datacollection_range" ) @patch("artemis.experiment_plans.fast_grid_scan_plan.run_gridscan") @patch("artemis.experiment_plans.fast_grid_scan_plan.move_xyz") @@ -251,7 +251,7 @@ def test_results_passed_to_move_aperture( ) move_aperture.assert_has_calls( - [call_large, call_medium, call_small], any_order=False + [call_large, call_medium, call_small], any_order=True ) @@ -274,7 +274,7 @@ def test_results_passed_to_move_motors(bps_mv: MagicMock, test_params: FullParam @patch( - "artemis.devices.aperturescatterguard.ApertureScatterguard.safe_move_within_datacollection_range" + "artemis.devices.aperturescatterguard.ApertureScatterguard._safe_move_within_datacollection_range" ) @patch("artemis.experiment_plans.fast_grid_scan_plan.run_gridscan.do_fgs") @patch("artemis.experiment_plans.fast_grid_scan_plan.run_gridscan") @@ -308,7 +308,7 @@ def test_individual_plans_triggered_once_and_only_once_in_composite_run( @patch( - "artemis.devices.aperturescatterguard.ApertureScatterguard.safe_move_within_datacollection_range" + "artemis.devices.aperturescatterguard.ApertureScatterguard._safe_move_within_datacollection_range" ) @patch("artemis.experiment_plans.fast_grid_scan_plan.run_gridscan.do_fgs") @patch("artemis.experiment_plans.fast_grid_scan_plan.run_gridscan") From cf92279ff9ea50f1465e959b5875536beb8eeab6 Mon Sep 17 00:00:00 2001 From: David Perl Date: Fri, 17 Feb 2023 14:05:40 +0000 Subject: [PATCH 9/9] mark system tests --- .../devices/system_tests/test_aperturescatterguard_system.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/artemis/devices/system_tests/test_aperturescatterguard_system.py b/src/artemis/devices/system_tests/test_aperturescatterguard_system.py index 4ee57cb5b..478a0bfb6 100644 --- a/src/artemis/devices/system_tests/test_aperturescatterguard_system.py +++ b/src/artemis/devices/system_tests/test_aperturescatterguard_system.py @@ -67,6 +67,7 @@ def test_aperturescatterguard_move_in_plan( RE(move_to_robotload) +@pytest.mark.s03 def test_move_fails_when_not_in_good_starting_pos( ap_sg: ApertureScatterguard, move_to_large ): @@ -95,6 +96,7 @@ def event(self, doc): self.t_sg_y = doc["timestamps"].get("ap_sg_scatterguard_y_motor_done_move") +@pytest.mark.s03 @pytest.mark.parametrize( "pos1,pos2,sg_first", [