Skip to content

Commit

Permalink
add repr to MM FOV and dataset types
Browse files Browse the repository at this point in the history
  • Loading branch information
ziw-liu committed Feb 22, 2024
1 parent 0da400c commit ebed5ee
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
17 changes: 17 additions & 0 deletions iohub/mm_fov.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from pathlib import Path

from xarray import DataArray

from iohub.fov import BaseFOV, BaseFOVMapping


Expand All @@ -10,6 +12,14 @@ def __init__(self, parent: MicroManagerFOVMapping, key: int) -> None:
self._position = key
self._parent = parent

def __repr__(self) -> str:
return (
f"Type: {type(self)}\n"
f"Parent: {self.parent}\n"
f"FOV key: {self._position}\n"
f"Data:\n"
) + self.xdata.__repr__()

@property
def parent(self) -> MicroManagerFOVMapping:
return self._parent
Expand All @@ -26,6 +36,10 @@ def zyx_scale(self) -> tuple[float, float, float]:
def channel_names(self) -> list[str]:
return self.parent.channel_names

@property
def xdata(self) -> DataArray:
raise NotImplementedError

def frame_metadata(self, t: int, z: int, c: int) -> dict | None:
"""
Return image plane metadata for a given camera frame.
Expand Down Expand Up @@ -53,6 +67,9 @@ def __init__(self):
self._stage_positions: list[dict[str, str | float]] = []
self.channel_names: list[str] = None

def __repr__(self) -> str:
return (f"Type: {type(self)}\nData:\n") + self.xdata.__repr__()

@property
def mm_meta(self):
return self._mm_meta
Expand Down
3 changes: 3 additions & 0 deletions tests/mmstack/test_mmstack.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def test_mmstack_ctx(ome_tiff):
with MMStack(ome_tiff) as mmstack:
assert isinstance(mmstack, MMStack)
assert len(mmstack) > 0
assert "MMStack" in mmstack.__repr__()


def test_mmstack_nonexisting(tmpdir):
Expand All @@ -34,6 +35,8 @@ def test_mmstack_getitem(ome_tiff):
for key, fov in mmstack:
assert isinstance(key, str)
assert isinstance(fov, MMOmeTiffFOV)
assert key in mmstack.__repr__()
assert key in fov.__repr__()
mmstack.close()


Expand Down
6 changes: 5 additions & 1 deletion tests/test_ndtiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def test_dataset_ctx(ndtiff_dataset):
with NDTiffDataset(ndtiff_dataset) as dataset:
assert isinstance(dataset, NDTiffDataset)
assert len(dataset) > 0
assert "NDTiffDataset" in dataset.__repr__()


def test_dataset_nonexisting(tmpdir):
Expand All @@ -36,9 +37,12 @@ def test_dataset_getitem_v2(ndtiff_v2):
def test_dataset_v3_labeled_positions():
dataset = NDTiffDataset(ndtiff_v3_labeled_positions)
assert len(dataset) == 3
for (key, fov), name in zip(dataset, ["Pos0", "Pos1", "Pos2"]):
positions = ["Pos0", "Pos1", "Pos2"]
for (key, fov), name in zip(dataset, positions):
assert key == name
assert isinstance(fov, NDTiffFOV)
assert name in dataset.__repr__()
assert key in fov.__repr__()
with pytest.raises(KeyError):
dataset["0"]
dataset[0]
Expand Down

0 comments on commit ebed5ee

Please sign in to comment.