bioimageflow-io-tools 0.1.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,23 @@
1
+ .DS_Store
2
+ .worktrees/
3
+ .claude/worktrees/
4
+ .pytest_cache/
5
+ .claude/
6
+ .venv/
7
+ TODO.md
8
+ bif_data/
9
+ data/
10
+ !example_workflows/fish_analysis/data/
11
+ example_workflows/bbbc038_segmentation_benchmark/data/
12
+ example_workflows/outputs/
13
+ !packages/bioimageflow-common-tools/bioimageflow_common_tools/data/
14
+ packages/bioimageflow-common-tools/bioimageflow_common_tools/data/*
15
+ !packages/bioimageflow-common-tools/bioimageflow_common_tools/data/blobs.txt
16
+ packages/bioimageflow-common-tools/bioimageflow_common_tools/.vscode/
17
+ __pycache__/
18
+ docs/build/
19
+ docs/_build/
20
+ wetlands/
21
+ wetlands-lib/
22
+ docs/parsl_phase1a_implementation_spec.md
23
+ example_workflows/fish_analysis/data/*.tif
@@ -0,0 +1,17 @@
1
+ BSD 4-Clause License
2
+
3
+ Copyright (c) 2026, BioImageFlow Contributors
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
9
+
10
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
11
+
12
+ 3. All advertising materials mentioning features or use of this software must display the following acknowledgement: This product includes software developed by the BioImageFlow Contributors.
13
+
14
+ 4. Neither the name of BioImageFlow nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17
+ IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES, INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT, INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,51 @@
1
+ Metadata-Version: 2.4
2
+ Name: bioimageflow-io-tools
3
+ Version: 0.1.6
4
+ Summary: Lightweight image IO tools for BioImageFlow
5
+ Project-URL: Homepage, https://github.com/bioimageit/bioimageflow
6
+ Project-URL: Repository, https://github.com/bioimageit/bioimageflow
7
+ Project-URL: Issues, https://github.com/bioimageit/bioimageflow/issues
8
+ Author: BioImageFlow Contributors
9
+ License-Expression: BSD-4-Clause
10
+ License-File: LICENSE
11
+ Keywords: bioimage-analysis,bioimageflow,microscopy,workflow
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: License :: OSI Approved :: BSD License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3 :: Only
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
21
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
22
+ Requires-Python: >=3.10
23
+ Requires-Dist: bioimageflow-core<0.2,>=0.1.6
24
+ Requires-Dist: imageio
25
+ Requires-Dist: numpy
26
+ Requires-Dist: tifffile
27
+ Description-Content-Type: text/markdown
28
+
29
+ # bioimageflow-io-tools
30
+
31
+ Optional BioImageFlow package for image ingestion, metadata inspection, axis validation, slicing, lightweight format conversion, and explicit bioio/plugin-backed conversion.
32
+
33
+ Core libraries for lightweight tools are imageio, NumPy, tifffile, and the package's minimal OME-Zarr writer.
34
+ `BioIOConvertImage` declares a separate bioio/plugin-backed runtime for broad formats such as CZI and OME-Zarr.
35
+
36
+ ## Tools
37
+
38
+ - `ReadImageMetadata`
39
+ - `ValidateImageLayout`
40
+ - `ConvertImageFormat`
41
+ - `BioIOConvertImage`
42
+ - `ConvertToOmeTiff`
43
+ - `ConvertToOmeZarr`
44
+ - `SelectScene`
45
+ - `SelectTimepoint`
46
+ - `SelectChannel`
47
+ - `SelectZRange`
48
+ - `SelectDimensions`
49
+
50
+ Use `BioIOConvertImage` for microscopy formats that need scene, channel, Z, timepoint, or dimension-order handling.
51
+ Use `ConvertImageFormat` for simple imageio/tifffile conversions.
@@ -0,0 +1,23 @@
1
+ # bioimageflow-io-tools
2
+
3
+ Optional BioImageFlow package for image ingestion, metadata inspection, axis validation, slicing, lightweight format conversion, and explicit bioio/plugin-backed conversion.
4
+
5
+ Core libraries for lightweight tools are imageio, NumPy, tifffile, and the package's minimal OME-Zarr writer.
6
+ `BioIOConvertImage` declares a separate bioio/plugin-backed runtime for broad formats such as CZI and OME-Zarr.
7
+
8
+ ## Tools
9
+
10
+ - `ReadImageMetadata`
11
+ - `ValidateImageLayout`
12
+ - `ConvertImageFormat`
13
+ - `BioIOConvertImage`
14
+ - `ConvertToOmeTiff`
15
+ - `ConvertToOmeZarr`
16
+ - `SelectScene`
17
+ - `SelectTimepoint`
18
+ - `SelectChannel`
19
+ - `SelectZRange`
20
+ - `SelectDimensions`
21
+
22
+ Use `BioIOConvertImage` for microscopy formats that need scene, channel, Z, timepoint, or dimension-order handling.
23
+ Use `ConvertImageFormat` for simple imageio/tifffile conversions.
@@ -0,0 +1,57 @@
1
+ """BioImageFlow IO Tools."""
2
+
3
+ from importlib import import_module
4
+ from typing import TYPE_CHECKING, Any
5
+
6
+ if TYPE_CHECKING:
7
+ from .bioio_convert import BioIOConvertImage as BioIOConvertImage
8
+ from .image_io import ConvertImageFormat as ConvertImageFormat
9
+ from .image_io import ConvertToOmeTiff as ConvertToOmeTiff
10
+ from .image_io import ConvertToOmeZarr as ConvertToOmeZarr
11
+ from .image_io import ReadImageMetadata as ReadImageMetadata
12
+ from .image_io import SelectChannel as SelectChannel
13
+ from .image_io import SelectDimensions as SelectDimensions
14
+ from .image_io import SelectScene as SelectScene
15
+ from .image_io import SelectTimepoint as SelectTimepoint
16
+ from .image_io import SelectZRange as SelectZRange
17
+ from .image_io import ValidateImageLayout as ValidateImageLayout
18
+
19
+
20
+ _EXPORTS = {
21
+ "BioIOConvertImage": ("bioio_convert", "BioIOConvertImage"),
22
+ "ConvertImageFormat": ("image_io", "ConvertImageFormat"),
23
+ "ConvertToOmeTiff": ("image_io", "ConvertToOmeTiff"),
24
+ "ConvertToOmeZarr": ("image_io", "ConvertToOmeZarr"),
25
+ "ReadImageMetadata": ("image_io", "ReadImageMetadata"),
26
+ "SelectChannel": ("image_io", "SelectChannel"),
27
+ "SelectDimensions": ("image_io", "SelectDimensions"),
28
+ "SelectScene": ("image_io", "SelectScene"),
29
+ "SelectTimepoint": ("image_io", "SelectTimepoint"),
30
+ "SelectZRange": ("image_io", "SelectZRange"),
31
+ "ValidateImageLayout": ("image_io", "ValidateImageLayout"),
32
+ }
33
+
34
+ __all__ = [
35
+ "BioIOConvertImage",
36
+ "ConvertImageFormat",
37
+ "ConvertToOmeTiff",
38
+ "ConvertToOmeZarr",
39
+ "ReadImageMetadata",
40
+ "SelectChannel",
41
+ "SelectDimensions",
42
+ "SelectScene",
43
+ "SelectTimepoint",
44
+ "SelectZRange",
45
+ "ValidateImageLayout",
46
+ ]
47
+
48
+
49
+ def __getattr__(name: str) -> Any:
50
+ try:
51
+ module_name, attribute_name = _EXPORTS[name]
52
+ except KeyError as exc:
53
+ raise AttributeError(name) from exc
54
+ module = import_module(f".{module_name}", __name__)
55
+ value = getattr(module, attribute_name)
56
+ globals()[name] = value
57
+ return value
@@ -0,0 +1,176 @@
1
+ """BioIOConvertImage — convert image file formats using bioio."""
2
+
3
+ from pathlib import Path
4
+ from typing import Annotated, Any
5
+
6
+ from bioimageflow_core import (
7
+ Arguments,
8
+ Category,
9
+ Connectable,
10
+ EnvironmentSpec,
11
+ GUIMeta,
12
+ ImageSpec,
13
+ IOModel,
14
+ ProcessingTool,
15
+ Template,
16
+ )
17
+
18
+ bioio_env = EnvironmentSpec(
19
+ name="bioio-all",
20
+ dependencies={
21
+ "python": "3.12",
22
+ "pip": [
23
+ "bioio==3.4.0",
24
+ "bioio-ome-zarr==3.5.1",
25
+ "bioio-ome-tiff==1.4.0",
26
+ "bioio-czi==2.8.0",
27
+ "bioio-imageio==1.3.0",
28
+ "bioio-tifffile==1.3.0",
29
+ "bioio-tiff-glob==1.2.0",
30
+ ]
31
+ }
32
+ )
33
+
34
+
35
+ class BioIOConvertImage(ProcessingTool):
36
+ """Convert image file formats using bioio.
37
+
38
+ Supports reading CZI, DV, PNG, GIF, LIF, ND2, OME-TIFF, OME-ZARR,
39
+ SLDY, TIFF, and Bio-Formats files. The extension of the output file
40
+ specifies the target format.
41
+ """
42
+ display_name = "BioIO Convert Image"
43
+ documentation = (
44
+ "Convert broad microscopy image file formats using bioio. The output format is "
45
+ "determined by the output file extension."
46
+ )
47
+ category = Category.CONVERSION
48
+ tags = ["format conversion", "bioio"]
49
+ environment = bioio_env
50
+
51
+ class Inputs(IOModel):
52
+ input_image: Annotated[
53
+ Path,
54
+ ImageSpec(),
55
+ GUIMeta(
56
+ display_name="Input image",
57
+ description="Source image file to convert.",
58
+ connectable=Connectable.BY_DEFAULT,
59
+ )
60
+ ]
61
+ dim_order: Annotated[str, GUIMeta(
62
+ display_name="Dimension order",
63
+ description="Target dimension order used when reading the image.",
64
+ )] = "TCZYX"
65
+ scene: Annotated[int | None, GUIMeta(
66
+ display_name="Scene",
67
+ description="Optional scene index for multi-scene files. Leave empty to keep the default scene.",
68
+ min=0, step=1,
69
+ )] = None
70
+ channel: Annotated[int | None, GUIMeta(
71
+ display_name="Channel",
72
+ description="Optional channel index to select (0-based). Leave empty to keep all channels.",
73
+ min=0, step=1,
74
+ )] = None
75
+ z: Annotated[int | None, GUIMeta(
76
+ display_name="Z slice",
77
+ description="Optional Z-slice index to select (0-based). Leave empty to keep all Z slices.",
78
+ min=0, step=1,
79
+ )] = None
80
+ timepoint: Annotated[int | None, GUIMeta(
81
+ display_name="Timepoint",
82
+ description="Optional timepoint index to select (0-based). Leave empty to keep all timepoints.",
83
+ min=0, step=1,
84
+ )] = None
85
+
86
+ class Outputs(IOModel):
87
+ output_image: Annotated[
88
+ Path,
89
+ ImageSpec(),
90
+ GUIMeta(
91
+ display_name="Output image",
92
+ description="Converted image. The file extension controls the output format (e.g. .ome.tiff, .ome.zarr, .tif, .png).",
93
+ )
94
+ ] = Template("{input_image.stem}.ome.tiff")
95
+
96
+ def process_row(self, arguments: Arguments, *, context: Any = None) -> Any:
97
+ from bioio import BioImage #type: ignore
98
+ from bioio_ome_tiff.writers import OmeTiffWriter #type: ignore
99
+ from bioio_ome_zarr.writers import OMEZarrWriter #type: ignore
100
+ from bioio_imageio.writers import TwoDWriter #type: ignore
101
+ import numpy as np
102
+ import tifffile
103
+
104
+ input_path = Path(arguments.input_image)
105
+ output_path = Path(arguments.output_image)
106
+ output_path.parent.mkdir(parents=True, exist_ok=True)
107
+
108
+ print(f"Converting {input_path.name}...")
109
+ image = BioImage(input_path)
110
+
111
+ if arguments.scene is not None:
112
+ image.set_scene(arguments.scene)
113
+
114
+ # Show dimension sizes
115
+ print(f"Image: {input_path.name}")
116
+ print(f" Dimensions: {image.dims}")
117
+ print(f" Shape: {image.shape}")
118
+ print(f" Dtype: {image.dtype}")
119
+
120
+ dim_kwargs: dict[str, int] = {}
121
+ if arguments.channel is not None:
122
+ dim_kwargs["C"] = arguments.channel
123
+ if arguments.z is not None:
124
+ dim_kwargs["Z"] = arguments.z
125
+ if arguments.timepoint is not None:
126
+ dim_kwargs["T"] = arguments.timepoint
127
+
128
+ # Use user-specified dim_order for reading
129
+ dim_order = arguments.dim_order
130
+ if dim_kwargs:
131
+ data = image.get_image_data(dim_order, **dim_kwargs)
132
+ else:
133
+ data = image.get_image_data(dim_order)
134
+
135
+ # Squeeze singleton leading dimensions (T, Z) so downstream tools
136
+ # see CYX / YX shapes rather than TCZYX with size-1 axes.
137
+ while data.ndim > 2 and data.shape[0] == 1:
138
+ data = data[0]
139
+ dim_order = dim_order[1:]
140
+
141
+ print(f" Output shape ({dim_order}): {data.shape}")
142
+
143
+ suffixes = "".join(output_path.suffixes).lower()
144
+
145
+ if suffixes.endswith(".ome.tiff") or suffixes.endswith(".ome.tif"):
146
+ OmeTiffWriter.save(data, str(output_path), dim_order=dim_order)
147
+ elif suffixes.endswith(".ome.zarr"):
148
+ axes_map = {
149
+ "T": ("t", "time"), "C": ("c", "channel"), "Z": ("z", "space"),
150
+ "Y": ("y", "space"), "X": ("x", "space"), "S": ("s", "channel"),
151
+ }
152
+ axes_names = [axes_map[c][0] for c in dim_order]
153
+ axes_types = [axes_map[c][1] for c in dim_order]
154
+ writer = OMEZarrWriter(
155
+ store=str(output_path),
156
+ level_shapes=data.shape,
157
+ dtype=data.dtype,
158
+ axes_names=axes_names,
159
+ axes_types=axes_types,
160
+ )
161
+ writer.write_full_volume(data)
162
+ elif suffixes.endswith(".tiff") or suffixes.endswith(".tif"):
163
+ tifffile.imwrite(str(output_path), data)
164
+ else:
165
+ img_2d = np.squeeze(data)
166
+ if img_2d.ndim > 3:
167
+ raise ValueError(
168
+ f"Cannot save {img_2d.ndim}D data to {output_path.suffix}. "
169
+ f"Use dimension selection (channel, z, timepoint) to reduce."
170
+ )
171
+ if img_2d.ndim == 3 and img_2d.shape[0] in (1, 3, 4):
172
+ TwoDWriter.save(img_2d, str(output_path), "SYX")
173
+ else:
174
+ TwoDWriter.save(img_2d, str(output_path))
175
+
176
+ return self.Outputs(output_image=output_path)