Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 13 additions & 2 deletions src/ome_zarr_models/_v06/axes.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from collections.abc import Sequence
from typing import Literal
from typing import Literal, Self

from pydantic import model_validator

from ome_zarr_models.common.axes import Axis as BaseAxis
from ome_zarr_models.common.axes import AxisType
Expand Down Expand Up @@ -31,10 +33,19 @@

class Axis(BaseAxis):
"""
Model for an element of multiscale axes.
Model for an element of `Multiscale.axes`.
"""

orientation: Orientation | None = None

@model_validator(mode="after")
def _check_orientation_only_on_spatial(self) -> Self:
if self.type != "space" and self.orientation is not None:
raise ValueError(
f"Orientation can only be set on a spatial axis "
Comment thread
dstansby marked this conversation as resolved.
f"(got Axis type='{self.type}')"
)
return self


Axes = Sequence[Axis]
11 changes: 11 additions & 0 deletions tests/_v06/test_axes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import pytest
from pydantic import ValidationError

from ome_zarr_models._v06.axes import Axis


def test_orientation_only_spatial() -> None:
with pytest.raises(
ValidationError, match="Orientation can only be set on a spatial axis"
):
Axis(name="my_axis", type="time", orientation="anterior-to-posterior")
3 changes: 1 addition & 2 deletions tests/_v06/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def test_image(store: Store) -> None:
name="t",
type="time",
unit="millisecond",
orientation="left-to-right",
),
Axis(name="c", type="channel", unit=None, orientation=None),
Axis(
Expand All @@ -62,7 +61,7 @@ def test_image(store: Store) -> None:
name="x",
type="space",
unit="micrometer",
orientation=None,
orientation="left-to-right",
),
],
datasets=(
Expand Down
10 changes: 7 additions & 3 deletions tests/data/examples/v06/image_example.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
{
"name": "t",
"type": "time",
"unit": "millisecond",
"orientation": "left-to-right"
"unit": "millisecond"
},
{ "name": "c", "type": "channel" },
{ "name": "z", "type": "space", "unit": "micrometer" },
{ "name": "y", "type": "space", "unit": "micrometer" },
{ "name": "x", "type": "space", "unit": "micrometer" }
{
"name": "x",
"type": "space",
"unit": "micrometer",
"orientation": "left-to-right"
}
],
"datasets": [
{
Expand Down