{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Accessing NOAA's Sea Surface Temperature - Wood Hole Oceanographic Institution (WHOI) Climate Data Record (CDR) with the Planetary Computer STAC API\n", "\n", "The Sea Surface Temperature-Woods Hole Oceanographic Institution (WHOI) Climate Data Record (CDR) is one of three CDRs which combine to form the NOAA Ocean Surface Bundle (OSB) CDR. The resultant sea surface temperature (SST) data are produced through modeling the diurnal variability in combination with AVHRR SST observations. The final record is output to a 3-hourly 0.25° resolution grid over the global ice-free oceans from January 1988—present.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Data access\n", "\n", "This notebook works with or without an API key, but you will be given more permissive access to the data with an API key. The [Planetary Computer Hub](https://planetarycomputer.microsoft.com/compute) sets the environment variable \"PC_SDK_SUBSCRIPTION_KEY\" when your server is started. When your Planetary Computer [account request](https://planetarycomputer.microsoft.com/account/request) was approved, a pair of subscription keys were automatically generated for you. You can view your keys by singing in to the [developer portal](https://planetarycomputer.developer.azure-api.net/). The API key may be set manually via the following code:\n", "\n", "```python\n", "pc.settings.set_subscription_key()\n", "```\n", "\n", "The datasets hosted by the Planetary Computer are available from [Azure Blob Storage](https://docs.microsoft.com/en-us/azure/storage/blobs/). We'll use [pystac-client](https://pystac-client.readthedocs.io/) to search the Planetary Computer's [STAC API](https://planetarycomputer.microsoft.com/api/stac/v1/docs) for the subset of the data that we care about, and then we'll load the data directly from Azure Blob Storage. We'll specify a `modifier` so that we can access the data stored in the Planetary Computer's private Blob Storage Containers. See [Reading from the STAC API](https://planetarycomputer.microsoft.com/docs/quickstarts/reading-stac/) and [Using tokens for data access](https://planetarycomputer.microsoft.com/docs/concepts/sas/) for more. \n", "\n", "First, let's fetch all items from the first day of 1988." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[, , , , , , , ]\n" ] } ], "source": [ "import planetary_computer\n", "import pystac_client\n", "\n", "client = pystac_client.Client.open(\n", " \"https://planetarycomputer.microsoft.com/api/stac/v1\",\n", " modifier=planetary_computer.sign_inplace,\n", ")\n", "item_search = client.search(\n", " collections=\"noaa-cdr-sea-surface-temperature-whoi\",\n", " datetime=\"1988-01-01\",\n", ")\n", "items = list(item_search.items())\n", "print(items)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Assets\n", "\n", "Each item has a Cloud Optimized GeoTIFF (COG) asset containing the sea surface temperature in degrees Celsius." ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n",
       "┃ Key                      Title                               ┃\n",
       "┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n",
       "│ fill_missing_qc         │ Quality flag for missing data       │\n",
       "│ sea_surface_temperature │ NOAA CDR of sea surface temperature │\n",
       "│ tilejson                │ TileJSON with default rendering     │\n",
       "│ rendered_preview        │ Rendered preview                    │\n",
       "└─────────────────────────┴─────────────────────────────────────┘\n",
       "
\n" ], "text/plain": [ "┏━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n", "┃\u001b[1m \u001b[0m\u001b[1mKey \u001b[0m\u001b[1m \u001b[0m┃\u001b[1m \u001b[0m\u001b[1mTitle \u001b[0m\u001b[1m \u001b[0m┃\n", "┡━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩\n", "│ fill_missing_qc │ Quality flag for missing data │\n", "│ sea_surface_temperature │ NOAA CDR of sea surface temperature │\n", "│ tilejson │ TileJSON with default rendering │\n", "│ rendered_preview │ Rendered preview │\n", "└─────────────────────────┴─────────────────────────────────────┘\n" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from rich.table import Table\n", "\n", "item = items[0]\n", "table = Table(\"Key\", \"Title\")\n", "for key, asset in item.assets.items():\n", " table.add_row(key, asset.title)\n", "table" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Load data\n", "\n", "Let's load all the data into an xarray using [odc-stac](https://github.com/opendatacube/odc-stac)." ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "\n", "
<xarray.Dataset>\n",
       "Dimensions:                  (latitude: 720, longitude: 1440, time: 8)\n",
       "Coordinates:\n",
       "  * latitude                 (latitude) float64 89.88 89.62 ... -89.62 -89.88\n",
       "  * longitude                (longitude) float64 -179.9 -179.6 ... 179.6 179.9\n",
       "    spatial_ref              int32 4326\n",
       "  * time                     (time) datetime64[ns] 1988-01-01 ... 1988-01-01T...\n",
       "Data variables:\n",
       "    sea_surface_temperature  (time, latitude, longitude) float32 nan nan ... nan
" ], "text/plain": [ "\n", "Dimensions: (latitude: 720, longitude: 1440, time: 8)\n", "Coordinates:\n", " * latitude (latitude) float64 89.88 89.62 ... -89.62 -89.88\n", " * longitude (longitude) float64 -179.9 -179.6 ... 179.6 179.9\n", " spatial_ref int32 4326\n", " * time (time) datetime64[ns] 1988-01-01 ... 1988-01-01T...\n", "Data variables:\n", " sea_surface_temperature (time, latitude, longitude) float32 nan nan ... nan" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import odc.stac\n", "\n", "data = odc.stac.load(items, bands=\"sea_surface_temperature\")\n", "data" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Visualize\n", "\n", "Now, let's visualize one three-hour window." ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "tags": [] }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "from cartopy import crs\n", "from matplotlib import pyplot\n", "\n", "figure = pyplot.figure(figsize=(12, 8))\n", "axes = pyplot.axes(projection=crs.Mercator())\n", "data[\"sea_surface_temperature\"][0].plot.imshow(cmap=\"RdYlBu_r\", vmin=0, vmax=35);" ] } ], "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.10.9" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }