Skip to content

Commit

Permalink
Merge pull request #1408 from girder/faster-import
Browse files Browse the repository at this point in the history
Speed up initial import
  • Loading branch information
manthey authored Dec 15, 2023
2 parents 29d8204 + bb0d273 commit 4531f64
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
23 changes: 6 additions & 17 deletions large_image/tilesource/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down
12 changes: 5 additions & 7 deletions large_image/tilesource/jupyter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@
likely lead to crashes. This is only for use in JupyterLab.
"""
import importlib.util
import json
import os
import weakref

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):
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4531f64

Please sign in to comment.