Skip to content

Commit

Permalink
ruff format, match fetch_deadtime public, Except on bad model/pixel_f…
Browse files Browse the repository at this point in the history
…ormat
  • Loading branch information
DiamondJoseph committed Apr 18, 2024
1 parent cfca527 commit 9f92767
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/ophyd_async/epics/areadetector/aravis.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import get_args

from bluesky.protocols import HasHints, Hints

from ophyd_async.core import (
DirectoryProvider,
StandardDetector,
Expand Down Expand Up @@ -52,7 +53,7 @@ def __init__(
)

async def _prepare(self, value: TriggerInfo) -> None:
await self.drv._fetch_deadtime()
await self.drv.fetch_deadtime()
await super()._prepare(value)

def get_external_trigger_gpio(self):
Expand Down
17 changes: 13 additions & 4 deletions src/ophyd_async/epics/areadetector/drivers/aravis_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,14 @@ class ADAravisTriggerSource(str, Enum):
line_4 = "Line4"


def _reverse_lookup(model_deadtimes: Dict[float, Tuple[str, ...]]) -> Callable[[str], float]:
def _reverse_lookup(
model_deadtimes: Dict[float, Tuple[str, ...]],
) -> Callable[[str], float]:
def inner(pixel_format: str) -> float:
for deadtime, pixel_formats in model_deadtimes.items():
if pixel_format in pixel_formats:
return deadtime
return nan
None

return inner

Expand Down Expand Up @@ -150,8 +152,15 @@ def __init__(self, prefix: str, name: str = "") -> None:
self.dead_time: Optional[float] = None
super().__init__(prefix, name=name)

async def _fetch_deadtime(self) -> float:
async def fetch_deadtime(self) -> float:
# All known in-use version B/C have same deadtime as non-B/C
model: str = (await self.model.get_value()).removesuffix("B").removesuffix("C")
pixel_format: str = await self.pixel_format.get_value()
self.dead_time = _deadtimes.get(model, lambda _: nan)(pixel_format)
if model not in _deadtimes:
raise ValueError(f"Aravis model {model} deadtimes not known")
deadtime = _deadtimes[model](pixel_format)
if deadtime is None:
raise ValueError(
f"Aravis model {model} deadtime not known for pixel_format {pixel_format}"
)
self.dead_time = deadtime
1 change: 0 additions & 1 deletion src/ophyd_async/panda/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from .panda import PandA, PcapBlock, PulseBlock, SeqBlock, SeqTable, TimeUnits
from .panda_controller import PandaPcapController
from .table import (
SeqTable,
SeqTableRow,
SeqTrigger,
seq_table_from_arrays,
Expand Down
23 changes: 22 additions & 1 deletion tests/epics/areadetector/test_aravis.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,33 @@ async def test_deadtime_read_from_file(
set_sim_value(adaravis.drv.model, model)
set_sim_value(adaravis.drv.pixel_format, pixel_format)

await adaravis.drv._fetch_deadtime()
await adaravis.drv.fetch_deadtime()
# deadtime invariant with exposure time
assert adaravis.controller.get_deadtime(0) == deadtime
assert adaravis.controller.get_deadtime(500) == deadtime


@pytest.mark.parametrize(
"model,pixel_format",
[("UnknownCamera", None), ("Mako G-040", "UnknownFormat")],
)
async def test_unknown_deadtime_read_from_file(
model: str,
pixel_format: str,
adaravis: ADAravisDetector,
):
set_sim_value(adaravis.drv.model, model)
set_sim_value(adaravis.drv.pixel_format, pixel_format)
expected_error = (
f"Aravis model {model} deadtimes not known"
if pixel_format is None
else f"Aravis model {model} deadtime not known for pixel_format {pixel_format}"
)

with pytest.raises(ValueError, match=expected_error):
await adaravis.drv.fetch_deadtime()


async def test_trigger_source_set_to_gpio_line(adaravis: ADAravisDetector):
async def trigger_and_complete():
await adaravis.controller.arm(num=1, trigger=DetectorTrigger.edge_trigger)
Expand Down

0 comments on commit 9f92767

Please sign in to comment.