Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into 716_full_grid_scan_sets_transmission_first
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicOram committed Jul 12, 2023
2 parents 5c31570 + 0b83859 commit 329a9e0
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 32 deletions.
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ install_requires =
xarray
doct
databroker
dodal @ git+https://github.com/DiamondLightSource/python-dodal.git@4337a5f797dd7e75122f05aad946ae71fe4bcf46
dodal @ git+https://github.com/DiamondLightSource/python-dodal.git@3106d1f2e4f97bde92720d115c8fbb827ad374b1
pydantic<2.0 # See https://github.com/DiamondLightSource/python-artemis/issues/774


[options.extras_require]
dev =
GitPython
Expand Down
8 changes: 1 addition & 7 deletions src/artemis/device_setup_plans/setup_oav.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@
from artemis.log import LOGGER


def start_mxsc(oav: OAV, input_plugin, min_callback_time, filename):
def start_mxsc(oav: OAV, min_callback_time, filename):
"""
Sets PVs relevant to edge detection plugin.
Args:
input_plugin: link to the camera stream
min_callback_time: the value to set the minimum callback time to
filename: filename of the python script to detect edge waveforms from camera stream.
Returns: None
"""
yield from bps.abs_set(oav.mxsc.input_plugin, input_plugin)

# Turns the area detector plugin on
yield from bps.abs_set(oav.mxsc.enable_callbacks, 1)

Expand Down Expand Up @@ -82,13 +79,10 @@ def pre_centring_setup_oav(oav: OAV, parameters: OAVParameters):
# Connect MXSC output to MJPG input
yield from start_mxsc(
oav,
parameters.input_plugin + "." + parameters.mxsc_input,
parameters.min_callback_time,
parameters.detection_script_filename,
)

yield from bps.abs_set(oav.snapshot.input_plugin, parameters.input_plugin + ".CAM")

