diff --git a/sources/bioformats/large_image_source_bioformats/__init__.py b/sources/bioformats/large_image_source_bioformats/__init__.py index 743d0c39c..1d2c5bf22 100644 --- a/sources/bioformats/large_image_source_bioformats/__init__.py +++ b/sources/bioformats/large_image_source_bioformats/__init__.py @@ -278,10 +278,14 @@ def __init__(self, path, **kwargs): # noqa if self.levels < 1: raise TileSourceError( - 'OpenSlide image must have at least one level.') + 'Bioformats image must have at least one level.') if self.sizeX <= 0 or self.sizeY <= 0: raise TileSourceError('Bioformats tile size is invalid.') + try: + self.getTile(0, 0, self.levels - 1) + except Exception as exc: + raise TileSourceError('Bioformats cannot read a tile: %r' % exc) def __del__(self): if getattr(self, '_bioimage', None) is not None: diff --git a/sources/deepzoom/large_image_source_deepzoom/__init__.py b/sources/deepzoom/large_image_source_deepzoom/__init__.py index 5bee17a85..5f9e6268f 100644 --- a/sources/deepzoom/large_image_source_deepzoom/__init__.py +++ b/sources/deepzoom/large_image_source_deepzoom/__init__.py @@ -48,7 +48,7 @@ def __init__(self, path, **kwargs): xml = ElementTree.parse(self._largeImagePath).getroot() self._info = etreeToDict(xml)['Image'] except (ElementTree.ParseError, KeyError, UnicodeDecodeError): - raise TileSourceError('File cannot be opened via Deepzoom reader.') + raise TileSourceError('File cannot be opened via deepzoom reader.') except FileNotFoundError: if not os.path.isfile(self._largeImagePath): raise TileSourceFileNotFoundError(self._largeImagePath) from None diff --git a/sources/gdal/large_image_source_gdal/__init__.py b/sources/gdal/large_image_source_gdal/__init__.py index 0b6244aa1..ab9f96891 100644 --- a/sources/gdal/large_image_source_gdal/__init__.py +++ b/sources/gdal/large_image_source_gdal/__init__.py @@ -159,15 +159,15 @@ def __init__(self, path, projection=None, unitsPerPixel=None, **kwargs): with self._getDatasetLock: self.sourceSizeX = self.sizeX = self.dataset.RasterXSize self.sourceSizeY = self.sizeY = self.dataset.RasterYSize - except AttributeError: + except AttributeError as exc: if not os.path.isfile(self._largeImagePath): raise TileSourceFileNotFoundError(self._largeImagePath) from None - raise TileSourceError('File cannot be opened via GDAL.') + raise TileSourceError('File cannot be opened via GDAL: %r' % exc) is_netcdf = self._checkNetCDF() try: scale = self.getPixelSizeInMeters() - except RuntimeError: - raise TileSourceError('File cannot be opened via GDAL.') + except RuntimeError as exc: + raise TileSourceError('File cannot be opened via GDAL: %r' % exc) if (self.projection or self._getDriver() in { 'PNG', }) and not scale and not is_netcdf: diff --git a/sources/openjpeg/large_image_source_openjpeg/__init__.py b/sources/openjpeg/large_image_source_openjpeg/__init__.py index d04efcdfd..575808642 100644 --- a/sources/openjpeg/large_image_source_openjpeg/__init__.py +++ b/sources/openjpeg/large_image_source_openjpeg/__init__.py @@ -99,8 +99,8 @@ def __init__(self, path, **kwargs): if not os.path.isfile(self._largeImagePath): raise FileNotFoundError() raise TileSourceError('File cannot be opened via Glymur and OpenJPEG.') - except (glymur.jp2box.InvalidJp2kError, struct.error): - raise TileSourceError('File cannot be opened via Glymur and OpenJPEG.') + except (glymur.jp2box.InvalidJp2kError, struct.error) as exc: + raise TileSourceError('File cannot be opened via Glymur and OpenJPEG: %r' % exc) except FileNotFoundError: if not os.path.isfile(self._largeImagePath): raise TileSourceFileNotFoundError(self._largeImagePath) from None @@ -112,8 +112,8 @@ def __init__(self, path, **kwargs): self._openjpegHandles.put(self._openjpeg) try: self.sizeY, self.sizeX = self._openjpeg.shape[:2] - except IndexError: - raise TileSourceError('File cannot be opened via Glymur and OpenJPEG.') + except IndexError as exc: + raise TileSourceError('File cannot be opened via Glymur and OpenJPEG: %r' % exc) self.levels = int(self._openjpeg.codestream.segment[2].num_res) + 1 self._minlevel = 0 self.tileWidth = self.tileHeight = 2 ** int(math.ceil(max( diff --git a/sources/tifffile/large_image_source_tifffile/__init__.py b/sources/tifffile/large_image_source_tifffile/__init__.py index fe9d77486..070aefe3a 100644 --- a/sources/tifffile/large_image_source_tifffile/__init__.py +++ b/sources/tifffile/large_image_source_tifffile/__init__.py @@ -137,6 +137,7 @@ def _biggestSeries(self): """ maxseries = None maxsamples = 0 + ex = 'no maximum series' try: for idx, s in enumerate(self._tf.series): samples = numpy.prod(s.shape) @@ -145,9 +146,11 @@ def _biggestSeries(self): maxsamples = samples except Exception as exc: self.logger.debug('Cannot use tifffile: %r', exc) + ex = exc maxseries = None if maxseries is None: - raise TileSourceError('File cannot be opened via tifffile source.') + raise TileSourceError( + 'File cannot be opened via tifffile source: %r' % ex) return maxseries, maxsamples def _findMatchingSeries(self): @@ -205,7 +208,7 @@ def _findAssociatedImages(self): """ Find associated images from unused pages and series. """ - pagesInSeries = [p for s in self._tf.series for l in s.pages.levels for p in l.pages] + pagesInSeries = [p for s in self._tf.series for ll in s.pages.levels for p in ll.pages] self._associatedImages = {} for p in self._tf.pages: if (p not in pagesInSeries and p.keyframe is not None and @@ -330,7 +333,7 @@ def getInternalMetadata(self, **kwargs): """ result = {} pages = [s.pages[0] for s in self._tf.series] - pagesInSeries = [p for s in self._tf.series for l in s.pages.levels for p in l.pages] + pagesInSeries = [p for s in self._tf.series for ll in s.pages.levels for p in ll.pages] pages.extend([page for page in self._tf.pages if page not in pagesInSeries]) for page in pages: for tag in getattr(page, 'tags', []): @@ -402,11 +405,11 @@ def getTile(self, x, y, z, pilImageAllowed=False, numpyAllowed=False, **kwargs): if hasattr(za[0], 'get_basic_selection'): bza = za[0] # we could cache this - for l in range(len(series.levels) - 1, 0, -1): - scale = round(max(za[0].shape[xidx] / za[l].shape[xidx], - za[0].shape[yidx] / za[l].shape[yidx])) + for ll in range(len(series.levels) - 1, 0, -1): + scale = round(max(za[0].shape[xidx] / za[ll].shape[xidx], + za[0].shape[yidx] / za[ll].shape[yidx])) if scale <= step and step // scale == step / scale: - bza = za[l] + bza = za[ll] x0 //= scale x1 //= scale y0 //= scale diff --git a/test/test_source_base.py b/test/test_source_base.py index a465f788a..0f106f9b9 100644 --- a/test/test_source_base.py +++ b/test/test_source_base.py @@ -20,9 +20,10 @@ SourceAndFiles = { 'bioformats': { 'read': r'\.(czi|jp2|svs|scn)$', + 'noread': r'(JK-kidney_B|TCGA-AA-A02O|\.scn$)', # We need to modify the bioformats reader similar to tiff's # getTileFromEmptyDirectory - 'skipTiles': r'(JK-kidney_B|TCGA-AA-A02O|TCGA-DU-6399|sample_jp2k_33003|\.scn$)'}, + 'skipTiles': r'(TCGA-DU-6399|sample_jp2k_33003)'}, 'deepzoom': {}, 'dummy': {'any': True, 'skipTiles': r''}, 'gdal': {