From 90e9bb69daef9f8e5785e73ac9f8ea1f80ae7302 Mon Sep 17 00:00:00 2001 From: hrodmn Date: Fri, 6 Feb 2026 06:20:00 -0600 Subject: [PATCH] add web-map-links tilejson links where possible --- add-web-maap-links.ipynb | 410 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 410 insertions(+) create mode 100644 add-web-maap-links.ipynb diff --git a/add-web-maap-links.ipynb b/add-web-maap-links.ipynb new file mode 100644 index 0000000..319b327 --- /dev/null +++ b/add-web-maap-links.ipynb @@ -0,0 +1,410 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "56baf009", + "metadata": {}, + "outputs": [], + "source": [ + "# /// script\n", + "# requires-python = \">=3.13\"\n", + "# dependencies = [\n", + "# \"boto3\",\n", + "# \"httpx\",\n", + "# \"pystac\",\n", + "# \"pystac-client\",\n", + "# \"smart-open\",\n", + "# \"stac-pydantic\",\n", + "# ]\n", + "# ///" + ] + }, + { + "cell_type": "markdown", + "id": "1c6de0c1-51e4-4365-ab91-ce05b901773c", + "metadata": {}, + "source": [ + "# Add web-map-links metadata to all relevant collections in the MAAP STAC\n", + "\n", + "**Author:** Henry Rodman\n", + "\n", + "**Date:** 2026-02-05\n", + "\n", + "The [web-map-links STAC extension](https://github.com/stac-extensions/web-map-links?tab=readme-ov-file) defines several link rel types that indicate to client applications that they represent links to web map services. These links are automatically used by applications like STAC Browser and the Federated Collection Discovery app.\n", + "\n", + "The plan is to add a render config and corresponding tilejson link to each collection that has image assets in a cloud-optimized format." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "19c67556", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "/home/henry/.cache/uv/environments-v2/juv-tmp-6m270dg6-592b1e6b49663e54/lib/python3.13/site-packages/pystac/collection.py:716: DeprecatedWarning: The collection 'icesat2-boreal' is deprecated.\n", + " warnings.warn(\n", + "/home/henry/.cache/uv/environments-v2/juv-tmp-6m270dg6-592b1e6b49663e54/lib/python3.13/site-packages/pystac/collection.py:716: DeprecatedWarning: The collection 'icesat2-boreal-v2.1-agb' is deprecated.\n", + " warnings.warn(\n", + "/home/henry/.cache/uv/environments-v2/juv-tmp-6m270dg6-592b1e6b49663e54/lib/python3.13/site-packages/pystac/collection.py:716: DeprecatedWarning: The collection 'icesat2-boreal-v2.1-ht' is deprecated.\n", + " warnings.warn(\n", + "/home/henry/.cache/uv/environments-v2/juv-tmp-6m270dg6-592b1e6b49663e54/lib/python3.13/site-packages/pystac/collection.py:716: DeprecatedWarning: The collection 'icesat2-boreal-v3.0-agb' is deprecated.\n", + " warnings.warn(\n", + "/home/henry/.cache/uv/environments-v2/juv-tmp-6m270dg6-592b1e6b49663e54/lib/python3.13/site-packages/pystac/collection.py:716: DeprecatedWarning: The collection 'icesat2-boreal-v3.0-ht' is deprecated.\n", + " warnings.warn(\n" + ] + } + ], + "source": [ + "import json\n", + "import os\n", + "import urllib.parse\n", + "\n", + "import boto3\n", + "import httpx\n", + "from pystac import Link\n", + "from pystac.extensions.render import Render, RenderExtension\n", + "from pystac_client import Client\n", + "\n", + "stage = os.getenv(\"STAGE\", \"test\")\n", + "\n", + "if stage == \"prod\":\n", + " STAC_LOADER_SNS_TOPIC_ARN = \"arn:aws:sns:us-west-2:916098889494:MAAP-STAC-dev-pgSTAC-stacitemloaderTopicD9D06088-m0iaNFNtnXUP\"\n", + "else:\n", + " STAC_LOADER_SNS_TOPIC_ARN = \"arn:aws:sns:us-west-2:916098889494:MAAP-STAC-test-pgSTAC-stacitemloaderTopicD9D06088-LutBraKgk6sT\"\n", + "\n", + "STAC_API_URL = \"https://stac.maap-project.org\"\n", + "TITILER_API_URL = \"https://titiler-pgstac.maap-project.org\"\n", + "\n", + "WEB_MAP_LINKS_SCHEMA_URL = (\n", + " \"https://stac-extensions.github.io/web-map-links/v1.2.0/schema.json\"\n", + ")\n", + "\n", + "client = Client.open(STAC_API_URL)\n", + "\n", + "# fetch all collections from the published catalog\n", + "collections = list(client.get_all_collections())" + ] + }, + { + "cell_type": "markdown", + "id": "fb642abb-d3a5-45c9-9590-4c53ee561a94", + "metadata": {}, + "source": [ + "Check to see what renders/tilejson/web-map-links metadata already exists:" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "d246c117-ab21-4583-a77b-7c90b10a2b59", + "metadata": {}, + "outputs": [], + "source": [ + "viz_status = {}\n", + "for collection in collections:\n", + " has_web_map_links = any(\n", + " \"web-map-links\" in ext for ext in collection.stac_extensions\n", + " )\n", + " has_tilejson = any(link.rel == \"tilejson\" for link in collection.links)\n", + " has_render = collection.ext.has(\"render\")\n", + " viz_status[collection] = {\n", + " \"renders\": list(collection.ext.render.keys()) if has_render else None,\n", + " \"tilejson\": has_tilejson,\n", + " \"web-map-links\": (\n", + " [link for link in collection.links if link.rel in [\"xyz\", \"tilejson\"]]\n", + " if has_web_map_links\n", + " else None\n", + " ),\n", + " }" + ] + }, + { + "cell_type": "markdown", + "id": "19c912fc-c8ad-4fdd-9729-0cec8ba7e3ea", + "metadata": {}, + "source": [ + "Some collections already have web-map-links (just icesat2-boreal-v3.0+)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "b3c2a3e2-9b10-4f7c-9854-6803a14f075d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "icesat2-boreal-v3.0-agb []\n", + "icesat2-boreal-v3.0-ht []\n", + "icesat2-boreal-v3.1-agb []\n", + "icesat2-boreal-v3.1-ht []\n" + ] + } + ], + "source": [ + "for collection, status in viz_status.items():\n", + " if links := status.get(\"web-map-links\"):\n", + " print(collection.id, links)" + ] + }, + { + "cell_type": "markdown", + "id": "3512cff4-ae79-4023-ba85-332796639ce7", + "metadata": {}, + "source": [ + "Collections that have a render config but no web-map-links will be easy! We can get the tilejson links from the titiler API automagically, we just need to pick one of the render configs to use." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "fdacae0b-1ac0-4776-b17e-e4cd2e566e6a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "glad-glclu2020-change-v2 ['2000-2020 change']\n", + "glad-glclu2020-v2 ['2000', '2005', '2010', '2015', '2020']\n", + "glad-global-forest-change-1.11 ['gain', 'lossyear', 'treecover2000']\n", + "global-mangrove-watch-3.0 ['change', 'mangroves']\n", + "icesat2-boreal ['agb']\n", + "icesat2-boreal-v2.1-agb ['agb_viridis', 'agb_gist_earth_r']\n", + "icesat2-boreal-v2.1-ht ['ht_inferno']\n" + ] + } + ], + "source": [ + "for collection, status in viz_status.items():\n", + " if status[\"renders\"] and not status[\"web-map-links\"]:\n", + " print(collection.id, status[\"renders\"])" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "cc93f38d-11ef-4bcb-b04a-401be7fe0b25", + "metadata": {}, + "outputs": [], + "source": [ + "render_choices = {\n", + " \"glad-glclu2020-change-v2\": \"2000-2020 change\",\n", + " \"glad-glclu2020-v2\": \"2020\",\n", + " \"glad-global-forest-change-1.11\": \"lossyear\",\n", + " \"global-mangrove-watch-3.0\": \"mangroves\",\n", + " \"icesat2-boreal\": \"agb\",\n", + " \"icesat2-boreal-v2.1-agb\": \"agb_viridis\",\n", + " \"icesat2-boreal-v2.1-ht\": \"ht_inferno\",\n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "0213fbc4-860c-4e69-856c-99568ee3be29", + "metadata": {}, + "source": [ + "These are collections that would benefit from new collection-level render configs (and web-map-links) so we can define the visualization parameters" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "368ddb71-9738-430f-bb23-571582a2d9c3", + "metadata": {}, + "outputs": [], + "source": [ + "new_render_params = {\n", + " \"ESACCI_Biomass_L4_AGB_V4_100m\": (\n", + " \"biomass\",\n", + " {\n", + " \"title\": \"biomass\",\n", + " \"assets\": [\"estimates\"],\n", + " \"rescale\": [[0, 400]],\n", + " \"colormap_name\": \"gist_earth_r\",\n", + " \"color_formula\": \"gamma r 1.05\",\n", + " },\n", + " ),\n", + " \"SRTMGL1_COD\": (\n", + " \"hillshade\",\n", + " {\n", + " \"title\": \"hillshade\",\n", + " \"assets\": [\"cog_default\"],\n", + " \"algorithm\": \"hillshade\",\n", + " \"buffer\": 3,\n", + " \"z_exaggeration\": 1e-06,\n", + " \"angle_altitude\": 70,\n", + " },\n", + " ),\n", + " \"NCEO_Africa_AGB_100m_2017\": (\n", + " \"biomass\",\n", + " {\n", + " \"title\": \"biomass\",\n", + " \"assets\": [\"biomass\"],\n", + " \"rescale\": [[0, 400]],\n", + " \"colormap_name\": \"gist_earth_r\",\n", + " \"color_formula\": \"gamma r 1.05\",\n", + " },\n", + " ),\n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "18d7f16e-1464-4511-9969-1d83a88600ba", + "metadata": {}, + "source": [ + "Apply the new render configs and add the tilejson links to each affected collection." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "4e0e99f0-54a5-474a-877f-590adf67ffd0", + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ESACCI_Biomass_L4_AGB_V4_100m {'rel': 'tilejson', 'href': 'https://titiler-pgstac.maap-project.org/collections/ESACCI_Biomass_L4_AGB_V4_100m/WebMercatorQuad/tilejson.json?title=biomass&assets=estimates&rescale=%5B0%2C+400%5D&colormap_name=gist_earth_r&color_formula=gamma+r+1.05', 'title': 'TileJSON link for biomass visualization', 'render': 'biomass'}\n", + "glad-glclu2020-change-v2 {'rel': 'tilejson', 'href': 'https://titiler-pgstac.maap-project.org/collections/glad-glclu2020-change-v2/WebMercatorQuad/tilejson.json?datetime=2000-01-01T00%3A00%3A00Z%2F2020-12-31T23%3A59%3A59Z&colormap=%7B%220%22%3A+%5B254%2C+254%2C+204%5D%2C+%221%22%3A+%5B250%2C+250%2C+195%5D%2C+%222%22%3A+%5B247%2C+247%2C+187%5D%2C+%223%22%3A+%5B244%2C+244%2C+179%5D%2C+%224%22%3A+%5B241%2C+241%2C+171%5D%2C+%225%22%3A+%5B237%2C+237%2C+162%5D%2C+%226%22%3A+%5B234%2C+234%2C+154%5D%2C+%227%22%3A+%5B231%2C+231%2C+146%5D%2C+%228%22%3A+%5B228%2C+228%2C+138%5D%2C+%229%22%3A+%5B224%2C+224%2C+129%5D%2C+%2210%22%3A+%5B221%2C+221%2C+121%5D%2C+%2211%22%3A+%5B218%2C+218%2C+113%5D%2C+%2212%22%3A+%5B215%2C+215%2C+105%5D%2C+%2213%22%3A+%5B211%2C+211%2C+96%5D%2C+%2214%22%3A+%5B208%2C+208%2C+88%5D%2C+%2215%22%3A+%5B205%2C+205%2C+80%5D%2C+%2216%22%3A+%5B202%2C+202%2C+72%5D%2C+%2217%22%3A+%5B198%2C+198%2C+63%5D%2C+%2218%22%3A+%5B195%2C+195%2C+55%5D%2C+%2219%22%3A+%5B192%2C+192%2C+47%5D%2C+%2220%22%3A+%5B189%2C+189%2C+39%5D%2C+%2221%22%3A+%5B185%2C+185%2C+30%5D%2C+%2222%22%3A+%5B182%2C+182%2C+22%5D%2C+%2223%22%3A+%5B179%2C+179%2C+14%5D%2C+%2224%22%3A+%5B176%2C+176%2C+6%5D%2C+%2225%22%3A+%5B96%2C+156%2C+96%5D%2C+%2226%22%3A+%5B92%2C+152%2C+92%5D%2C+%2227%22%3A+%5B88%2C+149%2C+88%5D%2C+%2228%22%3A+%5B84%2C+146%2C+84%5D%2C+%2229%22%3A+%5B80%2C+142%2C+80%5D%2C+%2230%22%3A+%5B76%2C+139%2C+76%5D%2C+%2231%22%3A+%5B72%2C+136%2C+72%5D%2C+%2232%22%3A+%5B68%2C+133%2C+68%5D%2C+%2233%22%3A+%5B64%2C+129%2C+64%5D%2C+%2234%22%3A+%5B60%2C+126%2C+60%5D%2C+%2235%22%3A+%5B56%2C+123%2C+56%5D%2C+%2236%22%3A+%5B52%2C+120%2C+52%5D%2C+%2237%22%3A+%5B49%2C+116%2C+49%5D%2C+%2238%22%3A+%5B45%2C+113%2C+45%5D%2C+%2239%22%3A+%5B41%2C+110%2C+41%5D%2C+%2240%22%3A+%5B37%2C+107%2C+37%5D%2C+%2241%22%3A+%5B33%2C+103%2C+33%5D%2C+%2242%22%3A+%5B29%2C+100%2C+29%5D%2C+%2243%22%3A+%5B25%2C+97%2C+25%5D%2C+%2244%22%3A+%5B21%2C+94%2C+21%5D%2C+%2245%22%3A+%5B17%2C+90%2C+17%5D%2C+%2246%22%3A+%5B13%2C+87%2C+13%5D%2C+%2247%22%3A+%5B9%2C+84%2C+9%5D%2C+%2248%22%3A+%5B6%2C+81%2C+6%5D%2C+%2249%22%3A+%5B100%2C+55%2C+0%5D%2C+%2250%22%3A+%5B100%2C+58%2C+0%5D%2C+%2251%22%3A+%5B100%2C+61%2C+0%5D%2C+%2252%22%3A+%5B100%2C+64%2C+0%5D%2C+%2253%22%3A+%5B100%2C+67%2C+0%5D%2C+%2254%22%3A+%5B100%2C+70%2C+0%5D%2C+%2255%22%3A+%5B100%2C+73%2C+0%5D%2C+%2256%22%3A+%5B101%2C+76%2C+0%5D%2C+%2257%22%3A+%5B101%2C+79%2C+0%5D%2C+%2258%22%3A+%5B101%2C+82%2C+0%5D%2C+%2259%22%3A+%5B101%2C+85%2C+0%5D%2C+%2260%22%3A+%5B101%2C+88%2C+0%5D%2C+%2261%22%3A+%5B101%2C+90%2C+0%5D%2C+%2262%22%3A+%5B101%2C+93%2C+0%5D%2C+%2263%22%3A+%5B101%2C+96%2C+0%5D%2C+%2264%22%3A+%5B101%2C+99%2C+0%5D%2C+%2265%22%3A+%5B102%2C+102%2C+0%5D%2C+%2266%22%3A+%5B102%2C+105%2C+0%5D%2C+%2267%22%3A+%5B102%2C+108%2C+0%5D%2C+%2268%22%3A+%5B102%2C+111%2C+0%5D%2C+%2269%22%3A+%5B102%2C+114%2C+0%5D%2C+%2270%22%3A+%5B102%2C+117%2C+0%5D%2C+%2271%22%3A+%5B102%2C+120%2C+0%5D%2C+%2272%22%3A+%5B102%2C+123%2C+0%5D%2C+%2273%22%3A+%5B255%2C+153%2C+255%5D%2C+%2274%22%3A+%5B252%2C+146%2C+252%5D%2C+%2275%22%3A+%5B249%2C+139%2C+249%5D%2C+%2276%22%3A+%5B246%2C+133%2C+246%5D%2C+%2277%22%3A+%5B243%2C+126%2C+243%5D%2C+%2278%22%3A+%5B240%2C+119%2C+240%5D%2C+%2279%22%3A+%5B237%2C+113%2C+237%5D%2C+%2280%22%3A+%5B234%2C+106%2C+234%5D%2C+%2281%22%3A+%5B231%2C+99%2C+231%5D%2C+%2282%22%3A+%5B228%2C+93%2C+228%5D%2C+%2283%22%3A+%5B225%2C+86%2C+225%5D%2C+%2284%22%3A+%5B222%2C+79%2C+222%5D%2C+%2285%22%3A+%5B219%2C+73%2C+219%5D%2C+%2286%22%3A+%5B216%2C+66%2C+216%5D%2C+%2287%22%3A+%5B213%2C+59%2C+213%5D%2C+%2288%22%3A+%5B210%2C+53%2C+210%5D%2C+%2289%22%3A+%5B207%2C+46%2C+207%5D%2C+%2290%22%3A+%5B204%2C+39%2C+204%5D%2C+%2291%22%3A+%5B201%2C+33%2C+201%5D%2C+%2292%22%3A+%5B198%2C+26%2C+198%5D%2C+%2293%22%3A+%5B195%2C+19%2C+195%5D%2C+%2294%22%3A+%5B192%2C+13%2C+192%5D%2C+%2295%22%3A+%5B189%2C+6%2C+189%5D%2C+%2296%22%3A+%5B187%2C+0%2C+187%5D%2C+%22100%22%3A+%5B191%2C+192%2C+192%5D%2C+%22101%22%3A+%5B183%2C+189%2C+194%5D%2C+%22102%22%3A+%5B175%2C+187%2C+196%5D%2C+%22103%22%3A+%5B168%2C+184%2C+198%5D%2C+%22104%22%3A+%5B160%2C+182%2C+201%5D%2C+%22105%22%3A+%5B153%2C+179%2C+203%5D%2C+%22106%22%3A+%5B145%2C+177%2C+205%5D%2C+%22107%22%3A+%5B137%2C+175%2C+208%5D%2C+%22108%22%3A+%5B130%2C+172%2C+210%5D%2C+%22109%22%3A+%5B122%2C+170%2C+212%5D%2C+%22110%22%3A+%5B115%2C+167%2C+214%5D%2C+%22111%22%3A+%5B107%2C+165%2C+217%5D%2C+%22112%22%3A+%5B100%2C+163%2C+219%5D%2C+%22113%22%3A+%5B92%2C+160%2C+221%5D%2C+%22114%22%3A+%5B84%2C+158%2C+224%5D%2C+%22115%22%3A+%5B77%2C+155%2C+226%5D%2C+%22116%22%3A+%5B69%2C+153%2C+228%5D%2C+%22117%22%3A+%5B62%2C+150%2C+230%5D%2C+%22118%22%3A+%5B54%2C+148%2C+233%5D%2C+%22119%22%3A+%5B46%2C+146%2C+235%5D%2C+%22120%22%3A+%5B39%2C+143%2C+237%5D%2C+%22121%22%3A+%5B31%2C+141%2C+240%5D%2C+%22122%22%3A+%5B24%2C+138%2C+242%5D%2C+%22123%22%3A+%5B16%2C+136%2C+244%5D%2C+%22124%22%3A+%5B9%2C+134%2C+247%5D%2C+%22125%22%3A+%5B85%2C+165%2C+165%5D%2C+%22126%22%3A+%5B83%2C+161%2C+162%5D%2C+%22127%22%3A+%5B81%2C+158%2C+159%5D%2C+%22128%22%3A+%5B79%2C+155%2C+156%5D%2C+%22129%22%3A+%5B77%2C+152%2C+154%5D%2C+%22130%22%3A+%5B75%2C+149%2C+151%5D%2C+%22131%22%3A+%5B73%2C+146%2C+148%5D%2C+%22132%22%3A+%5B71%2C+143%2C+145%5D%2C+%22133%22%3A+%5B69%2C+139%2C+143%5D%2C+%22134%22%3A+%5B67%2C+136%2C+140%5D%2C+%22135%22%3A+%5B65%2C+133%2C+137%5D%2C+%22136%22%3A+%5B63%2C+130%2C+134%5D%2C+%22137%22%3A+%5B61%2C+127%2C+132%5D%2C+%22138%22%3A+%5B59%2C+124%2C+129%5D%2C+%22139%22%3A+%5B57%2C+121%2C+126%5D%2C+%22140%22%3A+%5B55%2C+118%2C+123%5D%2C+%22141%22%3A+%5B53%2C+114%2C+121%5D%2C+%22142%22%3A+%5B51%2C+111%2C+118%5D%2C+%22143%22%3A+%5B49%2C+108%2C+115%5D%2C+%22144%22%3A+%5B47%2C+105%2C+112%5D%2C+%22145%22%3A+%5B45%2C+102%2C+110%5D%2C+%22146%22%3A+%5B43%2C+99%2C+107%5D%2C+%22147%22%3A+%5B41%2C+96%2C+104%5D%2C+%22148%22%3A+%5B40%2C+93%2C+102%5D%2C+%22149%22%3A+%5B187%2C+147%2C+176%5D%2C+%22150%22%3A+%5B183%2C+143%2C+172%5D%2C+%22151%22%3A+%5B180%2C+140%2C+169%5D%2C+%22152%22%3A+%5B177%2C+137%2C+166%5D%2C+%22153%22%3A+%5B174%2C+133%2C+162%5D%2C+%22154%22%3A+%5B170%2C+130%2C+159%5D%2C+%22155%22%3A+%5B167%2C+127%2C+156%5D%2C+%22156%22%3A+%5B164%2C+123%2C+153%5D%2C+%22157%22%3A+%5B161%2C+120%2C+149%5D%2C+%22158%22%3A+%5B158%2C+117%2C+146%5D%2C+%22159%22%3A+%5B154%2C+113%2C+143%5D%2C+%22160%22%3A+%5B151%2C+110%2C+140%5D%2C+%22161%22%3A+%5B148%2C+107%2C+136%5D%2C+%22162%22%3A+%5B145%2C+104%2C+133%5D%2C+%22163%22%3A+%5B141%2C+100%2C+130%5D%2C+%22164%22%3A+%5B138%2C+97%2C+127%5D%2C+%22165%22%3A+%5B135%2C+94%2C+123%5D%2C+%22166%22%3A+%5B132%2C+90%2C+120%5D%2C+%22167%22%3A+%5B129%2C+87%2C+117%5D%2C+%22168%22%3A+%5B125%2C+84%2C+114%5D%2C+%22169%22%3A+%5B122%2C+80%2C+110%5D%2C+%22170%22%3A+%5B119%2C+77%2C+107%5D%2C+%22171%22%3A+%5B116%2C+74%2C+104%5D%2C+%22172%22%3A+%5B113%2C+71%2C+101%5D%2C+%22173%22%3A+%5B222%2C+124%2C+187%5D%2C+%22174%22%3A+%5B218%2C+119%2C+183%5D%2C+%22175%22%3A+%5B215%2C+114%2C+179%5D%2C+%22176%22%3A+%5B212%2C+110%2C+175%5D%2C+%22177%22%3A+%5B209%2C+105%2C+171%5D%2C+%22178%22%3A+%5B206%2C+100%2C+168%5D%2C+%22179%22%3A+%5B203%2C+96%2C+164%5D%2C+%22180%22%3A+%5B200%2C+91%2C+160%5D%2C+%22181%22%3A+%5B196%2C+87%2C+156%5D%2C+%22182%22%3A+%5B193%2C+82%2C+152%5D%2C+%22183%22%3A+%5B190%2C+77%2C+149%5D%2C+%22184%22%3A+%5B187%2C+73%2C+145%5D%2C+%22185%22%3A+%5B184%2C+68%2C+141%5D%2C+%22186%22%3A+%5B181%2C+64%2C+137%5D%2C+%22187%22%3A+%5B178%2C+59%2C+134%5D%2C+%22188%22%3A+%5B175%2C+54%2C+130%5D%2C+%22189%22%3A+%5B171%2C+50%2C+126%5D%2C+%22190%22%3A+%5B168%2C+45%2C+122%5D%2C+%22191%22%3A+%5B165%2C+41%2C+118%5D%2C+%22192%22%3A+%5B162%2C+36%2C+115%5D%2C+%22193%22%3A+%5B159%2C+31%2C+111%5D%2C+%22194%22%3A+%5B156%2C+27%2C+107%5D%2C+%22195%22%3A+%5B153%2C+22%2C+103%5D%2C+%22196%22%3A+%5B150%2C+18%2C+100%5D%2C+%22208%22%3A+%5B0%2C+0%2C+186%5D%2C+%22209%22%3A+%5B4%2C+4%2C+100%5D%2C+%22210%22%3A+%5B0%2C+0%2C+255%5D%2C+%22211%22%3A+%5B48%2C+81%2C+207%5D%2C+%22240%22%3A+%5B255%2C+40%2C+40%5D%2C+%22241%22%3A+%5B255%2C+255%2C+255%5D%2C+%22242%22%3A+%5B208%2C+255%2C+255%5D%2C+%22243%22%3A+%5B255%2C+224%2C+208%5D%2C+%22244%22%3A+%5B255%2C+125%2C+0%5D%2C+%22245%22%3A+%5B250%2C+200%2C+0%5D%2C+%22246%22%3A+%5B200%2C+100%2C+0%5D%2C+%22247%22%3A+%5B255%2C+240%2C+0%5D%2C+%22248%22%3A+%5B175%2C+205%2C+150%5D%2C+%22249%22%3A+%5B175%2C+205%2C+150%5D%2C+%22250%22%3A+%5B100%2C+220%2C+220%5D%2C+%22251%22%3A+%5B0%2C+255%2C+255%5D%2C+%22252%22%3A+%5B0%2C+255%2C+255%5D%2C+%22253%22%3A+%5B0%2C+255%2C+255%5D%2C+%22254%22%3A+%5B17%2C+17%2C+51%5D%7D&assets=data', 'title': 'TileJSON link for 2000-2020 change visualization'}\n", + "glad-glclu2020-v2 {'rel': 'tilejson', 'href': 'https://titiler-pgstac.maap-project.org/collections/glad-glclu2020-v2/WebMercatorQuad/tilejson.json?datetime=2020-01-01T00%3A00%3A00Z%2F2020-12-31T23%3A59%3A59Z&colormap=%7B%220%22%3A+%5B254%2C+254%2C+204%5D%2C+%221%22%3A+%5B250%2C+250%2C+195%5D%2C+%222%22%3A+%5B247%2C+247%2C+187%5D%2C+%223%22%3A+%5B244%2C+244%2C+179%5D%2C+%224%22%3A+%5B241%2C+241%2C+171%5D%2C+%225%22%3A+%5B237%2C+237%2C+162%5D%2C+%226%22%3A+%5B234%2C+234%2C+154%5D%2C+%227%22%3A+%5B231%2C+231%2C+146%5D%2C+%228%22%3A+%5B228%2C+228%2C+138%5D%2C+%229%22%3A+%5B224%2C+224%2C+129%5D%2C+%2210%22%3A+%5B221%2C+221%2C+121%5D%2C+%2211%22%3A+%5B218%2C+218%2C+113%5D%2C+%2212%22%3A+%5B215%2C+215%2C+105%5D%2C+%2213%22%3A+%5B211%2C+211%2C+96%5D%2C+%2214%22%3A+%5B208%2C+208%2C+88%5D%2C+%2215%22%3A+%5B205%2C+205%2C+80%5D%2C+%2216%22%3A+%5B202%2C+202%2C+72%5D%2C+%2217%22%3A+%5B198%2C+198%2C+63%5D%2C+%2218%22%3A+%5B195%2C+195%2C+55%5D%2C+%2219%22%3A+%5B192%2C+192%2C+47%5D%2C+%2220%22%3A+%5B189%2C+189%2C+39%5D%2C+%2221%22%3A+%5B185%2C+185%2C+30%5D%2C+%2222%22%3A+%5B182%2C+182%2C+22%5D%2C+%2223%22%3A+%5B179%2C+179%2C+14%5D%2C+%2224%22%3A+%5B176%2C+176%2C+6%5D%2C+%2225%22%3A+%5B96%2C+156%2C+96%5D%2C+%2226%22%3A+%5B92%2C+152%2C+92%5D%2C+%2227%22%3A+%5B88%2C+149%2C+88%5D%2C+%2228%22%3A+%5B84%2C+146%2C+84%5D%2C+%2229%22%3A+%5B80%2C+142%2C+80%5D%2C+%2230%22%3A+%5B76%2C+139%2C+76%5D%2C+%2231%22%3A+%5B72%2C+136%2C+72%5D%2C+%2232%22%3A+%5B68%2C+133%2C+68%5D%2C+%2233%22%3A+%5B64%2C+129%2C+64%5D%2C+%2234%22%3A+%5B60%2C+126%2C+60%5D%2C+%2235%22%3A+%5B56%2C+123%2C+56%5D%2C+%2236%22%3A+%5B52%2C+120%2C+52%5D%2C+%2237%22%3A+%5B49%2C+116%2C+49%5D%2C+%2238%22%3A+%5B45%2C+113%2C+45%5D%2C+%2239%22%3A+%5B41%2C+110%2C+41%5D%2C+%2240%22%3A+%5B37%2C+107%2C+37%5D%2C+%2241%22%3A+%5B33%2C+103%2C+33%5D%2C+%2242%22%3A+%5B29%2C+100%2C+29%5D%2C+%2243%22%3A+%5B25%2C+97%2C+25%5D%2C+%2244%22%3A+%5B21%2C+94%2C+21%5D%2C+%2245%22%3A+%5B17%2C+90%2C+17%5D%2C+%2246%22%3A+%5B13%2C+87%2C+13%5D%2C+%2247%22%3A+%5B9%2C+84%2C+9%5D%2C+%2248%22%3A+%5B6%2C+81%2C+6%5D%2C+%22100%22%3A+%5B191%2C+192%2C+192%5D%2C+%22101%22%3A+%5B183%2C+189%2C+194%5D%2C+%22102%22%3A+%5B175%2C+187%2C+196%5D%2C+%22103%22%3A+%5B168%2C+184%2C+198%5D%2C+%22104%22%3A+%5B160%2C+182%2C+201%5D%2C+%22105%22%3A+%5B153%2C+179%2C+203%5D%2C+%22106%22%3A+%5B145%2C+177%2C+205%5D%2C+%22107%22%3A+%5B137%2C+175%2C+208%5D%2C+%22108%22%3A+%5B130%2C+172%2C+210%5D%2C+%22109%22%3A+%5B122%2C+170%2C+212%5D%2C+%22110%22%3A+%5B115%2C+167%2C+214%5D%2C+%22111%22%3A+%5B107%2C+165%2C+217%5D%2C+%22112%22%3A+%5B100%2C+163%2C+219%5D%2C+%22113%22%3A+%5B92%2C+160%2C+221%5D%2C+%22114%22%3A+%5B84%2C+158%2C+224%5D%2C+%22115%22%3A+%5B77%2C+155%2C+226%5D%2C+%22116%22%3A+%5B69%2C+153%2C+228%5D%2C+%22117%22%3A+%5B62%2C+150%2C+230%5D%2C+%22118%22%3A+%5B54%2C+148%2C+233%5D%2C+%22119%22%3A+%5B46%2C+146%2C+235%5D%2C+%22120%22%3A+%5B39%2C+143%2C+237%5D%2C+%22121%22%3A+%5B31%2C+141%2C+240%5D%2C+%22122%22%3A+%5B24%2C+138%2C+242%5D%2C+%22123%22%3A+%5B16%2C+136%2C+244%5D%2C+%22124%22%3A+%5B9%2C+134%2C+247%5D%2C+%22125%22%3A+%5B85%2C+165%2C+165%5D%2C+%22126%22%3A+%5B83%2C+161%2C+162%5D%2C+%22127%22%3A+%5B81%2C+158%2C+159%5D%2C+%22128%22%3A+%5B79%2C+155%2C+156%5D%2C+%22129%22%3A+%5B77%2C+152%2C+154%5D%2C+%22130%22%3A+%5B75%2C+149%2C+151%5D%2C+%22131%22%3A+%5B73%2C+146%2C+148%5D%2C+%22132%22%3A+%5B71%2C+143%2C+145%5D%2C+%22133%22%3A+%5B69%2C+139%2C+143%5D%2C+%22134%22%3A+%5B67%2C+136%2C+140%5D%2C+%22135%22%3A+%5B65%2C+133%2C+137%5D%2C+%22136%22%3A+%5B63%2C+130%2C+134%5D%2C+%22137%22%3A+%5B61%2C+127%2C+132%5D%2C+%22138%22%3A+%5B59%2C+124%2C+129%5D%2C+%22139%22%3A+%5B57%2C+121%2C+126%5D%2C+%22140%22%3A+%5B55%2C+118%2C+123%5D%2C+%22141%22%3A+%5B53%2C+114%2C+121%5D%2C+%22142%22%3A+%5B51%2C+111%2C+118%5D%2C+%22143%22%3A+%5B49%2C+108%2C+115%5D%2C+%22144%22%3A+%5B47%2C+105%2C+112%5D%2C+%22145%22%3A+%5B45%2C+102%2C+110%5D%2C+%22146%22%3A+%5B43%2C+99%2C+107%5D%2C+%22147%22%3A+%5B41%2C+96%2C+104%5D%2C+%22148%22%3A+%5B40%2C+93%2C+102%5D%2C+%22200%22%3A+%5B25%2C+100%2C+235%5D%2C+%22201%22%3A+%5B21%2C+85%2C+228%5D%2C+%22202%22%3A+%5B17%2C+71%2C+221%5D%2C+%22203%22%3A+%5B14%2C+57%2C+214%5D%2C+%22204%22%3A+%5B10%2C+42%2C+207%5D%2C+%22205%22%3A+%5B7%2C+28%2C+200%5D%2C+%22206%22%3A+%5B3%2C+14%2C+193%5D%2C+%22207%22%3A+%5B0%2C+0%2C+186%5D%2C+%22241%22%3A+%5B255%2C+255%2C+255%5D%2C+%22244%22%3A+%5B255%2C+125%2C+0%5D%2C+%22250%22%3A+%5B100%2C+220%2C+220%5D%2C+%22254%22%3A+%5B17%2C+17%2C+51%5D%7D&assets=data', 'title': 'TileJSON link for 2020 visualization'}\n", + "glad-global-forest-change-1.11 {'rel': 'tilejson', 'href': 'https://titiler-pgstac.maap-project.org/collections/glad-global-forest-change-1.11/WebMercatorQuad/tilejson.json?colormap=%7B%220%22%3A+%5B0%2C+0%2C+0%5D%2C+%221%22%3A+%5B255%2C+255%2C+0%5D%2C+%222%22%3A+%5B255%2C+243%2C+0%5D%2C+%223%22%3A+%5B255%2C+230%2C+0%5D%2C+%224%22%3A+%5B255%2C+217%2C+0%5D%2C+%225%22%3A+%5B255%2C+204%2C+0%5D%2C+%226%22%3A+%5B255%2C+192%2C+0%5D%2C+%227%22%3A+%5B255%2C+179%2C+0%5D%2C+%228%22%3A+%5B255%2C+166%2C+0%5D%2C+%229%22%3A+%5B255%2C+153%2C+0%5D%2C+%2210%22%3A+%5B255%2C+140%2C+0%5D%2C+%2211%22%3A+%5B255%2C+128%2C+0%5D%2C+%2212%22%3A+%5B255%2C+116%2C+0%5D%2C+%2213%22%3A+%5B255%2C+105%2C+0%5D%2C+%2214%22%3A+%5B255%2C+93%2C+0%5D%2C+%2215%22%3A+%5B255%2C+81%2C+0%5D%2C+%2216%22%3A+%5B255%2C+70%2C+0%5D%2C+%2217%22%3A+%5B255%2C+58%2C+0%5D%2C+%2218%22%3A+%5B255%2C+46%2C+0%5D%2C+%2219%22%3A+%5B255%2C+35%2C+0%5D%2C+%2220%22%3A+%5B255%2C+23%2C+0%5D%2C+%2221%22%3A+%5B255%2C+12%2C+0%5D%2C+%2222%22%3A+%5B255%2C+0%2C+0%5D%2C+%2223%22%3A+%5B0%2C+255%2C+255%5D%7D&assets=lossyear', 'title': 'TileJSON link for lossyear visualization'}\n", + "global-mangrove-watch-3.0 {'rel': 'tilejson', 'href': 'https://titiler-pgstac.maap-project.org/collections/global-mangrove-watch-3.0/WebMercatorQuad/tilejson.json?colormap=%7B%221%22%3A+%5B0%2C+150%2C+0%5D%7D&assets=cog', 'title': 'TileJSON link for mangroves visualization'}\n", + "icesat2-boreal {'rel': 'tilejson', 'href': 'https://titiler-pgstac.maap-project.org/collections/icesat2-boreal/WebMercatorQuad/tilejson.json?bidx=1&nodata=nan&colormap_name=gist_earth_r&rescale=0%2C400&assets=tif', 'title': 'TileJSON link for agb visualization'}\n", + "icesat2-boreal-v2.1-agb {'rel': 'tilejson', 'href': 'https://titiler-pgstac.maap-project.org/collections/icesat2-boreal-v2.1-agb/WebMercatorQuad/tilejson.json?maxzoom=18&minzoom=6&expression=cog_b1&colormap_name=viridis&rescale=0%2C125&assets=cog', 'title': 'TileJSON link for agb_viridis visualization'}\n", + "icesat2-boreal-v2.1-ht {'rel': 'tilejson', 'href': 'https://titiler-pgstac.maap-project.org/collections/icesat2-boreal-v2.1-ht/WebMercatorQuad/tilejson.json?maxzoom=18&minzoom=6&expression=cog_b1&colormap_name=inferno&rescale=0%2C30&assets=cog', 'title': 'TileJSON link for ht_inferno visualization'}\n", + "NCEO_Africa_AGB_100m_2017 {'rel': 'tilejson', 'href': 'https://titiler-pgstac.maap-project.org/collections/NCEO_Africa_AGB_100m_2017/WebMercatorQuad/tilejson.json?title=biomass&assets=biomass&rescale=%5B0%2C+400%5D&colormap_name=gist_earth_r&color_formula=gamma+r+1.05', 'title': 'TileJSON link for biomass visualization', 'render': 'biomass'}\n", + "SRTMGL1_COD {'rel': 'tilejson', 'href': 'https://titiler-pgstac.maap-project.org/collections/SRTMGL1_COD/WebMercatorQuad/tilejson.json?title=hillshade&assets=cog_default&algorithm=hillshade&buffer=3&z_exaggeration=1e-06&angle_altitude=70', 'title': 'TileJSON link for hillshade visualization', 'render': 'hillshade'}\n" + ] + } + ], + "source": [ + "new_collections = {}\n", + "collections = list(client.get_all_collections())\n", + "\n", + "for collection in collections:\n", + " if render_key := render_choices.get(collection.id):\n", + " titiler_info_url = f\"{TITILER_API_URL}/collections/{collection.id}/info\"\n", + " titiler_info = httpx.get(titiler_info_url).json()\n", + " link = next(\n", + " (\n", + " link\n", + " for link in titiler_info[\"links\"]\n", + " if (render_key in link[\"title\"] and link[\"rel\"] == \"tilejson\")\n", + " ),\n", + " None,\n", + " )\n", + " tilejson_href = link[\"href\"].format(tileMatrixSetId=\"WebMercatorQuad\")\n", + " elif collection.id in new_render_params:\n", + " render_key, render_params = new_render_params.get(collection.id)\n", + " tilejson_href = f\"{TITILER_API_URL}/collections/{collection.id}/WebMercatorQuad/tilejson.json?{urllib.parse.urlencode(render_params, doseq=True)}\"\n", + "\n", + " collection.ext.add(\"render\")\n", + " RenderExtension.ext(collection).apply({render_key: Render(render_params)})\n", + "\n", + " else:\n", + " continue\n", + "\n", + " new_link = Link(\n", + " rel=\"tilejson\",\n", + " target=tilejson_href,\n", + " title=f\"TileJSON link for {render_key} visualization\",\n", + " extra_fields={\"render\": render_key}\n", + " if collection.id in new_render_params\n", + " else None,\n", + " )\n", + "\n", + " print(collection.id, new_link.to_dict())\n", + "\n", + " collection.add_link(new_link)\n", + " collection.stac_extensions.append(WEB_MAP_LINKS_SCHEMA_URL)\n", + "\n", + " collection.validate()\n", + "\n", + " new_collections[collection.id] = collection.to_dict()" + ] + }, + { + "cell_type": "markdown", + "id": "a99ddf1a-fb80-42e1-bd2e-52037874a79e", + "metadata": {}, + "source": [ + "Post to the STAC Loader SNS topic to ingest to pgstac" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "923a05a4-e446-40fa-9f8c-eb1ed4ea2bfe", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ESACCI_Biomass_L4_AGB_V4_100m 200\n", + "glad-glclu2020-change-v2 200\n", + "glad-glclu2020-v2 200\n", + "glad-global-forest-change-1.11 200\n", + "global-mangrove-watch-3.0 200\n", + "icesat2-boreal 200\n", + "icesat2-boreal-v2.1-agb 200\n", + "icesat2-boreal-v2.1-ht 200\n", + "NCEO_Africa_AGB_100m_2017 200\n", + "SRTMGL1_COD 200\n" + ] + } + ], + "source": [ + "# post collections to StacLoader\n", + "sns_client = boto3.client(\"sns\")\n", + "\n", + "for collection_id, collection in new_collections.items():\n", + " response = sns_client.publish(\n", + " TopicArn=STAC_LOADER_SNS_TOPIC_ARN, Message=json.dumps(collection)\n", + " )\n", + " print(collection[\"id\"], response[\"ResponseMetadata\"][\"HTTPStatusCode\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dd08b28b-98df-4b23-b230-13eb4e7d4c5e", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.0" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}