zoom_level_str = f"{float(parameters.zoom)}x"
if zoom_level_str not in oav.zoom_controller.allowed_zoom_levels:
raise OAVError_ZoomLevelNotFound(
Expand Down
28 changes: 23 additions & 5 deletions src/artemis/experiment_plans/full_grid_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,14 @@ def wait_for_det_to_finish_moving(detector: DetectorMotion, timeout=120):
raise TimeoutError("Detector not finished moving")


def detect_grid_and_do_gridscan(
def start_arming_then_do_grid(
parameters: GridScanWithEdgeDetectInternalParameters,
attenuator: Attenuator,
backlight: Backlight,
eiger: EigerDetector,
aperture_scatterguard: ApertureScatterguard,
detector_motion: DetectorMotion,
oav_params: OAVParameters,
experiment_params: GridScanWithEdgeDetectParams,
):
# Start stage with asynchronous arming here
yield from bps.abs_set(eiger.do_arm, 1, group="ready_for_data_collection")
Expand All @@ -83,6 +82,27 @@ def detect_grid_and_do_gridscan(
parameters.artemis_params.ispyb_params.transmission,
group="ready_for_data_collection",
)

yield from bpp.finalize_wrapper(
detect_grid_and_do_gridscan(
parameters,
backlight,
aperture_scatterguard,
detector_motion,
oav_params,
),
bps.unstage(eiger),
)


def detect_grid_and_do_gridscan(
parameters: GridScanWithEdgeDetectInternalParameters,
backlight: Backlight,
aperture_scatterguard: ApertureScatterguard,
detector_motion: DetectorMotion,
oav_params: OAVParameters,
):
experiment_params: GridScanWithEdgeDetectParams = parameters.experiment_params
fgs_params = GridScanParams(dwell_time=experiment_params.exposure_time * 1000)

detector_params = parameters.artemis_params.detector_params
Expand Down Expand Up @@ -163,15 +183,13 @@ def get_plan(
eiger.set_detector_parameters(parameters.artemis_params.detector_params)

oav_params = OAVParameters("xrayCentring", **oav_param_files)
experiment_params: GridScanWithEdgeDetectParams = parameters.experiment_params

return detect_grid_and_do_gridscan(
return start_arming_then_do_grid(
parameters,
attenuator,
backlight,
eiger,
aperture_scatterguard,
detector_motion,
oav_params,
experiment_params,
)
5 changes: 2 additions & 3 deletions src/artemis/experiment_plans/oav_grid_detection_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def grid_detection_plan(
width,
box_size_microns,
),
reset_oav(parameters),
reset_oav(),
)


Expand Down Expand Up @@ -207,7 +207,6 @@ def grid_detection_main_plan(
out_parameters.z_step_size = box_size_um / 1000


def reset_oav(parameters: OAVParameters):
def reset_oav():
oav = i03.oav()
yield from bps.abs_set(oav.snapshot.input_plugin, parameters.input_plugin + ".CAM")
yield from bps.abs_set(oav.mxsc.enable_callbacks, 0)
5 changes: 0 additions & 5 deletions src/artemis/experiment_plans/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@ def eiger():
return i03.eiger(fake_with_ophyd_sim=True)


@pytest.fixture
def attenuator():
return i03.attenuator(fake_with_ophyd_sim=True)


@pytest.fixture
def smargon():
smargon = i03.smargon(fake_with_ophyd_sim=True)
Expand Down
75 changes: 64 additions & 11 deletions src/artemis/experiment_plans/tests/test_full_grid_scan_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from bluesky import RunEngine
from dodal.beamlines.i03 import detector_motion
from dodal.devices.aperturescatterguard import AperturePositions, ApertureScatterguard
from dodal.devices.attenuator import Attenuator
from dodal.devices.backlight import Backlight
from dodal.devices.detector_motion import DetectorMotion
from dodal.devices.eiger import EigerDetector
Expand All @@ -15,6 +14,7 @@
create_devices,
detect_grid_and_do_gridscan,
get_plan,
start_arming_then_do_grid,
wait_for_det_to_finish_moving,
)
from artemis.parameters.plan_specific.grid_scan_with_edge_detect_params import (
Expand Down Expand Up @@ -94,10 +94,8 @@ def test_detect_grid_and_do_gridscan(
mock_fast_grid_scan_plan: MagicMock,
mock_grid_detection_plan: MagicMock,
mock_wait_for_detector: MagicMock,
eiger: EigerDetector,
backlight: Backlight,
detector_motion: DetectorMotion,
attenuator: Attenuator,
aperture_scatterguard: ApertureScatterguard,
RE: RunEngine,
test_full_grid_scan_params: GridScanWithEdgeDetectInternalParameters,
Expand All @@ -108,7 +106,7 @@ def test_detect_grid_and_do_gridscan(
mock_oav_callback.out_upper_left = [[1, 1], [1, 1]]
mock_grid_detection_plan.side_effect = _fake_grid_detection

with patch.object(eiger.do_arm, "set", MagicMock()) as mock_eiger_set, patch.object(
with patch.object(
aperture_scatterguard, "set", MagicMock()
) as mock_aperture_scatterguard, patch(
"artemis.external_interaction.callbacks.fgs.fgs_callback_collection.FGSCallbackCollection.from_params",
Expand All @@ -117,19 +115,12 @@ def test_detect_grid_and_do_gridscan(
RE(
detect_grid_and_do_gridscan(
parameters=test_full_grid_scan_params,
attenuator=attenuator,
backlight=backlight,
eiger=eiger,
aperture_scatterguard=aperture_scatterguard,
detector_motion=detector_motion,
oav_params=OAVParameters("xrayCentring", **test_config_files),
experiment_params=test_full_grid_scan_params.experiment_params,
)
)

# Check detector was armed
mock_eiger_set.assert_called_once_with(1)

# Verify we called the grid detection plan
mock_grid_detection_plan.assert_called_once()

Expand All @@ -149,3 +140,65 @@ def test_detect_grid_and_do_gridscan(

# Check we called out to underlying fast grid scan plan
mock_fast_grid_scan_plan.assert_called_once_with(ANY, mock_subscriptions)


@patch("artemis.experiment_plans.full_grid_scan.grid_detection_plan")
@patch("artemis.experiment_plans.full_grid_scan.OavSnapshotCallback")
def test_grid_detection_running_when_exception_raised_then_eiger_unstaged(
mock_oav_callback: MagicMock,
mock_grid_detection_plan: MagicMock,
RE: RunEngine,
test_full_grid_scan_params: GridScanWithEdgeDetectInternalParameters,
mock_subscriptions: MagicMock,
test_config_files: Dict,
):
mock_grid_detection_plan.side_effect = Exception()
eiger: EigerDetector = MagicMock(spec=EigerDetector)

with patch(
"artemis.external_interaction.callbacks.fgs.fgs_callback_collection.FGSCallbackCollection.from_params",
return_value=mock_subscriptions,
):
with pytest.raises(Exception):
RE(
start_arming_then_do_grid(
parameters=test_full_grid_scan_params,
attenuator=MagicMock(),
backlight=MagicMock(),
eiger=eiger,
aperture_scatterguard=MagicMock(),
detector_motion=MagicMock(),
oav_params=OAVParameters("xrayCentring", **test_config_files),
)
)

# Check detector was armed
eiger.do_arm.set.assert_called_once_with(1)

eiger.unstage.assert_called_once()


@patch("artemis.experiment_plans.full_grid_scan.detect_grid_and_do_gridscan")
def test_when_start_arming_then_transmission_set(
mock_grid_detection_plan: MagicMock,
RE: RunEngine,
test_full_grid_scan_params: GridScanWithEdgeDetectInternalParameters,
test_config_files: Dict,
):
attenuator = MagicMock()
RE(
start_arming_then_do_grid(
parameters=test_full_grid_scan_params,
attenuator=attenuator,
backlight=MagicMock(),
eiger=MagicMock(),
aperture_scatterguard=MagicMock(),
detector_motion=MagicMock(),
oav_params=OAVParameters("xrayCentring", **test_config_files),
)
)

# Check transmission set
attenuator.set.assert_called_once_with(
test_full_grid_scan_params.artemis_params.ispyb_params.transmission
)

0 comments on commit 329a9e0

Please sign in to comment.