{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Visualizing MAAP STAC Dataset with titiler-pgstac\n", "\n", "Authors: Henry Rodman (Development Seed)\n", "\n", "Date: September 5, 2024\n", "\n", "Description: In this notebook, we visualize Cloud-Optimized GeoTIFFs (COGs) from the icesat2-boreal collection in MAAP's STAC using the `/collections` and `/searches` endpoints in [titiler-pgstac.maap-project.org](https://titiler-pgstac.maap-project.org)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Run This Notebook\n", "To access and run this tutorial within MAAP's Algorithm Development Environment (ADE), please refer to the [\"Getting started with the MAAP\"](https://docs.maap-project.org/en/latest/getting_started/getting_started.html) section of our documentation.\n", "\n", "Disclaimer: it is highly recommended to run a tutorial within MAAP's ADE, which already includes the required software dependencies. Running the tutorial outside of the MAAP ADE may lead to errors. The `pangeo` workspace in the MAAP ADE is already configured with all of the dependencies and access credentials." ] }, { "cell_type": "markdown", "metadata": { "jp-MarkdownHeadingCollapsed": true }, "source": [ "## Note About the Data\n", "\n", "From the collection description:\n", "> Aboveground biomass density c.2020 gridded to 30m derived from ICESat-2, Harmonized Landsat-Sentinel2 and Copernicus DEM. Band 1 is the data band. Band 2 is the standard deviation.\n", "\n", "These COGs are indexed in the [MAAP STAC](https://stac.maap-project.org/collections/SRTMGL1_COD/items)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Additional Resources\n", "- [MAAP titiler-pgstac API Documentation](https://titiler-pgstac.maap-project.org/api.html)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Importing and Installing Packages\n", "\n", "To be able to run this notebook you'll need the following requirements:\n", "\n", "- folium\n", "- httpx" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If the packages below are not installed already, uncomment the following cell:" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "tags": [] }, "outputs": [], "source": [ "# %pip install folium\n", "# %pip install httpx" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "tags": [] }, "outputs": [], "source": [ "import httpx\n", "from folium import GeoJson, LayerControl, Map, TileLayer\n", "from pprint import pprint\n", "from pystac_client import Client\n", "from shapely.geometry import box, mapping" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This demo uses the [MAAP titiler-pgstac deployment](https://titiler-pgstac.maap-project.org) to render tiles for a collection (`icesat2-boreal`) that is indexed in the [MAAP STAC](https://stac.maap-project.org). We will make use of some pre-defined `render` parameters stored in the [`render` extension](https://github.com/stac-extensions/render) metadata for the collection when we generate visualizations." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "tags": [] }, "outputs": [], "source": [ "TITILER_PGSTAC_ENDPOINT = \"https://titiler-pgstac.maap-project.org\" # MAAP titiler-pgstac endpoint\n", "COLLECTION_ID = \"icesat2-boreal\"\n", "RENDERING = \"agb\" # render parameters for aboveground biomass" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "{'links': [{'href': 'https://titiler-pgstac.maap-project.org/collections/icesat2-boreal/info',\n", " 'rel': 'self',\n", " 'title': 'Mosaic metadata'},\n", " {'href': 'https://titiler-pgstac.maap-project.org/collections/icesat2-boreal/{tileMatrixSetId}/tilejson.json',\n", " 'rel': 'tilejson',\n", " 'templated': True,\n", " 'title': 'TileJSON link (Template URL).'},\n", " {'href': 'https://titiler-pgstac.maap-project.org/collections/icesat2-boreal/{tileMatrixSetId}/tilejson.json?bidx=1&nodata=nan&colormap_name=gist_earth_r&rescale=0%2C400&assets=tif',\n", " 'rel': 'tilejson',\n", " 'templated': True,\n", " 'title': 'TileJSON link for `agb` layer (Template URL).'},\n", " {'href': 'https://titiler-pgstac.maap-project.org/collections/icesat2-boreal/{tileMatrixSetId}/map',\n", " 'rel': 'map',\n", " 'templated': True,\n", " 'title': 'Map viewer link (Template URL).'},\n", " {'href': 'https://titiler-pgstac.maap-project.org/collections/icesat2-boreal/{tileMatrixSetId}/map?bidx=1&nodata=nan&colormap_name=gist_earth_r&rescale=0%2C400&assets=tif',\n", " 'rel': 'map',\n", " 'templated': True,\n", " 'title': 'Map viewer link for `agb` layer (Template URL).'},\n", " {'href': 'https://titiler-pgstac.maap-project.org/collections/icesat2-boreal/{tileMatrixSetId}/WMTSCapabilities.xml',\n", " 'rel': 'wmts',\n", " 'templated': True,\n", " 'title': 'WMTS link (Template URL)'}],\n", " 'search': {'_where': \"collection = ANY ('{icesat2-boreal}') \",\n", " 'hash': '2b1c56237655c787dc5598c8592f5010',\n", " 'lastused': '2024-09-06T20:29:27.945205Z',\n", " 'metadata': {'assets': ['csv', 'tif'],\n", " 'bounds': [-180.0, 51.6, 180.0, 78.0],\n", " 'defaults': {'agb': {'assets': ['tif'],\n", " 'bidx': [1],\n", " 'colormap_name': 'gist_earth_r',\n", " 'nodata': 'nan',\n", " 'rescale': [[0, 400]]}},\n", " 'name': \"Mosaic for 'icesat2-boreal' Collection\",\n", " 'type': 'mosaic'},\n", " 'orderby': 'datetime DESC, id DESC',\n", " 'search': {'collections': ['icesat2-boreal']},\n", " 'usecount': 462}}\n" ] } ], "source": [ "# get some information about the collection including render parameters and spatial extent\n", "collection_info = httpx.get(\n", " f\"{TITILER_PGSTAC_ENDPOINT}/collections/{COLLECTION_ID}/info\",\n", " timeout=10,\n", ").json()\n", "pprint(collection_info)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "