-
Notifications
You must be signed in to change notification settings - Fork 106
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
add parse_color function #361
Conversation
rio_tiler/colormap.py
Outdated
|
||
""" | ||
if isinstance(value, str): | ||
if re.match("^#[a-fA-F0-9]{3,4}$", value): |
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 a regex is overkill here. You can just assert that the string starts with #
(if you want) and then if the string has <=4 more characters, you treat it as the first type, otherwise the second. And if an error is created that gets propagated to the user. But not a strong preference.
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.
FYI, that's how matplotlib does: https://github.com/matplotlib/matplotlib/blob/fa73bc09d62aef99842bbbd13dca687ac5bbd0b9/lib/matplotlib/colors.py#L237-L265
I think overkill regex are fine :-)
if len(rgba) == 3: | ||
rgba += (255,) | ||
|
||
return rgba # type: ignore |
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.
I couldn't keep mypy happy here because it lost the track on the number of items in rgba 🤷♂️
ref developmentseed/titiler#262
This PR adds a function to parse colormap value from HEX for list.