large-image-source-bioformats 1.27.5.dev6__py3-none-any.whl → 1.30.7.dev10__py3-none-any.whl

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.

Potentially problematic release.


This version of large-image-source-bioformats might be problematic. Click here for more details.

@@ -23,6 +23,7 @@
23
23
  # IFormatReader.html for interface details.
24
24
 
25
25
  import atexit
26
+ import builtins
26
27
  import logging
27
28
  import math
28
29
  import os
@@ -61,8 +62,7 @@ _openImages = []
61
62
 
62
63
 
63
64
  # Default to ignoring files with no extension and some specific extensions.
64
- config.ConfigValues['source_bioformats_ignored_names'] = \
65
- r'(^[^.]*|\.(jpg|jpeg|jpe|png|tif|tiff|ndpi|nd2|ome|nc|json|isyntax|mrxs|zarr(\.db|\.zip)))$'
65
+ config.ConfigValues['source_bioformats_ignored_names'] = r'(^[^.]*|\.(jpg|jpeg|jpe|png|tif|tiff|ndpi|nd2|ome|nc|json|geojson|fits|isyntax|mrxs|zip|zarr(\.db|\.zip)))$' # noqa
66
66
 
67
67
 
68
68
  def _monitor_thread():
@@ -82,7 +82,7 @@ def _monitor_thread():
82
82
  source._bioimage = None
83
83
  except Exception:
84
84
  pass
85
- except AssertionError:
85
+ except Exception:
86
86
  pass
87
87
  finally:
88
88
  if javabridge.get_env():
@@ -106,7 +106,7 @@ def _reduceLogging():
106
106
  'org/slf4j/LoggerFactory', 'getLogger',
107
107
  '(Ljava/lang/String;)Lorg/slf4j/Logger;', rootLoggerName)
108
108
  logLevel = javabridge.get_static_field(
109
- 'ch/qos/logback/classic/Level', 'ERROR', 'Lch/qos/logback/classic/Level;')
109
+ 'ch/qos/logback/classic/Level', 'OFF', 'Lch/qos/logback/classic/Level;')
110
110
  javabridge.call(rootLogger, 'setLevel', '(Lch/qos/logback/classic/Level;)V', logLevel)
111
111
  except Exception:
112
112
  pass
@@ -184,6 +184,7 @@ class BioformatsFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
184
184
  extensions = {
185
185
  None: SourcePriority.FALLBACK,
186
186
  'czi': SourcePriority.PREFERRED,
187
+ 'ets': SourcePriority.LOW, # part of vsi
187
188
  'lif': SourcePriority.MEDIUM,
188
189
  'vsi': SourcePriority.PREFERRED,
189
190
  }
@@ -212,16 +213,42 @@ class BioformatsFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
212
213
  largeImagePath = str(self._getLargeImagePath())
213
214
  config._ignoreSourceNames('bioformats', largeImagePath)
214
215
 
216
+ header = b''
217
+ if os.path.isfile(largeImagePath):
218
+ try:
219
+ header = builtins.open(largeImagePath, 'rb').read(5)
220
+ except Exception:
221
+ msg = 'File cannot be opened via Bioformats'
222
+ raise TileSourceError(msg)
223
+ # Never allow pdfs; they crash the JVM
224
+ if header[:5] == b'%PDF-':
225
+ msg = 'File cannot be opened via Bioformats'
226
+ raise TileSourceError(msg)
215
227
  if not _startJavabridge(self.logger):
216
228
  msg = 'File cannot be opened by bioformats reader because javabridge failed to start'
217
229
  raise TileSourceError(msg)
230
+ self.addKnownExtensions()
218
231
 
219
232
  self._tileLock = threading.RLock()
220
233
 
221
234
  try:
222
235
  javabridge.attach()
223
236
  try:
224
- self._bioimage = bioformats.ImageReader(largeImagePath)
237
+ self._bioimage = bioformats.ImageReader(largeImagePath, perform_init=False)
238
+ try:
239
+ # So this as a separate step so, if it fails, we can ask to
240
+ # open something that does not exist and bioformats will
241
+ # release some file handles.
242
+ self._bioimage.init_reader()
243
+ except Exception as exc:
244
+ try:
245
+ # Ask to open a file that should never exist
246
+ self._bioimage.rdr.setId('__\0__')
247
+ except Exception:
248
+ pass
249
+ self._bioimage.close()
250
+ self._bioimage = None
251
+ raise exc
225
252
  except (AttributeError, OSError) as exc:
