bfio 2.4.1__tar.gz → 2.4.3__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.
- {bfio-2.4.1/src/bfio.egg-info → bfio-2.4.3}/PKG-INFO +5 -5
- {bfio-2.4.1 → bfio-2.4.3}/README.md +4 -4
- {bfio-2.4.1 → bfio-2.4.3}/pyproject.toml +1 -1
- bfio-2.4.3/src/bfio/VERSION +1 -0
- {bfio-2.4.1 → bfio-2.4.3}/src/bfio/backends.py +73 -29
- {bfio-2.4.1 → bfio-2.4.3}/src/bfio/bfio.py +25 -5
- {bfio-2.4.1 → bfio-2.4.3}/src/bfio/ts_backends.py +19 -9
- {bfio-2.4.1 → bfio-2.4.3/src/bfio.egg-info}/PKG-INFO +5 -5
- {bfio-2.4.1 → bfio-2.4.3}/tests/test_read.py +73 -36
- {bfio-2.4.1 → bfio-2.4.3}/tests/test_write.py +62 -0
- bfio-2.4.1/src/bfio/VERSION +0 -1
- {bfio-2.4.1 → bfio-2.4.3}/LICENSE +0 -0
- {bfio-2.4.1 → bfio-2.4.3}/setup.cfg +0 -0
- {bfio-2.4.1 → bfio-2.4.3}/src/bfio/__init__.py +0 -0
- {bfio-2.4.1 → bfio-2.4.3}/src/bfio/base_classes.py +0 -0
- {bfio-2.4.1 → bfio-2.4.3}/src/bfio/utils.py +0 -0
- {bfio-2.4.1 → bfio-2.4.3}/src/bfio.egg-info/SOURCES.txt +0 -0
- {bfio-2.4.1 → bfio-2.4.3}/src/bfio.egg-info/dependency_links.txt +0 -0
- {bfio-2.4.1 → bfio-2.4.3}/src/bfio.egg-info/requires.txt +0 -0
- {bfio-2.4.1 → bfio-2.4.3}/src/bfio.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: bfio
|
|
3
|
-
Version: 2.4.
|
|
3
|
+
Version: 2.4.3
|
|
4
4
|
Summary: Simple reading and writing classes for tiled tiffs using Bio-Formats.
|
|
5
5
|
Author-email: Nick Schaub <nick.schaub@nih.gov>, Sameeul Bashir Samee <sameeul.samee@axleinfo.com>
|
|
6
6
|
Maintainer-email: Sameeul Bashir Samee <sameeul.samee@axleinfo.com>
|
|
@@ -47,7 +47,7 @@ Provides-Extra: dev
|
|
|
47
47
|
Requires-Dist: ome_zarr; extra == "dev"
|
|
48
48
|
Requires-Dist: requests>=2.26.0; extra == "dev"
|
|
49
49
|
|
|
50
|
-
# **B**io**F**ormats **I**nput/**O**utput utility (bfio 2.4.
|
|
50
|
+
# **B**io**F**ormats **I**nput/**O**utput utility (bfio 2.4.3)
|
|
51
51
|
|
|
52
52
|
[](https://bfio.readthedocs.io/en/latest/?badge=latest)
|
|
53
53
|
[](https://pypi.org/project/bfio/)
|
|
@@ -99,15 +99,15 @@ be installed using pip:
|
|
|
99
99
|
|
|
100
100
|
## Docker
|
|
101
101
|
|
|
102
|
-
### polusai/bfio:2.4.
|
|
102
|
+
### polusai/bfio:2.4.3
|
|
103
103
|
|
|
104
104
|
Ubuntu based container with bfio and all dependencies (including Java).
|
|
105
105
|
|
|
106
|
-
### polusai/bfio:2.4.
|
|
106
|
+
### polusai/bfio:2.4.3-imagej
|
|
107
107
|
|
|
108
108
|
Same as above, except comes with ImageJ and PyImageJ.
|
|
109
109
|
|
|
110
|
-
### polusai/bfio:2.4.
|
|
110
|
+
### polusai/bfio:2.4.3-tensorflow
|
|
111
111
|
|
|
112
112
|
Tensorflow container with bfio installed.
|
|
113
113
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# **B**io**F**ormats **I**nput/**O**utput utility (bfio 2.4.
|
|
1
|
+
# **B**io**F**ormats **I**nput/**O**utput utility (bfio 2.4.3)
|
|
2
2
|
|
|
3
3
|
[](https://bfio.readthedocs.io/en/latest/?badge=latest)
|
|
4
4
|
[](https://pypi.org/project/bfio/)
|
|
@@ -50,15 +50,15 @@ be installed using pip:
|
|
|
50
50
|
|
|
51
51
|
## Docker
|
|
52
52
|
|
|
53
|
-
### polusai/bfio:2.4.
|
|
53
|
+
### polusai/bfio:2.4.3
|
|
54
54
|
|
|
55
55
|
Ubuntu based container with bfio and all dependencies (including Java).
|
|
56
56
|
|
|
57
|
-
### polusai/bfio:2.4.
|
|
57
|
+
### polusai/bfio:2.4.3-imagej
|
|
58
58
|
|
|
59
59
|
Same as above, except comes with ImageJ and PyImageJ.
|
|
60
60
|
|
|
61
|
-
### polusai/bfio:2.4.
|
|
61
|
+
### polusai/bfio:2.4.3-tensorflow
|
|
62
62
|
|
|
63
63
|
Tensorflow container with bfio installed.
|
|
64
64
|
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
2.4.3
|
|
@@ -122,18 +122,26 @@ class PythonReader(bfio.base_classes.AbstractReader):
|
|
|
122
122
|
def __getstate__(self) -> Dict:
|
|
123
123
|
state_dict = {n: getattr(self, n) for n in self._STATE_DICT}
|
|
124
124
|
state_dict.update({"file_path": self.frontend._file_path})
|
|
125
|
+
state_dict.update({"level": self.frontend.level})
|
|
125
126
|
|
|
126
127
|
return state_dict
|
|
127
128
|
|
|
128
129
|
def __setstate__(self, state) -> None:
|
|
129
130
|
for k, v in state.items():
|
|
130
|
-
if k == "file_path":
|
|
131
|
-
|
|
132
|
-
self._rdr = tifffile.TiffFile(v)
|
|
133
|
-
self._rdr.filehandle.close()
|
|
131
|
+
if k == "file_path" or k == "level":
|
|
132
|
+
pass
|
|
134
133
|
else:
|
|
135
134
|
setattr(self, k, v)
|
|
136
135
|
|
|
136
|
+
self._lock = threading.Lock()
|
|
137
|
+
self._rdr = tifffile.TiffFile(state["file_path"])
|
|
138
|
+
self._rdr_pages = self._rdr.pages
|
|
139
|
+
if state["level"] is not None:
|
|
140
|
+
if len(self._rdr.series) != 0:
|
|
141
|
+
series = self._rdr.series[0]
|
|
142
|
+
self._rdr_pages = series.levels[state["level"]]
|
|
143
|
+
self._rdr.filehandle.close()
|
|
144
|
+
|
|
137
145
|
def read_metadata(self):
|
|
138
146
|
self.logger.debug("read_metadata(): Reading metadata...")
|
|
139
147
|
|
|
@@ -617,7 +625,15 @@ class PythonWriter(bfio.base_classes.AbstractWriter):
|
|
|
617
625
|
f"Image:{Path(self.frontend._file_path).name}"
|
|
618
626
|
)
|
|
619
627
|
|
|
620
|
-
if
|
|
628
|
+
if (
|
|
629
|
+
self.frontend.X
|
|
630
|
+
* self.frontend.Y
|
|
631
|
+
* self.frontend.Z
|
|
632
|
+
* self.frontend.C
|
|
633
|
+
* self.frontend.T
|
|
634
|
+
* self.frontend.bpp
|
|
635
|
+
> 2**31
|
|
636
|
+
):
|
|
621
637
|
big_tiff = True
|
|
622
638
|
else:
|
|
623
639
|
big_tiff = False
|
|
@@ -1405,8 +1421,9 @@ try:
|
|
|
1405
1421
|
In the future, it may be reasonable to not enforce read-only
|
|
1406
1422
|
|
|
1407
1423
|
"""
|
|
1408
|
-
if self.frontend.
|
|
1409
|
-
|
|
1424
|
+
if self.frontend.append is False:
|
|
1425
|
+
if self.frontend._file_path.exists():
|
|
1426
|
+
shutil.rmtree(self.frontend._file_path)
|
|
1410
1427
|
|
|
1411
1428
|
shape = (
|
|
1412
1429
|
self.frontend.T,
|
|
@@ -1417,8 +1434,12 @@ try:
|
|
|
1417
1434
|
)
|
|
1418
1435
|
|
|
1419
1436
|
compressor = Blosc(cname="zstd", clevel=1, shuffle=Blosc.SHUFFLE)
|
|
1420
|
-
|
|
1421
|
-
|
|
1437
|
+
mode = "w"
|
|
1438
|
+
if self.frontend.append is True:
|
|
1439
|
+
mode = "a"
|
|
1440
|
+
self._root = zarr.open_group(
|
|
1441
|
+
store=str(self.frontend._file_path.resolve()), mode=mode
|
|
1442
|
+
)
|
|
1422
1443
|
|
|
1423
1444
|
# Create the metadata
|
|
1424
1445
|
metadata_path = (
|
|
@@ -1426,30 +1447,53 @@ try:
|
|
|
1426
1447
|
.joinpath("OME")
|
|
1427
1448
|
.joinpath("METADATA.ome.xml")
|
|
1428
1449
|
)
|
|
1429
|
-
metadata_path.parent.mkdir(parents=True, exist_ok=True)
|
|
1430
|
-
with open(metadata_path, "w") as fw:
|
|
1431
|
-
fw.write(str(self.frontend._metadata.to_xml()))
|
|
1432
|
-
|
|
1433
|
-
self._root.attrs["multiscales"] = [
|
|
1434
|
-
{
|
|
1435
|
-
"version": "0.1",
|
|
1436
|
-
"name": self.frontend._file_path.name,
|
|
1437
|
-
"datasets": [{"path": "0"}],
|
|
1438
|
-
"metadata": {"method": "mean"},
|
|
1439
|
-
}
|
|
1440
|
-
]
|
|
1441
1450
|
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1448
|
-
|
|
1451
|
+
if self.frontend.append is False or (
|
|
1452
|
+
self.frontend.append is True and metadata_path.exists() is False
|
|
1453
|
+
):
|
|
1454
|
+
metadata_path.parent.mkdir(parents=True, exist_ok=True)
|
|
1455
|
+
with open(metadata_path, "w") as fw:
|
|
1456
|
+
fw.write(str(self.frontend._metadata.to_xml()))
|
|
1457
|
+
|
|
1458
|
+
self._root.attrs["multiscales"] = [
|
|
1459
|
+
{
|
|
1460
|
+
"version": "0.1",
|
|
1461
|
+
"name": self.frontend._file_path.name,
|
|
1462
|
+
"datasets": [{"path": "0"}],
|
|
1463
|
+
"metadata": {"method": "mean"},
|
|
1464
|
+
}
|
|
1465
|
+
]
|
|
1466
|
+
if (
|
|
1467
|
+
self.frontend.append is True
|
|
1468
|
+
and len(sorted(self._root.array_keys())) > 0
|
|
1469
|
+
):
|
|
1470
|
+
writer = self._root["0"]
|
|
1471
|
+
else:
|
|
1472
|
+
writer = self._root.zeros(
|
|
1473
|
+
"0",
|
|
1474
|
+
shape=shape,
|
|
1475
|
+
chunks=(
|
|
1476
|
+
1,
|
|
1477
|
+
1,
|
|
1478
|
+
1,
|
|
1479
|
+
self.frontend._TILE_SIZE,
|
|
1480
|
+
self.frontend._TILE_SIZE,
|
|
1481
|
+
),
|
|
1482
|
+
dtype=self.frontend.dtype,
|
|
1483
|
+
compressor=compressor,
|
|
1484
|
+
dimension_separator="/",
|
|
1485
|
+
)
|
|
1449
1486
|
|
|
1450
1487
|
# This is recommended to do for cloud storage to increase read/write
|
|
1451
1488
|
# speed, but it also increases write speed locally when threading.
|
|
1452
|
-
|
|
1489
|
+
consolidated_metadata_file = Path(self.frontend._file_path).joinpath(
|
|
1490
|
+
".zmetadata"
|
|
1491
|
+
)
|
|
1492
|
+
if self.frontend.append is False or (
|
|
1493
|
+
self.frontend.append is True
|
|
1494
|
+
and consolidated_metadata_file.exists() is False
|
|
1495
|
+
):
|
|
1496
|
+
zarr.consolidate_metadata(str(self.frontend._file_path.resolve()))
|
|
1453
1497
|
|
|
1454
1498
|
self._writer = writer
|
|
1455
1499
|
|
|
@@ -43,15 +43,15 @@ class BioReader(BioBase):
|
|
|
43
43
|
|
|
44
44
|
logger = logging.getLogger("bfio.bfio.BioReader")
|
|
45
45
|
_STATE_DICT = [
|
|
46
|
+
"level",
|
|
46
47
|
"_metadata",
|
|
47
48
|
"_DIMS",
|
|
48
49
|
"_file_path",
|
|
49
|
-
"
|
|
50
|
+
"_max_workers",
|
|
50
51
|
"_backend_name",
|
|
51
52
|
"clean_metadata",
|
|
52
53
|
"_read_only",
|
|
53
54
|
"_backend",
|
|
54
|
-
"level",
|
|
55
55
|
]
|
|
56
56
|
|
|
57
57
|
def __init__(
|
|
@@ -233,7 +233,15 @@ class BioReader(BioBase):
|
|
|
233
233
|
self._backend_name = backend.lower()
|
|
234
234
|
|
|
235
235
|
def __getstate__(self) -> typing.Dict:
|
|
236
|
-
|
|
236
|
+
if self._backend_name == "bioformats":
|
|
237
|
+
state_dict = {}
|
|
238
|
+
for n in self._STATE_DICT:
|
|
239
|
+
if n == "_backend":
|
|
240
|
+
state_dict[n] = "JavaReaderDummy"
|
|
241
|
+
else:
|
|
242
|
+
state_dict[n] = getattr(self, n)
|
|
243
|
+
else:
|
|
244
|
+
state_dict = {n: getattr(self, n) for n in self._STATE_DICT}
|
|
237
245
|
|
|
238
246
|
return state_dict
|
|
239
247
|
|
|
@@ -241,10 +249,17 @@ class BioReader(BioBase):
|
|
|
241
249
|
assert all(n in self._STATE_DICT for n in state.keys())
|
|
242
250
|
assert all(n in state.keys() for n in self._STATE_DICT)
|
|
243
251
|
|
|
252
|
+
bioformats_backend = False
|
|
244
253
|
for k, v in state.items():
|
|
245
|
-
|
|
254
|
+
if k == "_backend" and v == "JavaReaderDummy":
|
|
255
|
+
bioformats_backend = True
|
|
256
|
+
else:
|
|
257
|
+
setattr(self, k, v)
|
|
246
258
|
|
|
247
|
-
|
|
259
|
+
if bioformats_backend:
|
|
260
|
+
self._backend = backends.JavaReader(self)
|
|
261
|
+
else:
|
|
262
|
+
self._backend.frontend = self
|
|
248
263
|
|
|
249
264
|
def __getitem__(self, keys: typing.Union[tuple, slice]) -> numpy.ndarray:
|
|
250
265
|
"""Image loading using numpy-like indexing.
|
|
@@ -1070,6 +1085,11 @@ class BioWriter(BioBase):
|
|
|
1070
1085
|
setattr(self, k, v)
|
|
1071
1086
|
|
|
1072
1087
|
self.set_backend(backend)
|
|
1088
|
+
self.append = False
|
|
1089
|
+
if kwargs and "append" in kwargs:
|
|
1090
|
+
if kwargs["append"] is True:
|
|
1091
|
+
self.append = True
|
|
1092
|
+
|
|
1073
1093
|
# Ensure backend is supported
|
|
1074
1094
|
if self._backend_name == "python":
|
|
1075
1095
|
self._backend = backends.PythonWriter(self)
|
|
@@ -23,7 +23,19 @@ class TensorstoreReader(bfio.base_classes.TSAbstractReader):
|
|
|
23
23
|
|
|
24
24
|
_rdr = None
|
|
25
25
|
_offsets_bytes = None
|
|
26
|
-
_STATE_DICT = [
|
|
26
|
+
_STATE_DICT = [
|
|
27
|
+
"_metadata",
|
|
28
|
+
"frontend",
|
|
29
|
+
"X",
|
|
30
|
+
"Y",
|
|
31
|
+
"Z",
|
|
32
|
+
"C",
|
|
33
|
+
"T",
|
|
34
|
+
"data_type",
|
|
35
|
+
"_file_path",
|
|
36
|
+
"_file_type",
|
|
37
|
+
"_axes_list",
|
|
38
|
+
]
|
|
27
39
|
|
|
28
40
|
def __init__(self, frontend):
|
|
29
41
|
super().__init__(frontend)
|
|
@@ -33,7 +45,8 @@ class TensorstoreReader(bfio.base_classes.TSAbstractReader):
|
|
|
33
45
|
if extension.endswith(".ome.tif") or extension.endswith(".ome.tiff"):
|
|
34
46
|
# # check if it satisfies all the condition for python backend
|
|
35
47
|
self._file_type = FileType.OmeTiff
|
|
36
|
-
self.
|
|
48
|
+
self._file_path = str(self.frontend._file_path.resolve())
|
|
49
|
+
self._axes_list = ""
|
|
37
50
|
elif extension.endswith(".zarr"):
|
|
38
51
|
# if path exists, make sure it is a directory
|
|
39
52
|
if not Path.is_dir(self.frontend._file_path):
|
|
@@ -41,10 +54,10 @@ class TensorstoreReader(bfio.base_classes.TSAbstractReader):
|
|
|
41
54
|
"this filetype is not supported by tensorstore backend"
|
|
42
55
|
)
|
|
43
56
|
else:
|
|
44
|
-
|
|
57
|
+
self._file_path, self._axes_list = self.get_zarr_array_info()
|
|
45
58
|
self._file_type = FileType.OmeZarr
|
|
46
|
-
self._rdr = TSReader(zarr_path, FileType.OmeZarr, axes_list)
|
|
47
59
|
|
|
60
|
+
self._rdr = TSReader(self._file_path, self._file_type, self._axes_list)
|
|
48
61
|
self.X = self._rdr._X
|
|
49
62
|
self.Y = self._rdr._Y
|
|
50
63
|
self.Z = self._rdr._Z
|
|
@@ -141,16 +154,13 @@ class TensorstoreReader(bfio.base_classes.TSAbstractReader):
|
|
|
141
154
|
|
|
142
155
|
def __getstate__(self) -> Dict:
|
|
143
156
|
state_dict = {n: getattr(self, n) for n in self._STATE_DICT}
|
|
144
|
-
state_dict.update({"file_path": self.frontend._file_path})
|
|
145
157
|
|
|
146
158
|
return state_dict
|
|
147
159
|
|
|
148
160
|
def __setstate__(self, state) -> None:
|
|
149
161
|
for k, v in state.items():
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
else:
|
|
153
|
-
setattr(self, k, v)
|
|
162
|
+
setattr(self, k, v)
|
|
163
|
+
self._rdr = TSReader(self._file_path, self._file_type, self._axes_list)
|
|
154
164
|
|
|
155
165
|
def read_metadata(self):
|
|
156
166
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: bfio
|
|
3
|
-
Version: 2.4.
|
|
3
|
+
Version: 2.4.3
|
|
4
4
|
Summary: Simple reading and writing classes for tiled tiffs using Bio-Formats.
|
|
5
5
|
Author-email: Nick Schaub <nick.schaub@nih.gov>, Sameeul Bashir Samee <sameeul.samee@axleinfo.com>
|
|
6
6
|
Maintainer-email: Sameeul Bashir Samee <sameeul.samee@axleinfo.com>
|
|
@@ -47,7 +47,7 @@ Provides-Extra: dev
|
|
|
47
47
|
Requires-Dist: ome_zarr; extra == "dev"
|
|
48
48
|
Requires-Dist: requests>=2.26.0; extra == "dev"
|
|
49
49
|
|
|
50
|
-
# **B**io**F**ormats **I**nput/**O**utput utility (bfio 2.4.
|
|
50
|
+
# **B**io**F**ormats **I**nput/**O**utput utility (bfio 2.4.3)
|
|
51
51
|
|
|
52
52
|
[](https://bfio.readthedocs.io/en/latest/?badge=latest)
|
|
53
53
|
[](https://pypi.org/project/bfio/)
|
|
@@ -99,15 +99,15 @@ be installed using pip:
|
|
|
99
99
|
|
|
100
100
|
## Docker
|
|
101
101
|
|
|
102
|
-
### polusai/bfio:2.4.
|
|
102
|
+
### polusai/bfio:2.4.3
|
|
103
103
|
|
|
104
104
|
Ubuntu based container with bfio and all dependencies (including Java).
|
|
105
105
|
|
|
106
|
-
### polusai/bfio:2.4.
|
|
106
|
+
### polusai/bfio:2.4.3-imagej
|
|
107
107
|
|
|
108
108
|
Same as above, except comes with ImageJ and PyImageJ.
|
|
109
109
|
|
|
110
|
-
### polusai/bfio:2.4.
|
|
110
|
+
### polusai/bfio:2.4.3-tensorflow
|
|
111
111
|
|
|
112
112
|
Tensorflow container with bfio installed.
|
|
113
113
|
|
|
@@ -3,6 +3,7 @@ import unittest
|
|
|
3
3
|
import requests, pathlib, shutil, logging, sys
|
|
4
4
|
import bfio
|
|
5
5
|
import numpy as np
|
|
6
|
+
import pickle
|
|
6
7
|
import random
|
|
7
8
|
import zarr
|
|
8
9
|
from ome_zarr.utils import download as zarr_download
|
|
@@ -64,6 +65,19 @@ def setUpModule():
|
|
|
64
65
|
for z in range(br.Z):
|
|
65
66
|
zf[t, c, z, :, :] = br[:, :, z, c, t]
|
|
66
67
|
|
|
68
|
+
# create a 2D numpy array filled with random integer form 0-255
|
|
69
|
+
img_height = 8000
|
|
70
|
+
img_width = 7500
|
|
71
|
+
source_data = np.random.randint(0, 256, (img_height, img_width), dtype=np.uint16)
|
|
72
|
+
np.save(TEST_DIR.joinpath("random_image.npy"), source_data)
|
|
73
|
+
with bfio.BioWriter(
|
|
74
|
+
str(TEST_DIR.joinpath("random_image.ome.tiff")),
|
|
75
|
+
X=img_width,
|
|
76
|
+
Y=img_height,
|
|
77
|
+
dtype=np.uint16,
|
|
78
|
+
) as bw:
|
|
79
|
+
bw[0:img_height, 0:img_width, 0, 0, 0] = source_data
|
|
80
|
+
|
|
67
81
|
|
|
68
82
|
def tearDownModule():
|
|
69
83
|
"""Remove test images"""
|
|
@@ -141,24 +155,10 @@ class TestSimpleRead(unittest.TestCase):
|
|
|
141
155
|
I = br[:]
|
|
142
156
|
|
|
143
157
|
def test_read_unaligned_tile_boundary_python(self):
|
|
144
|
-
|
|
145
|
-
img_height = 8000
|
|
146
|
-
img_width = 7500
|
|
147
|
-
source_data = np.random.randint(
|
|
148
|
-
0, 256, (img_height, img_width), dtype=np.uint16
|
|
149
|
-
)
|
|
150
|
-
with bfio.BioWriter(
|
|
151
|
-
str(TEST_DIR.joinpath("test_output.ome.tiff")),
|
|
152
|
-
X=img_width,
|
|
153
|
-
Y=img_height,
|
|
154
|
-
dtype=np.uint16,
|
|
155
|
-
) as bw:
|
|
156
|
-
bw[0:img_height, 0:img_width, 0, 0, 0] = source_data
|
|
157
|
-
|
|
158
|
+
source_data = np.load(TEST_DIR.joinpath("random_image.npy"))
|
|
158
159
|
x_max = source_data.shape[0]
|
|
159
160
|
y_max = source_data.shape[1]
|
|
160
|
-
|
|
161
|
-
with bfio.BioReader(str(TEST_DIR.joinpath("test_output.ome.tiff"))) as test_br:
|
|
161
|
+
with bfio.BioReader(str(TEST_DIR.joinpath("random_image.ome.tiff"))) as br:
|
|
162
162
|
for i in range(100):
|
|
163
163
|
x_start = random.randint(0, x_max)
|
|
164
164
|
y_start = random.randint(0, y_max)
|
|
@@ -167,39 +167,25 @@ class TestSimpleRead(unittest.TestCase):
|
|
|
167
167
|
|
|
168
168
|
x_end = x_start + x_step
|
|
169
169
|
y_end = y_start + y_step
|
|
170
|
-
|
|
171
170
|
if x_end > x_max:
|
|
172
171
|
x_end = x_max
|
|
173
172
|
|
|
174
173
|
if y_end > y_max:
|
|
175
174
|
y_end = y_max
|
|
176
175
|
|
|
177
|
-
test_data =
|
|
176
|
+
test_data = br[x_start:x_end, y_start:y_end, ...]
|
|
178
177
|
assert (
|
|
179
178
|
np.sum(source_data[x_start:x_end, y_start:y_end] - test_data) == 0
|
|
180
179
|
)
|
|
181
180
|
|
|
182
181
|
def test_read_unaligned_tile_boundary_tensorstore(self):
|
|
183
|
-
# create a 2D numpy array filled with random integer form 0-255
|
|
184
|
-
img_height = 8000
|
|
185
|
-
img_width = 7500
|
|
186
|
-
source_data = np.random.randint(
|
|
187
|
-
0, 256, (img_height, img_width), dtype=np.uint16
|
|
188
|
-
)
|
|
189
|
-
with bfio.BioWriter(
|
|
190
|
-
str(TEST_DIR.joinpath("test_output.ome.tiff")),
|
|
191
|
-
X=img_width,
|
|
192
|
-
Y=img_height,
|
|
193
|
-
dtype=np.uint16,
|
|
194
|
-
) as bw:
|
|
195
|
-
bw[0:img_height, 0:img_width, 0, 0, 0] = source_data
|
|
196
182
|
|
|
183
|
+
source_data = np.load(TEST_DIR.joinpath("random_image.npy"))
|
|
197
184
|
x_max = source_data.shape[0]
|
|
198
185
|
y_max = source_data.shape[1]
|
|
199
|
-
|
|
200
186
|
with bfio.BioReader(
|
|
201
|
-
str(TEST_DIR.joinpath("
|
|
202
|
-
) as
|
|
187
|
+
str(TEST_DIR.joinpath("random_image.ome.tiff")), backend="tensorstore"
|
|
188
|
+
) as br:
|
|
203
189
|
for i in range(100):
|
|
204
190
|
x_start = random.randint(0, x_max)
|
|
205
191
|
y_start = random.randint(0, y_max)
|
|
@@ -208,14 +194,13 @@ class TestSimpleRead(unittest.TestCase):
|
|
|
208
194
|
|
|
209
195
|
x_end = x_start + x_step
|
|
210
196
|
y_end = y_start + y_step
|
|
211
|
-
|
|
212
197
|
if x_end > x_max:
|
|
213
198
|
x_end = x_max
|
|
214
199
|
|
|
215
200
|
if y_end > y_max:
|
|
216
201
|
y_end = y_max
|
|
217
202
|
|
|
218
|
-
test_data =
|
|
203
|
+
test_data = br[x_start:x_end, y_start:y_end, ...]
|
|
219
204
|
assert (
|
|
220
205
|
np.sum(source_data[x_start:x_end, y_start:y_end] - test_data) == 0
|
|
221
206
|
)
|
|
@@ -305,6 +290,21 @@ class TestJavaReader(unittest.TestCase):
|
|
|
305
290
|
get_dims(br)
|
|
306
291
|
self.assertEqual(br.shape, (1167, 404, 1, 3))
|
|
307
292
|
|
|
293
|
+
def test_bioformats_backend_pickle(self):
|
|
294
|
+
|
|
295
|
+
br = bfio.BioReader(str(TEST_DIR.joinpath("img_r001_c001.ome.tif")))
|
|
296
|
+
img_height = br.Y
|
|
297
|
+
img_width = br.X
|
|
298
|
+
data_sum = br[:].sum()
|
|
299
|
+
pickled_rdr = pickle.dumps(br)
|
|
300
|
+
br.close()
|
|
301
|
+
unpickled_rdr = pickle.loads(pickled_rdr)
|
|
302
|
+
|
|
303
|
+
assert unpickled_rdr.X == img_width
|
|
304
|
+
assert unpickled_rdr.Y == img_height
|
|
305
|
+
assert unpickled_rdr[:].sum() == data_sum
|
|
306
|
+
unpickled_rdr.close()
|
|
307
|
+
|
|
308
308
|
|
|
309
309
|
class TestZarrReader(unittest.TestCase):
|
|
310
310
|
def test_get_dims(self):
|
|
@@ -420,3 +420,40 @@ class TestZarrTesnsorstoreMetadata(unittest.TestCase):
|
|
|
420
420
|
logger.info(br.cnames)
|
|
421
421
|
logger.info(br.ps_x)
|
|
422
422
|
self.assertEqual(br.cnames[0], cname[0])
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
class TestBioReaderPickle(unittest.TestCase):
|
|
426
|
+
|
|
427
|
+
def test_python_backend_pickle(self):
|
|
428
|
+
|
|
429
|
+
br = bfio.BioReader(
|
|
430
|
+
str(TEST_DIR.joinpath("random_image.ome.tiff")), backend="python"
|
|
431
|
+
)
|
|
432
|
+
img_height = br.Y
|
|
433
|
+
img_width = br.X
|
|
434
|
+
data_sum = br[:].sum()
|
|
435
|
+
pickled_rdr = pickle.dumps(br)
|
|
436
|
+
br.close()
|
|
437
|
+
unpickled_rdr = pickle.loads(pickled_rdr)
|
|
438
|
+
|
|
439
|
+
assert unpickled_rdr.X == img_width
|
|
440
|
+
assert unpickled_rdr.Y == img_height
|
|
441
|
+
assert unpickled_rdr[:].sum() == data_sum
|
|
442
|
+
unpickled_rdr.close()
|
|
443
|
+
|
|
444
|
+
def test_tensorstore_backend_pickle(self):
|
|
445
|
+
|
|
446
|
+
br = bfio.BioReader(
|
|
447
|
+
str(TEST_DIR.joinpath("random_image.ome.tiff")), backend="tensorstore"
|
|
448
|
+
)
|
|
449
|
+
img_height = br.Y
|
|
450
|
+
img_width = br.X
|
|
451
|
+
data_sum = br[:].sum()
|
|
452
|
+
pickled_rdr = pickle.dumps(br)
|
|
453
|
+
br.close()
|
|
454
|
+
unpickled_rdr = pickle.loads(pickled_rdr)
|
|
455
|
+
|
|
456
|
+
assert unpickled_rdr.X == img_width
|
|
457
|
+
assert unpickled_rdr.Y == img_height
|
|
458
|
+
assert unpickled_rdr[:].sum() == data_sum
|
|
459
|
+
unpickled_rdr.close()
|
|
@@ -105,6 +105,68 @@ class TestOmeTiffWrite(unittest.TestCase):
|
|
|
105
105
|
assert np.array_equal(image[:], br[:])
|
|
106
106
|
|
|
107
107
|
|
|
108
|
+
class TestPythonZarrWriter(unittest.TestCase):
|
|
109
|
+
|
|
110
|
+
def test_write_zarr_append_no_file(self):
|
|
111
|
+
|
|
112
|
+
with bfio.BioReader(str(TEST_DIR.joinpath("5025551.zarr"))) as br:
|
|
113
|
+
|
|
114
|
+
actual_shape = br.shape
|
|
115
|
+
actual_dtype = br.dtype
|
|
116
|
+
actual_image = br[:]
|
|
117
|
+
actual_mdata = br.metadata
|
|
118
|
+
print(br.shape)
|
|
119
|
+
with tempfile.TemporaryDirectory() as dir:
|
|
120
|
+
|
|
121
|
+
test_file_path = os.path.join(dir, "out/test.ome.zarr")
|
|
122
|
+
|
|
123
|
+
with bfio.BioWriter(
|
|
124
|
+
test_file_path, metadata=actual_mdata, backend="zarr", append=True
|
|
125
|
+
) as bw:
|
|
126
|
+
|
|
127
|
+
expanded = np.expand_dims(actual_image, axis=-1)
|
|
128
|
+
bw[:, :, :, :, :] = expanded[:, :, :, :, :]
|
|
129
|
+
|
|
130
|
+
with bfio.BioReader(test_file_path) as br:
|
|
131
|
+
|
|
132
|
+
assert br.shape == actual_shape
|
|
133
|
+
assert br.dtype == actual_dtype
|
|
134
|
+
|
|
135
|
+
assert br[:].sum() == actual_image.sum()
|
|
136
|
+
|
|
137
|
+
def test_write_zarr_append_file_exist(self):
|
|
138
|
+
|
|
139
|
+
with bfio.BioReader(str(TEST_DIR.joinpath("5025551.zarr"))) as br:
|
|
140
|
+
|
|
141
|
+
actual_shape = br.shape
|
|
142
|
+
actual_dtype = br.dtype
|
|
143
|
+
actual_image = br[:]
|
|
144
|
+
actual_mdata = br.metadata
|
|
145
|
+
with tempfile.TemporaryDirectory() as dir:
|
|
146
|
+
|
|
147
|
+
test_file_path = os.path.join(dir, "out/test.ome.zarr")
|
|
148
|
+
|
|
149
|
+
with bfio.BioWriter(
|
|
150
|
+
test_file_path, metadata=actual_mdata, backend="zarr"
|
|
151
|
+
) as bw:
|
|
152
|
+
|
|
153
|
+
expanded = np.expand_dims(actual_image, axis=-1)
|
|
154
|
+
bw[:, :, :, 0:13, :] = expanded[:, :, :, 0:13, :]
|
|
155
|
+
|
|
156
|
+
with bfio.BioWriter(
|
|
157
|
+
test_file_path, metadata=actual_mdata, backend="zarr", append=True
|
|
158
|
+
) as bw:
|
|
159
|
+
|
|
160
|
+
expanded = np.expand_dims(actual_image, axis=-1)
|
|
161
|
+
bw[:, :, :, 13:, :] = expanded[:, :, :, 13:, :]
|
|
162
|
+
with bfio.BioReader(test_file_path) as br:
|
|
163
|
+
|
|
164
|
+
assert br.shape == actual_shape
|
|
165
|
+
assert br.dtype == actual_dtype
|
|
166
|
+
|
|
167
|
+
assert br[:].sum() == actual_image.sum()
|
|
168
|
+
|
|
169
|
+
|
|
108
170
|
class TestOmeZarrWriter(unittest.TestCase):
|
|
109
171
|
|
|
110
172
|
def test_write_zarr_tensorstore(self):
|
bfio-2.4.1/src/bfio/VERSION
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
2.4.1
|
|
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
|