Skip to content

Commit 3b514f8

Browse files
committed
_get_axis_type ->_guess_axis_type
user provided AxisIds might be uninterpretable
1 parent 447409f commit 3b514f8

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

bioimageio/core/axis.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,26 @@
88
from bioimageio.spec.model import v0_5
99

1010

11-
def _get_axis_type(a: Literal["b", "t", "i", "c", "x", "y", "z"]):
12-
if a == "b":
11+
def _guess_axis_type(a: str):
12+
if a in ("b", "batch"):
1313
return "batch"
14-
elif a == "t":
14+
elif a in ("t", "time"):
1515
return "time"
16-
elif a == "i":
16+
elif a in ("i", "index"):
1717
return "index"
18-
elif a == "c":
18+
elif a in ("c", "channel"):
1919
return "channel"
2020
elif a in ("x", "y", "z"):
2121
return "space"
2222
else:
23-
return "index" # return most unspecific axis
23+
raise ValueError(
24+
f"Failed to infer axis type for axis id '{a}'."
25+
+ " Consider using one of: '"
26+
+ "', '".join(
27+
["b", "batch", "t", "time", "i", "index", "c", "channel", "x", "y", "z"]
28+
)
29+
+ "'. Or creating an `Axis` object instead."
30+
)
2431

2532

2633
S = TypeVar("S", bound=str)
@@ -54,10 +61,10 @@ def create(cls, axis: AxisLike) -> Axis:
5461
return axis
5562
elif isinstance(axis, Axis):
5663
return Axis(id=axis.id, type=axis.type)
57-
elif isinstance(axis, str):
58-
return Axis(id=AxisId(axis), type=_get_axis_type(axis))
5964
elif isinstance(axis, v0_5.AxisBase):
6065
return Axis(id=AxisId(axis.id), type=axis.type)
66+
elif isinstance(axis, str):
67+
return Axis(id=AxisId(axis), type=_guess_axis_type(axis))
6168
else:
6269
assert_never(axis)
6370

0 commit comments

Comments
 (0)