bfio 2.4.2__tar.gz → 2.4.4__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bfio
3
- Version: 2.4.2
3
+ Version: 2.4.4
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.2)
50
+ # **B**io**F**ormats **I**nput/**O**utput utility (bfio 2.4.4)
51
51
 
52
52
  [![Documentation Status](https://readthedocs.org/projects/bfio/badge/?version=latest)](https://bfio.readthedocs.io/en/latest/?badge=latest)
53
53
  [![PyPI](https://img.shields.io/pypi/v/bfio)](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.2
102
+ ### polusai/bfio:2.4.4
103
103
 
104
104
  Ubuntu based container with bfio and all dependencies (including Java).
105
105
 
106
- ### polusai/bfio:2.4.2-imagej
106
+ ### polusai/bfio:2.4.4-imagej
107
107
 
108
108
  Same as above, except comes with ImageJ and PyImageJ.
109
109
 
110
- ### polusai/bfio:2.4.2-tensorflow
110
+ ### polusai/bfio:2.4.4-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.2)
1
+ # **B**io**F**ormats **I**nput/**O**utput utility (bfio 2.4.4)
2
2
 
3
3
  [![Documentation Status](https://readthedocs.org/projects/bfio/badge/?version=latest)](https://bfio.readthedocs.io/en/latest/?badge=latest)
4
4
  [![PyPI](https://img.shields.io/pypi/v/bfio)](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.2
53
+ ### polusai/bfio:2.4.4
54
54
 
55
55
  Ubuntu based container with bfio and all dependencies (including Java).
56
56
 
57
- ### polusai/bfio:2.4.2-imagej
57
+ ### polusai/bfio:2.4.4-imagej
58
58
 
59
59
  Same as above, except comes with ImageJ and PyImageJ.
60
60
 
61
- ### polusai/bfio:2.4.2-tensorflow
61
+ ### polusai/bfio:2.4.4-tensorflow
62
62
 
63
63
  Tensorflow container with bfio installed.
64
64
 
@@ -86,7 +86,7 @@ namespaces = false
86
86
 
87
87
 
88
88
  [tool.bumpversion]
89
- current_version = "2.4.2"
89
+ current_version = "2.4.4"
90
90
  commit = true
91
91
  tag = true
92
92
  commit_args = "--no-verify"
@@ -0,0 +1 @@
1
+ 2.4.4
@@ -20,7 +20,7 @@ from xml.etree import ElementTree as ET
20
20
  # bfio internals
21
21
  from bfio import __version__ as version
22
22
  import bfio.base_classes
23
- from bfio.utils import start, clean_ome_xml_for_known_issues
23
+ from bfio.utils import start, clean_ome_xml_for_known_issues, pixels_per_cm
24
24
 
25
25
  logging.basicConfig(
26
26
  format="%(asctime)s - %(name)-8s - %(levelname)-8s - %(message)s",
@@ -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
- self._lock = threading.Lock()
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
 
@@ -630,8 +638,16 @@ class PythonWriter(bfio.base_classes.AbstractWriter):
630
638
  else:
631
639
  big_tiff = False
632
640
 
641
+ if self.frontend._metadata.images[0].pixels.big_endian:
642
+ byte_order = ">"
643
+ else:
644
+ byte_order = "<"
645
+
633
646
  self._writer = tifffile.TiffWriter(
634
- self.frontend._file_path, bigtiff=big_tiff, append=False
647
+ self.frontend._file_path,
648
+ bigtiff=big_tiff,
649
+ byteorder=byte_order,
650
+ append=False,
635
651
  )
636
652
 
637
653
  self._byteorder = self._writer.tiff.byteorder
@@ -687,10 +703,28 @@ class PythonWriter(bfio.base_classes.AbstractWriter):
687
703
 
688
704
  if self.frontend.physical_size_x[0] is not None:
689
705
  self._addtag(
690
- 282, "2I", 1, rational(10000 / self.frontend.physical_size_x[0])
706
+ 282,
707
+ "2I",
708
+ 1,
709
+ rational(
710
+ pixels_per_cm(
711
+ self.frontend.X,
712
+ self.frontend.physical_size_x[0],
713
+ self.frontend.physical_size_x[1],
714
+ )
715
+ ),
691
716
  ) # XResolution in pixels/cm
692
717
  self._addtag(
693
- 283, "2I", 1, rational(10000 / self.frontend.physical_size_y[0])
718
+ 283,
719
+ "2I",
720
+ 1,
721
+ rational(
722
+ pixels_per_cm(
723
+ self.frontend.Y,
724
+ self.frontend.physical_size_y[0],
725
+ self.frontend.physical_size_y[1],
726
+ )
727
+ ),
694
728
  ) # YResolution in pixels/cm
695
729
  self._addtag(296, "H", 1, 3) # ResolutionUnit = cm
696
730
  else:
@@ -43,16 +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
- "max_workers",
50
+ "_max_workers",
50
51
  "_backend_name",
51
52
  "clean_metadata",
52
53
  "_read_only",
53
54
  "_backend",
54
- "level",
55
- "append",
56
55
  ]
57
56
 
58
57
  def __init__(
@@ -234,7 +233,15 @@ class BioReader(BioBase):
234
233
  self._backend_name = backend.lower()
235
234
 
236
235
  def __getstate__(self) -> typing.Dict:
237
- state_dict = {n: getattr(self, n) for n in self._STATE_DICT}
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}
238
245
 
239
246
  return state_dict
240
247
 
@@ -242,10 +249,17 @@ class BioReader(BioBase):
242
249
  assert all(n in self._STATE_DICT for n in state.keys())
243
250
  assert all(n in state.keys() for n in self._STATE_DICT)
244
251
 
252
+ bioformats_backend = False
245
253
  for k, v in state.items():
246
- setattr(self, k, v)
254
+ if k == "_backend" and v == "JavaReaderDummy":
255
+ bioformats_backend = True
256
+ else:
257
+ setattr(self, k, v)
247
258
 
248
- self._backend.frontend = self
259
+ if bioformats_backend:
260
+ self._backend = backends.JavaReader(self)
261
+ else:
262
+ self._backend.frontend = self
249
263
 
250
264
  def __getitem__(self, keys: typing.Union[tuple, slice]) -> numpy.ndarray:
251
265
  """Image loading using numpy-like indexing.
@@ -23,7 +23,19 @@ class TensorstoreReader(bfio.base_classes.TSAbstractReader):
23
23
 
24
24
  _rdr = None
25
25
  _offsets_bytes = None
26
- _STATE_DICT = ["_metadata", "frontend"]
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._rdr = TSReader(str(self.frontend._file_path), FileType.OmeTiff, "")
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
- zarr_path, axes_list = self.get_zarr_array_info()
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
- if k == "file_path":
151
- pass
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
 
@@ -11,6 +11,8 @@ import re
11
11
  from xml.etree import ElementTree as ET
12
12
  from xsdata.utils.dates import DateTimeParser
13
13
 
14
+ from ome_types.model import UnitsLength
15
+
14
16
  KNOWN_INVALID_OME_XSD_REFERENCES = [
15
17
  "www.openmicroscopy.org/Schemas/ome/2013-06",
16
18
  "www.openmicroscopy.org/Schemas/OME/2012-03",
@@ -364,3 +366,79 @@ def clean_ome_xml_for_known_issues(xml: str) -> str:
364
366
  )
365
367
 
366
368
  return xml
369
+
370
+
371
+ def pixels_per_cm(
372
+ image_dim_px: int, physical_dim: float, unit: UnitsLength = UnitsLength.CENTIMETER
373
+ ) -> int:
374
+ """
375
+ Calculate the number of pixels per centimeter based on image dimensions
376
+ and physical size.
377
+
378
+ Args:
379
+ image_dim_px (int): The image dimension in pixels.
380
+ physical_dim (float): The physical dimension of the image.
381
+ unit (UnitsLength, optional): The unit of the physical dimension.
382
+ Defaults to UnitsLength.CENTIMETER.
383
+
384
+ Returns:
385
+ int: The number of pixels per centimeter.
386
+
387
+ Raises:
388
+ ValueError: If an unsupported unit is provided.
389
+
390
+ Example:
391
+ >>> pixels_per_cm(1000, 5, UnitsLength.MILLIMETER)
392
+ 2000
393
+ """
394
+
395
+ # Conversion factors to centimeters
396
+ conversion_factors = {
397
+ # SI Units and SI-derived Units
398
+ UnitsLength.YOTTAMETER: 1e24, # 1 yottameter = 1e24 centimeters
399
+ UnitsLength.ZETTAMETER: 1e21, # 1 zettameter = 1e21 centimeters
400
+ UnitsLength.EXAMETER: 1e18, # 1 exameter = 1e18 centimeters
401
+ UnitsLength.PETAMETER: 1e15, # 1 petameter = 1e15 centimeters
402
+ UnitsLength.TERAMETER: 1e12, # 1 terameter = 1e12 centimeters
403
+ UnitsLength.GIGAMETER: 1e9, # 1 gigameter = 1e9 centimeters
404
+ UnitsLength.MEGAMETER: 1e6, # 1 megameter = 1e6 centimeters
405
+ UnitsLength.KILOMETER: 1e5, # 1 kilometer = 1e5 centimeters
406
+ UnitsLength.HECTOMETER: 1e4, # 1 hectometer = 1e4 centimeters
407
+ UnitsLength.DECAMETER: 1e3, # 1 decameter = 1e3 centimeters
408
+ UnitsLength.METER: 100, # 1 meter = 100 centimeters
409
+ UnitsLength.DECIMETER: 10, # 1 decimeter = 10 centimeters
410
+ UnitsLength.CENTIMETER: 1, # base unit (centimeters)
411
+ UnitsLength.MILLIMETER: 0.1, # 1 millimeter = 0.1 centimeters
412
+ UnitsLength.MICROMETER: 1e-4, # 1 micrometer = 1e-4 centimeters
413
+ UnitsLength.NANOMETER: 1e-7, # 1 nanometer = 1e-7 centimeters
414
+ UnitsLength.PICOMETER: 1e-10, # 1 picometer = 1e-10 centimeters
415
+ UnitsLength.FEMTOMETER: 1e-13, # 1 femtometer = 1e-13 centimeters
416
+ UnitsLength.ATTOMETER: 1e-16, # 1 attometer = 1e-16 centimeters
417
+ UnitsLength.ZEPTOMETER: 1e-19, # 1 zeptometer = 1e-19 centimeters
418
+ UnitsLength.YOCTOMETER: 1e-22, # 1 yoctometer = 1e-22 centimeters
419
+ # SI-derived Units
420
+ UnitsLength.ANGSTROM: 1e-8, # 1 ångström = 1e-8 centimeters
421
+ # Imperial Units
422
+ UnitsLength.THOU: 2.54e-3, # 1 thou (mil) = 0.001 inch = 2.54e-3 centimeters
423
+ UnitsLength.LINE: 2.11667, # 1 line = 1/12 inch = 2.11667 centimeters
424
+ UnitsLength.INCH: 2.54, # 1 inch = 2.54 centimeters
425
+ UnitsLength.FOOT: 30.48, # 1 foot = 12 inches = 30.48 centimeters
426
+ UnitsLength.YARD: 91.44, # 1 yard = 3 feet = 91.44 centimeters
427
+ UnitsLength.MILE: 160934.4, # 1 mile = 5280 feet = 160934.4 centimeters
428
+ }
429
+
430
+ # Ensure the unit is supported
431
+ if unit not in conversion_factors:
432
+ logger = logging.getLogger("bfio.backends")
433
+ logger.warning(
434
+ f"Unsupported unit '{unit}'."
435
+ f"Supported units are: {', '.join(conversion_factors.keys())}"
436
+ )
437
+
438
+ # Convert the physical dimensions to centimeters
439
+ physical_dim_cm = physical_dim * conversion_factors.get(unit, 1)
440
+
441
+ # Calculate pixels per centimeter for width and height
442
+ pixels_per_cm = image_dim_px / physical_dim_cm
443
+
444
+ return int(pixels_per_cm)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: bfio
3
- Version: 2.4.2
3
+ Version: 2.4.4
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.2)
50
+ # **B**io**F**ormats **I**nput/**O**utput utility (bfio 2.4.4)
51
51
 
52
52
  [![Documentation Status](https://readthedocs.org/projects/bfio/badge/?version=latest)](https://bfio.readthedocs.io/en/latest/?badge=latest)
53
53
  [![PyPI](https://img.shields.io/pypi/v/bfio)](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.2
102
+ ### polusai/bfio:2.4.4
103
103
 
104
104
  Ubuntu based container with bfio and all dependencies (including Java).
105
105
 
106
- ### polusai/bfio:2.4.2-imagej
106
+ ### polusai/bfio:2.4.4-imagej
107
107
 
108
108
  Same as above, except comes with ImageJ and PyImageJ.
109
109
 
110
- ### polusai/bfio:2.4.2-tensorflow
110
+ ### polusai/bfio:2.4.4-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
- # create a 2D numpy array filled with random integer form 0-255
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 = test_br[x_start:x_end, y_start:y_end, ...]
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("test_output.ome.tiff")), backend="tensorstore"
202
- ) as test_br:
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 = test_br[x_start:x_end, y_start:y_end, ...]
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()
@@ -1 +0,0 @@
1
- 2.4.2
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes