From 4ec49d5e97c709992f26f609399dfad9179056b8 Mon Sep 17 00:00:00 2001 From: Stanislaw Malinowski Date: Mon, 5 Aug 2024 16:37:49 +0000 Subject: [PATCH] move away from ophyd devices --- src/dodal/beamlines/i18.py | 28 ++++++++ src/dodal/beamlines/i22.py | 2 + src/dodal/devices/i18/sim_detector.py | 18 +++++ src/dodal/devices/i18/sim_motor_set.py | 88 ----------------------- src/dodal/devices/i18/sim_raster_stage.py | 11 +++ 5 files changed, 59 insertions(+), 88 deletions(-) create mode 100644 src/dodal/devices/i18/sim_detector.py delete mode 100644 src/dodal/devices/i18/sim_motor_set.py create mode 100644 src/dodal/devices/i18/sim_raster_stage.py diff --git a/src/dodal/beamlines/i18.py b/src/dodal/beamlines/i18.py index 92aa10417e..337a5632a2 100644 --- a/src/dodal/beamlines/i18.py +++ b/src/dodal/beamlines/i18.py @@ -1,3 +1,4 @@ +import os from pathlib import Path from ophyd_async.panda import HDFPanda @@ -13,6 +14,8 @@ from dodal.common.visit import DirectoryServiceClient, StaticVisitDirectoryProvider from dodal.devices.focusing_mirror import FocusingMirror from dodal.devices.i18.diode import Diode +from dodal.devices.i18.sim_detector import SimDetector +from dodal.devices.i18.sim_raster_stage import RasterStage from dodal.devices.i18.table import Table from dodal.devices.i22.dcm import DoubleCrystalMonochromator from dodal.devices.slits import Slits @@ -23,6 +26,9 @@ from dodal.log import set_beamline as set_log_beamline from dodal.utils import BeamlinePrefix, get_beamline_name, skip_device +# Make sure EPICS_CA_SERVER_PORT is set to correct value (6064 for DLS sim area detector and motors, 5064 on beamlines) +os.environ["EPICS_CA_SERVER_PORT"] = "6064" + BL = get_beamline_name("i18") set_log_beamline(BL) set_utils_beamline(BL) @@ -221,3 +227,25 @@ def table(wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False) - wait_for_connection, fake_with_ophyd_sim, ) + + +def raster_stage( + wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False +) -> RasterStage: + return device_instantiation( + RasterStage, + "raster_stage", + "-MO-SIM-01:", + wait_for_connection, + fake_with_ophyd_sim, + ) + + +def sim_detector(wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False): + return device_instantiation( + SimDetector, + "sim_detector", + "-MO-SIM-01:", + wait_for_connection, + fake_with_ophyd_sim, + ) diff --git a/src/dodal/beamlines/i22.py b/src/dodal/beamlines/i22.py index 8fbb67d92a..d573a794ab 100644 --- a/src/dodal/beamlines/i22.py +++ b/src/dodal/beamlines/i22.py @@ -158,6 +158,8 @@ def hfm( crystal_metadata = CrystalMetadata("Si111") + + def dcm( wait_for_connection: bool = True, fake_with_ophyd_sim: bool = False, diff --git a/src/dodal/devices/i18/sim_detector.py b/src/dodal/devices/i18/sim_detector.py new file mode 100644 index 0000000000..2e5d074814 --- /dev/null +++ b/src/dodal/devices/i18/sim_detector.py @@ -0,0 +1,18 @@ +from ophyd_async.epics.motion import Motor +from ophyd_async.sim import PatternGenerator + + +class SimDetector: + def __init__(self, name: str, motor: Motor, motor_field: str): + self.name = name + self.motor = motor + self.motor_field = motor_field + self.pattern_generator = PatternGenerator( + saturation_exposure_time=0.1, detector_height=100, detector_width=100 + ) + + def read(self): + return {self.name: {"value": self.pattern_generator}} + + def describe(self): + return {self.name: {"source": "synthetic", "dtype": "number"}} diff --git a/src/dodal/devices/i18/sim_motor_set.py b/src/dodal/devices/i18/sim_motor_set.py deleted file mode 100644 index e829cb5d33..0000000000 --- a/src/dodal/devices/i18/sim_motor_set.py +++ /dev/null @@ -1,88 +0,0 @@ -import os - -from ophyd import EpicsMotor -from ophyd.sim import Syn2DGauss, SynAxis, SynGauss - - -def create_epics_motor(motor_name="epics_motor", motor_base_pv="ws416-MO-SIM-01:M1"): - print(f"Creating Epics motor for {motor_base_pv}") - epics_motor = EpicsMotor(motor_base_pv, name=motor_name) - # epics_motor.wait_for_connection(timeout=5) # blueapi fails to connect any PVs! - return epics_motor - - -def create_dummy_motor(motor_name="dummy_motor"): - print(f"Creating dummy motor {motor_name}") - return SynAxis(name=motor_name, labels={"motors"}) - - -def create_syn_gaussian(det_name, motor, motor_field, noise="none", noise_multiplier=1): - print(f"Creating synthetic Gaussian detector {det_name}") - syn_gauss = SynGauss( - det_name, motor, motor_field, center=0, Imax=5, sigma=0.5, labels={"detectors"} - ) - syn_gauss.noise.put(noise) - syn_gauss.noise_multiplier.put(noise_multiplier) - return syn_gauss - - -def create_syn_2d_gaussian( - det_name, - motor1, - motor1_field, - motor2, - motor2_field, - noise="none", - noise_multiplier=1, -): - print(f"Creating synthetic 2d Gaussian detector {det_name}") - - syn_gauss = Syn2DGauss( - det_name, - motor1, - motor1_field, - motor2, - motor2_field, - center=0, - Imax=1, - labels={"detectors"}, - ) - syn_gauss.noise.put(noise) - syn_gauss.noise_multiplier.put(noise_multiplier) - return syn_gauss - - -dummy_mot1 = create_dummy_motor("dummy_motor1") -dummy_mot2 = create_dummy_motor("dummy_motor2") -dummy_mot1.delay = 0.05 - - -def dummy_motor1(name: str = "dummy_motor1") -> SynAxis: - return dummy_mot1 - - -def dummy_motor2(name: str = "dummy_motor2") -> SynAxis: - return dummy_mot2 - - -def sim_gauss_det(name: str = "sim_gauss_det") -> SynGauss: - return create_syn_gaussian(name, dummy_mot1, "dummy_motor1") - - -def sim_2d_gauss_det(name: str = "sim_2d_gauss_det") -> Syn2DGauss: - return create_syn_2d_gaussian( - name, dummy_mot1, "dummy_motor1", dummy_mot2, "dummy_motor2" - ) - - -# Make sure EPICS_CA_SERVER_PORT is set to correct value (6064 for DLS sim area detector and motors, 5064 on beamlines) -os.environ["EPICS_CA_SERVER_PORT"] = "6064" - - -# def sim_x(name : str, pv_name : str) -> EpicsMotor: -def sim_x(name: str = "sim_x", pv_name: str = "ws416-MO-SIM-01:M1") -> EpicsMotor: - return create_epics_motor(name, pv_name) - - -def sim_y(name: str = "sim_y", pv_name: str = "ws416-MO-SIM-01:M2") -> EpicsMotor: - return create_epics_motor(name, pv_name) diff --git a/src/dodal/devices/i18/sim_raster_stage.py b/src/dodal/devices/i18/sim_raster_stage.py new file mode 100644 index 0000000000..c2fc598bbe --- /dev/null +++ b/src/dodal/devices/i18/sim_raster_stage.py @@ -0,0 +1,11 @@ +from bluesky.protocols import Movable +from ophyd_async.core import StandardReadable +from ophyd_async.epics.motion import Motor + + +class RasterStage(StandardReadable, Movable): + def __init__(self, prefix: str, name: str = "") -> None: + with self.add_children_as_readables(): + self.offset_in_mm = Motor(prefix + "M1") + self.perp_in_mm = Motor(prefix + "M2") + super().__init__(name)