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

Fixes for ophyd-async 0.9.0a2 #1014

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ description = "Ophyd devices and other utils that could be used across DLS beaml
dependencies = [
"click",
"ophyd",
"ophyd-async == 0.9.0a1",
"ophyd-async >= 0.9.0a2",
"bluesky",
"pyepics",
"dataclasses-json",
Expand Down
2 changes: 1 addition & 1 deletion src/dodal/beamlines/adsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,5 @@ def det() -> SimDetector:
f"{PREFIX.beamline_prefix}-DI-CAM-01:",
path_provider=get_path_provider(),
drv_suffix="DET:",
hdf_suffix="HDF:",
fileio_suffix="HDF:",
)
2 changes: 1 addition & 1 deletion src/dodal/beamlines/b01_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ def manta() -> AravisDetector:
f"{PREFIX.beamline_prefix}-DI-DCAM-02:",
path_provider=get_path_provider(),
drv_suffix="CAM:",
hdf_suffix=HDF5_PREFIX,
fileio_suffix=HDF5_PREFIX,
)
4 changes: 2 additions & 2 deletions src/dodal/beamlines/i13_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def side_camera(
name="side_camera",
bl_prefix=False,
drv_suffix="CAM:",
hdf_suffix="HDF5:",
fileio_suffix="HDF5:",
path_provider=get_path_provider(),
wait=wait_for_connection,
fake=fake_with_ophyd_sim,
Expand All @@ -77,7 +77,7 @@ def merlin(
name="merlin",
bl_prefix=False,
drv_suffix="CAM:",
hdf_suffix="HDF5:",
fileio_suffix="HDF5:",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we at least be consistent about whether or not we are using HDF5_PREFIX?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've adjusted all of the existing beamlines to make use of it- and CAM_SUFFIX/DET_SUFFIX to at least make it clear we have 2 standards and absolutely for sure definitely never any more.

path_provider=get_path_provider(),
wait=wait_for_connection,
fake=fake_with_ophyd_sim,
Expand Down
6 changes: 3 additions & 3 deletions src/dodal/beamlines/i22.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def saxs() -> PilatusDetector:
prefix=f"{PREFIX.beamline_prefix}-EA-PILAT-01:",
path_provider=get_path_provider(),
drv_suffix="CAM:",
hdf_suffix=HDF5_PREFIX,
fileio_suffix=HDF5_PREFIX,
metadata_holder=metadata_holder,
)

Expand All @@ -89,7 +89,7 @@ def waxs() -> PilatusDetector:
prefix=f"{PREFIX.beamline_prefix}-EA-PILAT-03:",
path_provider=get_path_provider(),
drv_suffix="CAM:",
hdf_suffix=HDF5_PREFIX,
fileio_suffix=HDF5_PREFIX,
metadata_holder=metadata_holder,
)

Expand Down Expand Up @@ -249,7 +249,7 @@ def oav() -> AravisDetector:
return NXSasOAV(
prefix=f"{PREFIX.beamline_prefix}-DI-OAV-01:",
drv_suffix="DET:",
hdf_suffix=HDF5_PREFIX,
fileio_suffix=HDF5_PREFIX,
path_provider=get_path_provider(),
metadata_holder=metadata_holder,
)
Expand Down
6 changes: 3 additions & 3 deletions src/dodal/beamlines/p38.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def d3(
wait_for_connection,
fake_with_ophyd_sim,
drv_suffix="DET:",
hdf_suffix="HDF5:",
fileio_suffix="HDF5:",
path_provider=get_path_provider(),
)

Expand All @@ -72,7 +72,7 @@ def d11(
wait_for_connection,
fake_with_ophyd_sim,
drv_suffix="DET:",
hdf_suffix="HDF5:",
fileio_suffix="HDF5:",
path_provider=get_path_provider(),
)

Expand All @@ -87,7 +87,7 @@ def d12(
wait_for_connection,
fake_with_ophyd_sim,
drv_suffix="DET:",
hdf_suffix="HDF5:",
fileio_suffix="HDF5:",
path_provider=get_path_provider(),
)

Expand Down
4 changes: 2 additions & 2 deletions src/dodal/beamlines/p45.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def det(
wait_for_connection,
fake_with_ophyd_sim,
drv_suffix="DET:",
hdf_suffix="HDF5:",
fileio_suffix="HDF5:",
path_provider=get_path_provider(),
)

Expand All @@ -78,7 +78,7 @@ def diff(
wait_for_connection,
fake_with_ophyd_sim,
drv_suffix="DET:",
hdf_suffix="HDF5:",
fileio_suffix="HDF5:",
path_provider=get_path_provider(),
)

Expand Down
2 changes: 1 addition & 1 deletion src/dodal/beamlines/training_rig.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def det() -> AravisDetector:
f"{PREFIX.beamline_prefix}-EA-DET-01:",
path_provider=get_path_provider(),
drv_suffix="DET:",
hdf_suffix=HDF5_PREFIX,
fileio_suffix=HDF5_PREFIX,
)


Expand Down
4 changes: 2 additions & 2 deletions src/dodal/devices/i13_1/merlin.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ def __init__(
prefix: str,
path_provider: PathProvider,
drv_suffix="CAM:",
hdf_suffix="HDF:",
fileio_suffix="HDF:",
name: str = "",
):
self.drv = MerlinDriverIO(prefix + drv_suffix)
self.hdf = adcore.NDFileHDFIO(prefix + hdf_suffix)
self.hdf = adcore.NDFileHDFIO(prefix + fileio_suffix)

super().__init__(
MerlinController(self.drv),
Expand Down
9 changes: 2 additions & 7 deletions src/dodal/devices/i13_1/merlin_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
from ophyd_async.core import (
DEFAULT_TIMEOUT,
AsyncStatus,
DetectorController,
TriggerInfo,
)
from ophyd_async.epics import adcore
from ophyd_async.epics.adcore import ADBaseController

from dodal.devices.i13_1.merlin_io import MerlinDriverIO, MerlinImageMode


class MerlinController(DetectorController):
class MerlinController(ADBaseController):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't properly check if this is correct but it looked about right

def __init__(
self,
driver: MerlinDriverIO,
Expand All @@ -37,11 +37,6 @@ async def prepare(self, trigger_info: TriggerInfo):
self.driver.image_mode.set(MerlinImageMode.MULTIPLE),
)

async def arm(self):
self._arm_status = await adcore.start_acquiring_driver_and_ensure_status(
self.driver, good_states=self.good_states, timeout=self.frame_timeout
)

async def wait_for_idle(self):
if self._arm_status:
await self._arm_status
Expand Down
8 changes: 4 additions & 4 deletions src/dodal/devices/i22/nxsas.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def __init__(
prefix: str,
path_provider: PathProvider,
drv_suffix: str,
hdf_suffix: str,
fileio_suffix: str,
metadata_holder: NXSasMetadataHolder,
name: str = "",
):
Expand All @@ -116,7 +116,7 @@ def __init__(
prefix,
path_provider,
drv_suffix=drv_suffix,
hdf_suffix=hdf_suffix,
fileio_suffix=fileio_suffix,
name=name,
)
self._metadata_holder = metadata_holder
Expand Down Expand Up @@ -146,7 +146,7 @@ def __init__(
prefix: str,
path_provider: PathProvider,
drv_suffix: str,
hdf_suffix: str,
fileio_suffix: str,
metadata_holder: NXSasMetadataHolder,
name: str = "",
gpio_number: AravisController.GPIO_NUMBER = 1,
Expand All @@ -160,7 +160,7 @@ def __init__(
prefix,
path_provider,
drv_suffix=drv_suffix,
hdf_suffix=hdf_suffix,
fileio_suffix=fileio_suffix,
name=name,
gpio_number=gpio_number,
)
Expand Down
4 changes: 2 additions & 2 deletions src/dodal/devices/motors.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class XYZPositioner(StandardReadable):
Notes
-----
Example usage::
async with DeviceCollector():
async with init_devices():
xyz_stage = XYZPositioner("BLXX-MO-STAGE-XX:")
Or::
with DeviceCollector():
with init_devices():
xyz_stage = XYZPositioner("BLXX-MO-STAGE-XX:", infix = ("A", "B", "C"))
"""
Expand Down
41 changes: 27 additions & 14 deletions src/dodal/plans/save_panda.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
from typing import cast

from bluesky.run_engine import RunEngine
from ophyd_async.core import Device, save_device
from ophyd_async.fastcs.panda import phase_sorter
from ophyd_async.core import Device, YamlSettingsProvider
from ophyd_async.plan_stubs import (
store_settings,
)

from dodal.beamlines import module_name_for_beamline
from dodal.utils import make_device
Expand All @@ -17,27 +19,35 @@ def main(argv: list[str]):
"""CLI Utility to save the panda configuration."""
parser = ArgumentParser(description="Save an ophyd_async panda to yaml")
parser.add_argument(
"--beamline", help="beamline to save from e.g. i03. Defaults to BEAMLINE"
"--beamline", help="Beamline to save from e.g. i03. Defaults to BEAMLINE"
)
parser.add_argument(
"--device-name",
help='name of the device. The default is "panda"',
help='Name of the device. The default is "panda"',
default="panda",
)
parser.add_argument(
"--file-name",
help="Name of the output save file",
default="panda_settings.yaml",
)
parser.add_argument(
"--output-directory", help="Directory in which save file is output"
)
parser.add_argument(
"-f",
"--force",
action=argparse.BooleanOptionalAction,
help="Force overwriting an existing file",
)
parser.add_argument("output_file", help="output filename")

# this exit()s with message/help unless args parsed successfully
args = parser.parse_args(argv[1:])

beamline = args.beamline
device_name = args.device_name
output_file = args.output_file
file_name = args.file_name
output_directory = args.output_directory
force = args.force
Copy link
Contributor

@rtuck99 rtuck99 Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could just leave the options unchanged and do

p = Path(output_file)
output_directory, file_name = str(p.parent), str(p.name)

then you wouldn't need two parameters. It's a bit strange to make the output directory a mandatory option but the filename optional, normally the output file is the last parameter for most tools


if beamline:
Expand All @@ -49,19 +59,19 @@ def main(argv: list[str]):
sys.stderr.write("BEAMLINE not set and --beamline not specified\n")
return 1

if Path(output_file).exists() and not force:
if Path(file_name).exists() and not force:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't this now need to be output directory / file_name?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah thanks, good catch

sys.stderr.write(
f"Output file {output_file} already exists and --force not specified."
f"Output file {file_name} already exists and --force not specified."
)
return 1

_save_panda(beamline, device_name, output_file)
_save_panda(beamline, device_name, output_directory, file_name)

print("Done.")
return 0


def _save_panda(beamline, device_name, output_file):
def _save_panda(beamline, device_name, output_directory, file_name):
RE = RunEngine()
print("Creating devices...")
module_name = module_name_for_beamline(beamline)
Expand All @@ -72,13 +82,16 @@ def _save_panda(beamline, device_name, output_file):
sys.exit(1)

panda = devices[device_name]
print(f"Saving to {output_file} from {device_name} on {beamline}...")
_save_panda_to_file(RE, cast(Device, panda), output_file)
print(f"Saving to {file_name} from {device_name} on {beamline}...")
_save_panda_to_yaml(RE, cast(Device, panda), file_name, output_directory)


def _save_panda_to_file(RE: RunEngine, panda: Device, path: str):
def _save_panda_to_yaml(
RE: RunEngine, panda: Device, file_name: str, output_directory: str
):
def save_to_file():
yield from save_device(panda, path, sorter=phase_sorter)
provider = YamlSettingsProvider(output_directory)
yield from store_settings(provider, file_name, panda)

RE(save_to_file())

Expand Down
4 changes: 2 additions & 2 deletions system_tests/test_aperturescatterguard_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from bluesky.callbacks import CallbackBase
from bluesky.run_engine import RunEngine
from event_model import Event
from ophyd_async.core import DeviceCollector
from ophyd_async.core import init_devices

from dodal.common.beamlines.beamline_parameters import GDABeamlineParameters
from dodal.devices.aperturescatterguard import (
Expand All @@ -28,7 +28,7 @@ async def ap_sg():
positions = load_positions_from_beamline_parameters(params)
tolerances = AperturePosition.tolerances_from_gda_params(params)

async with DeviceCollector():
async with init_devices():
ap_sg = ApertureScatterguard(
prefix="BL03S",
name="ap_sg",
Expand Down
4 changes: 2 additions & 2 deletions system_tests/test_oav_system.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import bluesky.plan_stubs as bps
import pytest
from bluesky.run_engine import RunEngine
from ophyd_async.core import DeviceCollector
from ophyd_async.core import init_devices

from dodal.devices.oav.oav_detector import OAV, OAVConfig, ZoomController

Expand All @@ -19,7 +19,7 @@
@pytest.fixture
async def oav() -> OAV:
oav_config = OAVConfig(ZOOM_LEVELS_XML, DISPLAY_CONFIGURATION)
async with DeviceCollector(connect=True):
async with init_devices(connect=True):
oav = OAV("", config=oav_config, name="oav")
return oav

Expand Down
4 changes: 2 additions & 2 deletions system_tests/test_oav_to_redis_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

import pytest
from aiohttp.client_exceptions import ClientConnectorError
from ophyd_async.core import DeviceCollector
from ophyd_async.core import init_devices
from ophyd_async.testing import set_mock_value

from dodal.devices.oav.oav_to_redis_forwarder import OAVToRedisForwarder, Source


def _oav_to_redis_forwarder(mock):
with DeviceCollector(mock=mock):
with init_devices(mock=mock):
oav_forwarder = OAVToRedisForwarder("BL04I-DI-OAV-01:", "", "")
oav_forwarder.redis_client.hset = AsyncMock()
oav_forwarder.redis_client.expire = AsyncMock()
Expand Down
4 changes: 2 additions & 2 deletions system_tests/test_undulator_system.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from ophyd_async.core import DeviceCollector
from ophyd_async.core import init_devices

from dodal.devices.undulator import Undulator

Expand All @@ -12,7 +12,7 @@

@pytest.mark.s03
def test_undulator_connects():
with DeviceCollector():
with init_devices():
undulator = Undulator( # noqa: F841
f"{SIM_INSERTION_PREFIX}-MO-SERVC-01:",
id_gap_lookup_table_path=ID_GAP_LOOKUP_TABLE_PATH,
Expand Down
4 changes: 2 additions & 2 deletions tests/devices/i04/test_transfocator.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pytest
from ophyd_async.core import (
DeviceCollector,
init_devices,
wait_for_value,
)
from ophyd_async.testing import set_mock_value
Expand All @@ -13,7 +13,7 @@

@pytest.fixture
async def fake_transfocator() -> Transfocator:
async with DeviceCollector(mock=True):
async with init_devices(mock=True):
transfocator = Transfocator(prefix="", name="transfocator")
return transfocator

Expand Down
Loading
Loading