opengeos / leafmap

A Python package for interactive mapping and geospatial analysis with minimal coding in a Jupyter environment
https://leafmap.org
MIT License
3.22k stars 386 forks source link

Add support for Actinia #348

Closed giswqs closed 11 months ago

giswqs commented 1 year ago

https://github.com/actinia-org/actinia-core https://github.com/actinia-org/actinia-python-client/ https://github.com/actinia-org/actinia-jupyter https://actinia.mundialis.de/ https://neteler.gitlab.io/actinia-introduction/

giswqs commented 1 year ago

Since rasterio has fixed the authentication issue (https://github.com/rasterio/rasterio/issues/2776), we can start integrating Actinia into leafmap now.

@neteler Would you like to contribute a notebook here?

neteler commented 1 year ago

Yes, definitely. I have already a draft, to be finished and submitted as a new PR.

neteler commented 1 year ago

I am on it but currently it fails:

m = leafmap.Map()

# define colors as hex or RGB values
colors = [(0, 0, 0), (255, 255, 255)]
vmin = -11
vmax = 221

m.add_colorbar(colors=colors, vmin=vmin, vmax=vmax)

m.add_cog_layer(url, name="North Carolina elevation hillshaded map", 
                attribution='<a href="https://grass.osgeo.org/download/data/">https://grass.osgeo.org/download/data/</a>')
# show map
m
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In [13], line 10
      6 vmax = 221
      8 m.add_colorbar(colors=colors, vmin=vmin, vmax=vmax)
---> 10 m.add_cog_layer(url, name="North Carolina elevation hillshaded map", 
     11                 attribution='<a href="https://grass.osgeo.org/download/data/">https://grass.osgeo.org/download/data/</a>')
     12 # show map
     13 m

File ~/.local/lib/python3.11/site-packages/leafmap/leafmap.py:866, in Map.add_cog_layer(self, url, name, attribution, opacity, shown, bands, titiler_endpoint, zoom_to_layer, **kwargs)
    838 def add_cog_layer(
    839     self,
    840     url,
   (...)
    848     **kwargs,
    849 ):
    850     """Adds a COG TileLayer to the map.
    851 
    852     Args:
   (...)
    864             apply a rescaling to multiple bands, use something like `rescale=["164,223","130,211","99,212"]`.
    865     """
--> 866     tile_url = cog_tile(url, bands, titiler_endpoint, **kwargs)
    867     bounds = cog_bounds(url, titiler_endpoint)
    868     self.add_tile_layer(tile_url, name, attribution, opacity, shown)

File ~/.local/lib/python3.11/site-packages/leafmap/stac.py:147, in cog_tile(url, bands, titiler_endpoint, **kwargs)
    143 titiler_endpoint = check_titiler_endpoint(titiler_endpoint)
    145 kwargs["url"] = url
--> 147 band_names = cog_bands(url, titiler_endpoint)
    149 if isinstance(bands, str):
    150     bands = [bands]

File ~/.local/lib/python3.11/site-packages/leafmap/stac.py:406, in cog_bands(url, titiler_endpoint)
    398 titiler_endpoint = check_titiler_endpoint(titiler_endpoint)
    399 r = requests.get(
    400     f"{titiler_endpoint}/cog/info",
    401     params={
    402         "url": url,
    403     },
    404 ).json()
--> 406 bands = [b[0] for b in r["band_descriptions"]]
    407 return bands

KeyError: 'band_descriptions'

I believe to have updated but no success yet. Any hint?

giswqs commented 1 year ago

Sorry, I forgot to follow up with this. Can you share the COG url for testing?

neteler commented 1 year ago

I tested my new actinia notebook again, no longer errors.

Shall I submit it as 83_actinia.ipynb?

giswqs commented 1 year ago

Yes, please. Thanks

neteler commented 1 year ago

Still some optimization incl. an change in actinia is needed, notebook still forthcoming.

giswqs commented 1 year ago

Good to know. Thanks for the update.