Skip to content

Commit eb1a764

Browse files
committed
more extensions and examples
1 parent 6584013 commit eb1a764

File tree

5 files changed

+478
-20
lines changed

5 files changed

+478
-20
lines changed

notebooks/nex_gddp_cmip6.ipynb

Lines changed: 350 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,350 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# NASA Earth Exchange Global Daily Downscaled Projections (NEX-GDDP-CMIP6)\n",
8+
"\n",
9+
"\n",
10+
"### Description\n",
11+
"\n",
12+
"The NEX-GDDP-CMIP6 dataset is comprised of global downscaled climate scenarios derived from the General Circulation Model (GCM) runs conducted under the Coupled Model Intercomparison Project Phase 6 (CMIP6) and across two of the four \"Tier 1\" greenhouse gas emissions scenarios known as Shared Socioeconomic Pathways (SSPs). The CMIP6 GCM runs were developed in support of the Sixth Assessment Report of the Intergovernmental Panel on Climate Change (IPCC AR6). This dataset includes downscaled projections from ScenarioMIP model runs for which daily scenarios were produced and distributed through the Earth System Grid Federation. The purpose of this dataset is to provide a set of global, high resolution, bias-corrected climate change projections that can be used to evaluate climate change impacts on processes that are sensitive to finer-scale climate gradients and the effects of local topography on climate conditions.\n",
13+
"\n",
14+
"ref: https://registry.opendata.aws/nex-gddp-cmip6/"
15+
]
16+
},
17+
{
18+
"cell_type": "code",
19+
"execution_count": 18,
20+
"metadata": {},
21+
"outputs": [],
22+
"source": [
23+
"import httpx\n",
24+
"import json\n",
25+
"\n",
26+
"endpoint = \"https://t4z3zffpeh.execute-api.us-east-1.amazonaws.com/md\""
27+
]
28+
},
29+
{
30+
"cell_type": "markdown",
31+
"metadata": {},
32+
"source": [
33+
"#### Variables\n",
34+
"\n",
35+
"Before we can `visualize` the dataset we HAVE TO get the list of available variables within the NetCDF file. For this we can use the `/variables` endpoint."
36+
]
37+
},
38+
{
39+
"cell_type": "code",
40+
"execution_count": 19,
41+
"metadata": {},
42+
"outputs": [
43+
{
44+
"name": "stdout",
45+
"output_type": "stream",
46+
"text": [
47+
"['huss']\n"
48+
]
49+
}
50+
],
51+
"source": [
52+
"resp = httpx.get(\n",
53+
" f\"{endpoint}/variables\",\n",
54+
" params={\n",
55+
" \"url\": \"s3://nex-gddp-cmip6/NEX-GDDP-CMIP6/CESM2/historical/r4i1p1f1/huss/huss_day_CESM2_historical_r4i1p1f1_gn_2014.nc\",\n",
56+
" \"decode_times\": True,\n",
57+
" },\n",
58+
" timeout=20,\n",
59+
")\n",
60+
"print(resp.json())\n",
61+
"\n"
62+
]
63+
},
64+
{
65+
"cell_type": "markdown",
66+
"metadata": {},
67+
"source": [
68+
"### Dimensions"
69+
]
70+
},
71+
{
72+
"cell_type": "code",
73+
"execution_count": 29,
74+
"metadata": {},
75+
"outputs": [
76+
{
77+
"name": "stdout",
78+
"output_type": "stream",
79+
"text": [
80+
"{\n",
81+
" \"time\": {\n",
82+
" \"min\": \"2014-01-01 00:00:00\",\n",
83+
" \"max\": \"2014-12-31 00:00:00\",\n",
84+
" \"len\": 365\n",
85+
" },\n",
86+
" \"lat\": {\n",
87+
" \"min\": \"-59.875\",\n",
88+
" \"max\": \"89.875\",\n",
89+
" \"len\": 600\n",
90+
" },\n",
91+
" \"lon\": {\n",
92+
" \"min\": \"0.125\",\n",
93+
" \"max\": \"359.875\",\n",
94+
" \"len\": 1440\n",
95+
" }\n",
96+
"}\n"
97+
]
98+
}
99+
],
100+
"source": [
101+
"resp = httpx.get(\n",
102+
" f\"{endpoint}/dims\",\n",
103+
" params={\n",
104+
" \"url\": \"s3://nex-gddp-cmip6/NEX-GDDP-CMIP6/CESM2/historical/r4i1p1f1/huss/huss_day_CESM2_historical_r4i1p1f1_gn_2014.nc\",\n",
105+
" \"variable\": \"huss\",\n",
106+
" \"decode_times\": True,\n",
107+
" },\n",
108+
" timeout=20,\n",
109+
")\n",
110+
"print(json.dumps(resp.json(), indent=4))"
111+
]
112+
},
113+
{
114+
"cell_type": "markdown",
115+
"metadata": {},
116+
"source": [
117+
"### Dataset Info"
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": 21,
123+
"metadata": {},
124+
"outputs": [
125+
{
126+
"name": "stdout",
127+
"output_type": "stream",
128+
"text": [
129+
"{\n",
130+
" \"bounds\": [\n",
131+
" -180.0,\n",
132+
" -60.0,\n",
133+
" 180.0,\n",
134+
" 90.0\n",
135+
" ],\n",
136+
" \"crs\": \"http://www.opengis.net/def/crs/EPSG/0/4326\",\n",
137+
" \"band_metadata\": [\n",
138+
" [\n",
139+
" \"b1\",\n",
140+
" {}\n",
141+
" ]\n",
142+
" ],\n",
143+
" \"band_descriptions\": [\n",
144+
" [\n",
145+
" \"b1\",\n",
146+
" \"value\"\n",
147+
" ]\n",
148+
" ],\n",
149+
" \"dtype\": \"float32\",\n",
150+
" \"nodata_type\": \"Nodata\",\n",
151+
" \"name\": \"huss\",\n",
152+
" \"count\": 1,\n",
153+
" \"width\": 1440,\n",
154+
" \"height\": 600,\n",
155+
" \"attrs\": {\n",
156+
" \"standard_name\": \"specific_humidity\",\n",
157+
" \"long_name\": \"Near-Surface Specific Humidity\",\n",
158+
" \"units\": \"1\",\n",
159+
" \"cell_methods\": \"area: time: mean\",\n",
160+
" \"comment\": \"Near-surface (usually, 2 meter) specific humidity.\",\n",
161+
" \"description\": \"Near-surface (usually, 2 meter) specific humidity.\",\n",
162+
" \"frequency\": \"day\",\n",
163+
" \"id\": \"huss\",\n",
164+
" \"mipTable\": \"day\",\n",
165+
" \"out_name\": \"huss\",\n",
166+
" \"prov\": \"day ((isd.003))\",\n",
167+
" \"realm\": \"atmos\",\n",
168+
" \"time_label\": \"time-mean\",\n",
169+
" \"time_title\": \"Temporal mean\",\n",
170+
" \"title\": \"Near-Surface Specific Humidity\",\n",
171+
" \"type\": \"real\",\n",
172+
" \"variable_id\": \"huss\"\n",
173+
" }\n",
174+
"}\n"
175+
]
176+
}
177+
],
178+
"source": [
179+
"resp = httpx.get(\n",
180+
" f\"{endpoint}/info\",\n",
181+
" params={\n",
182+
" \"url\": \"s3://nex-gddp-cmip6/NEX-GDDP-CMIP6/CESM2/historical/r4i1p1f1/huss/huss_day_CESM2_historical_r4i1p1f1_gn_2014.nc\",\n",
183+
" \"variable\": \"huss\",\n",
184+
" \"decode_times\": True,\n",
185+
" \"datetime\": \"2014-12-31T00:00:00Z\"\n",
186+
" },\n",
187+
" timeout=20,\n",
188+
")\n",
189+
"print(json.dumps(resp.json(), indent=4))"
190+
]
191+
},
192+
{
193+
"cell_type": "markdown",
194+
"metadata": {},
195+
"source": [
196+
"### Map"
197+
]
198+
},
199+
{
200+
"cell_type": "code",
201+
"execution_count": 31,
202+
"metadata": {},
203+
"outputs": [
204+
{
205+
"data": {
206+
"text/html": [
207+
"<div style=\"width:100%;\"><div style=\"position:relative;width:100%;height:0;padding-bottom:60%;\"><span style=\"color:#565656\">Make this Notebook Trusted to load map: File -> Trust Notebook</span><iframe srcdoc=\"&lt;!DOCTYPE html&gt;\n",
208+
"&lt;head&gt; \n",
209+
" &lt;meta http-equiv=&quot;content-type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;\n",
210+
" \n",
211+
" &lt;script&gt;\n",
212+
" L_NO_TOUCH = false;\n",
213+
" L_DISABLE_3D = false;\n",
214+
" &lt;/script&gt;\n",
215+
" \n",
216+
" &lt;style&gt;html, body {width: 100%;height: 100%;margin: 0;padding: 0;}&lt;/style&gt;\n",
217+
" &lt;style&gt;#map {position:absolute;top:0;bottom:0;right:0;left:0;}&lt;/style&gt;\n",
218+
" &lt;script src=&quot;https://cdn.jsdelivr.net/npm/leaflet@1.6.0/dist/leaflet.js&quot;&gt;&lt;/script&gt;\n",
219+
" &lt;script src=&quot;https://code.jquery.com/jquery-1.12.4.min.js&quot;&gt;&lt;/script&gt;\n",
220+
" &lt;script src=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js&quot;&gt;&lt;/script&gt;\n",
221+
" &lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.js&quot;&gt;&lt;/script&gt;\n",
222+
" &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/npm/leaflet@1.6.0/dist/leaflet.css&quot;/&gt;\n",
223+
" &lt;link rel=&quot;stylesheet&quot; href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css&quot;/&gt;\n",
224+
" &lt;link rel=&quot;stylesheet&quot; href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css&quot;/&gt;\n",
225+
" &lt;link rel=&quot;stylesheet&quot; href=&quot;https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css&quot;/&gt;\n",
226+
" &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.css&quot;/&gt;\n",
227+
" &lt;link rel=&quot;stylesheet&quot; href=&quot;https://cdn.jsdelivr.net/gh/python-visualization/folium/folium/templates/leaflet.awesome.rotate.min.css&quot;/&gt;\n",
228+
" \n",
229+
" &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width,\n",
230+
" initial-scale=1.0, maximum-scale=1.0, user-scalable=no&quot; /&gt;\n",
231+
" &lt;style&gt;\n",
232+
" #map_78154250af135798ac7f2bc569a59169 {\n",
233+
" position: relative;\n",
234+
" width: 100.0%;\n",
235+
" height: 100.0%;\n",
236+
" left: 0.0%;\n",
237+
" top: 0.0%;\n",
238+
" }\n",
239+
" &lt;/style&gt;\n",
240+
" \n",
241+
"&lt;/head&gt;\n",
242+
"&lt;body&gt; \n",
243+
" \n",
244+
" &lt;div class=&quot;folium-map&quot; id=&quot;map_78154250af135798ac7f2bc569a59169&quot; &gt;&lt;/div&gt;\n",
245+
" \n",
246+
"&lt;/body&gt;\n",
247+
"&lt;script&gt; \n",
248+
" \n",
249+
" var map_78154250af135798ac7f2bc569a59169 = L.map(\n",
250+
" &quot;map_78154250af135798ac7f2bc569a59169&quot;,\n",
251+
" {\n",
252+
" center: [15.0, 0.0],\n",
253+
" crs: L.CRS.EPSG3857,\n",
254+
" zoom: 0,\n",
255+
" zoomControl: true,\n",
256+
" preferCanvas: false,\n",
257+
" }\n",
258+
" );\n",
259+
"\n",
260+
" \n",
261+
"\n",
262+
" \n",
263+
" \n",
264+
" var tile_layer_31cd067f08493791f9a7ac06ebbd6ccf = L.tileLayer(\n",
265+
" &quot;https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png&quot;,\n",
266+
" {&quot;attribution&quot;: &quot;Data by \\u0026copy; \\u003ca href=\\&quot;http://openstreetmap.org\\&quot;\\u003eOpenStreetMap\\u003c/a\\u003e, under \\u003ca href=\\&quot;http://www.openstreetmap.org/copyright\\&quot;\\u003eODbL\\u003c/a\\u003e.&quot;, &quot;detectRetina&quot;: false, &quot;maxNativeZoom&quot;: 18, &quot;maxZoom&quot;: 18, &quot;minZoom&quot;: 0, &quot;noWrap&quot;: false, &quot;opacity&quot;: 1, &quot;subdomains&quot;: &quot;abc&quot;, &quot;tms&quot;: false}\n",
267+
" ).addTo(map_78154250af135798ac7f2bc569a59169);\n",
268+
" \n",
269+
" \n",
270+
" var tile_layer_50f9ffe305dd1bd56a62210a2a1028aa = L.tileLayer(\n",
271+
" &quot;https://t4z3zffpeh.execute-api.us-east-1.amazonaws.com/md/tiles/WebMercatorQuad/{z}/{x}/{y}@1x?url=s3%3A%2F%2Fnex-gddp-cmip6%2FNEX-GDDP-CMIP6%2FCESM2%2Fhistorical%2Fr4i1p1f1%2Fhuss%2Fhuss_day_CESM2_historical_r4i1p1f1_gn_2014.nc\\u0026variable=huss\\u0026decode_times=true\\u0026rescale=0%2C0.001\\u0026colormap_name=viridis\\u0026datetime=2014-12-31T00%3A00%3A00Z&quot;,\n",
272+
" {&quot;attribution&quot;: &quot;NASA&quot;, &quot;detectRetina&quot;: false, &quot;maxNativeZoom&quot;: 18, &quot;maxZoom&quot;: 18, &quot;minNativeZoom&quot;: 0, &quot;minZoom&quot;: 0, &quot;noWrap&quot;: false, &quot;opacity&quot;: 1, &quot;subdomains&quot;: &quot;abc&quot;, &quot;tms&quot;: false}\n",
273+
" ).addTo(map_78154250af135798ac7f2bc569a59169);\n",
274+
" \n",
275+
"&lt;/script&gt;\" style=\"position:absolute;width:100%;height:100%;left:0;top:0;border:none !important;\" allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe></div></div>"
276+
],
277+
"text/plain": [
278+
"<folium.folium.Map at 0x119e24640>"
279+
]
280+
},
281+
"execution_count": 31,
282+
"metadata": {},
283+
"output_type": "execute_result"
284+
}
285+
],
286+
"source": [
287+
"from folium import Map, TileLayer\n",
288+
"\n",
289+
"r = httpx.get(\n",
290+
" f\"{endpoint}/WebMercatorQuad/tilejson.json\",\n",
291+
" params = {\n",
292+
" \"url\": \"s3://nex-gddp-cmip6/NEX-GDDP-CMIP6/CESM2/historical/r4i1p1f1/huss/huss_day_CESM2_historical_r4i1p1f1_gn_2014.nc\",\n",
293+
" \"variable\": \"huss\",\n",
294+
" \"decode_times\": True,\n",
295+
" \"rescale\": \"0,0.001\",\n",
296+
" \"colormap_name\": \"viridis\",\n",
297+
" \"datetime\": \"2014-12-31T00:00:00Z\"\n",
298+
" },\n",
299+
" timeout=20,\n",
300+
").json()\n",
301+
"\n",
302+
"bounds = r[\"bounds\"]\n",
303+
"maxzoom = r[\"maxzoom\"]\n",
304+
"\n",
305+
"m = Map(\n",
306+
" location=((bounds[1] + bounds[3]) / 2,(bounds[0] + bounds[2]) / 2),\n",
307+
" zoom_start=maxzoom\n",
308+
")\n",
309+
"\n",
310+
"TileLayer(\n",
311+
" tiles=r[\"tiles\"][0],\n",
312+
" opacity=1,\n",
313+
" attr=\"NASA\",\n",
314+
" min_native_zoom=maxzoom,\n",
315+
" max_native_zoom=maxzoom,\n",
316+
").add_to(m)\n",
317+
"\n",
318+
"m"
319+
]
320+
},
321+
{
322+
"cell_type": "code",
323+
"execution_count": null,
324+
"metadata": {},
325+
"outputs": [],
326+
"source": []
327+
}
328+
],
329+
"metadata": {
330+
"kernelspec": {
331+
"display_name": "py39",
332+
"language": "python",
333+
"name": "python3"
334+
},
335+
"language_info": {
336+
"codemirror_mode": {
337+
"name": "ipython",
338+
"version": 3
339+
},
340+
"file_extension": ".py",
341+
"mimetype": "text/x-python",
342+
"name": "python",
343+
"nbconvert_exporter": "python",
344+
"pygments_lexer": "ipython3",
345+
"version": "3.9.19"
346+
}
347+
},
348+
"nbformat": 4,
349+
"nbformat_minor": 2
350+
}

0 commit comments

Comments
 (0)