-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow named color palettes to be used by all sources. #724
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is excellent! However, I'm having some trouble getting this to work:
No problem:
>>> large_image.open('/Users/bane/Desktop/TC_NG_SFBay_US_Geo.tif', style=json.dumps({"band": 1, "palette": ["#000", "#f00"]}))
<large_image_source_gdal.GDALFileTileSource object at 0x7fa138fe3430>
>>>
Problem:
>>> large_image.open('/Users/bane/Desktop/TC_NG_SFBay_US_Geo.tif', style=json.dumps({"band": 1, "palette": "viridis"}))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Users/bane/Software/kw/large_image/large_image/tilesource/__init__.py", line 140, in open
return getTileSource(*args, **kwargs)
File "/Users/bane/Software/kw/large_image/large_image/tilesource/__init__.py", line 128, in getTileSource
return getTileSourceFromDict(AvailableTileSources, *args, **kwargs)
File "/Users/bane/Software/kw/large_image/large_image/tilesource/__init__.py", line 113, in getTileSourceFromDict
sourceName = getSourceNameFromDict(availableSources, pathOrUri, *args, **kwargs)
File "/Users/bane/Software/kw/large_image/large_image/tilesource/__init__.py", line 98, in getSourceNameFromDict
if availableSources[sourceName].canRead(pathOrUri, *args, **kwargs):
File "/Users/bane/Software/kw/large_image/large_image/tilesource/base.py", line 2360, in canRead
cls(path, *args, **kwargs)
File "/Users/bane/Software/kw/large_image/large_image/cache_util/cache.py", line 193, in __call__
instance = super().__call__(*args, **kwargs)
File "/Users/bane/Software/kw/large_image/sources/gdal/large_image_source_gdal/__init__.py", line 156, in __init__
self._setDefaultStyle()
File "/Users/bane/Software/kw/large_image/sources/gdal/large_image_source_gdal/__init__.py", line 227, in _setDefaultStyle
bstyle['palette'] = self.getHexColors(bstyle['palette'])
File "/Users/bane/Software/kw/large_image/sources/gdal/large_image_source_gdal/__init__.py", line 358, in getHexColors
return ['#%02X%02X%02X%02X' % tuple(clr) for clr in palette]
File "/Users/bane/Software/kw/large_image/sources/gdal/large_image_source_gdal/__init__.py", line 358, in <listcomp>
return ['#%02X%02X%02X%02X' % tuple(clr) for clr in palette]
TypeError: %X format: an integer is required, not numpy.float64
>>>
This also increase the ability to handle css and named colors.
97b9c6f
to
6895f2d
Compare
Should be fixed and tested now. |
large_image/tilesource/utilities.py
Outdated
except (ImportError, ValueError): | ||
pass | ||
if palette is None: | ||
raise TileSourceError('Value cannot be used as a color palette.') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, this should be a ValueError
. Any particular reason that TileSourceError
is used here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thought was that it prevents the tile source from working, but I'll change it to a ValueError
.
Would it make sense to fail back to a known value? For example, This might not be desired by everyone though... |
Also could we implement an |
Sure -- this would just be
|
Could we also have a |
I'd rather not. It seems like passing something like |
Fair enough - leaving it as is works for me |
Should such a function actually be called |
I was just thinking that -- yes
I think so, I think anything named should be returned (e.g., "red", etc.) |
Add isValidPalette utility function.
Let's push off adding |
@banesullivan There is a now a |
This also increase the ability to handle css and named colors.
This generalized and supercedes #714. This closes #716.