diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bdd7d7ef..854db6445 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ - Read more metadata from DICOMweb ([#1378](../../pull/1378)) - Remove logic for determining DICOMweb transfer syntax ([#1393](../../pull/1393)) - Speed up tile output ([#1407](../../pull/1407)) +- Speed up import time ([#1408](../../pull/1408)) ### Changes - Use an enum for priority constants ([#1400](../../pull/1400)) diff --git a/large_image/tilesource/base.py b/large_image/tilesource/base.py index e3356ce75..334ddd63a 100644 --- a/large_image/tilesource/base.py +++ b/large_image/tilesource/base.py @@ -285,7 +285,7 @@ def dtype(self): @property def bandCount(self): if not self._bandCount: - if not self._dtype or str(self._dtype) == 'check': + if not self._dtype or (isinstance(self._dtype, str) and self._dtype == 'check'): return None return self._bandCount @@ -1134,20 +1134,6 @@ def histogram(self, dtype=None, onlyMinMax=False, bins=256, # noqa entry['hist'] = entry['hist'].astype(float) / entry['samples'] return results - def _unstyledClassKey(self): - """ - Create a class key that doesn't use style. If already created, just - return the created value. - """ - if not hasattr(self, '_classkey_unstyled'): - key = self._classkey - if '__STYLEEND__' in key: - parts = key.split('__STYLEEND__', 1) - key = key.split('__STYLESTART__', 1)[0] + parts[1] - key += '__unstyled' - self._classkey_unstyled = key - return self._classkey_unstyled - def _scanForMinMax(self, dtype, frame=None, analysisSize=1024, onlyMinMax=True, **kwargs): """ Scan the image at a lower resolution to find the minimum and maximum @@ -1597,7 +1583,10 @@ def _outputTileNumpyStyle(self, tile, applyStyle, x, y, z, frame=None): :returns: a numpy array and a target PIL image mode. """ tile, mode = _imageToNumpy(tile) - if applyStyle and (getattr(self, 'style', None) or hasattr(self, '_iccprofiles')): + # if applyStyle and (getattr(self, 'style', None) or hasattr(self, '_iccprofiles')): + if (applyStyle and (getattr(self, 'style', None) or hasattr(self, '_iccprofiles')) and + (not getattr(self, 'style', None) or len(self.style) != 1 or + self.style.get('icc') is not False)): tile = self._applyStyle(tile, getattr(self, 'style', None), x, y, z, frame) if tile.shape[0] != self.tileHeight or tile.shape[1] != self.tileWidth: extend = np.zeros( @@ -1641,7 +1630,7 @@ def _outputTile(self, tile, tileEncoding, x, y, z, pilImageAllowed=False, not isEdge and (not applyStyle or not hasStyle)): return tile - if self._dtype is None or str(self._dtype) == 'check': + if self._dtype is None or (isinstance(self._dtype, str) and self._dtype == 'check'): if tileEncoding == TILE_FORMAT_NUMPY: self._dtype = tile.dtype self._bandCount = tile.shape[-1] if len(tile.shape) == 3 else 1 diff --git a/large_image/tilesource/jupyter.py b/large_image/tilesource/jupyter.py index 86e0fb3c9..cff3ee331 100644 --- a/large_image/tilesource/jupyter.py +++ b/large_image/tilesource/jupyter.py @@ -14,6 +14,7 @@ likely lead to crashes. This is only for use in JupyterLab. """ +import importlib.util import json import os import weakref @@ -21,10 +22,7 @@ from large_image.exceptions import TileSourceXYZRangeError from large_image.tilesource.utilities import JSONDict -try: - import ipyleaflet -except ImportError: # pragma: no cover - ipyleaflet = None +ipyleafletPresent = importlib.util.find_spec('ipyleaflet') is not None def launch_tile_server(tile_source, port=0): @@ -146,7 +144,7 @@ def __init__(self, *, ts=None, metadata=None, url=None, gc=None, id=None, resour self._layer = self.make_layer(metadata, url) self._map = self.make_map(metadata) - if ipyleaflet: + if ipyleafletPresent: def _ipython_display_(self): from IPython.display import display @@ -382,7 +380,7 @@ class IPyLeafletMixin: def __init__(self, *args, **kwargs): self._jupyter_server_manager = None self._map = Map() - if ipyleaflet: + if ipyleafletPresent: self.to_map = self._map.to_map self.from_map = self._map.from_map @@ -411,7 +409,7 @@ def as_leaflet_layer(self, **kwargs): return self._map.make_layer(self.metadata, f'{base_url}/{endpoint}') # Only make _ipython_display_ available if ipyleaflet is installed - if ipyleaflet: + if ipyleafletPresent: def _ipython_display_(self): from IPython.display import display