diff --git a/large_image/tilesource/base.py b/large_image/tilesource/base.py index 4170a4062..4d68eaa0f 100644 --- a/large_image/tilesource/base.py +++ b/large_image/tilesource/base.py @@ -1591,7 +1591,7 @@ def getInternalMetadata(self, **kwargs): """ return None - def _xyzInRange(self, x, y, z): + def _xyzInRange(self, x, y, z, frame=None, numFrames=None): """ Check if a tile at x, y, z is in range based on self.levels, self.tileWidth, self.tileHeight, self.sizeX, and self.sizeY, Raise an @@ -1606,6 +1606,9 @@ def _xyzInRange(self, x, y, z): offsety = y * self.tileHeight * scale if not (0 <= offsety < self.sizeY): raise exceptions.TileSourceException('y is outside layer') + if frame is not None and numFrames is not None: + if frame < 0 or frame >= numFrames: + raise exceptions.TileSourceException('Frame does not exist') @methodcache() def getTile(self, x, y, z, pilImageAllowed=False, numpyAllowed=False, diff --git a/sources/nd2/large_image_source_nd2/__init__.py b/sources/nd2/large_image_source_nd2/__init__.py index 9be14ad6b..3be76ed10 100644 --- a/sources/nd2/large_image_source_nd2/__init__.py +++ b/sources/nd2/large_image_source_nd2/__init__.py @@ -302,16 +302,13 @@ def getInternalMetadata(self, **kwargs): @methodcache() def getTile(self, x, y, z, pilImageAllowed=False, numpyAllowed=False, **kwargs): - self._xyzInRange(x, y, z) + frame = int(kwargs.get('frame') or 0) + self._xyzInRange(x, y, z, frame, len(self._nd2)) step = int(2 ** (self.levels - 1 - z)) x0 = x * step * self.tileWidth x1 = min((x + 1) * step * self.tileWidth, self.sizeX) y0 = y * step * self.tileHeight y1 = min((y + 1) * step * self.tileHeight, self.sizeY) - frame = kwargs.get('frame') - frame = int(frame) if frame else 0 - if frame < 0 or frame >= len(self._nd2): - raise TileSourceException('Frame does not exist') with self._tileLock: if frame in self._recentFrames: tileframe = self._recentFrames[frame] diff --git a/sources/ometiff/large_image_source_ometiff/__init__.py b/sources/ometiff/large_image_source_ometiff/__init__.py index 6b4403ee2..f8237103c 100644 --- a/sources/ometiff/large_image_source_ometiff/__init__.py +++ b/sources/ometiff/large_image_source_ometiff/__init__.py @@ -84,6 +84,7 @@ def __init__(self, path, **kwargs): :param path: a filesystem path for the tile source. """ + # Note this is the super of the parent class, not of this class. super(TiffFileTileSource, self).__init__(path, **kwargs) largeImagePath = self._getLargeImagePath() diff --git a/sources/openslide/large_image_source_openslide/__init__.py b/sources/openslide/large_image_source_openslide/__init__.py index 3ecd4f551..c2cf57ed3 100644 --- a/sources/openslide/large_image_source_openslide/__init__.py +++ b/sources/openslide/large_image_source_openslide/__init__.py @@ -271,10 +271,7 @@ def getInternalMetadata(self, **kwargs): @methodcache() def getTile(self, x, y, z, pilImageAllowed=False, numpyAllowed=False, **kwargs): self._xyzInRange(x, y, z) - try: - svslevel = self._svslevels[z] - except IndexError: - raise TileSourceException('z layer does not exist') + svslevel = self._svslevels[z] # When we read a region from the SVS, we have to ask for it in the # SVS level 0 coordinate system. Our x and y is in tile space at the # specifed z level, so the offset in SVS level 0 coordinates has to be