226
253
  if not os.path.isfile(largeImagePath):
227
254
  raise TileSourceFileNotFoundError(largeImagePath) from None
@@ -482,13 +509,15 @@ class BioformatsFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
482
509
 
483
510
  def _computeMagnification(self):
484
511
  self._magnification = {}
485
- metadata = self._metadata['metadata']
512
+ metadata = self._metadata.get('seriesMetadata', {}).copy()
513
+ metadata.update(self._metadata['metadata'])
486
514
  valuekeys = {
487
515
  'x': [('Scaling|Distance|Value #1', 1e3)],
488
516
  'y': [('Scaling|Distance|Value #2', 1e3)],
489
517
  }
490
518
  tuplekeys = [
491
519
  ('Physical pixel size', 1e-3),
520
+ ('0028,0030 Pixel Spacing', 1),
492
521
  ]
493
522
  magkeys = [
494
523
  'Information|Instrument|Objective|NominalMagnification #1',
@@ -501,11 +530,11 @@ class BioformatsFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
501
530
  if 'mm_x' not in self._magnification and 'mm_y' not in self._magnification:
502
531
  for key, units in tuplekeys:
503
532
  if metadata.get(key):
504
- found = re.match(r'^\D*(\d+(|\.\d+))\D+(\d+(|\.\d+))\D*$', metadata[key])
533
+ found = re.match(r'^[^0-9.]*(\d*\.?\d+)[^0-9.]+(\d*\.?\d+)\D*$', metadata[key])
505
534
  if found:
506
535
  try:
507
536
  self._magnification['mm_x'], self._magnification['mm_y'] = (
508
- float(found.groups()[0]) * units, float(found.groups()[2]) * units)
537
+ float(found.groups()[0]) * units, float(found.groups()[1]) * units)
509
538
  except Exception:
510
539
  pass
511
540
  for key in magkeys:
@@ -617,7 +646,7 @@ class BioformatsFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
617
646
  height = min(height, sizeYAtScale - offsety)
618
647
 
619
648
  if scale >= 2 ** self._maxSkippedLevels:
620
- tile = self._getTileFromEmptyLevel(x, y, z, **kwargs)
649
+ tile, _format = self._getTileFromEmptyLevel(x, y, z, **kwargs)
621
650
  tile = large_image.tilesource.base._imageToNumpy(tile)[0]
622
651
  format = TILE_FORMAT_NUMPY
623
652
  else:
@@ -651,6 +680,8 @@ class BioformatsFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
651
680
  fillValue = 0
652
681
  if tile.dtype == np.uint16:
653
682
  fillValue = 65535
683
+ elif tile.dtype == np.int16:
684
+ fillValue = 32767
654
685
  elif tile.dtype == np.uint8:
655
686
  fillValue = 255
656
687
  elif tile.dtype.kind == 'f':
@@ -681,7 +712,7 @@ class BioformatsFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
681
712
  """
682
713
  info = self._metadata['seriesAssociatedImages'].get(imageKey)
683
714
  if info is None:
684
- return
715
+ return None
685
716
  series = info['seriesNum']
686
717
  with self._tileLock:
687
718
  try:
@@ -699,6 +730,31 @@ class BioformatsFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
699
730
  javabridge.detach()
700
731
  return large_image.tilesource.base._imageToPIL(image)
701
732
 
733
+ @classmethod
734
+ def addKnownExtensions(cls):
735
+ # This starts javabridge/bioformats if needed
736
+ _getBioformatsVersion()
737
+ if not hasattr(cls, '_addedExtensions'):
738
+ cls._addedExtensions = True
739
+ cls.extensions = cls.extensions.copy()
740
+ for dotext in bioformats.READABLE_FORMATS:
741
+ ext = dotext.strip('.')
742
+ if ext not in cls.extensions:
743
+ cls.extensions[ext] = SourcePriority.IMPLICIT
744
+ # The python modules doesn't list all the extensions that can be
745
+ # read, so supplement from the jar
746
+ readerlist = zipfile.ZipFile(
747
+ pathlib.Path(bioformats.__file__).parent /
748
+ 'jars/bioformats_package.jar',
749
+ ).open('loci/formats/readers.txt').read(100000).decode().split('\n')
750
+ pattern = re.compile(r'^loci\.formats\.in\..* # (?:.*?\b(\w{2,})\b(?:,|\s|$))')
751
+ for line in readerlist:
752
+ for ext in set(pattern.findall(line)) - {
753
+ 'pattern', 'urlreader', 'screen', 'zip', 'zarr', 'db',
754
+ 'fake', 'no'}:
755
+ if ext not in cls.extensions:
756
+ cls.extensions[ext] = SourcePriority.IMPLICIT
757
+
702
758
 
703
759
  def open(*args, **kwargs):
704
760
  """
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.1
1
+ Metadata-Version: 2.2
2
2
  Name: large-image-source-bioformats
