Skip to content

Commit

Permalink
Merge pull request #52 from MAAP-Project/ab/fix-other-titiler-endpoints
Browse files Browse the repository at this point in the history
Ab/fix other titiler endpoints
  • Loading branch information
abarciauskas-bgse authored Apr 5, 2023
2 parents 689d1b2 + adf7206 commit ec937f0
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 41 deletions.
27 changes: 13 additions & 14 deletions biomass-layers.csv
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
Layer Name,Tiles URL
Nceo africa sd,https://titiler.maap-project.org/cog/tiles/{z}/{x}/{y}.png?url=s3://maap-landing-zone-gccops/user-added/uploaded_objects/96a28977-02db-46a0-8429-70f5b4267d38/SD_map_2017v0m_COG.tif&rescale=0%2C310&colormap_name=reds
Nasa jpl se,"https://titiler.maap-project.org/mosaicjson/mosaics/210e8e5d-35c0-4549-8fc1-2b2145ad6ecf/tiles/{z}/{x}/{y}?bidx=1&max_size=1024&resampling_method=nearest&rescale=0,150&return_mask=true&colormap_name=reds&nodata=0"
Paraguay estimated biomass,"https://titiler.maap-project.org/cog/tiles/{z}/{x}/{y}.png?url=s3://maap-landing-zone-gccops/user-added/uploaded_objects/0bfec58c-45fb-464e-b301-b1afbdf5249e/5_biomass_cog.masked.tif&nodata=0&bidx=1&rescale=0,400&colormap_name=gist_earth_r"
Icesat2 boreal biomass,"https://titiler.maap-project.org/mosaicjson/mosaics/74c9966e-e865-4c6b-bfe8-d12130f9d6ad/tiles/{z}/{x}/{y}.png?bidx=1&rescale=0,400&colormap_name=gist_earth_r"
Nceo africa,"https://titiler.maap-project.org/cog/tiles/{z}/{x}/{y}.png?url=s3://maap-landing-zone-gccops/user-added/uploaded_objects/ae841191-8a43-4226-9c5e-db4f500adb45/AGB_map_2017v0m_COG.tif&rescale=0,400&colormap_name=gist_earth_r"
Nasa jpl,"https://titiler.maap-project.org/mosaicjson/mosaics/f0e6f941-4e50-46b3-9463-11b3c2181662/tiles/{z}/{x}/{y}?bidx=1&max_size=1024&resampling_method=nearest&rescale=0,400&return_mask=true&colormap_name=gist_earth_r"
Icesat2 boreal biomass se,https://titiler.maap-project.org/mosaicjson/mosaics/e7e26f4d-9a2f-4a3b-9256-0821e372e40e/tiles/{z}/{x}/{y}.png?bidx=2&rescale=0%2C20&colormap_name=reds
Gedi l4b,"https://nm8joechck.execute-api.us-west-2.amazonaws.com/cog/tiles/{z}/{x}/{y}.png?url=s3://ornl-cumulus-prod-protected/gedi/GEDI_L4B_Gridded_Biomass/data/GEDI04_B_MW019MW138_02_002_05_R01000M_MU.tif&rescale=0,400&colormap_name=gist_earth_r"
Gedi l4b se,"https://nm8joechck.execute-api.us-west-2.amazonaws.com/cog/tiles/{z}/{x}/{y}.png?url=s3://ornl-cumulus-prod-protected/gedi/GEDI_L4B_Gridded_Biomass/data/GEDI04_B_MW019MW138_02_002_05_R01000M_SE.tif&rescale=0,310&colormap_name=reds"
Cci biomass sd,"https://titiler.maap-project.org/mosaicjson/mosaics/f343756d-bf15-4095-a8f3-f4fcbb26b5f9/tiles/{z}/{x}/{y}?rescale=0,500&bidx=2&colormap_name=reds"
Gedi calval plots,"https://titiler.maap-project.org/mosaicjson/mosaics/f343756d-bf15-4095-a8f3-f4fcbb26b5f9/tiles/{z}/{x}/{y}?rescale=0,500&bidx=2&colormap_name=reds"
Paraguay forest mask,"https://titiler.maap-project.org/cog/tiles/{z}/{x}/{y}.png?url=s3://maap-landing-zone-gccops/user-added/uploaded_objects/45fe2e6f-2007-4cb1-964a-f337f39f4fdc/1_forest_cog.masked.tif&rescale=0,1&nodata=0&colormap_name=greens"
Paraguay tree cover,"https://titiler.maap-project.org/cog/tiles/{z}/{x}/{y}.png?url=s3://maap-landing-zone-gccops/user-added/uploaded_objects/ee5eb60c-3c01-4789-ae8e-c03f1d719440/4_tree_cover_cog.masked.tif&rescale=0,75&nodata=0&colormap_name=greens"
Cci biomass,"https://titiler.maap-project.org/mosaicjson/mosaics/f343756d-bf15-4095-a8f3-f4fcbb26b5f9/tiles/{z}/{x}/{y}?rescale=0,400&bidx=1&colormap_name=gist_earth_r"
NASA JPL,"https://titiler.maap-project.org/mosaics/f0e6f941-4e50-46b3-9463-11b3c2181662/tiles/{z}/{x}/{y}?bidx=1&max_size=1024&resampling_method=nearest&rescale=0,400&return_mask=true&colormap_name=gist_earth_r"
NASA JPL SE,"https://titiler.maap-project.org/mosaics/210e8e5d-35c0-4549-8fc1-2b2145ad6ecf/tiles/{z}/{x}/{y}?bidx=1&max_size=1024&resampling_method=nearest&rescale=0,150&return_mask=true&colormap_name=reds&nodata=0"
ICESat-2 Boreal Biomass (Use zoom >=8),"https://titiler.maap-project.org/mosaics/74c9966e-e865-4c6b-bfe8-d12130f9d6ad/tiles/{z}/{x}/{y}.png?bidx=1&rescale=0,400&colormap_name=gist_earth_r"
ICESat-2 Boreal Biomass SE (Use zoom >=8),"https://titiler.maap-project.org/mosaics/e7e26f4d-9a2f-4a3b-9256-0821e372e40e/tiles/{z}/{x}/{y}.png?bidx=2&rescale=0%2C20&colormap_name=reds"
NCEO Africa,"https://titiler.maap-project.org/cog/tiles/{z}/{x}/{y}.png?url=s3://maap-landing-zone-gccops/user-added/uploaded_objects/ae841191-8a43-4226-9c5e-db4f500adb45/AGB_map_2017v0m_COG.tif&rescale=0,400&colormap_name=gist_earth_r"
NCEO Africa SD,"https://titiler.maap-project.org/cog/tiles/{z}/{x}/{y}.png?url=s3://maap-landing-zone-gccops/user-added/uploaded_objects/96a28977-02db-46a0-8429-70f5b4267d38/SD_map_2017v0m_COG.tif&rescale=0%2C310&colormap_name=reds"
GEDI L4B,"https://titiler.dit.maap-project.org/cog/tiles/{z}/{x}/{y}.png?url=s3://ornl-cumulus-prod-protected/gedi/GEDI_L4B_Gridded_Biomass/data/GEDI04_B_MW019MW138_02_002_05_R01000M_MU.tif&rescale=0,400&colormap_name=gist_earth_r"
GEDI L4B SE,"https://titiler.dit.maap-project.org/cog/tiles/{z}/{x}/{y}.png?url=s3://ornl-cumulus-prod-protected/gedi/GEDI_L4B_Gridded_Biomass/data/GEDI04_B_MW019MW138_02_002_05_R01000M_SE.tif&rescale=0,310&colormap_name=reds"
CCI Biomass,"https://titiler.maap-project.org/mosaics/f343756d-bf15-4095-a8f3-f4fcbb26b5f9/tiles/{z}/{x}/{y}?rescale=0,400&bidx=1&colormap_name=gist_earth_r"
CCI Biomass SD,"https://titiler.maap-project.org/mosaics/f343756d-bf15-4095-a8f3-f4fcbb26b5f9/tiles/{z}/{x}/{y}?rescale=0,500&bidx=2&colormap_name=reds"
Paraguay Estimated Biomass,"https://titiler.maap-project.org/cog/tiles/{z}/{x}/{y}.png?url=s3://maap-landing-zone-gccops/user-added/uploaded_objects/0bfec58c-45fb-464e-b301-b1afbdf5249e/5_Biomass_cog.masked.tif&nodata=0&bidx=1&rescale=0,400&colormap_name=gist_earth_r"
Paraguay Forest Mask,"https://titiler.maap-project.org/cog/tiles/{z}/{x}/{y}.png?url=s3://maap-landing-zone-gccops/user-added/uploaded_objects/45fe2e6f-2007-4cb1-964a-f337f39f4fdc/1_forest_cog.masked.tif&rescale=0,1&nodata=0&colormap_name=greens"
Paraguay Tree Cover,"https://titiler.maap-project.org/cog/tiles/{z}/{x}/{y}.png?url=s3://maap-landing-zone-gccops/user-added/uploaded_objects/ee5eb60c-3c01-4789-ae8e-c03f1d719440/4_tree_cover_cog.masked.tif&rescale=0,75&nodata=0&colormap_name=greens"
5 changes: 2 additions & 3 deletions demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "619f0be9996d4cc5904a86bb946b1f67",
"model_id": "3a03ad2140da4cd198721f5ba3e089c6",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"StacIpyleaflet(center=[20, 0], controls=(ZoomControl(options=['position', 'zoom_in_text', 'zoom_in_title', 'zo…"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
"output_type": "display_data"
}
],
"source": [
Expand Down
8 changes: 5 additions & 3 deletions stac_ipyleaflet/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class StacIpyleaflet(Map):
draw_control: DrawControl
# TODO(aimee): right now this is specific to MAAP but we should make it generic.
titiler_endpoint: str = "https://titiler.maap-project.org"
titiler_stac_endpoint: str = "https://titiler-stac.maap-project.org"
histogram_layer: Popup
warning_layer: Popup = None
loading_widget_layer: Popup = None
Expand Down Expand Up @@ -264,13 +265,14 @@ def update_selected_data(self):
# Aimee(TODO): Check the assumption (origin = upper left corner)
ds = xds.sel(x=slice(bounds[0], bounds[2]), y=slice(bounds[3], bounds[1]))
else:
match = re.search(f"({self.titiler_endpoint}/mosaicjson/mosaics/.+)/tiles", layer_url)
uuid_pattern = r'([a-f\d]{8}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{4}-[a-f\d]{12})'
match = re.search(f"({self.titiler_endpoint}/mosaics/{uuid_pattern})/tiles", layer_url)
if match:
mosaic_url = match.groups()[0]
# From titiler docs http://titiler.maap-project.org/docs
# /mosaicjson/{minx},{miny},{maxx},{maxy}/assets
# /{minx},{miny},{maxx},{maxy}/assets
str_bounds = f"{bounds[0]},{bounds[1]},{bounds[2]},{bounds[3]}"
assets_endpoint = f"{self.titiler_endpoint}/mosaicjson/{str_bounds}/assets?url={mosaic_url}/mosaicjson"
assets_endpoint = f"{self.titiler_stac_endpoint}/mosaicjson/{str_bounds}/assets?url={mosaic_url}/mosaicjson"
# create a dataset from multiple COGs
assets_response = requests.get(assets_endpoint)
datasets = []
Expand Down
40 changes: 20 additions & 20 deletions stac_ipyleaflet/stac_discovery/stac.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@

class Stac():

def stac_bands(url=None, collection=None, item=None, titiler_endpoint=None, **kwargs):
def stac_bands(url=None, collection=None, item=None, titiler_stac_endpoint=None, **kwargs):
"""Get band names of a single SpatialTemporal Asset Catalog (STAC) item.
Args:
url (str): HTTP URL to a STAC item
collection (str): STAC collection ID, e.g., landsat-8-c2-l2.
item (str): STAC item ID, e.g., LC08_L2SP_047027_20201204_02_T1.
titiler_endpoint (str, optional): Titiler endpoint. Defaults to None.
titiler_stac_endpoint (str, optional): Titiler endpoint. Defaults to None.
Returns:
list: A list of band names
"""
Expand All @@ -27,10 +27,10 @@ def stac_bands(url=None, collection=None, item=None, titiler_endpoint=None, **kw
if item is not None:
kwargs["item"] = item

if isinstance(titiler_endpoint, str):
r = requests.get(f"{titiler_endpoint}/stac/assets", params=kwargs).json()
if isinstance(titiler_stac_endpoint, str):
r = requests.get(f"{titiler_stac_endpoint}/stac/assets", params=kwargs).json()
else:
r = requests.get(titiler_endpoint.url_for_stac_assets(), params=kwargs).json()
r = requests.get(titiler_stac_endpoint.url_for_stac_assets(), params=kwargs).json()

return r

Expand All @@ -40,7 +40,7 @@ def stac_tile(
item=None,
assets=None,
bands=None,
titiler_endpoint=None,
titiler_stac_endpoint=None,
**kwargs,
):
"""Get a tile layer from a single SpatialTemporal Asset Catalog (STAC) item.
Expand All @@ -50,7 +50,7 @@ def stac_tile(
item (str): STAC item ID, e.g., LC08_L2SP_047027_20201204_02_T1.
assets (str | list): STAC asset ID, e.g., ["SR_B7", "SR_B5", "SR_B4"].
bands (list): A list of band names, e.g., ["SR_B7", "SR_B5", "SR_B4"]
titiler_endpoint (str, optional): Titiler endpoint, Defaults to None.
titiler_stac_endpoint (str, optional): Titiler endpoint, Defaults to None.
Returns:
str: Returns the STAC Tile layer URL.
"""
Expand Down Expand Up @@ -88,22 +88,22 @@ def stac_tile(
TileMatrixSetId = kwargs["TileMatrixSetId"]
kwargs.pop("TileMatrixSetId")

if isinstance(titiler_endpoint, str):
if isinstance(titiler_stac_endpoint, str):
r = requests.get(
f"{titiler_endpoint}/stac/{TileMatrixSetId}/tilejson.json",
f"{titiler_stac_endpoint}/stac/{TileMatrixSetId}/tilejson.json",
params=kwargs,
).json()
else:
r = requests.get(titiler_endpoint.url_for_stac_item(), params=kwargs).json()
r = requests.get(titiler_stac_endpoint.url_for_stac_item(), params=kwargs).json()
return r["tiles"][0]

def stac_bounds(url=None, collection=None, item=None, titiler_endpoint=None, **kwargs):
def stac_bounds(url=None, collection=None, item=None, titiler_stac_endpoint=None, **kwargs):
"""Get the bounding box of a single SpatialTemporal Asset Catalog (STAC) item.
Args:
url (str): HTTP URL to a STAC item
collection (str): STAC collection ID, e.g., landsat-8-c2-l2.
item (str): STAC item ID, e.g., LC08_L2SP_047027_20201204_02_T1.
titiler_endpoint (str, optional): Titiler endpoint, Defaults to None.
titiler_stac_endpoint (str, optional): Titiler endpoint, Defaults to None.
Returns:
list: A list of values representing [left, bottom, right, top]
"""
Expand All @@ -117,10 +117,10 @@ def stac_bounds(url=None, collection=None, item=None, titiler_endpoint=None, **k
if item is not None:
kwargs["item"] = item

if isinstance(titiler_endpoint, str):
r = requests.get(f"{titiler_endpoint}/stac/bounds", params=kwargs).json()
if isinstance(titiler_stac_endpoint, str):
r = requests.get(f"{titiler_stac_endpoint}/stac/bounds", params=kwargs).json()
else:
r = requests.get(titiler_endpoint.url_for_stac_bounds(), params=kwargs).json()
r = requests.get(titiler_stac_endpoint.url_for_stac_bounds(), params=kwargs).json()

bounds = r["bounds"]
return bounds
Expand All @@ -132,7 +132,7 @@ def add_stac_layer(
item=None,
assets=None,
bands=None,
titiler_endpoint=None,
titiler_stac_endpoint=None,
name="STAC Layer",
attribution="",
opacity=1.0,
Expand All @@ -146,16 +146,16 @@ def add_stac_layer(
item (str): STAC item ID, e.g., LC08_L2SP_047027_20201204_02_T1.
assets (str | list): STAC asset ID, e.g., ["SR_B7", "SR_B5", "SR_B4"].
bands (list): A list of band names, e.g., ["SR_B7", "SR_B5", "SR_B4"]
titiler_endpoint (str, optional): Titiler endpoint, Defaults to None.
titiler_stac_endpoint (str, optional): Titiler endpoint, Defaults to None.
name (str, optional): The layer name to use for the layer. Defaults to 'STAC Layer'.
attribution (str, optional): The attribution to use. Defaults to ''.
opacity (float, optional): The opacity of the layer. Defaults to 1.
shown (bool, optional): A flag indicating whether the layer should be on by default. Defaults to True.
"""
tile_url = Stac.stac_tile(
url, collection, item, assets, bands, titiler_endpoint, **kwargs
url, collection, item, assets, bands, titiler_stac_endpoint, **kwargs
)
bounds = Stac.stac_bounds(url, collection, item, titiler_endpoint)
bounds = Stac.stac_bounds(url, collection, item, titiler_stac_endpoint)
self.add_tile_layer(tile_url, name, attribution, opacity, shown)
self.fit_bounds([[bounds[1], bounds[0]], [bounds[3], bounds[2]]])

Expand All @@ -171,7 +171,7 @@ def add_stac_layer(
"item": item,
"assets": assets,
"bounds": bounds,
"titiler_endpoint": self.titiler_endpoint,
"titiler_stac_endpoint": self.titiler_stac_endpoint,
"type": "STAC",
}

Expand Down
2 changes: 1 addition & 1 deletion stac_ipyleaflet/stac_discovery/stac_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ def button_clicked(change):
item=items.value,
assets=assets,
name=layer_name.value,
titiler_endpoint=self.titiler_endpoint,
titiler_stac_endpoint=self.titiler_stac_endpoint,
**vis_params,
)
self.stac_data = stac_data[0][items.value]
Expand Down

0 comments on commit ec937f0

Please sign in to comment.