diff --git a/iohub/mm_fov.py b/iohub/mm_fov.py index ee345e0d..2f6d7521 100644 --- a/iohub/mm_fov.py +++ b/iohub/mm_fov.py @@ -2,6 +2,8 @@ from pathlib import Path +from xarray import DataArray + from iohub.fov import BaseFOV, BaseFOVMapping @@ -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 @@ -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. @@ -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 diff --git a/tests/mmstack/test_mmstack.py b/tests/mmstack/test_mmstack.py index 26a6294b..9bccf59c 100644 --- a/tests/mmstack/test_mmstack.py +++ b/tests/mmstack/test_mmstack.py @@ -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): @@ -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() diff --git a/tests/test_ndtiff.py b/tests/test_ndtiff.py index faeebb52..25f8730c 100644 --- a/tests/test_ndtiff.py +++ b/tests/test_ndtiff.py @@ -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): @@ -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]