|
13 | 13 | "id": "941120d0", |
14 | 14 | "metadata": {}, |
15 | 15 | "source": [ |
16 | | - "Set-up the pystac client to access the Microsoft Planetary Computer catalog" |
| 16 | + "This example notebook provides a walkthrough accessing the [Met Office UK Near Surface collection](https://planetarycomputer.microsoft.com/dataset/met-office-uk-deterministic-near-surface) on Microsoft Planetary Computer. This notebook outputs an image of UK surface temperatures across a forecast period.\n", |
| 17 | + "\n", |
| 18 | + "First, import required libraries and set-up the pystac client to access the Planetary Computer STAC API." |
17 | 19 | ] |
18 | 20 | }, |
19 | 21 | { |
|
23 | 25 | "metadata": {}, |
24 | 26 | "outputs": [], |
25 | 27 | "source": [ |
| 28 | + "import fsspec\n", |
| 29 | + "import matplotlib.pyplot as plt\n", |
26 | 30 | "from pystac_client import Client\n", |
27 | 31 | "import planetary_computer\n", |
| 32 | + "import xarray as xr\n", |
28 | 33 | "\n", |
29 | 34 | "catalog = Client.open(\n", |
30 | 35 | " \"https://planetarycomputer.microsoft.com/api/stac/v1\",\n", |
|
42 | 47 | }, |
43 | 48 | { |
44 | 49 | "cell_type": "code", |
45 | | - "execution_count": null, |
| 50 | + "execution_count": 6, |
46 | 51 | "id": "8f95ecac", |
47 | 52 | "metadata": {}, |
48 | 53 | "outputs": [], |
|
56 | 61 | " \"op\": \"=\",\n", |
57 | 62 | " \"args\": [\n", |
58 | 63 | " {\"property\": \"forecast:reference_datetime\"},\n", |
59 | | - " \"2026-01-21T09:00:00Z\",\n", |
| 64 | + " \"2026-01-30T09:00:00Z\",\n", |
60 | 65 | " ],\n", |
61 | 66 | " },\n", |
62 | 67 | " {\"op\": \"=\", \"args\": [{\"property\": \"forecast:horizon\"}, \"PT0054H00M\"]},\n", |
| 68 | + " {\"op\": \"=\", \"args\": [{\"property\": \"forecast:variable\"}, \"surface_temperature\"]},\n", |
63 | 69 | " ],\n", |
64 | 70 | "}" |
65 | 71 | ] |
|
77 | 83 | "execution_count": null, |
78 | 84 | "id": "edb71afa", |
79 | 85 | "metadata": {}, |
80 | | - "outputs": [ |
81 | | - { |
82 | | - "ename": "StopIteration", |
83 | | - "evalue": "", |
84 | | - "output_type": "error", |
85 | | - "traceback": [ |
86 | | - "\u001b[31m---------------------------------------------------------------------------\u001b[39m", |
87 | | - "\u001b[31mStopIteration\u001b[39m Traceback (most recent call last)", |
88 | | - "\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", |
89 | | - "\u001b[31mStopIteration\u001b[39m: " |
90 | | - ] |
91 | | - } |
92 | | - ], |
| 86 | + "outputs": [], |
93 | 87 | "source": [ |
94 | 88 | "search = catalog.search(\n", |
95 | | - " collections=collections,\n", |
96 | | - " filter_lang=\"cql2-json\",\n", |
97 | | - " filter=forecast_extension_filters,\n", |
| 89 | + " collections=collections, filter_lang=\"cql2-json\", filter=forecast_extension_filters\n", |
98 | 90 | ")\n", |
99 | 91 | "\n", |
100 | | - "asset_url = next(search.items()).assets[asset_id].href" |
| 92 | + "items = search.item_collection()\n", |
| 93 | + "print (f\"Item Dictionary - {items.items[0].assets}\")\n", |
| 94 | + "\n", |
| 95 | + "asset_url = items.items[0].assets[asset_id].href\n", |
| 96 | + "print(f\"URL for specific NetCDF - {asset_url}\")" |
101 | 97 | ] |
102 | 98 | }, |
103 | 99 | { |
104 | 100 | "cell_type": "markdown", |
105 | 101 | "id": "56d27e19", |
106 | 102 | "metadata": {}, |
107 | 103 | "source": [ |
108 | | - "Example usage: Plot NetCDF data on a map" |
| 104 | + "Example usage: Open and inspect NetCDF data" |
109 | 105 | ] |
110 | 106 | }, |
111 | 107 | { |
|
115 | 111 | "metadata": {}, |
116 | 112 | "outputs": [], |
117 | 113 | "source": [ |
118 | | - "import fsspec\n", |
119 | | - "import xarray as xr\n", |
120 | | - "import matplotlib.pyplot as plt\n", |
121 | | - "\n", |
122 | | - "example_netcdf = xr.open_dataset(fsspec.open(asset_url, expand=True).open())\n", |
| 114 | + "example_netcdf = xr.open_dataset(fsspec.open(asset_url, expand=True).open(), decode_timedelta=True)\n", |
| 115 | + "example_netcdf" |
| 116 | + ] |
| 117 | + }, |
| 118 | + { |
| 119 | + "cell_type": "markdown", |
| 120 | + "id": "ffa6be66", |
| 121 | + "metadata": {}, |
| 122 | + "source": [ |
| 123 | + "Plot surface temperatures on a map" |
| 124 | + ] |
| 125 | + }, |
| 126 | + { |
| 127 | + "cell_type": "code", |
| 128 | + "execution_count": null, |
| 129 | + "id": "820f3c35", |
| 130 | + "metadata": {}, |
| 131 | + "outputs": [], |
| 132 | + "source": [ |
123 | 133 | "plt.figure(figsize=(10, 5))\n", |
124 | 134 | "example_netcdf[\"surface_temperature\"].plot()" |
125 | 135 | ] |
126 | 136 | } |
127 | 137 | ], |
128 | 138 | "metadata": { |
129 | 139 | "kernelspec": { |
130 | | - "display_name": "PlanetaryComputerExamples", |
| 140 | + "display_name": ".venv", |
131 | 141 | "language": "python", |
132 | 142 | "name": "python3" |
133 | 143 | }, |
|
141 | 151 | "name": "python", |
142 | 152 | "nbconvert_exporter": "python", |
143 | 153 | "pygments_lexer": "ipython3", |
144 | | - "version": "3.13.2" |
| 154 | + "version": "3.13.11" |
145 | 155 | } |
146 | 156 | }, |
147 | 157 | "nbformat": 4, |
|
0 commit comments