Skip to content

Commit ac5d8de

Browse files
committed
add Met Office example notebooks
1 parent 5d386ae commit ac5d8de

8 files changed

+1106
-0
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "fbf471b1",
6+
"metadata": {},
7+
"source": [
8+
"# Accessing Global Height data from Microsoft Planetary Computer"
9+
]
10+
},
11+
{
12+
"cell_type": "markdown",
13+
"id": "941120d0",
14+
"metadata": {},
15+
"source": [
16+
"Set-up the pystac client to access the Microsoft Planetary Computer catalog"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": null,
22+
"id": "4bafd899",
23+
"metadata": {},
24+
"outputs": [],
25+
"source": [
26+
"from pystac_client import Client\n",
27+
"import planetary_computer\n",
28+
"\n",
29+
"catalog = Client.open(\n",
30+
" \"https://planetarycomputer.microsoft.com/api/stac/v1\",\n",
31+
" modifier=planetary_computer.sign_inplace,\n",
32+
")"
33+
]
34+
},
35+
{
36+
"cell_type": "markdown",
37+
"id": "b5a6a858",
38+
"metadata": {},
39+
"source": [
40+
"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"
41+
]
42+
},
43+
{
44+
"cell_type": "code",
45+
"execution_count": null,
46+
"id": "2132d393",
47+
"metadata": {},
48+
"outputs": [],
49+
"source": [
50+
"collections = [\"met-office-global-deterministic-height\"]\n",
51+
"asset_id = \"cloud_amount_on_height_levels\"\n",
52+
"datacube_extension_filters = {\n",
53+
" \"op\": \"and\",\n",
54+
" \"args\": [\n",
55+
" {\n",
56+
" \"op\": \"=\",\n",
57+
" \"args\": [ { \"property\": \"forecast:reference_datetime\" }, \"2026-01-14T12:00:00Z\" ]\n",
58+
" },\n",
59+
" {\n",
60+
" \"op\": \"=\",\n",
61+
" \"args\": [ { \"property\": \"forecast:horizon\" }, \"PT0144H00M\" ]\n",
62+
" }\n",
63+
" ]\n",
64+
"}"
65+
]
66+
},
67+
{
68+
"cell_type": "markdown",
69+
"id": "dec7c74b",
70+
"metadata": {},
71+
"source": [
72+
"Search Planetary Computer catalog for STAC items and retrieve STAC Asset URL"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": null,
78+
"id": "edb71afa",
79+
"metadata": {},
80+
"outputs": [],
81+
"source": [
82+
"search = catalog.search(\n",
83+
" collections=collections,\n",
84+
" filter_lang= \"cql2-json\",\n",
85+
" filter=datacube_extension_filters\n",
86+
")\n",
87+
"\n",
88+
"items = search.item_collection()\n",
89+
"asset_url = items.items[0].assets[asset_id].href"
90+
]
91+
},
92+
{
93+
"cell_type": "markdown",
94+
"id": "ee73ba3d",
95+
"metadata": {},
96+
"source": [
97+
"Example usage: Plot NetCDF data"
98+
]
99+
},
100+
{
101+
"cell_type": "code",
102+
"execution_count": null,
103+
"id": "fbc72d2a",
104+
"metadata": {},
105+
"outputs": [],
106+
"source": [
107+
"import fsspec\n",
108+
"import xarray as xr\n",
109+
"import matplotlib.pyplot as plt\n",
110+
"\n",
111+
"example_netcdf = xr.open_dataset(fsspec.open(asset_url, expand=True).open())\n",
112+
"plt.figure(figsize=(10, 5))\n",
113+
"example_netcdf[\"cloud_volume_fraction_in_atmosphere_layer\"].plot()"
114+
]
115+
}
116+
],
117+
"metadata": {
118+
"kernelspec": {
119+
"display_name": ".venv",
120+
"language": "python",
121+
"name": "python3"
122+
},
123+
"language_info": {
124+
"codemirror_mode": {
125+
"name": "ipython",
126+
"version": 3
127+
},
128+
"file_extension": ".py",
129+
"mimetype": "text/x-python",
130+
"name": "python",
131+
"nbconvert_exporter": "python",
132+
"pygments_lexer": "ipython3",
133+
"version": "3.13.11"
134+
}
135+
},
136+
"nbformat": 4,
137+
"nbformat_minor": 5
138+
}
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "fbf471b1",
6+
"metadata": {},
7+
"source": [
8+
"# Accessing Global Surface data from Microsoft Planetary Computer"
9+
]
10+
},
11+
{
12+
"cell_type": "markdown",
13+
"id": "941120d0",
14+
"metadata": {},
15+
"source": [
16+
"Set-up the pystac client to access the Microsoft Planetary Computer catalog"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": null,
22+
"id": "4bafd899",
23+
"metadata": {},
24+
"outputs": [],
25+
"source": [
26+
"from pystac_client import Client\n",
27+
"import planetary_computer\n",
28+
"\n",
29+
"catalog = Client.open(\n",
30+
" \"https://planetarycomputer.microsoft.com/api/stac/v1\",\n",
31+
" modifier=planetary_computer.sign_inplace,\n",
32+
")"
33+
]
34+
},
35+
{
36+
"cell_type": "markdown",
37+
"id": "b5a6a858",
38+
"metadata": {},
39+
"source": [
40+
"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"
41+
]
42+
},
43+
{
44+
"cell_type": "code",
45+
"execution_count": null,
46+
"id": "2132d393",
47+
"metadata": {},
48+
"outputs": [],
49+
"source": [
50+
"collections = [\"met-office-global-deterministic-near-surface\"]\n",
51+
"asset_id = \"temperature_at_surface\"\n",
52+
"datacube_extension_filters = {\n",
53+
" \"op\": \"and\",\n",
54+
" \"args\": [\n",
55+
" {\n",
56+
" \"op\": \"=\",\n",
57+
" \"args\": [ { \"property\": \"forecast:reference_datetime\" }, \"2025-12-05T12:00:00Z\" ]\n",
58+
" },\n",
59+
" {\n",
60+
" \"op\": \"=\",\n",
61+
" \"args\": [ { \"property\": \"forecast:horizon\" }, \"PT0120H00M\" ]\n",
62+
" }\n",
63+
" ]\n",
64+
"}"
65+
]
66+
},
67+
{
68+
"cell_type": "markdown",
69+
"id": "dec7c74b",
70+
"metadata": {},
71+
"source": [
72+
"Search Planetary Computer catalog for STAC items and retrieve STAC Asset URL"
73+
]
74+
},
75+
{
76+
"cell_type": "code",
77+
"execution_count": null,
78+
"id": "edb71afa",
79+
"metadata": {},
80+
"outputs": [],
81+
"source": [
82+
"search = catalog.search(\n",
83+
" collections=collections,\n",
84+
" filter_lang= \"cql2-json\",\n",
85+
" filter=datacube_extension_filters\n",
86+
")\n",
87+
"\n",
88+
"items = search.item_collection()\n",
89+
"asset_url = items.items[0].assets[asset_id].href"
90+
]
91+
},
92+
{
93+
"cell_type": "markdown",
94+
"id": "ee73ba3d",
95+
"metadata": {},
96+
"source": [
97+
"Example usage: Plot NetCDF data on a map"
98+
]
99+
},
100+
{
101+
"cell_type": "code",
102+
"execution_count": null,
103+
"id": "fbc72d2a",
104+
"metadata": {},
105+
"outputs": [],
106+
"source": [
107+
"import fsspec\n",
108+
"import xarray as xr\n",
109+
"import matplotlib.pyplot as plt\n",
110+
"\n",
111+
"example_netcdf = xr.open_dataset(fsspec.open(asset_url, expand=True).open())\n",
112+
"plt.figure(figsize=(10, 5))\n",
113+
"example_netcdf[\"surface_temperature\"].plot()"
114+
]
115+
}
116+
],
117+
"metadata": {
118+
"kernelspec": {
119+
"display_name": ".venv",
120+
"language": "python",
121+
"name": "python3"
122+
},
123+
"language_info": {
124+
"codemirror_mode": {
125+
"name": "ipython",
126+
"version": 3
127+
},
128+
"file_extension": ".py",
129+
"mimetype": "text/x-python",
130+
"name": "python",
131+
"nbconvert_exporter": "python",
132+
"pygments_lexer": "ipython3",
133+
"version": "3.13.11"
134+
}
135+
},
136+
"nbformat": 4,
137+
"nbformat_minor": 5
138+
}

0 commit comments

Comments
 (0)