From 3eddcc0a0bc9d63f7330506c007a6c8bb52cddf9 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Fri, 5 Aug 2022 11:14:10 -0400 Subject: [PATCH 1/2] Fix styling with nodata. Handle nodata when passed as a string. --- CHANGELOG.md | 1 + large_image/tilesource/base.py | 2 +- test/test_source_gdal.py | 12 ++++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8457d316c..e3cc14b48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ - Inheritable config files ([897](../../pull/897)) - Add geospatial property ([818](../../pull/818), [908](../../pull/908)) - Improve repr of image bytes ([902](../../pull/902)) +- Handle nodata style when specified as a string ([914](../../pull/914)) ### Changes - Be more consistent in source class name attribute assignment ([884](../../pull/884)) diff --git a/large_image/tilesource/base.py b/large_image/tilesource/base.py index 2cd665f98..facb2ec98 100644 --- a/large_image/tilesource/base.py +++ b/large_image/tilesource/base.py @@ -1191,7 +1191,7 @@ def _applyStyle(self, image, style, x, y, z, frame=None): # noqa clamp = entry.get('clamp', True) delta = max - min if max != min else 1 if nodata is not None: - keep = band != nodata + keep = band != float(nodata) else: keep = numpy.full(image.shape[:2], True) band = (band - min) / delta diff --git a/test/test_source_gdal.py b/test/test_source_gdal.py index f0f84f50a..4e85ced3f 100644 --- a/test/test_source_gdal.py +++ b/test/test_source_gdal.py @@ -568,3 +568,15 @@ def testVfsCogValidation(): imagePath, projection='EPSG:3857', encoding='PNG') with pytest.raises(TileSourceInefficientError): source.validateCOG() + + +def testNoData(): + imagePath = datastore.get_url('TC_NG_SFBay_US_Geo_COG.tif') + source = large_image_source_gdal.open( + imagePath, projection='EPSG:3857', + style={'bands': [{'band': 1, 'max': '100', 'min': '5', 'nodata': '0'}]}) + assert source.getThumbnail()[0] is not None + source = large_image_source_gdal.open( + imagePath, projection='EPSG:3857', + style={'bands': [{'band': 1, 'max': 100, 'min': 5, 'nodata': 0}]}) + assert source.getThumbnail()[0] is not None From 8f36e91ddb2098be2830156af7e8559b1bedeff5 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Fri, 5 Aug 2022 11:49:14 -0400 Subject: [PATCH 2/2] Improve test. --- test/test_source_gdal.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_source_gdal.py b/test/test_source_gdal.py index 4e85ced3f..886064f49 100644 --- a/test/test_source_gdal.py +++ b/test/test_source_gdal.py @@ -575,8 +575,8 @@ def testNoData(): source = large_image_source_gdal.open( imagePath, projection='EPSG:3857', style={'bands': [{'band': 1, 'max': '100', 'min': '5', 'nodata': '0'}]}) - assert source.getThumbnail()[0] is not None + assert source.getThumbnail()[0] source = large_image_source_gdal.open( imagePath, projection='EPSG:3857', style={'bands': [{'band': 1, 'max': 100, 'min': 5, 'nodata': 0}]}) - assert source.getThumbnail()[0] is not None + assert source.getThumbnail()[0]