Skip to content

Commit d5f0525

Browse files
authored
feat: make Axis public (#201)
1 parent 569c207 commit d5f0525

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

src/useq/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
TIntervalDuration,
2929
TIntervalLoops,
3030
)
31+
from useq._utils import Axis
3132
from useq._z import (
3233
AnyZPlan,
3334
ZAboveBelow,
@@ -46,6 +47,7 @@
4647
"AnyZPlan",
4748
"AutoFocusPlan",
4849
"AxesBasedAF",
50+
"Axis",
4951
"Channel",
5052
"GridFromEdges",
5153
"GridRelative",

src/useq/_mda_sequence.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,8 @@ def _check_order(
345345
)
346346
):
347347
raise ValueError(
348-
f"{Axis.Z!r} cannot precede {Axis.POSITION!r} in acquisition order if "
349-
"any position specifies a z_plan"
348+
f"{str(Axis.Z)!r} cannot precede {str(Axis.POSITION)!r} in acquisition "
349+
"order if any position specifies a z_plan"
350350
)
351351

352352
if (
@@ -426,12 +426,12 @@ def used_axes(self) -> str:
426426
def iter_axis(self, axis: str) -> Iterator[Channel | float | PositionBase]:
427427
"""Iterate over the positions or items of a given axis."""
428428
plan = {
429-
Axis.TIME: self.time_plan,
430-
Axis.POSITION: self.stage_positions,
431-
Axis.Z: self.z_plan,
432-
Axis.CHANNEL: self.channels,
433-
Axis.GRID: self.grid_plan,
434-
}[axis]
429+
str(Axis.TIME): self.time_plan,
430+
str(Axis.POSITION): self.stage_positions,
431+
str(Axis.Z): self.z_plan,
432+
str(Axis.CHANNEL): self.channels,
433+
str(Axis.GRID): self.grid_plan,
434+
}[str(axis).lower()]
435435
if plan:
436436
yield from plan
437437

src/useq/_utils.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
import re
44
from datetime import timedelta
5-
from typing import TYPE_CHECKING, Literal, NamedTuple, TypeVar
5+
from enum import Enum
6+
from typing import TYPE_CHECKING, NamedTuple
67

78
if TYPE_CHECKING:
8-
from typing import Final
9+
from typing import Final, Literal, TypeVar
910

1011
from typing_extensions import TypeGuard
1112

@@ -17,18 +18,35 @@
1718

1819

1920
# could be an enum, but this more easily allows Axis.Z to be a string
20-
class Axis:
21-
"""Recognized axis names."""
21+
class Axis(str, Enum):
22+
"""Recognized useq-schema axis keys.
2223
23-
TIME: Final[Literal["t"]] = "t"
24-
POSITION: Final[Literal["p"]] = "p"
25-
GRID: Final[Literal["g"]] = "g"
26-
CHANNEL: Final[Literal["c"]] = "c"
27-
Z: Final[Literal["z"]] = "z"
24+
Attributes
25+
----------
26+
TIME : Literal["t"]
27+
Time axis.
28+
POSITION : Literal["p"]
29+
XY Stage Position axis.
30+
GRID : Literal["g"]
31+
Grid axis (usually an additional row/column iteration around a position).
32+
CHANNEL : Literal["c"]
33+
Channel axis.
34+
Z : Literal["z"]
35+
Z axis.
36+
"""
37+
38+
TIME: Literal["t"] = "t"
39+
POSITION: Literal["p"] = "p"
40+
GRID: Literal["g"] = "g"
41+
CHANNEL: Literal["c"] = "c"
42+
Z: Literal["z"] = "z"
43+
44+
def __str__(self) -> Literal["t", "p", "g", "c", "z"]:
45+
return self.value # type: ignore [no-any-return]
2846

2947

3048
# note: order affects the default axis_order in MDASequence
31-
AXES: Final[tuple[str, ...]] = (
49+
AXES: Final[tuple[Axis, ...]] = (
3250
Axis.TIME,
3351
Axis.POSITION,
3452
Axis.GRID,

0 commit comments

Comments
 (0)