|
2 | 2 |
|
3 | 3 | from abc import ABC, abstractmethod
|
4 | 4 | from dataclasses import dataclass
|
5 |
| -from typing import Any, Iterable, Iterator, MutableSequence, Sequence, Tuple |
| 5 | +from typing import Any, Iterable, Iterator, MutableSequence, Sequence, Set, Tuple |
6 | 6 |
|
7 | 7 | import numpy as np
|
8 | 8 | from pyeditdistance.distance import levenshtein
|
@@ -209,11 +209,27 @@ def __init__(self, dims: Iterable[str]):
|
209 | 209 | for required_axis in "X", "Y":
|
210 | 210 | if required_axis not in axes:
|
211 | 211 | raise ValueError(f"Missing required axis {required_axis!r}")
|
| 212 | + |
212 | 213 | axes.difference_update(self.CANONICAL_DIMS)
|
213 | 214 | if axes:
|
214 |
| - raise ValueError(f"{axes.pop()!r} is not a valid Axis") |
| 215 | + if len(axes) == 1: |
| 216 | + # Assign extra/custom dimension as Time TBC |
| 217 | + dims = self._canonical_transformation(dims, axes) |
| 218 | + else: |
| 219 | + raise ValueError(f"{axes.pop()!r} is not a valid Axis") |
215 | 220 | object.__setattr__(self, "dims", dims)
|
216 | 221 |
|
| 222 | + @staticmethod |
| 223 | + def _canonical_transformation(dims: str, axes: Set[str]) -> str: |
| 224 | + custom_axis = f"{axes.pop()}".replace("'", "") |
| 225 | + if "T" not in dims: |
| 226 | + dims.replace(custom_axis, "T") |
| 227 | + elif "Z" not in dims: |
| 228 | + dims.replace(custom_axis, "Z") |
| 229 | + else: |
| 230 | + raise ValueError(f"{custom_axis!r} cannot be mapped to a canonical value") |
| 231 | + return dims |
| 232 | + |
217 | 233 | def canonical(self, shape: Tuple[int, ...]) -> Axes:
|
218 | 234 | """
|
219 | 235 | Return a new Axes instance with the dimensions of this axes whose size in `shape`
|
|
0 commit comments