large-image-source-bioformats 1.27.5.dev6__py3-none-any.whl → 1.30.7.dev12__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.
- large_image_source_bioformats/__init__.py +83 -14
- {large_image_source_bioformats-1.27.5.dev6.dist-info → large_image_source_bioformats-1.30.7.dev12.dist-info}/METADATA +19 -5
- large_image_source_bioformats-1.30.7.dev12.dist-info/RECORD +8 -0
- {large_image_source_bioformats-1.27.5.dev6.dist-info → large_image_source_bioformats-1.30.7.dev12.dist-info}/WHEEL +1 -1
- large_image_source_bioformats-1.27.5.dev6.dist-info/RECORD +0 -8
- {large_image_source_bioformats-1.27.5.dev6.dist-info → large_image_source_bioformats-1.30.7.dev12.dist-info}/LICENSE +0 -0
- {large_image_source_bioformats-1.27.5.dev6.dist-info → large_image_source_bioformats-1.30.7.dev12.dist-info}/entry_points.txt +0 -0
- {large_image_source_bioformats-1.27.5.dev6.dist-info → large_image_source_bioformats-1.30.7.dev12.dist-info}/top_level.txt +0 -0
|
@@ -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
|
|
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', '
|
|
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
|
|
@@ -294,8 +321,15 @@ class BioformatsFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
|
|
|
294
321
|
if self.sizeX <= 0 or self.sizeY <= 0:
|
|
295
322
|
msg = 'Bioformats tile size is invalid.'
|
|
296
323
|
raise TileSourceError(msg)
|
|
324
|
+
if ('JPEG' in self._metadata['readerClassName'] and
|
|
325
|
+
(self._metadata['optimalTileWidth'] > 16384 or
|
|
326
|
+
self._metadata['optimalTileHeight'] > 16384)):
|
|
327
|
+
msg = 'Bioformats will be too inefficient to read this file.'
|
|
328
|
+
raise TileSourceError(msg)
|
|
297
329
|
try:
|
|
330
|
+
self._lastGetTileException = 'raise'
|
|
298
331
|
self.getTile(0, 0, self.levels - 1)
|
|
332
|
+
delattr(self, '_lastGetTileException')
|
|
299
333
|
except Exception as exc:
|
|
300
334
|
raise TileSourceError('Bioformats cannot read a tile: %r' % exc)
|
|
301
335
|
self._populatedLevels = len([
|
|
@@ -343,6 +377,7 @@ class BioformatsFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
|
|
|
343
377
|
'optimalTileWidth': rdr.getOptimalTileWidth(),
|
|
344
378
|
'optimalTileHeight': rdr.getOptimalTileHeight(),
|
|
345
379
|
'resolutionCount': rdr.getResolutionCount(),
|
|
380
|
+
'readerClassName': rdr.get_class_name(),
|
|
346
381
|
})
|
|
347
382
|
|
|
348
383
|
def _getSeriesStarts(self, rdr): # noqa
|
|
@@ -482,13 +517,15 @@ class BioformatsFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
|
|
|
482
517
|
|
|
483
518
|
def _computeMagnification(self):
|
|
484
519
|
self._magnification = {}
|
|
485
|
-
metadata = self._metadata
|
|
520
|
+
metadata = self._metadata.get('seriesMetadata', {}).copy()
|
|
521
|
+
metadata.update(self._metadata['metadata'])
|
|
486
522
|
valuekeys = {
|
|
487
523
|
'x': [('Scaling|Distance|Value #1', 1e3)],
|
|
488
524
|
'y': [('Scaling|Distance|Value #2', 1e3)],
|
|
489
525
|
}
|
|
490
526
|
tuplekeys = [
|
|
491
527
|
('Physical pixel size', 1e-3),
|
|
528
|
+
('0028,0030 Pixel Spacing', 1),
|
|
492
529
|
]
|
|
493
530
|
magkeys = [
|
|
494
531
|
'Information|Instrument|Objective|NominalMagnification #1',
|
|
@@ -501,11 +538,11 @@ class BioformatsFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
|
|
|
501
538
|
if 'mm_x' not in self._magnification and 'mm_y' not in self._magnification:
|
|
502
539
|
for key, units in tuplekeys:
|
|
503
540
|
if metadata.get(key):
|
|
504
|
-
found = re.match(r'
|
|
541
|
+
found = re.match(r'^[^0-9.]*(\d*\.?\d+)[^0-9.]+(\d*\.?\d+)\D*$', metadata[key])
|
|
505
542
|
if found:
|
|
506
543
|
try:
|
|
507
544
|
self._magnification['mm_x'], self._magnification['mm_y'] = (
|
|
508
|
-
float(found.groups()[0]) * units, float(found.groups()[
|
|
545
|
+
float(found.groups()[0]) * units, float(found.groups()[1]) * units)
|
|
509
546
|
except Exception:
|
|
510
547
|
pass
|
|
511
548
|
for key in magkeys:
|
|
@@ -584,7 +621,7 @@ class BioformatsFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
|
|
|
584
621
|
return self._metadata
|
|
585
622
|
|
|
586
623
|
@methodcache()
|
|
587
|
-
def getTile(self, x, y, z, pilImageAllowed=False, numpyAllowed=False, **kwargs):
|
|
624
|
+
def getTile(self, x, y, z, pilImageAllowed=False, numpyAllowed=False, **kwargs): # noqa
|
|
588
625
|
self._xyzInRange(x, y, z)
|
|
589
626
|
ft = fc = fz = 0
|
|
590
627
|
fseries = self._metadata['frameSeries'][0]
|
|
@@ -617,7 +654,7 @@ class BioformatsFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
|
|
|
617
654
|
height = min(height, sizeYAtScale - offsety)
|
|
618
655
|
|
|
619
656
|
if scale >= 2 ** self._maxSkippedLevels:
|
|
620
|
-
tile = self._getTileFromEmptyLevel(x, y, z, **kwargs)
|
|
657
|
+
tile, _format = self._getTileFromEmptyLevel(x, y, z, **kwargs)
|
|
621
658
|
tile = large_image.tilesource.base._imageToNumpy(tile)[0]
|
|
622
659
|
format = TILE_FORMAT_NUMPY
|
|
623
660
|
else:
|
|
@@ -639,9 +676,14 @@ class BioformatsFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
|
|
|
639
676
|
format = TILE_FORMAT_NUMPY
|
|
640
677
|
except javabridge.JavaException as exc:
|
|
641
678
|
es = javabridge.to_string(exc.throwable)
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
679
|
+
self.logger.exception('Failed to getTile (%r)', es)
|
|
680
|
+
if getattr(self, '_lastGetTileException', None) == 'raise':
|
|
681
|
+
raise TileSourceError('Failed to get Bioformat region (%s, %r).' % (es, (
|
|
682
|
+
fc, fz, ft, fseries, self.sizeX, self.sizeY, offsetx,
|
|
683
|
+
offsety, width, height)))
|
|
684
|
+
self._lastGetTileException = repr(es)
|
|
685
|
+
tile = np.zeros((1, 1))
|
|
686
|
+
format = TILE_FORMAT_NUMPY
|
|
645
687
|
finally:
|
|
646
688
|
if javabridge.get_env():
|
|
647
689
|
javabridge.detach()
|
|
@@ -651,6 +693,8 @@ class BioformatsFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
|
|
|
651
693
|
fillValue = 0
|
|
652
694
|
if tile.dtype == np.uint16:
|
|
653
695
|
fillValue = 65535
|
|
696
|
+
elif tile.dtype == np.int16:
|
|
697
|
+
fillValue = 32767
|
|
654
698
|
elif tile.dtype == np.uint8:
|
|
655
699
|
fillValue = 255
|
|
656
700
|
elif tile.dtype.kind == 'f':
|
|
@@ -681,7 +725,7 @@ class BioformatsFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
|
|
|
681
725
|
"""
|
|
682
726
|
info = self._metadata['seriesAssociatedImages'].get(imageKey)
|
|
683
727
|
if info is None:
|
|
684
|
-
return
|
|
728
|
+
return None
|
|
685
729
|
series = info['seriesNum']
|
|
686
730
|
with self._tileLock:
|
|
687
731
|
try:
|
|
@@ -699,6 +743,31 @@ class BioformatsFileTileSource(FileTileSource, metaclass=LruCacheMetaclass):
|
|
|
699
743
|
javabridge.detach()
|
|
700
744
|
return large_image.tilesource.base._imageToPIL(image)
|
|
701
745
|
|
|
746
|
+
@classmethod
|
|
747
|
+
def addKnownExtensions(cls):
|
|
748
|
+
# This starts javabridge/bioformats if needed
|
|
749
|
+
_getBioformatsVersion()
|
|
750
|
+
if not hasattr(cls, '_addedExtensions'):
|
|
751
|
+
cls._addedExtensions = True
|
|
752
|
+
cls.extensions = cls.extensions.copy()
|
|
753
|
+
for dotext in bioformats.READABLE_FORMATS:
|
|
754
|
+
ext = dotext.strip('.')
|
|
755
|
+
if ext not in cls.extensions:
|
|
756
|
+
cls.extensions[ext] = SourcePriority.IMPLICIT
|
|
757
|
+
# The python modules doesn't list all the extensions that can be
|
|
758
|
+
# read, so supplement from the jar
|
|
759
|
+
readerlist = zipfile.ZipFile(
|
|
760
|
+
pathlib.Path(bioformats.__file__).parent /
|
|
761
|
+
'jars/bioformats_package.jar',
|
|
762
|
+
).open('loci/formats/readers.txt').read(100000).decode().split('\n')
|
|
763
|
+
pattern = re.compile(r'^loci\.formats\.in\..* # (?:.*?\b(\w{2,})\b(?:,|\s|$))')
|
|
764
|
+
for line in readerlist:
|
|
765
|
+
for ext in set(pattern.findall(line)) - {
|
|
766
|
+
'pattern', 'urlreader', 'screen', 'zip', 'zarr', 'db',
|
|
767
|
+
'fake', 'no'}:
|
|
768
|
+
if ext not in cls.extensions:
|
|
769
|
+
cls.extensions[ext] = SourcePriority.IMPLICIT
|
|
770
|
+
|
|
702
771
|
|
|
703
772
|
def open(*args, **kwargs):
|
|
704
773
|
"""
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: large-image-source-bioformats
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.30.7.dev12
|
|
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
|
|
21
|
-
Requires-Dist: python-bioformats
|
|
22
|
+
Requires-Dist: large-image>=1.30.7.dev12
|
|
23
|
+
Requires-Dist: python-bioformats>=1.5.2
|
|
22
24
|
Provides-Extra: girder
|
|
23
|
-
Requires-Dist: girder-large-image
|
|
25
|
+
Requires-Dist: girder-large-image>=1.30.7.dev12; 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=KGs5DY7YZrmaEhkvSYeQOdz3Wt-DDnHaIi4vfHAe07Q,33975
|
|
2
|
+
large_image_source_bioformats/girder_source.py,sha256=t0X1P0m4qMsRklpdxoPH-yqgHByMvQIzFJ4qRIUykVI,1355
|
|
3
|
+
large_image_source_bioformats-1.30.7.dev12.dist-info/LICENSE,sha256=psuoW8kuDP96RQsdhzwOqi6fyWv0ct8CR6Jr7He_P_k,10173
|
|
4
|
+
large_image_source_bioformats-1.30.7.dev12.dist-info/METADATA,sha256=F90J1NBmms4xP0N-aEmZaHxx652cARynfMm8mqgp0i4,1377
|
|
5
|
+
large_image_source_bioformats-1.30.7.dev12.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
|
|
6
|
+
large_image_source_bioformats-1.30.7.dev12.dist-info/entry_points.txt,sha256=xgIbKr53QhQkyRFkr87fkagfPWweeqhHHekUEMrcpF8,202
|
|
7
|
+
large_image_source_bioformats-1.30.7.dev12.dist-info/top_level.txt,sha256=e0enjlcFXwPi638IhE71Rk5-eeriA7W3M3IsQ6yH3RI,30
|
|
8
|
+
large_image_source_bioformats-1.30.7.dev12.dist-info/RECORD,,
|
|
@@ -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,,
|
|
File without changes
|
|
File without changes
|