3
- Version: 1.27.5.dev6
3
+ Version: 1.30.7.dev10
4
4
  Summary: An bioformats tilesource for large_image.
5
5
  Home-page: https://github.com/girder/large_image
6
6
  Author: Kitware, Inc.
@@ -15,12 +15,26 @@ Classifier: Programming Language :: Python :: 3.9
15
15
  Classifier: Programming Language :: Python :: 3.10
16
16
  Classifier: Programming Language :: Python :: 3.11
17
17
  Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.13
18
19
  Requires-Python: >=3.8
20
+ Description-Content-Type: text/x-rst
19
21
  License-File: LICENSE
20
- Requires-Dist: large-image >=1.27.5.dev6
21
- Requires-Dist: python-bioformats >=1.5.2
22
+ Requires-Dist: large-image>=1.30.7.dev10
23
+ Requires-Dist: python-bioformats>=1.5.2
22
24
  Provides-Extra: girder
23
- Requires-Dist: girder-large-image >=1.27.5.dev6 ; extra == 'girder'
25
+ Requires-Dist: girder-large-image>=1.30.7.dev10; extra == "girder"
26
+ Dynamic: author
27
+ Dynamic: author-email
28
+ Dynamic: classifier
29
+ Dynamic: description
30
+ Dynamic: description-content-type
31
+ Dynamic: home-page
32
+ Dynamic: keywords
33
+ Dynamic: license
34
+ Dynamic: provides-extra
35
+ Dynamic: requires-dist
36
+ Dynamic: requires-python
37
+ Dynamic: summary
24
38
 
25
39
  An bioformats tilesource for large_image.
26
40
 
@@ -0,0 +1,8 @@
1
+ large_image_source_bioformats/__init__.py,sha256=lJawSrn3ScKHffmtl7Rut_tgmVKJru3xbbmMn47c1p0,33201
2
+ large_image_source_bioformats/girder_source.py,sha256=t0X1P0m4qMsRklpdxoPH-yqgHByMvQIzFJ4qRIUykVI,1355
3
+ large_image_source_bioformats-1.30.7.dev10.dist-info/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
4
+ large_image_source_bioformats-1.30.7.dev10.dist-info/METADATA,sha256=P3z_lom_tPQYEMFbs_btzvJnzpT2ayoOUjYcuvZriPk,1377
5
+ large_image_source_bioformats-1.30.7.dev10.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
6
+ large_image_source_bioformats-1.30.7.dev10.dist-info/entry_points.txt,sha256=xgIbKr53QhQkyRFkr87fkagfPWweeqhHHekUEMrcpF8,202
7
+ large_image_source_bioformats-1.30.7.dev10.dist-info/top_level.txt,sha256=e0enjlcFXwPi638IhE71Rk5-eeriA7W3M3IsQ6yH3RI,30
8
+ large_image_source_bioformats-1.30.7.dev10.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.43.0)
2
+ Generator: setuptools (75.8.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,8 +0,0 @@
1
- large_image_source_bioformats/__init__.py,sha256=wqym0jzlyedMVBGrbNnTMmXq0Ju91HndNI0K_a44ZFo,30482
2
- large_image_source_bioformats/girder_source.py,sha256=t0X1P0m4qMsRklpdxoPH-yqgHByMvQIzFJ4qRIUykVI,1355
3
- large_image_source_bioformats-1.27.5.dev6.dist-info/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
4
- large_image_source_bioformats-1.27.5.dev6.dist-info/METADATA,sha256=N3ZJVc0Mf2nxn1TVRNyLx55ikT6ZSoHD7YYNxGSURnE,1034
5
- large_image_source_bioformats-1.27.5.dev6.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
6
- large_image_source_bioformats-1.27.5.dev6.dist-info/entry_points.txt,sha256=xgIbKr53QhQkyRFkr87fkagfPWweeqhHHekUEMrcpF8,202
7
- large_image_source_bioformats-1.27.5.dev6.dist-info/top_level.txt,sha256=e0enjlcFXwPi638IhE71Rk5-eeriA7W3M3IsQ6yH3RI,30
8
- large_image_source_bioformats-1.27.5.dev6.dist-info/RECORD,,