{ "cells": [ { "cell_type": "markdown", "id": "e861f4db-f66d-474f-95bc-eaefba6437ff", "metadata": {}, "source": [ "## Accessing Planet - NICFI Data on the Planetary Computer\n", "\n", "We've partnered with the [Group on Earth Observation](https://www.earthobservations.org/geo_blog_obs.php?id=528) and [Planet](https://www.planet.com/pulse/nicfi-satellite-data-program-extended-to-include-recipients-of-the-geo-microsoft-planetary-computer-grants-program/) to provide access to data from the NICFI Satellite Data Program to winners of the GEO - Microsoft Planetary Computer grants program. Data from these collections are only available to the grantees. Others wishing to use the data can sign up and access it from Planet at https://www.planet.com/nicfi/.\n", "\n", "In this example, we'll use the STAC API to search for items matching some spatio-temporal query." ] }, { "cell_type": "markdown", "id": "b7ddc6f4-374e-43b0-8f21-13ca3bdf79b7", "metadata": {}, "source": [ "### Data access\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." ] }, { "cell_type": "code", "execution_count": 1, "id": "5b77a015-45fd-45a9-a8b8-4dccb8e002d5", "metadata": {}, "outputs": [], "source": [ "import pystac_client\n", "import planetary_computer\n", "\n", "catalog = pystac_client.Client.open(\n", " \"https://planetarycomputer.microsoft.com/api/stac/v1\",\n", " modifier=planetary_computer.sign_inplace,\n", ")" ] }, { "cell_type": "code", "execution_count": 2, "id": "8d08ea6d-3c91-455c-8913-efda41e273b1", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "24" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "point = {\"type\": \"Point\", \"coordinates\": (-60.556640599999994, -0.96674985)}\n", "search = catalog.search(collections=[\"planet-nicfi-visual\"], intersects=point)\n", "items = search.item_collection()\n", "len(items)" ] }, { "cell_type": "markdown", "id": "654ff5f7-c001-47ee-a8f1-a958c186cd9d", "metadata": {}, "source": [ "Next, we'll load the oldest and newest items to visually compare the change in this area over the six years." ] }, { "cell_type": "code", "execution_count": 3, "id": "325911a6-fad1-4d6a-9354-fa0e6c9eb5f7", "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import rioxarray\n", "import matplotlib.pyplot as plt\n", "\n", "a = rioxarray.open_rasterio(items[0].assets[\"data\"].href)\n", "b = rioxarray.open_rasterio(items[-1].assets[\"data\"].href)\n", "\n", "fig, axes = plt.subplots(figsize=(20, 10), ncols=2, sharex=True, sharey=True)\n", "\n", "a.plot.imshow(ax=axes[0], rgb=\"band\")\n", "axes[0].set(title=items[0].datetime)\n", "\n", "b.plot.imshow(ax=axes[1], rgb=\"band\")\n", "axes[1].set(title=items[-1].datetime)\n", "plt.tight_layout();" ] }, { "cell_type": "markdown", "id": "fab8d8a1-877e-4faa-8195-a93246615517", "metadata": {}, "source": [ "An analytic product is also available, which includes a near-infrared band." ] }, { "cell_type": "code", "execution_count": 4, "id": "52cc16aa-3ba7-48da-9e92-639c1f3f753b", "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "search = catalog.search(collections=[\"planet-nicfi-analytic\"], intersects=point)\n", "item = next(search.items())\n", "\n", "mesh = (\n", " rioxarray.open_rasterio(item.assets[\"data\"].href)\n", " .sel(band=4)\n", " .plot(cmap=\"Reds\", size=8)\n", ")\n", "mesh.axes.set_axis_off()\n", "mesh.axes.set(title=\"Near-infrared band\");" ] } ], "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.8.13" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 5 }