bioio-conversion 2.2.0__tar.gz → 2.3.0__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.
- bioio_conversion-2.3.0/.gitattributes +1 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/PKG-INFO +4 -2
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/bioio_conversion/converters/ome_zarr_converter.py +56 -10
- bioio_conversion-2.3.0/bioio_conversion/provenance.py +223 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/bioio_conversion.egg-info/PKG-INFO +4 -2
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/bioio_conversion.egg-info/SOURCES.txt +2 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/bioio_conversion.egg-info/requires.txt +3 -1
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/bioio_conversion.egg-info/scm_file_list.json +31 -25
- bioio_conversion-2.3.0/bioio_conversion.egg-info/scm_version.json +8 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/pyproject.toml +3 -1
- bioio_conversion-2.2.0/bioio_conversion.egg-info/scm_version.json +0 -8
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/.github/CODEOWNERS +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/.github/dependabot.yml +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/.github/workflows/ci.yml +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/.github/workflows/docs.yml +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/.gitignore +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/.pre-commit-config.yaml +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/CODE_OF_CONDUCT.md +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/Justfile +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/LICENSE +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/MANIFEST.in +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/README.md +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/bioio_conversion/__init__.py +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/bioio_conversion/bin/cli_batch_convert.py +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/bioio_conversion/bin/cli_convert.py +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/bioio_conversion/bin/ome_zarr_options.py +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/bioio_conversion/converters/__init__.py +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/bioio_conversion/converters/batch_converter.py +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/bioio_conversion/sharding.py +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/bioio_conversion.egg-info/dependency_links.txt +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/bioio_conversion.egg-info/entry_points.txt +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/bioio_conversion.egg-info/not-zip-safe +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/bioio_conversion.egg-info/top_level.txt +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/docs/api_reference.rst +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/docs/conf.py +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/docs/index.rst +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/docs/overview.rst +0 -0
- {bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/setup.cfg +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*.nd2 filter=lfs diff=lfs merge=lfs -text
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bioio-conversion
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.3.0
|
|
4
4
|
Summary: A BioIO conversion tool for going between image formats
|
|
5
5
|
Author-email: bioio-devs <brian.whitney@alleninstitute.org>
|
|
6
6
|
License: MIT License
|
|
@@ -14,18 +14,20 @@ Description-Content-Type: text/markdown
|
|
|
14
14
|
License-File: LICENSE
|
|
15
15
|
Requires-Dist: bioio>=3.0.0
|
|
16
16
|
Requires-Dist: bioio-base>=3.4.0
|
|
17
|
-
Requires-Dist: bioio-ome-zarr>=3.
|
|
17
|
+
Requires-Dist: bioio-ome-zarr>=3.6.0
|
|
18
18
|
Requires-Dist: numpy>=1.24.0
|
|
19
19
|
Requires-Dist: dask>=2021.10.0
|
|
20
20
|
Requires-Dist: numcodecs>=0.10.0
|
|
21
21
|
Requires-Dist: psutil>=5.8.0
|
|
22
22
|
Requires-Dist: scikit-image>=0.19.0
|
|
23
|
+
Requires-Dist: xmltodict>=0.13.0
|
|
23
24
|
Provides-Extra: lint
|
|
24
25
|
Requires-Dist: pre-commit>=2.20.0; extra == "lint"
|
|
25
26
|
Provides-Extra: test
|
|
26
27
|
Requires-Dist: coverage>=5.1; extra == "test"
|
|
27
28
|
Requires-Dist: bioio-ome-tiff>=1.4.0; extra == "test"
|
|
28
29
|
Requires-Dist: bioio-czi>=2.8.0; extra == "test"
|
|
30
|
+
Requires-Dist: bioio-nd2>=1.7.0; extra == "test"
|
|
29
31
|
Requires-Dist: pytest>=5.4.3; extra == "test"
|
|
30
32
|
Requires-Dist: pytest-cov>=2.9.0; extra == "test"
|
|
31
33
|
Requires-Dist: pytest-raises>=0.11; extra == "test"
|
{bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/bioio_conversion/converters/ome_zarr_converter.py
RENAMED
|
@@ -5,6 +5,7 @@ from concurrent.futures import ProcessPoolExecutor
|
|
|
5
5
|
from pathlib import Path
|
|
6
6
|
from typing import Any, Dict, List, Optional, Tuple, Union
|
|
7
7
|
|
|
8
|
+
import fsspec
|
|
8
9
|
import numcodecs
|
|
9
10
|
import numpy as np
|
|
10
11
|
import psutil
|
|
@@ -16,6 +17,7 @@ from bioio_ome_zarr.writers.ome_zarr_writer import MultiResolutionShapeSpec
|
|
|
16
17
|
from bioio_ome_zarr.writers.utils import multiscale_chunk_size_from_memory_target
|
|
17
18
|
from zarr.codecs import BloscCodec
|
|
18
19
|
|
|
20
|
+
from ..provenance import ProvenanceBuilder, write_sidecars
|
|
19
21
|
from ..sharding import (
|
|
20
22
|
DEFAULT_CHUNK_LIMIT_BYTES,
|
|
21
23
|
DEFAULT_SHARD_LIMIT_BYTES,
|
|
@@ -123,6 +125,8 @@ class OmeZarrConverter:
|
|
|
123
125
|
dtype: Optional[Union[str, np.dtype]] = None,
|
|
124
126
|
n_workers: Optional[int] = None,
|
|
125
127
|
shard_limit_bytes: int = DEFAULT_SHARD_LIMIT_BYTES,
|
|
128
|
+
include_provenance: bool = False,
|
|
129
|
+
provenance_reader_kwargs: Optional[Dict[str, Any]] = None,
|
|
126
130
|
) -> None:
|
|
127
131
|
"""
|
|
128
132
|
Initialize an OME-Zarr converter with flexible scene selection,
|
|
@@ -133,8 +137,9 @@ class OmeZarrConverter:
|
|
|
133
137
|
source : str
|
|
134
138
|
Path to the input image (any format supported by BioImage).
|
|
135
139
|
destination : Optional[str]
|
|
136
|
-
|
|
137
|
-
If ``None``, the converter will use the current working
|
|
140
|
+
Local directory or remote URI under which to write the ``.ome.zarr``
|
|
141
|
+
output(s). If ``None``, the converter will use the current working
|
|
142
|
+
directory
|
|
138
143
|
scenes : Optional[Union[int, List[int]]]
|
|
139
144
|
Which scene(s) to export:
|
|
140
145
|
- ``None`` → export all scenes
|
|
@@ -216,10 +221,19 @@ class OmeZarrConverter:
|
|
|
216
221
|
n_workers : Optional[int]
|
|
217
222
|
Number of worker *processes* for shard writes (auto-layout path).
|
|
218
223
|
If ``None`` (default), derived from the cores actually available to
|
|
219
|
-
the process. One process per core,
|
|
220
|
-
floored at 1.
|
|
224
|
+
the process. One process per core, floored at 1.
|
|
221
225
|
shard_limit_bytes : int
|
|
222
226
|
Maximum uncompressed size of a level-0 shard. Default: 4 GiB.
|
|
227
|
+
include_provenance : bool, default = False
|
|
228
|
+
When True, write source provenance for each scene into a top-level
|
|
229
|
+
``"bioio_conversion"`` attributes block: the source's ``standard_metadata``,
|
|
230
|
+
the reader plugin and package versions, and the native/OME metadata
|
|
231
|
+
as JSON sidecars under ``bioio/``. Off by default; see
|
|
232
|
+
:class:`bioio_conversion.provenance.ProvenanceBuilder`.
|
|
233
|
+
provenance_reader_kwargs : dict, optional
|
|
234
|
+
Extra kwargs forwarded to ``BioImage`` when opening a dedicated
|
|
235
|
+
metadata reader for provenance. When ``None`` (default) the pixel
|
|
236
|
+
reader is reused as-is. Ignored when ``include_provenance=False``.
|
|
223
237
|
"""
|
|
224
238
|
self.source = source
|
|
225
239
|
self.destination = destination or str(Path.cwd())
|
|
@@ -275,6 +289,17 @@ class OmeZarrConverter:
|
|
|
275
289
|
# not oversubscribe a partial node; it is floored at 1.
|
|
276
290
|
self._n_workers = n_workers or _available_cores()
|
|
277
291
|
self._shard_limit_bytes = shard_limit_bytes
|
|
292
|
+
# Provenance (the "bioio_conversion" attribute block + source-metadata sidecars)
|
|
293
|
+
self._provenance = (
|
|
294
|
+
ProvenanceBuilder(
|
|
295
|
+
self.source,
|
|
296
|
+
self.bioimage,
|
|
297
|
+
self.scene_names,
|
|
298
|
+
metadata_reader_kwargs=provenance_reader_kwargs,
|
|
299
|
+
)
|
|
300
|
+
if include_provenance
|
|
301
|
+
else None
|
|
302
|
+
)
|
|
278
303
|
|
|
279
304
|
# -------------------------------------------------------------------------
|
|
280
305
|
# Internal helpers
|
|
@@ -546,13 +571,29 @@ class OmeZarrConverter:
|
|
|
546
571
|
else f"{self.output_basename}_{scene_name}"
|
|
547
572
|
)
|
|
548
573
|
base = re.sub(r"[<>:\"/\\|?*]", "_", base)
|
|
549
|
-
|
|
550
|
-
if
|
|
574
|
+
|
|
575
|
+
if fsspec.utils.get_protocol(self.destination) == "file":
|
|
576
|
+
# Destination is a local path
|
|
577
|
+
out_path = str(Path(self.destination) / f"{base}.ome.zarr")
|
|
578
|
+
else:
|
|
579
|
+
# Destination is a URI (e.g., S3, GCS, etc.)
|
|
580
|
+
out_path = self.destination.rstrip("/") + f"/{base}.ome.zarr"
|
|
581
|
+
|
|
582
|
+
fs, _ = fsspec.core.url_to_fs(self.destination)
|
|
583
|
+
if fs.exists(out_path):
|
|
551
584
|
raise FileExistsError(f"{out_path} already exists.")
|
|
552
585
|
|
|
553
|
-
# (6) Build writer kwargs
|
|
586
|
+
# (6) Build writer kwargs. Provenance ("bioio_conversion" attrs) is merged
|
|
587
|
+
# the root group's attributes by the writer during initialize(); the
|
|
588
|
+
# matching XML sidecars are written afterwards, once the store exists.
|
|
589
|
+
if self._provenance is not None:
|
|
590
|
+
bioio_attrs, bioio_sidecars = self._provenance.provenance_from_scene(
|
|
591
|
+
scene_index
|
|
592
|
+
)
|
|
593
|
+
else:
|
|
594
|
+
bioio_attrs, bioio_sidecars = None, {}
|
|
554
595
|
writer_kwargs: Dict[str, Any] = {
|
|
555
|
-
"store":
|
|
596
|
+
"store": out_path,
|
|
556
597
|
"level_shapes": writer_level_shapes_param,
|
|
557
598
|
"dtype": self.output_dtype,
|
|
558
599
|
**{
|
|
@@ -571,6 +612,7 @@ class OmeZarrConverter:
|
|
|
571
612
|
"axes_types": self._writer_axes_types,
|
|
572
613
|
"axes_units": self._infer_axes_units(axis_names),
|
|
573
614
|
"physical_pixel_size": pps,
|
|
615
|
+
"attributes": bioio_attrs,
|
|
574
616
|
}.items()
|
|
575
617
|
if v is not None
|
|
576
618
|
},
|
|
@@ -588,6 +630,10 @@ class OmeZarrConverter:
|
|
|
588
630
|
# so no shard is ever read back to be merged (no read-modify-write).
|
|
589
631
|
writer.initialize()
|
|
590
632
|
|
|
633
|
+
# Attach the source metadata XML sidecars under bioio/ now that the
|
|
634
|
+
# store exists (as json).
|
|
635
|
+
write_sidecars(Path(out_path), bioio_sidecars)
|
|
636
|
+
|
|
591
637
|
if can_auto_layout:
|
|
592
638
|
self._write_auto_layout_shards(
|
|
593
639
|
out_path, native_order, scene_index, auto_shards, level0_shape
|
|
@@ -598,7 +644,7 @@ class OmeZarrConverter:
|
|
|
598
644
|
|
|
599
645
|
def _write_auto_layout_shards(
|
|
600
646
|
self,
|
|
601
|
-
out_path:
|
|
647
|
+
out_path: str,
|
|
602
648
|
native_order: str,
|
|
603
649
|
scene_index: int,
|
|
604
650
|
auto_shards: MultiResolutionShapeSpec,
|
|
@@ -632,7 +678,7 @@ class OmeZarrConverter:
|
|
|
632
678
|
pool.submit(
|
|
633
679
|
_write_shard_process,
|
|
634
680
|
self.source,
|
|
635
|
-
|
|
681
|
+
out_path,
|
|
636
682
|
native_order,
|
|
637
683
|
scene_index,
|
|
638
684
|
out_dtype_str,
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import dataclasses
|
|
2
|
+
import datetime
|
|
3
|
+
import importlib.metadata
|
|
4
|
+
import json
|
|
5
|
+
import warnings
|
|
6
|
+
import xml.etree.ElementTree as ET
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
from typing import Any, Dict, Optional, Sequence, Tuple
|
|
9
|
+
|
|
10
|
+
import xmltodict
|
|
11
|
+
from bioio import BioImage
|
|
12
|
+
|
|
13
|
+
# Root attributes key holding the provenance block.
|
|
14
|
+
PROVENANCE_ATTR_KEY = "bioio_conversion"
|
|
15
|
+
|
|
16
|
+
# Store-relative paths for the source metadata sidecars.
|
|
17
|
+
NATIVE_METADATA_PATH = "metadata.native.json"
|
|
18
|
+
OME_METADATA_PATH = "metadata.ome.json"
|
|
19
|
+
STANDARD_METADATA_PATH = "standard_metadata.json"
|
|
20
|
+
|
|
21
|
+
# Provenance-block keys pointing at each sidecar above.
|
|
22
|
+
NATIVE_METADATA_KEY = "source_metadata"
|
|
23
|
+
OME_METADATA_KEY = "ome_metadata"
|
|
24
|
+
STANDARD_METADATA_KEY = "standard_metadata"
|
|
25
|
+
|
|
26
|
+
# Remaining provenance-block field keys.
|
|
27
|
+
SOURCE_FILE_KEY = "source_file"
|
|
28
|
+
CONVERTED_KEY = "converted"
|
|
29
|
+
PACKAGE_VERSIONS_KEY = "bioio_package_versions"
|
|
30
|
+
PLUGIN_KEY = "plugin"
|
|
31
|
+
|
|
32
|
+
# Packages whose versions are always recorded, alongside the reader plugin.
|
|
33
|
+
TRACKED_PACKAGES = ("bioio", "bioio-base", "bioio-ome-zarr", "bioio-conversion")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _json_safe(value: Any) -> Any:
|
|
37
|
+
"""Coerce a ``StandardMetadata`` value into a JSON-serializable primitive."""
|
|
38
|
+
if isinstance(value, datetime.datetime):
|
|
39
|
+
return value.isoformat()
|
|
40
|
+
if isinstance(value, datetime.timedelta):
|
|
41
|
+
return value.total_seconds()
|
|
42
|
+
return value
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _package_version(name: str) -> Optional[str]:
|
|
46
|
+
"""Installed version of ``name``, or ``None`` if it cannot be determined."""
|
|
47
|
+
try:
|
|
48
|
+
return importlib.metadata.version(name)
|
|
49
|
+
except importlib.metadata.PackageNotFoundError:
|
|
50
|
+
warnings.warn(f"Could not determine version for {name!r}", UserWarning)
|
|
51
|
+
return None
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def _metadata_as_dict(bio: BioImage, attr: str, label: str) -> Optional[Dict[str, Any]]:
|
|
55
|
+
"""Convert a metadata object to a JSON-serializable dict, or None."""
|
|
56
|
+
try:
|
|
57
|
+
md = getattr(bio, attr)
|
|
58
|
+
if md is None:
|
|
59
|
+
return None
|
|
60
|
+
if hasattr(md, "model_dump"):
|
|
61
|
+
return md.model_dump(mode="json") # ome-types / Pydantic v2
|
|
62
|
+
if callable(getattr(md, "json", None)):
|
|
63
|
+
return json.loads(md.json()) # Pydantic v1
|
|
64
|
+
if hasattr(md, "tag") and hasattr(md, "iter"):
|
|
65
|
+
return xmltodict.parse(ET.tostring(md, encoding="unicode"))
|
|
66
|
+
return None
|
|
67
|
+
except Exception as exc: # metadata transfer is best-effort
|
|
68
|
+
warnings.warn(f"Could not read {label} metadata: {exc}", UserWarning)
|
|
69
|
+
return None
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
class ProvenanceBuilder:
|
|
73
|
+
def __init__(
|
|
74
|
+
self,
|
|
75
|
+
source: str,
|
|
76
|
+
bioimage: BioImage,
|
|
77
|
+
scene_names: Sequence[str],
|
|
78
|
+
metadata_reader_kwargs: Optional[Dict[str, Any]] = None,
|
|
79
|
+
) -> None:
|
|
80
|
+
"""
|
|
81
|
+
Builds the ``"bioio_conversion"`` provenance attributes and XML sidecars.
|
|
82
|
+
|
|
83
|
+
Parameters
|
|
84
|
+
----------
|
|
85
|
+
source : str
|
|
86
|
+
Path to the source image.
|
|
87
|
+
bioimage : BioImage
|
|
88
|
+
The conversion's pixel reader.
|
|
89
|
+
scene_names : Sequence[str]
|
|
90
|
+
The pixel reader's scene names, indexed by ``scene_index``.
|
|
91
|
+
metadata_reader_kwargs : dict, optional
|
|
92
|
+
Extra kwargs forwarded to ``BioImage`` when opening a dedicated
|
|
93
|
+
metadata reader. When ``None`` (default) the pixel reader is used
|
|
94
|
+
as-is for provenance.
|
|
95
|
+
"""
|
|
96
|
+
self._source = source
|
|
97
|
+
self._bioimage = bioimage
|
|
98
|
+
self._scene_names = scene_names
|
|
99
|
+
self._plugin = type(bioimage.reader).__module__.split(".")[0].replace("_", "-")
|
|
100
|
+
self._metadata_reader_kwargs = metadata_reader_kwargs
|
|
101
|
+
self._metadata_bioimage: Optional[BioImage] = None
|
|
102
|
+
self._metadata_cache: Optional[
|
|
103
|
+
Tuple[Optional[Dict[str, Any]], Optional[Dict[str, Any]]]
|
|
104
|
+
] = None
|
|
105
|
+
self._whole_file_cache: Optional[Tuple[Dict[str, Any], Dict[str, Any]]] = None
|
|
106
|
+
|
|
107
|
+
def _metadata_reader(self) -> BioImage:
|
|
108
|
+
"""The reader used to source provenance metadata, cached across scenes."""
|
|
109
|
+
if self._metadata_bioimage is not None:
|
|
110
|
+
return self._metadata_bioimage
|
|
111
|
+
|
|
112
|
+
self._metadata_bioimage = self._bioimage
|
|
113
|
+
if self._metadata_reader_kwargs is None:
|
|
114
|
+
return self._metadata_bioimage
|
|
115
|
+
|
|
116
|
+
try:
|
|
117
|
+
img = BioImage(self._source, **self._metadata_reader_kwargs)
|
|
118
|
+
except Exception as exc:
|
|
119
|
+
warnings.warn(
|
|
120
|
+
f"Could not open a dedicated {self._plugin} metadata reader, "
|
|
121
|
+
f"using the default reader for provenance: {exc}",
|
|
122
|
+
UserWarning,
|
|
123
|
+
)
|
|
124
|
+
return self._metadata_bioimage
|
|
125
|
+
|
|
126
|
+
self._metadata_bioimage = img
|
|
127
|
+
return self._metadata_bioimage
|
|
128
|
+
|
|
129
|
+
def _metadata_dicts(
|
|
130
|
+
self,
|
|
131
|
+
) -> Tuple[Optional[Dict[str, Any]], Optional[Dict[str, Any]]]:
|
|
132
|
+
"""Whole-file ``(ome_dict, native_dict)`` for the source, computed once."""
|
|
133
|
+
if self._metadata_cache is None:
|
|
134
|
+
meta = self._metadata_reader()
|
|
135
|
+
self._metadata_cache = (
|
|
136
|
+
_metadata_as_dict(meta, "ome_metadata", "OME"),
|
|
137
|
+
_metadata_as_dict(meta, "metadata", "native"),
|
|
138
|
+
)
|
|
139
|
+
return self._metadata_cache
|
|
140
|
+
|
|
141
|
+
def _whole_file_provenance(
|
|
142
|
+
self,
|
|
143
|
+
) -> Tuple[Dict[str, Any], Dict[str, Any]]:
|
|
144
|
+
"""The whole-file part of the block and its sidecars.
|
|
145
|
+
|
|
146
|
+
File name, conversion timestamp, package versions, reader plugin, and the
|
|
147
|
+
metadata sidecars are all scene-independent, so they are built on first
|
|
148
|
+
use and reused for every scene.
|
|
149
|
+
"""
|
|
150
|
+
if self._whole_file_cache is not None:
|
|
151
|
+
return self._whole_file_cache
|
|
152
|
+
|
|
153
|
+
versions: Dict[str, str] = {}
|
|
154
|
+
for name in (*TRACKED_PACKAGES, self._plugin):
|
|
155
|
+
version = _package_version(name)
|
|
156
|
+
if version is not None:
|
|
157
|
+
versions[name] = version
|
|
158
|
+
|
|
159
|
+
block: Dict[str, Any] = {
|
|
160
|
+
SOURCE_FILE_KEY: Path(self._source).name,
|
|
161
|
+
CONVERTED_KEY: datetime.datetime.now(datetime.timezone.utc).isoformat(),
|
|
162
|
+
PACKAGE_VERSIONS_KEY: versions,
|
|
163
|
+
PLUGIN_KEY: self._plugin,
|
|
164
|
+
}
|
|
165
|
+
sidecars: Dict[str, Any] = {}
|
|
166
|
+
|
|
167
|
+
def attach(
|
|
168
|
+
pointer_key: str, path: str, content: Optional[Dict[str, Any]]
|
|
169
|
+
) -> None:
|
|
170
|
+
if content is None:
|
|
171
|
+
return
|
|
172
|
+
for existing_path, existing in sidecars.items():
|
|
173
|
+
if existing == content:
|
|
174
|
+
block[pointer_key] = existing_path
|
|
175
|
+
return
|
|
176
|
+
block[pointer_key] = path
|
|
177
|
+
sidecars[path] = content
|
|
178
|
+
|
|
179
|
+
ome_dict, native_dict = self._metadata_dicts()
|
|
180
|
+
attach(OME_METADATA_KEY, OME_METADATA_PATH, ome_dict)
|
|
181
|
+
attach(NATIVE_METADATA_KEY, NATIVE_METADATA_PATH, native_dict)
|
|
182
|
+
|
|
183
|
+
self._whole_file_cache = (block, sidecars)
|
|
184
|
+
return self._whole_file_cache
|
|
185
|
+
|
|
186
|
+
def provenance_from_scene(
|
|
187
|
+
self,
|
|
188
|
+
scene_index: int,
|
|
189
|
+
) -> Tuple[Optional[Dict[str, Any]], Dict[str, Any]]:
|
|
190
|
+
"""Derive provenance for a scene."""
|
|
191
|
+
meta = self._metadata_reader()
|
|
192
|
+
meta.set_scene(scene_index)
|
|
193
|
+
try:
|
|
194
|
+
fields = {
|
|
195
|
+
k: _json_safe(v)
|
|
196
|
+
for k, v in dataclasses.asdict(meta.standard_metadata).items()
|
|
197
|
+
}
|
|
198
|
+
except Exception as exc:
|
|
199
|
+
warnings.warn(
|
|
200
|
+
f"Could not read standard_metadata, omitting "
|
|
201
|
+
f"{PROVENANCE_ATTR_KEY!r} attributes: {exc}",
|
|
202
|
+
UserWarning,
|
|
203
|
+
)
|
|
204
|
+
return None, {}
|
|
205
|
+
|
|
206
|
+
base, whole_file_sidecars = self._whole_file_provenance()
|
|
207
|
+
sidecars = {**whole_file_sidecars, STANDARD_METADATA_PATH: fields}
|
|
208
|
+
block = {**base, STANDARD_METADATA_KEY: STANDARD_METADATA_PATH}
|
|
209
|
+
return {PROVENANCE_ATTR_KEY: block}, sidecars
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def write_sidecars(store_path: Path, sidecars: Dict[str, Any]) -> None:
|
|
213
|
+
"""Write metadata sidecar dicts."""
|
|
214
|
+
for rel_path, content in sidecars.items():
|
|
215
|
+
try:
|
|
216
|
+
sidecar_path = store_path / rel_path
|
|
217
|
+
sidecar_path.parent.mkdir(parents=True, exist_ok=True)
|
|
218
|
+
sidecar_path.write_text(json.dumps(content), encoding="utf-8")
|
|
219
|
+
except Exception as exc:
|
|
220
|
+
warnings.warn(
|
|
221
|
+
f"Could not write metadata sidecar {rel_path!r}: {exc}",
|
|
222
|
+
UserWarning,
|
|
223
|
+
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: bioio-conversion
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.3.0
|
|
4
4
|
Summary: A BioIO conversion tool for going between image formats
|
|
5
5
|
Author-email: bioio-devs <brian.whitney@alleninstitute.org>
|
|
6
6
|
License: MIT License
|
|
@@ -14,18 +14,20 @@ Description-Content-Type: text/markdown
|
|
|
14
14
|
License-File: LICENSE
|
|
15
15
|
Requires-Dist: bioio>=3.0.0
|
|
16
16
|
Requires-Dist: bioio-base>=3.4.0
|
|
17
|
-
Requires-Dist: bioio-ome-zarr>=3.
|
|
17
|
+
Requires-Dist: bioio-ome-zarr>=3.6.0
|
|
18
18
|
Requires-Dist: numpy>=1.24.0
|
|
19
19
|
Requires-Dist: dask>=2021.10.0
|
|
20
20
|
Requires-Dist: numcodecs>=0.10.0
|
|
21
21
|
Requires-Dist: psutil>=5.8.0
|
|
22
22
|
Requires-Dist: scikit-image>=0.19.0
|
|
23
|
+
Requires-Dist: xmltodict>=0.13.0
|
|
23
24
|
Provides-Extra: lint
|
|
24
25
|
Requires-Dist: pre-commit>=2.20.0; extra == "lint"
|
|
25
26
|
Provides-Extra: test
|
|
26
27
|
Requires-Dist: coverage>=5.1; extra == "test"
|
|
27
28
|
Requires-Dist: bioio-ome-tiff>=1.4.0; extra == "test"
|
|
28
29
|
Requires-Dist: bioio-czi>=2.8.0; extra == "test"
|
|
30
|
+
Requires-Dist: bioio-nd2>=1.7.0; extra == "test"
|
|
29
31
|
Requires-Dist: pytest>=5.4.3; extra == "test"
|
|
30
32
|
Requires-Dist: pytest-cov>=2.9.0; extra == "test"
|
|
31
33
|
Requires-Dist: pytest-raises>=0.11; extra == "test"
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
.gitattributes
|
|
1
2
|
.gitignore
|
|
2
3
|
.pre-commit-config.yaml
|
|
3
4
|
CODE_OF_CONDUCT.md
|
|
@@ -14,6 +15,7 @@ pyproject.toml
|
|
|
14
15
|
.github/workflows/ci.yml
|
|
15
16
|
.github/workflows/docs.yml
|
|
16
17
|
bioio_conversion/__init__.py
|
|
18
|
+
bioio_conversion/provenance.py
|
|
17
19
|
bioio_conversion/sharding.py
|
|
18
20
|
bioio_conversion.egg-info/PKG-INFO
|
|
19
21
|
bioio_conversion.egg-info/SOURCES.txt
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
bioio>=3.0.0
|
|
2
2
|
bioio-base>=3.4.0
|
|
3
|
-
bioio-ome-zarr>=3.
|
|
3
|
+
bioio-ome-zarr>=3.6.0
|
|
4
4
|
numpy>=1.24.0
|
|
5
5
|
dask>=2021.10.0
|
|
6
6
|
numcodecs>=0.10.0
|
|
7
7
|
psutil>=5.8.0
|
|
8
8
|
scikit-image>=0.19.0
|
|
9
|
+
xmltodict>=0.13.0
|
|
9
10
|
|
|
10
11
|
[docs]
|
|
11
12
|
gitchangelog>=3.0.4
|
|
@@ -23,6 +24,7 @@ pre-commit>=2.20.0
|
|
|
23
24
|
coverage>=5.1
|
|
24
25
|
bioio-ome-tiff>=1.4.0
|
|
25
26
|
bioio-czi>=2.8.0
|
|
27
|
+
bioio-nd2>=1.7.0
|
|
26
28
|
pytest>=5.4.3
|
|
27
29
|
pytest-cov>=2.9.0
|
|
28
30
|
pytest-raises>=0.11
|
{bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/bioio_conversion.egg-info/scm_file_list.json
RENAMED
|
@@ -1,47 +1,53 @@
|
|
|
1
1
|
{
|
|
2
2
|
"files": [
|
|
3
|
+
".gitattributes",
|
|
3
4
|
".pre-commit-config.yaml",
|
|
4
|
-
"
|
|
5
|
-
"LICENSE",
|
|
5
|
+
"MANIFEST.in",
|
|
6
6
|
"pyproject.toml",
|
|
7
|
+
"CODE_OF_CONDUCT.md",
|
|
8
|
+
"LICENSE",
|
|
9
|
+
"README.md",
|
|
7
10
|
"Justfile",
|
|
8
|
-
"MANIFEST.in",
|
|
9
11
|
".gitignore",
|
|
10
|
-
"
|
|
12
|
+
".github/PULL_REQUEST_TEMPLATE.md",
|
|
13
|
+
".github/CODEOWNERS",
|
|
14
|
+
".github/dependabot.yml",
|
|
15
|
+
".github/ISSUE_TEMPLATE/bug_report.md",
|
|
16
|
+
".github/ISSUE_TEMPLATE/feature_request.md",
|
|
17
|
+
".github/workflows/ci.yml",
|
|
18
|
+
".github/workflows/docs.yml",
|
|
19
|
+
"scripts/benchmark/benchmark_results.csv",
|
|
20
|
+
"scripts/benchmark/benchmark.py",
|
|
11
21
|
"scripts/benchmark/run_benchmark.sh",
|
|
12
22
|
"scripts/benchmark/data_source.json",
|
|
13
|
-
"scripts/benchmark/benchmark.py",
|
|
14
|
-
"scripts/benchmark/benchmark_results.csv",
|
|
15
|
-
"docs/overview.rst",
|
|
16
23
|
"docs/index.rst",
|
|
17
24
|
"docs/api_reference.rst",
|
|
18
25
|
"docs/conf.py",
|
|
19
|
-
"
|
|
26
|
+
"docs/overview.rst",
|
|
27
|
+
"bioio_conversion/provenance.py",
|
|
20
28
|
"bioio_conversion/__init__.py",
|
|
21
|
-
"bioio_conversion/
|
|
22
|
-
"bioio_conversion/
|
|
23
|
-
"bioio_conversion/bin/cli_batch_convert.py",
|
|
29
|
+
"bioio_conversion/sharding.py",
|
|
30
|
+
"bioio_conversion/tests/test_conversion_cli.py",
|
|
24
31
|
"bioio_conversion/tests/__init__.py",
|
|
25
32
|
"bioio_conversion/tests/test_cli_batch_conversion.py",
|
|
26
|
-
"bioio_conversion/tests/test_conversion_cli.py",
|
|
27
|
-
"bioio_conversion/tests/conftest.py",
|
|
28
33
|
"bioio_conversion/tests/test_sharding.py",
|
|
29
|
-
"bioio_conversion/tests/
|
|
30
|
-
"bioio_conversion/tests/resources/s_3_t_1_c_3_z_5.ome.tiff",
|
|
31
|
-
"bioio_conversion/tests/resources/s_3_t_1_c_3_z_5.czi",
|
|
32
|
-
"bioio_conversion/tests/resources/s_1_t_1_c_1_z_1.ome.tiff",
|
|
34
|
+
"bioio_conversion/tests/conftest.py",
|
|
33
35
|
"bioio_conversion/tests/converters/test_batch_converter.py",
|
|
36
|
+
"bioio_conversion/tests/converters/test_provenance.py",
|
|
34
37
|
"bioio_conversion/tests/converters/__init__.py",
|
|
35
38
|
"bioio_conversion/tests/converters/test_ome_zarr_converter.py",
|
|
36
|
-
"bioio_conversion/
|
|
39
|
+
"bioio_conversion/tests/resources/ND2_dims_p2z5t3-2c4y32x32.nd2",
|
|
40
|
+
"bioio_conversion/tests/resources/ND2_dims_t3c2y32x32.nd2",
|
|
41
|
+
"bioio_conversion/tests/resources/s_3_t_1_c_3_z_5.czi",
|
|
42
|
+
"bioio_conversion/tests/resources/s_1_t_1_c_1_z_1.ome.tiff",
|
|
43
|
+
"bioio_conversion/tests/resources/s_1_t_1_c_1_z_1.czi",
|
|
44
|
+
"bioio_conversion/tests/resources/ND2_dims_c2y32x32.nd2",
|
|
45
|
+
"bioio_conversion/tests/resources/s_3_t_1_c_3_z_5.ome.tiff",
|
|
37
46
|
"bioio_conversion/converters/batch_converter.py",
|
|
47
|
+
"bioio_conversion/converters/__init__.py",
|
|
38
48
|
"bioio_conversion/converters/ome_zarr_converter.py",
|
|
39
|
-
"
|
|
40
|
-
".
|
|
41
|
-
"
|
|
42
|
-
".github/ISSUE_TEMPLATE/bug_report.md",
|
|
43
|
-
".github/ISSUE_TEMPLATE/feature_request.md",
|
|
44
|
-
".github/workflows/docs.yml",
|
|
45
|
-
".github/workflows/ci.yml"
|
|
49
|
+
"bioio_conversion/bin/cli_batch_convert.py",
|
|
50
|
+
"bioio_conversion/bin/ome_zarr_options.py",
|
|
51
|
+
"bioio_conversion/bin/cli_convert.py"
|
|
46
52
|
]
|
|
47
53
|
}
|
|
@@ -30,12 +30,13 @@ dynamic = ["version"]
|
|
|
30
30
|
dependencies = [
|
|
31
31
|
"bioio>=3.0.0",
|
|
32
32
|
"bioio-base>=3.4.0",
|
|
33
|
-
"bioio-ome-zarr>=3.
|
|
33
|
+
"bioio-ome-zarr>=3.6.0",
|
|
34
34
|
"numpy>=1.24.0",
|
|
35
35
|
"dask>=2021.10.0",
|
|
36
36
|
"numcodecs>=0.10.0",
|
|
37
37
|
"psutil>=5.8.0",
|
|
38
38
|
"scikit-image>=0.19.0",
|
|
39
|
+
"xmltodict>=0.13.0",
|
|
39
40
|
]
|
|
40
41
|
|
|
41
42
|
# Console script entry points
|
|
@@ -54,6 +55,7 @@ test = [
|
|
|
54
55
|
"coverage>=5.1",
|
|
55
56
|
"bioio-ome-tiff>=1.4.0",
|
|
56
57
|
"bioio-czi>=2.8.0",
|
|
58
|
+
"bioio-nd2>=1.7.0",
|
|
57
59
|
"pytest>=5.4.3",
|
|
58
60
|
"pytest-cov>=2.9.0",
|
|
59
61
|
"pytest-raises>=0.11",
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/bioio_conversion/converters/batch_converter.py
RENAMED
|
File without changes
|
|
File without changes
|
{bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/bioio_conversion.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{bioio_conversion-2.2.0 → bioio_conversion-2.3.0}/bioio_conversion.egg-info/entry_points.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|