|
1 | 1 | from contextlib import contextmanager |
2 | 2 | from os import PathLike |
3 | 3 | from pathlib import Path |
4 | | -from typing import Iterator, List, Set |
| 4 | +from typing import Dict, Iterator, List, Set |
5 | 5 |
|
6 | 6 | import numpy as np |
7 | 7 |
|
@@ -47,20 +47,23 @@ def class_exts(cls) -> Set[str]: |
47 | 47 | def __init__(self, path: PathLike, czi_channel: int = 0) -> None: |
48 | 48 | self.path = Path(path) |
49 | 49 | self.czi_channel = czi_channel |
| 50 | + self.axis_offsets: Dict[str, int] = {} |
50 | 51 | super().__init__() |
51 | 52 | with self.czi_file() as czi_file: |
52 | 53 | for axis, ( |
53 | 54 | start, |
54 | | - length, |
| 55 | + end, |
55 | 56 | ) in czi_file.total_bounding_box.items(): |
56 | 57 | axis = axis.lower() |
57 | 58 | if axis == "c": |
58 | 59 | continue |
59 | | - assert start == 0 |
| 60 | + length = end - start |
60 | 61 | if axis not in "xy" and length == 1: |
61 | 62 | # not propagating axes of length one |
62 | 63 | continue |
| 64 | + assert length >= 0, f"axis length must be >= 0, got {length}" |
63 | 65 | self._init_axis(axis, length) |
| 66 | + self.axis_offsets[axis] = start |
64 | 67 | self._czi_pixel_type = czi_file.get_channel_pixel_type(self.czi_channel) |
65 | 68 | if self._czi_pixel_type.startswith("Bgra"): |
66 | 69 | self._init_axis("c", 4) |
@@ -94,6 +97,9 @@ def pixel_type(self) -> np.dtype: |
94 | 97 |
|
95 | 98 | def get_frame_2D(self, **ind: int) -> np.ndarray: |
96 | 99 | plane = {k.upper(): v for k, v in ind.items()} |
| 100 | + for axis in plane.keys(): |
| 101 | + if axis in self.axis_offsets: |
| 102 | + plane[axis] += self.axis_offsets[axis] |
97 | 103 |
|
98 | 104 | # safe-guard against x/y in ind argument, |
99 | 105 | # we always read the whole slice here: |
|
0 commit comments