bfio 2.4.3__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.3
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.3)
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.3
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.3-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.3-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.3)
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.3
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.3-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.3-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.3"
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",
@@ -638,8 +638,16 @@ class PythonWriter(bfio.base_classes.AbstractWriter):
638
638
  else:
639
639
  big_tiff = False
640
640
 
641
+ if self.frontend._metadata.images[0].pixels.big_endian:
642
+ byte_order = ">"
643
+ else:
644
+ byte_order = "<"
645
+
641
646
  self._writer = tifffile.TiffWriter(
642
- 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,
643
651
  )
644
652
 
645
653
  self._byteorder = self._writer.tiff.byteorder
@@ -695,10 +703,28 @@ class PythonWriter(bfio.base_classes.AbstractWriter):
695
703
 
696
704
  if self.frontend.physical_size_x[0] is not None:
697
705
  self._addtag(
698
- 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
+ ),
699
716
  ) # XResolution in pixels/cm
700
717
  self._addtag(
701
- 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
+ ),
702
728
  ) # YResolution in pixels/cm
703
729
  self._addtag(296, "H", 1, 3) # ResolutionUnit = cm
704
730
  else:
@@ -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.3
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.3)
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.3
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.3-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.3-tensorflow
110
+ ### polusai/bfio:2.4.4-tensorflow
111
111
 
112
112
  Tensorflow container with bfio installed.
113
113
 
@@ -1 +0,0 @@
1
- 2.4.3
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