Skip to content

Commit

Permalink
Comply with new upstream typing
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom-Willemsen committed Oct 22, 2024
1 parent b45c6f2 commit 025a137
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 43 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ classifiers = [

dependencies = [
"bluesky",
"ophyd-async[ca]",
"ophyd-async[ca] @ git+https://github.com/bluesky/ophyd-async@signal-typing",
"matplotlib",
"lmfit",
"scipy",
Expand Down
6 changes: 4 additions & 2 deletions src/ibex_bluesky_core/devices/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import binascii
import os
import zlib
from typing import Type
from typing import Type, TypeVar

from ophyd_async.core import SignalRW, T
from ophyd_async.core import SignalDatatype, SignalRW
from ophyd_async.epics.signal import epics_signal_rw

T = TypeVar("T", bound=SignalDatatype)


def get_pv_prefix() -> str:
"""Return the PV prefix for the current instrument."""
Expand Down
3 changes: 2 additions & 1 deletion src/ibex_bluesky_core/devices/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from ophyd_async.core import (
AsyncStatus,
HintedSignal,
SignalDatatype,
SignalR,
SignalRW,
StandardReadable,
Expand All @@ -19,7 +20,7 @@
from ibex_bluesky_core.devices import get_pv_prefix

"""Block data type"""
T = TypeVar("T")
T = TypeVar("T", bound=SignalDatatype)


__all__ = [
Expand Down
15 changes: 6 additions & 9 deletions src/ibex_bluesky_core/devices/dae/dae.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
"""ophyd-async devices for communicating with the ISIS data acquisition electronics."""

from enum import Enum

from numpy import int32
from numpy.typing import NDArray
from ophyd_async.core import SignalR, SignalRW, StandardReadable
from ophyd_async.core import Array1D, SignalR, SignalRW, StandardReadable, StrictEnum
from ophyd_async.epics.signal import epics_signal_r, epics_signal_rw

from ibex_bluesky_core.devices import isis_epics_signal_rw
Expand All @@ -18,7 +15,7 @@
from ibex_bluesky_core.devices.dae.dae_tcb_settings import DaeTCBSettings


class RunstateEnum(str, Enum):
class RunstateEnum(StrictEnum):
"""The run state."""

PROCESSING = "PROCESSING"
Expand Down Expand Up @@ -81,11 +78,11 @@ def __init__(self, prefix: str, name: str = "DAE") -> None:
self.period_settings = DaePeriodSettings(dae_prefix)
self.tcb_settings = DaeTCBSettings(dae_prefix)

self.raw_spectra_integrals: SignalR[NDArray[int32]] = epics_signal_r(
NDArray[int32], f"{dae_prefix}SPECINTEGRALS"
self.raw_spectra_integrals: SignalR[Array1D[int32]] = epics_signal_r(
Array1D[int32], f"{dae_prefix}SPECINTEGRALS"
)
self.raw_spectra_data: SignalR[NDArray[int32]] = epics_signal_r(
NDArray[int32], f"{dae_prefix}SPECDATA"
self.raw_spectra_data: SignalR[Array1D[int32]] = epics_signal_r(
Array1D[int32], f"{dae_prefix}SPECDATA"
)

self.monitor = DaeMonitor(dae_prefix)
Expand Down
4 changes: 2 additions & 2 deletions src/ibex_bluesky_core/devices/dae/dae_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from xml.etree.ElementTree import tostring

from bluesky.protocols import Locatable, Location, Movable
from ophyd_async.core import AsyncStatus, Device, SignalRW
from ophyd_async.core import AsyncStatus, SignalRW, StandardReadable

from ibex_bluesky_core.devices import (
isis_epics_signal_rw,
Expand Down Expand Up @@ -147,7 +147,7 @@ def _convert_dae_settings_to_xml(current_xml: str, settings: DaeSettingsData) ->
return tostring(root, encoding="unicode")


class DaeSettings(Device, Locatable, Movable):
class DaeSettings(StandardReadable, Locatable, Movable):
"""Subdevice for the DAE general settings."""

def __init__(self, dae_prefix: str, name: str = "") -> None:
Expand Down
18 changes: 9 additions & 9 deletions src/ibex_bluesky_core/devices/dae/dae_spectra.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from event_model.documents.event_descriptor import DataKey
from numpy import float32
from numpy.typing import NDArray
from ophyd_async.core import SignalR, StandardReadable
from ophyd_async.core import Array1D, SignalR, StandardReadable
from ophyd_async.epics.signal import epics_signal_r


Expand All @@ -17,17 +17,17 @@ def __init__(self, dae_prefix: str, *, spectra: int, period: int, name: str = ""
"""Set up signals for a single DAE spectra."""
# x-axis; time-of-flight.
# These are bin-centre coordinates.
self.tof: SignalR[NDArray[float32]] = epics_signal_r(
NDArray[float32], f"{dae_prefix}SPEC:{period}:{spectra}:X"
self.tof: SignalR[Array1D[float32]] = epics_signal_r(
Array1D[float32], f"{dae_prefix}SPEC:{period}:{spectra}:X"
)
self.tof_size: SignalR[int] = epics_signal_r(
int, f"{dae_prefix}SPEC:{period}:{spectra}:X.NORD"
)

# x-axis; time-of-flight.
# These are bin-edge coordinates, with a size one more than the corresponding data.
self.tof_edges: SignalR[NDArray[float32]] = epics_signal_r(
NDArray[float32], f"{dae_prefix}SPEC:{period}:{spectra}:XE"
self.tof_edges: SignalR[Array1D[float32]] = epics_signal_r(
Array1D[float32], f"{dae_prefix}SPEC:{period}:{spectra}:XE"
)
self.tof_edges_size: SignalR[int] = epics_signal_r(
int, f"{dae_prefix}SPEC:{period}:{spectra}:XE.NORD"
Expand All @@ -38,8 +38,8 @@ def __init__(self, dae_prefix: str, *, spectra: int, period: int, name: str = ""
# that ToF bin.
# - Unsuitable for summing counts directly.
# - Will give a continuous plot for non-uniform bin sizes.
self.counts_per_time: SignalR[NDArray[float32]] = epics_signal_r(
NDArray[float32], f"{dae_prefix}SPEC:{period}:{spectra}:Y"
self.counts_per_time: SignalR[Array1D[float32]] = epics_signal_r(
Array1D[float32], f"{dae_prefix}SPEC:{period}:{spectra}:Y"
)
self.counts_per_time_size: SignalR[int] = epics_signal_r(
int, f"{dae_prefix}SPEC:{period}:{spectra}:Y.NORD"
Expand All @@ -49,8 +49,8 @@ def __init__(self, dae_prefix: str, *, spectra: int, period: int, name: str = ""
# This is unnormalized number of counts per ToF bin.
# - Suitable for summing counts
# - This will give a discontinuous plot for non-uniform bin sizes.
self.counts: SignalR[NDArray[float32]] = epics_signal_r(
NDArray[float32], f"{dae_prefix}SPEC:{period}:{spectra}:YC"
self.counts: SignalR[Array1D[float32]] = epics_signal_r(
Array1D[float32], f"{dae_prefix}SPEC:{period}:{spectra}:YC"
)
self.counts_size: SignalR[int] = epics_signal_r(
int, f"{dae_prefix}SPEC:{period}:{spectra}:YC.NORD"
Expand Down
24 changes: 8 additions & 16 deletions tests/devices/simpledae/test_controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,51 +44,43 @@ async def test_period_per_point_controller_begins_run_in_setup_and_ends_in_teard
set_mock_value(simpledae.run_state, RunstateEnum.PAUSED)
await period_per_point_controller.setup(simpledae)
get_mock_put(simpledae.controls.begin_run_ex._raw_begin_run_ex).assert_called_once_with(
BeginRunExBits.BEGIN_PAUSED, wait=True, timeout=None
BeginRunExBits.BEGIN_PAUSED, wait=True
)
set_mock_value(simpledae.run_state, RunstateEnum.SETUP)
await period_per_point_controller.teardown(simpledae)
get_mock_put(simpledae.controls.end_run).assert_called_once_with(None, wait=True, timeout=None)
get_mock_put(simpledae.controls.end_run).assert_called_once_with(None, wait=True)


async def test_aborting_period_per_point_controller_aborts_in_teardown(
simpledae: SimpleDae, aborting_period_per_point_controller: PeriodPerPointController
):
set_mock_value(simpledae.run_state, RunstateEnum.SETUP)
await aborting_period_per_point_controller.teardown(simpledae)
get_mock_put(simpledae.controls.abort_run).assert_called_once_with(
None, wait=True, timeout=None
)
get_mock_put(simpledae.controls.abort_run).assert_called_once_with(None, wait=True)


async def test_period_per_point_controller_changes_periods_and_counts(
simpledae: SimpleDae, period_per_point_controller: PeriodPerPointController
):
set_mock_value(simpledae.run_state, RunstateEnum.RUNNING)
await period_per_point_controller.start_counting(simpledae)
get_mock_put(simpledae.controls.resume_run).assert_called_once_with(
None, wait=True, timeout=None
)
get_mock_put(simpledae.period_num).assert_called_once_with(1, wait=True, timeout=None)
get_mock_put(simpledae.controls.resume_run).assert_called_once_with(None, wait=True)
get_mock_put(simpledae.period_num).assert_called_once_with(1, wait=True)

set_mock_value(simpledae.run_state, RunstateEnum.PAUSED)
await period_per_point_controller.stop_counting(simpledae)
get_mock_put(simpledae.controls.pause_run).assert_called_once_with(
None, wait=True, timeout=None
)
get_mock_put(simpledae.controls.pause_run).assert_called_once_with(None, wait=True)


async def test_run_per_point_controller_starts_and_ends_runs(
simpledae: SimpleDae, run_per_point_controller: RunPerPointController
):
set_mock_value(simpledae.run_state, RunstateEnum.RUNNING)
await run_per_point_controller.start_counting(simpledae)
get_mock_put(simpledae.controls.begin_run).assert_called_once_with(
None, wait=True, timeout=None
)
get_mock_put(simpledae.controls.begin_run).assert_called_once_with(None, wait=True)

await run_per_point_controller.stop_counting(simpledae)
get_mock_put(simpledae.controls.end_run).assert_called_once_with(None, wait=True, timeout=None)
get_mock_put(simpledae.controls.end_run).assert_called_once_with(None, wait=True)


async def test_run_per_point_controller_publishes_run(
Expand Down
6 changes: 3 additions & 3 deletions tests/devices/test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,13 @@ async def test_read_and_describe_configuration(readable_block):
async def test_block_set(writable_block):
set_mock_value(writable_block.setpoint, 10)
await writable_block.set(20)
get_mock_put(writable_block.setpoint).assert_called_once_with(20, wait=True, timeout=None)
get_mock_put(writable_block.setpoint).assert_called_once_with(20, wait=True)


async def test_block_set_without_epics_completion_callback():
block = await _block_with_write_config(BlockWriteConfig(use_completion_callback=False))
await block.set(20)
get_mock_put(block.setpoint).assert_called_once_with(20, wait=False, timeout=None)
get_mock_put(block.setpoint).assert_called_once_with(20, wait=False)


async def test_block_set_with_arbitrary_completion_function():
Expand Down Expand Up @@ -286,4 +286,4 @@ def test_plan_trigger_block(RE, readable_block):
def test_plan_mv_block(RE, writable_block):
set_mock_value(writable_block.setpoint, 123.0)
RE(bps.mv(writable_block, 456.0))
get_mock_put(writable_block.setpoint).assert_called_once_with(456.0, wait=True, timeout=None)
get_mock_put(writable_block.setpoint).assert_called_once_with(456.0, wait=True)

0 comments on commit 025a137

Please sign in to comment.