Skip to content

Commit 103816c

Browse files
Merge pull request #126 from bioio-devs/feature/migrate-writers
feature/migrate-writers
2 parents da6ab37 + 3f5944c commit 103816c

24 files changed

+117
-3677
lines changed

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,30 @@ this registry.
7171

7272
Each reader plugin should closely follow the specification laid out in `bioio-base`. As such, it is likely common that reader plugins won't distribute their own documentation and users should instead review [`bioio_base.reader.Reader`](https://bioio-devs.github.io/bioio-base/bioio_base.html#bioio_base.reader.Reader) for API documentation for the underlying Reader API. We encourage plugin authors to publish their own documentation if they change or include new features into their published image readers.
7373

74+
## Writer Registry
75+
76+
BioIO supports a set of writer backends for exporting image data. The writer registry below lists maintained writer plug-ins.
77+
78+
| Writer | Extension | Documentation |
79+
| ---------------- | ------------------------------------------------------ | ------------- |
80+
| OmeTiffWriter | .ome.tiff | [Repo](https://github.com/bioio-devs/bioio-ome-tiff) |
81+
| OmeZarrWriterV2 | .ome.zarr (OME 0.4.0, Zarr 2) | [Repo](https://github.com/bioio-devs/bioio-ome-zarr) |
82+
| OmeZarrWriterV3 | .ome.zarr (OME 0.5.0, Zarr 3) | [Repo](https://github.com/bioio-devs/bioio-ome-zarr) |
83+
| TimeSeriesWriter | .gif, .mp4, .mkv | [Repo](https://github.com/bioio-devs/bioio-imageio) |
84+
| TwoDWriter | .png, .bmp, .jpg, .mov, .avi, .mpg, .mpeg, .mp4, .mkv, .wmv, .ogg | [Repo](https://github.com/bioio-devs/bioio-imageio) |
85+
86+
87+
### Writer Installation and Usage
88+
Writers will be installed with the respective plugin. Once installed they can be imported via `bioio.writers`.
89+
ex. `bioio.writers<Writer Name>`
90+
91+
```python
92+
import numpy as np
93+
from bioio.writers import OmeTiffWriter # with bioio-ome-tiff installed
94+
95+
image = np.random.rand(10, 3, 1024, 2048)
96+
OmeTiffWriter.save(image, "file.ome.tiff", dim_order="ZCYX")
97+
```
98+
7499
## Issues
75100
[_Click here to view all open issues in bioio-devs organization at once_](https://github.com/search?q=user%3Abioio-devs+is%3Aissue+is%3Aopen&type=issues&ref=advsearch)

bioio/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# -*- coding: utf-8 -*-
1+
#!/usr/bin/env python
22

33
"""Top-level package for bioio."""
44

bioio/bio_image.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1134,6 +1134,7 @@ def save(
11341134
) -> None:
11351135
"""
11361136
Saves the file data to OME-TIFF format with general naive best practices.
1137+
(Requires bioio-ome-tiff plugin installed)
11371138
11381139
Parameters
11391140
----------
@@ -1146,17 +1147,27 @@ def save(
11461147
11471148
Notes
11481149
-----
1149-
See `bioio.writers.OmeTiffWriter` for more in-depth specification
1150-
and the `bioio.writers` module as a whole for list of all available
1151-
file writers.
1150+
See `bioio_ome_tiff.writers.OmeTiffWriter` for more in-depth specification
1151+
and the bioio writer registry in the README module as a whole for list of
1152+
all available file writers.
11521153
11531154
When reading in the produced OME-TIFF file, scenes IDs may have changed.
11541155
This is due to how certain file and metadata formats do or do-not have IDs
11551156
and simply names. In converting to OME-TIFF we will always store the scene
11561157
ids in each Image's name attribute but IDs will be generated. The order of the
11571158
scenes will be the same (or whatever order was specified / provided).
11581159
"""
1159-
from .writers import OmeTiffWriter
1160+
import bioio.writers as _writers # type: ignore[attr-defined]
1161+
1162+
OmeTiffWriter = getattr(_writers, "OmeTiffWriter", None)
1163+
1164+
if OmeTiffWriter is None:
1165+
log.warning(
1166+
"TIFF writing support (OmeTiffWriter) is not available. "
1167+
"To enable it, install the plugin:\n"
1168+
" pip install bioio-ome-tiff"
1169+
)
1170+
return
11601171

11611172
# Get all parameters as dict of lists, or static because of unchanging values
11621173
datas: List[biob.types.ArrayLike] = []

bioio/tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# -*- coding: utf-8 -*-
1+
#!/usr/bin/env python
22

33
"""Unit test package for bioio."""
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from typing import Any
2+
3+
import bioio_base as biob
4+
from bioio_base.writer import Writer
5+
6+
7+
class DummyWriter(Writer):
8+
"""
9+
A dummy writer for testing bioio.writers entry-point discovery.
10+
"""
11+
12+
@staticmethod
13+
def save(
14+
data: biob.types.ArrayLike,
15+
uri: biob.types.PathLike,
16+
dim_order: str = biob.dimensions.DEFAULT_DIMENSION_ORDER,
17+
**kwargs: Any,
18+
) -> None:
19+
"""
20+
Stub implementation that deliberately isn’t implemented.
21+
"""
22+
raise NotImplementedError("DummyWriter.save is a stub")

bioio/tests/dummy-plugin/pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ test = [
4747
[project.entry-points."bioio.readers"]
4848
dummy-plugin = "dummy_plugin"
4949

50+
[project.entry-points."bioio.writers"]
51+
DummyWriter = "dummy_plugin.writer:DummyWriter"
52+
5053
# build settings
5154
# https://setuptools.pypa.io/en/latest/userguide/pyproject_config.html
5255
[tool.setuptools]

bioio/tests/test_bio_image.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22
# -*- coding: utf-8 -*-
33

44
import pathlib
5-
import sys
6-
7-
if sys.version_info < (3, 10):
8-
from importlib_metadata import EntryPoint
9-
else:
10-
from importlib.metadata import EntryPoint
5+
from importlib.metadata import EntryPoint
116

127
import bioio_base as biob
138
import numpy as np

bioio/tests/test_writer.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from importlib.metadata import entry_points
2+
3+
import pytest
4+
5+
6+
def test_dummy_writer_discovery_and_api(dummy_plugin: str) -> None:
7+
# Entry-point registration
8+
eps = entry_points(group="bioio.writers")
9+
names = {ep.name for ep in eps}
10+
assert "DummyWriter" in names, f"found: {sorted(names)}"
11+
12+
# Public API (__all__)
13+
import bioio.writers as pkg
14+
15+
assert "DummyWriter" in getattr(pkg, "__all__", [])
16+
17+
# Import works (dynamic, so ignore mypy attr-defined error)
18+
from bioio.writers import DummyWriter # type: ignore[attr-defined]
19+
20+
assert DummyWriter.__name__ == "DummyWriter"
21+
22+
23+
def test_dummy_writer_save_stub(dummy_plugin: str) -> None:
24+
# The save() stub should raise NotImplementedError
25+
from bioio.writers import DummyWriter # type: ignore[attr-defined]
26+
27+
with pytest.raises(NotImplementedError):
28+
DummyWriter.save(data=[1], uri="unused", dim_order="XYZ")

bioio/tests/writers/__init__.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)