Skip to content

Commit

Permalink
Transforming custom axes to canonical up to 5D
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsitsi committed Feb 4, 2025
1 parent 4d3ff12 commit eb4d8da
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions tiledb/bioimg/converters/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from abc import ABC, abstractmethod
from dataclasses import dataclass
from typing import Any, Iterable, Iterator, MutableSequence, Sequence, Tuple
from typing import Any, Iterable, Iterator, MutableSequence, Sequence, Tuple, Set

import numpy as np
from pyeditdistance.distance import levenshtein
Expand Down Expand Up @@ -209,11 +209,27 @@ def __init__(self, dims: Iterable[str]):
for required_axis in "X", "Y":
if required_axis not in axes:
raise ValueError(f"Missing required axis {required_axis!r}")

axes.difference_update(self.CANONICAL_DIMS)
if axes:
raise ValueError(f"{axes.pop()!r} is not a valid Axis")
if len(axes) == 1:
# Assign extra/custom dimension as Time TBC
dims = self._canonical_transformation(dims, axes)
else:
raise ValueError(f"{axes.pop()!r} is not a valid Axis")
object.__setattr__(self, "dims", dims)

@staticmethod
def _canonical_transformation(dims: str, axes: Set[str]) -> str:
custom_axis = f"{axes.pop()}".replace("'", "")
if "T" not in dims:
dims.replace(custom_axis, "T")
elif "Z" not in dims:
dims.replace(custom_axis, "Z")
else:
raise ValueError(f"{custom_axis!r} cannot be mapped to a canonical value")
return dims

def canonical(self, shape: Tuple[int, ...]) -> Axes:
"""
Return a new Axes instance with the dimensions of this axes whose size in `shape`
Expand Down

0 comments on commit eb4d8da

Please sign in to comment.