From e8c1b9fa9e87e6a831a460c587416f1dd7d8510c Mon Sep 17 00:00:00 2001 From: Robert Tuck Date: Mon, 29 Apr 2024 09:11:08 +0100 Subject: [PATCH] (DiamondLightSource/dodal#466) changes to support directory provider in panda * Change references from PandA to HDFPanda * Apply directory path from params --- setup.cfg | 2 +- .../device_setup_plans/setup_panda.py | 8 ++--- .../flyscan_xray_centre_plan.py | 4 +-- .../grid_detect_then_xray_centre_plan.py | 4 +-- .../panda_flyscan_xray_centre_plan.py | 5 +++ .../robot_load_then_centre_plan.py | 4 +-- .../test_panda_flyscan_xray_centre_plan.py | 35 +++++++++++++++++++ 7 files changed, 51 insertions(+), 11 deletions(-) diff --git a/setup.cfg b/setup.cfg index 7d09abc96..8b1ef4b29 100644 --- a/setup.cfg +++ b/setup.cfg @@ -33,7 +33,7 @@ install_requires = xarray doct databroker - dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@7ecd49eb11060a8528ed8b6d31e6c94179bdc2a3 + dls-dodal @ git+https://github.com/DiamondLightSource/dodal.git@aac89a96686218add67bbbcc80118f6e94f0bdc9 pydantic<2.0 # See https://github.com/DiamondLightSource/hyperion/issues/774 scipy pyzmq<25 # See https://github.com/DiamondLightSource/hyperion/issues/1103 diff --git a/src/hyperion/device_setup_plans/setup_panda.py b/src/hyperion/device_setup_plans/setup_panda.py index 7c84d801f..6d4c64918 100644 --- a/src/hyperion/device_setup_plans/setup_panda.py +++ b/src/hyperion/device_setup_plans/setup_panda.py @@ -5,7 +5,7 @@ from dodal.devices.panda_fast_grid_scan import PandAGridScanParams from ophyd_async.core import load_device from ophyd_async.panda import ( - PandA, + HDFPanda, SeqTable, SeqTableRow, SeqTrigger, @@ -109,7 +109,7 @@ def get_seq_table( def setup_panda_for_flyscan( - panda: PandA, + panda: HDFPanda, config_yaml_path: str, parameters: PandAGridScanParams, initial_x: float, @@ -123,7 +123,7 @@ def setup_panda_for_flyscan( created using ophyd_async.core.save_device() Args: - panda (PandA): The PandA Ophyd device + panda (HDFPanda): The PandA Ophyd device config_yaml_path (str): Path to the yaml file containing the desired PandA PVs parameters (PandAGridScanParams): Grid parameters initial_x (float): Motor positions at time of PandA setup @@ -177,7 +177,7 @@ def setup_panda_for_flyscan( yield from arm_panda_for_gridscan(panda) -def arm_panda_for_gridscan(panda: PandA, group="arm_panda_gridscan"): +def arm_panda_for_gridscan(panda: HDFPanda, group="arm_panda_gridscan"): yield from bps.abs_set(panda.seq[1].enable, Enabled.ENABLED.value, group=group) # type: ignore yield from bps.abs_set(panda.pulse[1].enable, Enabled.ENABLED.value, group=group) # type: ignore yield from bps.abs_set(panda.counter[1].enable, Enabled.ENABLED.value, group=group) # type: ignore diff --git a/src/hyperion/experiment_plans/flyscan_xray_centre_plan.py b/src/hyperion/experiment_plans/flyscan_xray_centre_plan.py index e24d57460..019f8e6fe 100755 --- a/src/hyperion/experiment_plans/flyscan_xray_centre_plan.py +++ b/src/hyperion/experiment_plans/flyscan_xray_centre_plan.py @@ -33,7 +33,7 @@ get_processing_result, ) from dodal.plans.check_topup import check_topup_and_wait_if_necessary -from ophyd_async.panda import PandA +from ophyd_async.panda import HDFPanda from hyperion.device_setup_plans.manipulate_sample import move_x_y_z from hyperion.device_setup_plans.read_hardware_for_setup import ( @@ -85,7 +85,7 @@ class FlyScanXRayCentreComposite: xbpm_feedback: XBPMFeedback zebra: Zebra zocalo: ZocaloResults - panda: PandA + panda: HDFPanda panda_fast_grid_scan: PandAFastGridScan robot: BartRobot diff --git a/src/hyperion/experiment_plans/grid_detect_then_xray_centre_plan.py b/src/hyperion/experiment_plans/grid_detect_then_xray_centre_plan.py index 446293cf2..69316958b 100644 --- a/src/hyperion/experiment_plans/grid_detect_then_xray_centre_plan.py +++ b/src/hyperion/experiment_plans/grid_detect_then_xray_centre_plan.py @@ -27,7 +27,7 @@ from dodal.devices.xbpm_feedback import XBPMFeedback from dodal.devices.zebra import Zebra from dodal.devices.zocalo import ZocaloResults -from ophyd_async.panda import PandA +from ophyd_async.panda import HDFPanda from hyperion.device_setup_plans.utils import ( start_preparing_data_collection_then_do_plan, @@ -88,7 +88,7 @@ class GridDetectThenXRayCentreComposite: xbpm_feedback: XBPMFeedback zebra: Zebra zocalo: ZocaloResults - panda: PandA + panda: HDFPanda panda_fast_grid_scan: PandAFastGridScan robot: BartRobot diff --git a/src/hyperion/experiment_plans/panda_flyscan_xray_centre_plan.py b/src/hyperion/experiment_plans/panda_flyscan_xray_centre_plan.py index 9089a0429..0e8f421ee 100755 --- a/src/hyperion/experiment_plans/panda_flyscan_xray_centre_plan.py +++ b/src/hyperion/experiment_plans/panda_flyscan_xray_centre_plan.py @@ -1,11 +1,13 @@ from __future__ import annotations +from pathlib import Path from typing import TYPE_CHECKING, Any, Union import bluesky.plan_stubs as bps import bluesky.preprocessors as bpp import numpy as np from blueapi.core import BlueskyContext, MsgGenerator +from dodal.common import udc_directory_provider from dodal.devices.panda_fast_grid_scan import ( set_fast_grid_scan_params as set_flyscan_params, ) @@ -194,6 +196,9 @@ def run_gridscan_and_move( time_between_x_steps_ms, ) + udc_directory_provider.set_directory( + Path(parameters.hyperion_params.detector_params.directory) + ) yield from setup_panda_for_flyscan( fgs_composite.panda, PANDA_SETUP_PATH, diff --git a/src/hyperion/experiment_plans/robot_load_then_centre_plan.py b/src/hyperion/experiment_plans/robot_load_then_centre_plan.py index dccd7096a..144ee73d8 100644 --- a/src/hyperion/experiment_plans/robot_load_then_centre_plan.py +++ b/src/hyperion/experiment_plans/robot_load_then_centre_plan.py @@ -31,7 +31,7 @@ from dodal.devices.xbpm_feedback import XBPMFeedback from dodal.devices.zebra import Zebra from dodal.devices.zocalo import ZocaloResults -from ophyd_async.panda import PandA +from ophyd_async.panda import HDFPanda from hyperion.device_setup_plans.utils import ( start_preparing_data_collection_then_do_plan, @@ -79,7 +79,7 @@ class RobotLoadThenCentreComposite: undulator: Undulator zebra: Zebra zocalo: ZocaloResults - panda: PandA + panda: HDFPanda panda_fast_grid_scan: PandAFastGridScan # SetEnergyComposite fields diff --git a/tests/unit_tests/experiment_plans/test_panda_flyscan_xray_centre_plan.py b/tests/unit_tests/experiment_plans/test_panda_flyscan_xray_centre_plan.py index 3c8e87158..9cebfa132 100644 --- a/tests/unit_tests/experiment_plans/test_panda_flyscan_xray_centre_plan.py +++ b/tests/unit_tests/experiment_plans/test_panda_flyscan_xray_centre_plan.py @@ -1,5 +1,6 @@ import random import types +from pathlib import Path from typing import Any, Tuple from unittest.mock import DEFAULT, MagicMock, call, patch @@ -470,6 +471,40 @@ def wrapped_run_gridscan_and_move(): call = app_to_comment.call_args_list[0] assert "Crystal 1: Strength 999999" in call.args[1] + @patch( + "dodal.devices.aperturescatterguard.ApertureScatterguard.set", + new=MagicMock(return_value=Status(done=True, success=True)), + ) + @patch( + "hyperion.experiment_plans.panda_flyscan_xray_centre_plan.move_x_y_z", + new=MagicMock(autospec=True), + ) + @patch( + "hyperion.experiment_plans.panda_flyscan_xray_centre_plan.setup_panda_for_flyscan", + new=MagicMock(autospec=True), + ) + @patch( + "hyperion.experiment_plans.panda_flyscan_xray_centre_plan.run_gridscan", + new=MagicMock(return_value=iter([])), + ) + @patch( + "hyperion.experiment_plans.panda_flyscan_xray_centre_plan.udc_directory_provider.set_directory", + autospec=True, + ) + def test_when_gridscan_run_panda_directory_applied( + self, + set_directory, + RE_with_subs: tuple[RunEngine, Any], + test_panda_fgs_params: PandAGridscanInternalParameters, + fake_fgs_composite: FlyScanXRayCentreComposite, + ): + RE_with_subs[0].subscribe(VerbosePlanExecutionLoggingCallback()) + RE_with_subs[0]( + run_gridscan_and_move(fake_fgs_composite, test_panda_fgs_params) + ) + expected_path = Path("/dls/i03/data/2023/cm33866-5/test_hyperion") + set_directory.assert_called_once_with(expected_path) + @patch( "hyperion.experiment_plans.panda_flyscan_xray_centre_plan.run_gridscan", autospec=True,