Skip to content

Commit

Permalink
Merge pull request #496 from girder/expose-more-region-options
Browse files Browse the repository at this point in the history
Expose more resample options for region and histogram.
  • Loading branch information
manthey authored Nov 20, 2020
2 parents 4c838a2 + ed6ce38 commit 1ab6324
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- Reduce caching associated images when the parent item changes (#491)
- Test with Python 3.9 (#493)
- Add a hideAnnotation function in the client (#490)
- Expose more resample options for region and histogram endpoints (#496)
- Improve OME tiff preferred level calculation for OME tiffs with subifds (#496)

### Changes
- Include the annotationType to the annotation conversion method in the client (#490)
Expand Down
18 changes: 15 additions & 3 deletions girder/girder_large_image/rest/tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ def _parseParams(cls, params, keepUnknownParams, typeList):
for entry in typeList:
key, dataType, outkey1, outkey2 = (list(entry) + [None] * 2)[:4]
if key in params:
if dataType == 'boolOrInt':
dataType = bool if str(params[key]).lower() in (
'true', 'false', 'on', 'off', 'yes', 'no') else int
try:
if dataType is bool:
results[key] = str(params[key]).lower() in (
Expand Down Expand Up @@ -670,6 +673,12 @@ def getTilesThumbnail(self, item, params):
'image', required=False,
enum=['raw', 'tiff_lzw', 'jpeg', 'tiff_adobe_deflate'])
.param('style', 'JSON-encoded style string', required=False)
.param('resample', 'If false, an existing level of the image is used '
'for the histogram. If true, the internal values are '
'interpolated to match the specified size as needed. 0-3 for '
'a specific interpolation method (0-nearest, 1-lanczos, '
'2-bilinear, 3-bicubic)', required=False,
enum=['false', 'true', '0', '1', '2', '3'], default='false')
.param('contentDisposition', 'Specify the Content-Disposition response '
'header disposition-type value.', required=False,
enum=['inline', 'attachment'])
Expand Down Expand Up @@ -704,6 +713,7 @@ def getTilesRegion(self, item, params):
('jpegSubsampling', int),
('tiffCompression', str),
('style', str),
('resample', 'boolOrInt'),
('contentDisposition', str),
])
_handleETag('getTilesRegion', item, params)
Expand Down Expand Up @@ -773,8 +783,10 @@ def getTilesPixel(self, item, params):
default=2048, required=False, dataType='int')
.param('resample', 'If false, an existing level of the image is used '
'for the histogram. If true, the internal values are '
'interpolated to match the specified size as needed.',
required=False, dataType='boolean', default=False)
'interpolated to match the specified size as needed. 0-3 for '
'a specific interpolation method (0-nearest, 1-lanczos, '
'2-bilinear, 3-bicubic)', required=False,
enum=['false', 'true', '0', '1', '2', '3'], default='false')
.param('frame', 'For multiframe images, the 0-based frame number. '
'This is ignored on non-multiframe images.', required=False,
dataType='int')
Expand Down Expand Up @@ -817,7 +829,7 @@ def getHistogram(self, item, params):
('jpegSubsampling', int),
('tiffCompression', str),
('style', str),
('resample', bool),
('resample', 'boolOrInt'),
('bins', int),
('rangeMin', int),
('rangeMax', int),
Expand Down
24 changes: 24 additions & 0 deletions sources/ometiff/large_image_source_ometiff/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,27 @@ def getTile(self, x, y, z, pilImageAllowed=False, numpyAllowed=False,
x, y, z, pilImageAllowed=pilImageAllowed,
numpyAllowed=numpyAllowed, sparseFallback=sparseFallback,
exception=e, **kwargs)

def getPreferredLevel(self, level):
"""
Given a desired level (0 is minimum resolution, self.levels - 1 is max
resolution), return the level that contains actual data that is no
lower resolution.
:param level: desired level
:returns level: a level with actual data that is no lower resolution.
"""
level = max(0, min(level, self.levels - 1))
baselevel = level
while self._tiffDirectories[level] is None and level < self.levels - 1:
try:
dirnum = int(self._omeLevels[-1]['TiffData'][0].get('IFD', 0))
subdir = self.levels - 1 - level
if self._getDirFromCache(dirnum, subdir):
break
except Exception:
pass
level += 1
while level - baselevel > self._maxSkippedLevels:
level -= self._maxSkippedLevels
return level
2 changes: 2 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ python =
3.6: py36
3.7: py37, docs, flake8, lintclient, lintannotationclient
3.8: py38
3.9: py39

[testenv]
passenv = PYTEST_*
Expand All @@ -29,6 +30,7 @@ deps =
pytest-girder>=3.0.4,<3.1; python_version < '3.6'
pytest-xdist
celery!=4.4.4,<5
urllib3<1.26
# celery 4.4.4 is broken; avoid it until a new version is released
whitelist_externals =
rm
Expand Down

0 comments on commit 1ab6324

Please sign in to comment.