Skip to content
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

Need to add titiler_endpoint argument when calling cog_tile_vmin_vmax in add_cog_layer #883

Merged
merged 2 commits into from
Sep 3, 2024

Conversation

flyhamsw
Copy link
Contributor

@flyhamsw flyhamsw commented Sep 3, 2024

Fixed a problem when running add_cog_layer with custom titiler_endpoint.

When a user run add_cog_layer with custom titiler_endpoint, the user will encounter following error message.

---------------------------------------------------------------------------
File ~/Desktop/workspace/leafmap/leafmap/stac.py:246, in cog_tile_vmin_vmax(url, bands, titiler_endpoint, percentile, **kwargs)
    [243](https://file+.vscode-resource.vscode-cdn.net/Users/swham/Desktop/workspace/leafmap/~/Desktop/workspace/leafmap/leafmap/stac.py:243)     stats = {s: stats[s] for s in stats if s in bands}
    [245](https://file+.vscode-resource.vscode-cdn.net/Users/swham/Desktop/workspace/leafmap/~/Desktop/workspace/leafmap/leafmap/stac.py:245) if percentile:
--> [246](https://file+.vscode-resource.vscode-cdn.net/Users/swham/Desktop/workspace/leafmap/~/Desktop/workspace/leafmap/leafmap/stac.py:246)     vmin = min([stats[s]["percentile_2"] for s in stats])
    [247](https://file+.vscode-resource.vscode-cdn.net/Users/swham/Desktop/workspace/leafmap/~/Desktop/workspace/leafmap/leafmap/stac.py:247)     vmax = max([stats[s]["percentile_98"] for s in stats])
    [248](https://file+.vscode-resource.vscode-cdn.net/Users/swham/Desktop/workspace/leafmap/~/Desktop/workspace/leafmap/leafmap/stac.py:248) else:

TypeError: string indices must be integers, not 'str'

This error is occured in leafmap.stac.cog_tile_vmin_vmax function due to wrong response from titiler. However, although the user provided the custom titiler_endpoint, this is not passed to the function, so the function tries to retrieve environment variable named TITILER_ENDPOINT. As a result, this function sends request to another URL rather than the URL that the user wants.

The problem can be simply solved by adding titiler_endpoint argument when calling leafmap.stac.cog_tile_vmin_vmax function in add_cog_layer.

Copy link
Member

@giswqs giswqs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you for the fix.

@mergify mergify bot merged commit 3932db9 into opengeos:master Sep 3, 2024
14 checks passed
Copy link

mergify bot commented Sep 3, 2024

Thanks for the contribution @flyhamsw 🤩

@flyhamsw flyhamsw deleted the pass-titiler-endpoint branch September 6, 2024 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants