Skip to content

Commit

Permalink
Rename to _validate_axes_name()
Browse files Browse the repository at this point in the history
  • Loading branch information
will-moore committed Oct 27, 2021
1 parent 9e018f6 commit b33e9f0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
5 changes: 3 additions & 2 deletions ome_zarr/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
LOGGER = logging.getLogger("ome_zarr.writer")


def validate_axes_names(
def _validate_axes_names(
ndim: int, axes: Union[str, List[str]] = None, fmt: Format = CurrentFormat()
) -> Union[None, List[str]]:
"""Returns validated list of axes names or raise exception if invalid"""

if fmt.version in ("0.1", "0.2"):
if axes is not None:
Expand Down Expand Up @@ -95,7 +96,7 @@ def write_multiscale(
"""

dims = len(pyramid[0].shape)
axes = validate_axes_names(dims, axes, fmt)
axes = _validate_axes_names(dims, axes, fmt)

paths = []
for path, dataset in enumerate(pyramid):
Expand Down
22 changes: 11 additions & 11 deletions tests/test_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ome_zarr.io import parse_url
from ome_zarr.reader import Multiscales, Reader
from ome_zarr.scale import Scaler
from ome_zarr.writer import validate_axes_names, write_image
from ome_zarr.writer import _validate_axes_names, write_image


class TestWriter:
Expand Down Expand Up @@ -84,21 +84,21 @@ def test_dim_names(self):

# v0.3 MUST specify axes for 3D or 4D data
with pytest.raises(ValueError):
validate_axes_names(3, axes=None, fmt=v03)
_validate_axes_names(3, axes=None, fmt=v03)

# ndims must match axes length
with pytest.raises(ValueError):
validate_axes_names(3, axes="yx", fmt=v03)
_validate_axes_names(3, axes="yx", fmt=v03)

# axes must be ordered tczyx
with pytest.raises(ValueError):
validate_axes_names(3, axes="yxt", fmt=v03)
_validate_axes_names(3, axes="yxt", fmt=v03)
with pytest.raises(ValueError):
validate_axes_names(2, axes=["x", "y"], fmt=v03)
_validate_axes_names(2, axes=["x", "y"], fmt=v03)

# valid axes - no change, converted to list
assert validate_axes_names(2, axes=["y", "x"], fmt=v03) == ["y", "x"]
assert validate_axes_names(5, axes="tczyx", fmt=v03) == [
assert _validate_axes_names(2, axes=["y", "x"], fmt=v03) == ["y", "x"]
assert _validate_axes_names(5, axes="tczyx", fmt=v03) == [
"t",
"c",
"z",
Expand All @@ -107,12 +107,12 @@ def test_dim_names(self):
]

# if 2D or 5D, axes can be assigned automatically
assert validate_axes_names(2, axes=None, fmt=v03) == ["y", "x"]
assert validate_axes_names(5, axes=None, fmt=v03) == ["t", "c", "z", "y", "x"]
assert _validate_axes_names(2, axes=None, fmt=v03) == ["y", "x"]
assert _validate_axes_names(5, axes=None, fmt=v03) == ["t", "c", "z", "y", "x"]

# for v0.1 or v0.2, axes should be None
assert validate_axes_names(2, axes=["y", "x"], fmt=FormatV01()) is None
assert validate_axes_names(2, axes=["y", "x"], fmt=FormatV02()) is None
assert _validate_axes_names(2, axes=["y", "x"], fmt=FormatV01()) is None
assert _validate_axes_names(2, axes=["y", "x"], fmt=FormatV02()) is None

# check that write_image is checking axes
data = self.create_data((125, 125))
Expand Down

0 comments on commit b33e9f0

Please sign in to comment.