Skip to content

Commit 13727cb

Browse files
committed
Add stac demo
1 parent f6b7b07 commit 13727cb

File tree

1 file changed

+177
-0
lines changed

1 file changed

+177
-0
lines changed
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"import xarray as xr\n",
10+
"import pystac_client\n",
11+
"import planetary_computer\n",
12+
"\n",
13+
"from dask.distributed import Client, LocalCluster"
14+
]
15+
},
16+
{
17+
"cell_type": "code",
18+
"execution_count": null,
19+
"metadata": {},
20+
"outputs": [],
21+
"source": [
22+
"cluster = LocalCluster(n_workers=4, threads_per_worker=1)\n",
23+
"client = Client(cluster)\n",
24+
"client"
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": null,
30+
"metadata": {},
31+
"outputs": [],
32+
"source": [
33+
"path = 'gs://gcp-public-data-arco-era5/ar/1959-2022-6h-1440x721.zarr'\n",
34+
"era5_ds = xr.open_dataset(path, engine='zarr').chunk('auto')\n",
35+
"era5_temperature = era5_ds['2m_temperature']\n",
36+
"era5_precipitation = era5_ds['total_precipitation_6hr']"
37+
]
38+
},
39+
{
40+
"cell_type": "code",
41+
"execution_count": null,
42+
"metadata": {},
43+
"outputs": [],
44+
"source": [
45+
"era5_precipitation"
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": null,
51+
"metadata": {},
52+
"outputs": [],
53+
"source": [
54+
"catalog = pystac_client.Client.open(\n",
55+
" \"https://planetarycomputer.microsoft.com/api/stac/v1/\",\n",
56+
" modifier=planetary_computer.sign_inplace,\n",
57+
")\n",
58+
"collection = catalog.get_collection(\"cil-gdpcir-cc-by\")\n",
59+
"\n",
60+
"summary = collection.summaries.to_dict()\n",
61+
"available_keys = list(summary.keys())\n",
62+
"print(available_keys)"
63+
]
64+
},
65+
{
66+
"cell_type": "markdown",
67+
"metadata": {},
68+
"source": [
69+
"## What physical variables are stored in the dataset?"
70+
]
71+
},
72+
{
73+
"cell_type": "code",
74+
"execution_count": null,
75+
"metadata": {},
76+
"outputs": [],
77+
"source": [
78+
"summary['cmip6:variable']"
79+
]
80+
},
81+
{
82+
"cell_type": "markdown",
83+
"metadata": {},
84+
"source": [
85+
"## What GCMs are used in the dataset?"
86+
]
87+
},
88+
{
89+
"cell_type": "code",
90+
"execution_count": null,
91+
"metadata": {},
92+
"outputs": [],
93+
"source": [
94+
"summary['cmip6:source_id']"
95+
]
96+
},
97+
{
98+
"cell_type": "markdown",
99+
"metadata": {},
100+
"source": [
101+
"## What are the SSPs in the dataset?"
102+
]
103+
},
104+
{
105+
"cell_type": "code",
106+
"execution_count": null,
107+
"metadata": {},
108+
"outputs": [],
109+
"source": [
110+
"summary['cmip6:experiment_id']"
111+
]
112+
},
113+
{
114+
"cell_type": "markdown",
115+
"metadata": {},
116+
"source": [
117+
"## How do we use this information to actually get the data?"
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": null,
123+
"metadata": {},
124+
"outputs": [],
125+
"source": [
126+
"search = catalog.search(\n",
127+
" collections=['cil-gdpcir-cc-by'],\n",
128+
" query={'cmip6:experiment_id': {'eq': 'historical'}}\n",
129+
")\n",
130+
"historic_data = search.item_collection()\n",
131+
"historic_data"
132+
]
133+
},
134+
{
135+
"cell_type": "code",
136+
"execution_count": null,
137+
"metadata": {},
138+
"outputs": [],
139+
"source": [
140+
"search = catalog.search(\n",
141+
" collections=['cil-gdpcir-cc-by'],\n",
142+
" query={'cmip6:source_id': {'eq': 'GFDL-ESM4'}}\n",
143+
")\n",
144+
"gfdl_data = search.item_collection()\n",
145+
"gfdl_data"
146+
]
147+
},
148+
{
149+
"cell_type": "code",
150+
"execution_count": null,
151+
"metadata": {},
152+
"outputs": [],
153+
"source": []
154+
}
155+
],
156+
"metadata": {
157+
"kernelspec": {
158+
"display_name": "init",
159+
"language": "python",
160+
"name": "python3"
161+
},
162+
"language_info": {
163+
"codemirror_mode": {
164+
"name": "ipython",
165+
"version": 3
166+
},
167+
"file_extension": ".py",
168+
"mimetype": "text/x-python",
169+
"name": "python",
170+
"nbconvert_exporter": "python",
171+
"pygments_lexer": "ipython3",
172+
"version": "3.10.13"
173+
}
174+
},
175+
"nbformat": 4,
176+
"nbformat_minor": 2
177+
}

0 commit comments

Comments
 (0)