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

feat: make af-device name optional #145

Merged
merged 2 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/useq/_actions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Union
from typing import Optional, Union

from typing_extensions import Literal

Expand Down Expand Up @@ -43,18 +43,21 @@ class HardwareAutofocus(Action):
----------
type : Literal["hardware_autofocus"]
This action can be used to trigger hardware autofocus.
autofocus_device_name : str
The name of the hardware autofocus device.
autofocus_motor_offset: float
autofocus_device_name : str, optional
The name of the autofocus offset motor device (if applicable). If `None`,
acquisition engines may attempt to set the offset however they see fit (such as
using a current or default autofocus device.)
autofocus_motor_offset: float, optional
Before autofocus is performed, the autofocus motor should be moved to this
offset.
offset, if applicable. (Not all autofocus devices have an offset motor.)
If None, the autofocus motor should not be moved.
max_retries : int
The number of retries if autofocus fails. By default, 3.
"""

type: Literal["hardware_autofocus"] = "hardware_autofocus"
autofocus_device_name: str
autofocus_motor_offset: float
autofocus_device_name: Optional[str] = None
autofocus_motor_offset: Optional[float] = None
max_retries: int = 3


Expand Down
11 changes: 7 additions & 4 deletions src/useq/_hardware_autofocus.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ class AutoFocusPlan(FrozenModel):

Attributes
----------
autofocus_device_name : str
Name of the hardware autofocus z device.
autofocus_device_name : str | None
Optional name of the offset motor device. If `None`, acquisition engines may
attempt to set the offset however they see fit (such as using a current
or default autofocus device.)
autofocus_motor_offset : float | None
Before autofocus is performed, the autofocus motor should be moved to this
offset.
offset, if applicable. (Not all autofocus devices have an offset motor.)
If None, the autofocus motor should not be moved.
"""

autofocus_device_name: str
autofocus_device_name: Optional[str] = None
autofocus_motor_offset: Optional[float] = None

def as_action(self) -> HardwareAutofocus:
Expand Down
9 changes: 9 additions & 0 deletions tests/test_autofocus.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,12 @@ def test_autofocus_z_pos_multi_plans() -> None:
)

assert all(e.z_pos == 200 for e in mda if isinstance(e.action, HardwareAutofocus))


def test_af_no_name() -> None:
list(
MDASequence(
time_plan={"interval": 1, "loops": 2},
autofocus_plan=AxesBasedAF(axes=("t", "c")),
)
)