Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
173 changes: 173 additions & 0 deletions datasets/met-office/met-office-global-deterministic-height.ipynb

Large diffs are not rendered by default.

167 changes: 167 additions & 0 deletions datasets/met-office/met-office-global-deterministic-near-surface.ipynb

Large diffs are not rendered by default.

173 changes: 173 additions & 0 deletions datasets/met-office/met-office-global-deterministic-pressure.ipynb

Large diffs are not rendered by default.

Large diffs are not rendered by default.

171 changes: 171 additions & 0 deletions datasets/met-office/met-office-uk-deterministic-height.ipynb

Large diffs are not rendered by default.

149 changes: 149 additions & 0 deletions datasets/met-office/met-office-uk-deterministic-near-surface.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "fbf471b1",
"metadata": {},
"source": [
"# Accessing UK Model Surface data from Microsoft Planetary Computer"
]
},
{
"cell_type": "markdown",
"id": "941120d0",
"metadata": {},
"source": [
"Set-up the pystac client to access the Microsoft Planetary Computer catalog"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "4bafd899",
"metadata": {},
"outputs": [],
"source": [
"from pystac_client import Client\n",
"import planetary_computer\n",
"\n",
"catalog = Client.open(\n",
" \"https://planetarycomputer.microsoft.com/api/stac/v1\",\n",
" modifier=planetary_computer.sign_inplace,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "2cab8be1",
"metadata": {},
"source": [
"Define collection and assets to retrieve and construct [STAC API filters](https://github.com/stac-api-extensions/filter) for efficient query performance against Planetary Computer API"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8f95ecac",
"metadata": {},
"outputs": [],
"source": [
"collections = [\"met-office-uk-deterministic-near-surface\"]\n",
"asset_id = \"temperature_at_surface\"\n",
"forecast_extension_filters = {\n",
" \"op\": \"and\",\n",
" \"args\": [\n",
" {\n",
" \"op\": \"=\",\n",
" \"args\": [\n",
" {\"property\": \"forecast:reference_datetime\"},\n",
" \"2026-01-21T09:00:00Z\",\n",
" ],\n",
" },\n",
" {\"op\": \"=\", \"args\": [{\"property\": \"forecast:horizon\"}, \"PT0054H00M\"]},\n",
" ],\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "b5a6a858",
"metadata": {},
"source": [
"Search Planetary Computer catalog for STAC items and retrieve STAC Asset URL"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "edb71afa",
"metadata": {},
"outputs": [
{
"ename": "StopIteration",
"evalue": "",
"output_type": "error",
"traceback": [
"\u001b[31m---------------------------------------------------------------------------\u001b[39m",
"\u001b[31mStopIteration\u001b[39m Traceback (most recent call last)",
"\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[19]\u001b[39m\u001b[32m, line 6\u001b[39m\n\u001b[32m 1\u001b[39m search = catalog.search(\n\u001b[32m 2\u001b[39m collections=collections,\n\u001b[32m 3\u001b[39m datetime=\u001b[33m\"\u001b[39m\u001b[33m2026-01-21T09:00:00Z\u001b[39m\u001b[33m\"\u001b[39m,\n\u001b[32m 4\u001b[39m )\n\u001b[32m----> \u001b[39m\u001b[32m6\u001b[39m asset_url = \u001b[38;5;28;43mnext\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mitem\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mfor\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mitem\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;129;43;01min\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43msearch\u001b[49m\u001b[43m.\u001b[49m\u001b[43mitems\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mif\u001b[39;49;00m\u001b[43m \u001b[49m\u001b[43mitem\u001b[49m\u001b[43m.\u001b[49m\u001b[43mproperties\u001b[49m\u001b[43m[\u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mforecast:horizon\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m \u001b[49m\u001b[43m==\u001b[49m\u001b[43m \u001b[49m\u001b[33;43m\"\u001b[39;49m\u001b[33;43mPT0054H00M\u001b[39;49m\u001b[33;43m\"\u001b[39;49m\u001b[43m)\u001b[49m.assets[asset_id].href\n",
"\u001b[31mStopIteration\u001b[39m: "
]
}
],
"source": [
"search = catalog.search(\n",
" collections=collections,\n",
" filter_lang=\"cql2-json\",\n",
" filter=forecast_extension_filters,\n",
")\n",
"\n",
"asset_url = next(search.items()).assets[asset_id].href"
]
},
{
"cell_type": "markdown",
"id": "56d27e19",
"metadata": {},
"source": [
"Example usage: Plot NetCDF data on a map"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "45613dda",
"metadata": {},
"outputs": [],
"source": [
"import fsspec\n",
"import xarray as xr\n",
"import matplotlib.pyplot as plt\n",
"\n",
"example_netcdf = xr.open_dataset(fsspec.open(asset_url, expand=True).open())\n",
"plt.figure(figsize=(10, 5))\n",
"example_netcdf[\"surface_temperature\"].plot()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "PlanetaryComputerExamples",
"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.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
136 changes: 136 additions & 0 deletions datasets/met-office/met-office-uk-deterministic-pressure.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "fbf471b1",
"metadata": {},
"source": [
"# Accessing UK Model Pressure Level data from Microsoft Planetary Computer"
]
},
{
"cell_type": "markdown",
"id": "941120d0",
"metadata": {},
"source": [
"Set-up the pystac client to access the Microsoft Planetary Computer catalog"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4bafd899",
"metadata": {},
"outputs": [],
"source": [
"from pystac_client import Client\n",
"import planetary_computer\n",
"\n",
"catalog = Client.open(\n",
" \"https://planetarycomputer.microsoft.com/api/stac/v1\",\n",
" modifier=planetary_computer.sign_inplace,\n",
")"
]
},
{
"cell_type": "markdown",
"id": "2cab8be1",
"metadata": {},
"source": [
"Define collection and assets to retrieve and construct [STAC API filters](https://github.com/stac-api-extensions/filter) for efficient query performance against Planetary Computer API"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8f95ecac",
"metadata": {},
"outputs": [],
"source": [
"collections = [\"met-office-uk-deterministic-pressure\"]\n",
"asset_id = \"wet_bulb_potential_temperature_on_pressure_levels\"\n",
"forecast_extension_filters = {\n",
" \"op\": \"and\",\n",
" \"args\": [\n",
" {\n",
" \"op\": \"=\",\n",
" \"args\": [\n",
" {\"property\": \"forecast:reference_datetime\"},\n",
" \"2026-01-14T12:00:00Z\",\n",
" ],\n",
" },\n",
" {\"op\": \"=\", \"args\": [{\"property\": \"forecast:horizon\"}, \"PT0052H00M\"]},\n",
" ],\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "b5a6a858",
"metadata": {},
"source": [
"Search Planetary Computer catalog for STAC items and retrieve STAC Asset URL"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "edb71afa",
"metadata": {},
"outputs": [],
"source": [
"search = catalog.search(\n",
" collections=collections, filter_lang=\"cql2-json\", filter=forecast_extension_filters\n",
")\n",
"\n",
"items = search.item_collection()\n",
"asset_url = items.items[0].assets[asset_id].href"
]
},
{
"cell_type": "markdown",
"id": "56d27e19",
"metadata": {},
"source": [
"Example usage: Plot NetCDF data on a map"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "45613dda",
"metadata": {},
"outputs": [],
"source": [
"import fsspec\n",
"import xarray as xr\n",
"import matplotlib.pyplot as plt\n",
"\n",
"example_netcdf = xr.open_dataset(fsspec.open(asset_url, expand=True).open())\n",
"plt.figure(figsize=(10, 5))\n",
"example_netcdf[\"wet_bulb_potential_temperature\"].plot()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"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.11"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading
Loading