Debian Codegraph @

examples/nwm.ipynb

raw
1 {
2 "cells": [
3 {
4 "cell_type": "markdown",
5 "id": "d741d57e-03a1-4c35-b6af-6273992cdb03",
6 "metadata": {},
7 "source": [
8 "# Explore the National Water Model Reanalysis v2.1 \n",
9 "\n",
10 "\n",
11 "### CASE 1: each HDF file contains chunks in multiple variables; doesn't need h5py\n",
12 "\n",
13 "370k files."
14 ]
15 },
16 {
17 "cell_type": "code",
18 "execution_count": 1,
19 "id": "cab2ddcf",
20 "metadata": {},
21 "outputs": [
22 {
23 "name": "stderr",
24 "output_type": "stream",
25 "text": [
26 "/Users/mdurant/conda/envs/py38/lib/python3.8/site-packages/xarray/conventions.py:512: SerializationWarning: variable 'qBtmVertRunoff' has multiple fill values {-9999000, 0}, decoding all values to NaN.\n",
27 " new_vars[k] = decode_cf_variable(\n",
28 "/Users/mdurant/conda/envs/py38/lib/python3.8/site-packages/xarray/conventions.py:512: SerializationWarning: variable 'qBucket' has multiple fill values {-999900000, 0}, decoding all values to NaN.\n",
29 " new_vars[k] = decode_cf_variable(\n",
30 "/Users/mdurant/conda/envs/py38/lib/python3.8/site-packages/xarray/conventions.py:512: SerializationWarning: variable 'qSfcLatRunoff' has multiple fill values {-999900000, 0}, decoding all values to NaN.\n",
31 " new_vars[k] = decode_cf_variable(\n",
32 "/Users/mdurant/conda/envs/py38/lib/python3.8/site-packages/xarray/conventions.py:512: SerializationWarning: variable 'q_lateral' has multiple fill values {0, -99990}, decoding all values to NaN.\n",
33 " new_vars[k] = decode_cf_variable(\n",
34 "/Users/mdurant/conda/envs/py38/lib/python3.8/site-packages/xarray/conventions.py:512: SerializationWarning: variable 'streamflow' has multiple fill values {0, -999900}, decoding all values to NaN.\n",
35 " new_vars[k] = decode_cf_variable(\n",
36 "/Users/mdurant/conda/envs/py38/lib/python3.8/site-packages/xarray/conventions.py:512: SerializationWarning: variable 'velocity' has multiple fill values {0, -999900}, decoding all values to NaN.\n",
37 " new_vars[k] = decode_cf_variable(\n"
38 ]
39 },
40 {
41 "name": "stdout",
42 "output_type": "stream",
43 "text": [
44 "CPU times: user 38.5 s, sys: 1.56 s, total: 40.1 s\n",
45 "Wall time: 45.3 s\n"
46 ]
47 }
48 ],
49 "source": [
50 "%%time\n",
51 "import fsspec\n",
52 "import xarray as xr\n",
53 "mapper = fsspec.get_mapper(\n",
54 " \"reference://\",\n",
55 " fo=\"s3://esip-qhub-public/noaa/nwm/nwm_reanalysis.json.zst\",\n",
56 " target_options={\n",
57 " \"anon\": True,\n",
58 " \"compression\": \"zstd\"\n",
59 " },\n",
60 " remote_options={\"anon\": True}\n",
61 ")\n",
62 "ds = xr.open_dataset(mapper, engine=\"zarr\", backend_kwargs={\"consolidated\": False})"
63 ]
64 },
65 {
66 "cell_type": "code",
67 "execution_count": 2,
68 "id": "c656c93e-9c10-4676-a8c0-3e7f24306f70",
69 "metadata": {},
70 "outputs": [
71 {
72 "data": {
73 "text/html": [
74 "<div><svg style=\"position: absolute; width: 0; height: 0; overflow: hidden\">\n",
75 "<defs>\n",
76 "<symbol id=\"icon-database\" viewBox=\"0 0 32 32\">\n",
77 "<path d=\"M16 0c-8.837 0-16 2.239-16 5v4c0 2.761 7.163 5 16 5s16-2.239 16-5v-4c0-2.761-7.163-5-16-5z\"></path>\n",
78 "<path d=\"M16 17c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
79 "<path d=\"M16 26c-8.837 0-16-2.239-16-5v6c0 2.761 7.163 5 16 5s16-2.239 16-5v-6c0 2.761-7.163 5-16 5z\"></path>\n",
80 "</symbol>\n",
81 "<symbol id=\"icon-file-text2\" viewBox=\"0 0 32 32\">\n",
82 "<path d=\"M28.681 7.159c-0.694-0.947-1.662-2.053-2.724-3.116s-2.169-2.030-3.116-2.724c-1.612-1.182-2.393-1.319-2.841-1.319h-15.5c-1.378 0-2.5 1.121-2.5 2.5v27c0 1.378 1.122 2.5 2.5 2.5h23c1.378 0 2.5-1.122 2.5-2.5v-19.5c0-0.448-0.137-1.23-1.319-2.841zM24.543 5.457c0.959 0.959 1.712 1.825 2.268 2.543h-4.811v-4.811c0.718 0.556 1.584 1.309 2.543 2.268zM28 29.5c0 0.271-0.229 0.5-0.5 0.5h-23c-0.271 0-0.5-0.229-0.5-0.5v-27c0-0.271 0.229-0.5 0.5-0.5 0 0 15.499-0 15.5 0v7c0 0.552 0.448 1 1 1h7v19.5z\"></path>\n",
83 "<path d=\"M23 26h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
84 "<path d=\"M23 22h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
85 "<path d=\"M23 18h-14c-0.552 0-1-0.448-1-1s0.448-1 1-1h14c0.552 0 1 0.448 1 1s-0.448 1-1 1z\"></path>\n",
86 "</symbol>\n",
87 "</defs>\n",
88 "</svg>\n",
89 "<style>/* CSS stylesheet for displaying xarray objects in jupyterlab.\n",
90 " *\n",
91 " */\n",
92 "\n",
93 ":root {\n",
94 " --xr-font-color0: var(--jp-content-font-color0, rgba(0, 0, 0, 1));\n",
95 " --xr-font-color2: var(--jp-content-font-color2, rgba(0, 0, 0, 0.54));\n",
96 " --xr-font-color3: var(--jp-content-font-color3, rgba(0, 0, 0, 0.38));\n",
97 " --xr-border-color: var(--jp-border-color2, #e0e0e0);\n",
98 " --xr-disabled-color: var(--jp-layout-color3, #bdbdbd);\n",
99 " --xr-background-color: var(--jp-layout-color0, white);\n",
100 " --xr-background-color-row-even: var(--jp-layout-color1, white);\n",
101 " --xr-background-color-row-odd: var(--jp-layout-color2, #eeeeee);\n",
102 "}\n",
103 "\n",
104 "html[theme=dark],\n",
105 "body.vscode-dark {\n",
106 " --xr-font-color0: rgba(255, 255, 255, 1);\n",
107 " --xr-font-color2: rgba(255, 255, 255, 0.54);\n",
108 " --xr-font-color3: rgba(255, 255, 255, 0.38);\n",
109 " --xr-border-color: #1F1F1F;\n",
110 " --xr-disabled-color: #515151;\n",
111 " --xr-background-color: #111111;\n",
112 " --xr-background-color-row-even: #111111;\n",
113 " --xr-background-color-row-odd: #313131;\n",
114 "}\n",
115 "\n",
116 ".xr-wrap {\n",
117 " display: block;\n",
118 " min-width: 300px;\n",
119 " max-width: 700px;\n",
120 "}\n",
121 "\n",
122 ".xr-text-repr-fallback {\n",
123 " /* fallback to plain text repr when CSS is not injected (untrusted notebook) */\n",
124 " display: none;\n",
125 "}\n",
126 "\n",
127 ".xr-header {\n",
128 " padding-top: 6px;\n",
129 " padding-bottom: 6px;\n",
130 " margin-bottom: 4px;\n",
131 " border-bottom: solid 1px var(--xr-border-color);\n",
132 "}\n",
133 "\n",
134 ".xr-header > div,\n",
135 ".xr-header > ul {\n",
136 " display: inline;\n",
137 " margin-top: 0;\n",
138 " margin-bottom: 0;\n",
139 "}\n",
140 "\n",
141 ".xr-obj-type,\n",
142 ".xr-array-name {\n",
143 " margin-left: 2px;\n",
144 " margin-right: 10px;\n",
145 "}\n",
146 "\n",
147 ".xr-obj-type {\n",
148 " color: var(--xr-font-color2);\n",
149 "}\n",
150 "\n",
151 ".xr-sections {\n",
152 " padding-left: 0 !important;\n",
153 " display: grid;\n",
154 " grid-template-columns: 150px auto auto 1fr 20px 20px;\n",
155 "}\n",
156 "\n",
157 ".xr-section-item {\n",
158 " display: contents;\n",
159 "}\n",
160 "\n",
161 ".xr-section-item input {\n",
162 " display: none;\n",
163 "}\n",
164 "\n",
165 ".xr-section-item input + label {\n",
166 " color: var(--xr-disabled-color);\n",
167 "}\n",
168 "\n",
169 ".xr-section-item input:enabled + label {\n",
170 " cursor: pointer;\n",
171 " color: var(--xr-font-color2);\n",
172 "}\n",
173 "\n",
174 ".xr-section-item input:enabled + label:hover {\n",
175 " color: var(--xr-font-color0);\n",
176 "}\n",
177 "\n",
178 ".xr-section-summary {\n",
179 " grid-column: 1;\n",
180 " color: var(--xr-font-color2);\n",
181 " font-weight: 500;\n",
182 "}\n",
183 "\n",
184 ".xr-section-summary > span {\n",
185 " display: inline-block;\n",
186 " padding-left: 0.5em;\n",
187 "}\n",
188 "\n",
189 ".xr-section-summary-in:disabled + label {\n",
190 " color: var(--xr-font-color2);\n",
191 "}\n",
192 "\n",
193 ".xr-section-summary-in + label:before {\n",
194 " display: inline-block;\n",
195 " content: '►';\n",
196 " font-size: 11px;\n",
197 " width: 15px;\n",
198 " text-align: center;\n",
199 "}\n",
200 "\n",
201 ".xr-section-summary-in:disabled + label:before {\n",
202 " color: var(--xr-disabled-color);\n",
203 "}\n",
204 "\n",
205 ".xr-section-summary-in:checked + label:before {\n",
206 " content: '▼';\n",
207 "}\n",
208 "\n",
209 ".xr-section-summary-in:checked + label > span {\n",
210 " display: none;\n",
211 "}\n",
212 "\n",
213 ".xr-section-summary,\n",
214 ".xr-section-inline-details {\n",
215 " padding-top: 4px;\n",
216 " padding-bottom: 4px;\n",
217 "}\n",
218 "\n",
219 ".xr-section-inline-details {\n",
220 " grid-column: 2 / -1;\n",
221 "}\n",
222 "\n",
223 ".xr-section-details {\n",
224 " display: none;\n",
225 " grid-column: 1 / -1;\n",
226 " margin-bottom: 5px;\n",
227 "}\n",
228 "\n",
229 ".xr-section-summary-in:checked ~ .xr-section-details {\n",
230 " display: contents;\n",
231 "}\n",
232 "\n",
233 ".xr-array-wrap {\n",
234 " grid-column: 1 / -1;\n",
235 " display: grid;\n",
236 " grid-template-columns: 20px auto;\n",
237 "}\n",
238 "\n",
239 ".xr-array-wrap > label {\n",
240 " grid-column: 1;\n",
241 " vertical-align: top;\n",
242 "}\n",
243 "\n",
244 ".xr-preview {\n",
245 " color: var(--xr-font-color3);\n",
246 "}\n",
247 "\n",
248 ".xr-array-preview,\n",
249 ".xr-array-data {\n",
250 " padding: 0 5px !important;\n",
251 " grid-column: 2;\n",
252 "}\n",
253 "\n",
254 ".xr-array-data,\n",
255 ".xr-array-in:checked ~ .xr-array-preview {\n",
256 " display: none;\n",
257 "}\n",
258 "\n",
259 ".xr-array-in:checked ~ .xr-array-data,\n",
260 ".xr-array-preview {\n",
261 " display: inline-block;\n",
262 "}\n",
263 "\n",
264 ".xr-dim-list {\n",
265 " display: inline-block !important;\n",
266 " list-style: none;\n",
267 " padding: 0 !important;\n",
268 " margin: 0;\n",
269 "}\n",
270 "\n",
271 ".xr-dim-list li {\n",
272 " display: inline-block;\n",
273 " padding: 0;\n",
274 " margin: 0;\n",
275 "}\n",
276 "\n",
277 ".xr-dim-list:before {\n",
278 " content: '(';\n",
279 "}\n",
280 "\n",
281 ".xr-dim-list:after {\n",
282 " content: ')';\n",
283 "}\n",
284 "\n",
285 ".xr-dim-list li:not(:last-child):after {\n",
286 " content: ',';\n",
287 " padding-right: 5px;\n",
288 "}\n",
289 "\n",
290 ".xr-has-index {\n",
291 " font-weight: bold;\n",
292 "}\n",
293 "\n",
294 ".xr-var-list,\n",
295 ".xr-var-item {\n",
296 " display: contents;\n",
297 "}\n",
298 "\n",
299 ".xr-var-item > div,\n",
300 ".xr-var-item label,\n",
301 ".xr-var-item > .xr-var-name span {\n",
302 " background-color: var(--xr-background-color-row-even);\n",
303 " margin-bottom: 0;\n",
304 "}\n",
305 "\n",
306 ".xr-var-item > .xr-var-name:hover span {\n",
307 " padding-right: 5px;\n",
308 "}\n",
309 "\n",
310 ".xr-var-list > li:nth-child(odd) > div,\n",
311 ".xr-var-list > li:nth-child(odd) > label,\n",
312 ".xr-var-list > li:nth-child(odd) > .xr-var-name span {\n",
313 " background-color: var(--xr-background-color-row-odd);\n",
314 "}\n",
315 "\n",
316 ".xr-var-name {\n",
317 " grid-column: 1;\n",
318 "}\n",
319 "\n",
320 ".xr-var-dims {\n",
321 " grid-column: 2;\n",
322 "}\n",
323 "\n",
324 ".xr-var-dtype {\n",
325 " grid-column: 3;\n",
326 " text-align: right;\n",
327 " color: var(--xr-font-color2);\n",
328 "}\n",
329 "\n",
330 ".xr-var-preview {\n",
331 " grid-column: 4;\n",
332 "}\n",
333 "\n",
334 ".xr-var-name,\n",
335 ".xr-var-dims,\n",
336 ".xr-var-dtype,\n",
337 ".xr-preview,\n",
338 ".xr-attrs dt {\n",
339 " white-space: nowrap;\n",
340 " overflow: hidden;\n",
341 " text-overflow: ellipsis;\n",
342 " padding-right: 10px;\n",
343 "}\n",
344 "\n",
345 ".xr-var-name:hover,\n",
346 ".xr-var-dims:hover,\n",
347 ".xr-var-dtype:hover,\n",
348 ".xr-attrs dt:hover {\n",
349 " overflow: visible;\n",
350 " width: auto;\n",
351 " z-index: 1;\n",
352 "}\n",
353 "\n",
354 ".xr-var-attrs,\n",
355 ".xr-var-data {\n",
356 " display: none;\n",
357 " background-color: var(--xr-background-color) !important;\n",
358 " padding-bottom: 5px !important;\n",
359 "}\n",
360 "\n",
361 ".xr-var-attrs-in:checked ~ .xr-var-attrs,\n",
362 ".xr-var-data-in:checked ~ .xr-var-data {\n",
363 " display: block;\n",
364 "}\n",
365 "\n",
366 ".xr-var-data > table {\n",
367 " float: right;\n",
368 "}\n",
369 "\n",
370 ".xr-var-name span,\n",
371 ".xr-var-data,\n",
372 ".xr-attrs {\n",
373 " padding-left: 25px !important;\n",
374 "}\n",
375 "\n",
376 ".xr-attrs,\n",
377 ".xr-var-attrs,\n",
378 ".xr-var-data {\n",
379 " grid-column: 1 / -1;\n",
380 "}\n",
381 "\n",
382 "dl.xr-attrs {\n",
383 " padding: 0;\n",
384 " margin: 0;\n",
385 " display: grid;\n",
386 " grid-template-columns: 125px auto;\n",
387 "}\n",
388 "\n",
389 ".xr-attrs dt,\n",
390 ".xr-attrs dd {\n",
391 " padding: 0;\n",
392 " margin: 0;\n",
393 " float: left;\n",
394 " padding-right: 10px;\n",
395 " width: auto;\n",
396 "}\n",
397 "\n",
398 ".xr-attrs dt {\n",
399 " font-weight: normal;\n",
400 " grid-column: 1;\n",
401 "}\n",
402 "\n",
403 ".xr-attrs dt:hover span {\n",
404 " display: inline-block;\n",
405 " background: var(--xr-background-color);\n",
406 " padding-right: 10px;\n",
407 "}\n",
408 "\n",
409 ".xr-attrs dd {\n",
410 " grid-column: 2;\n",
411 " white-space: pre-wrap;\n",
412 " word-break: break-all;\n",
413 "}\n",
414 "\n",
415 ".xr-icon-database,\n",
416 ".xr-icon-file-text2 {\n",
417 " display: inline-block;\n",
418 " vertical-align: middle;\n",
419 " width: 1em;\n",
420 " height: 1.5em !important;\n",
421 " stroke-width: 0;\n",
422 " stroke: currentColor;\n",
423 " fill: currentColor;\n",
424 "}\n",
425 "</style><pre class='xr-text-repr-fallback'>&lt;xarray.Dataset&gt;\n",
426 "Dimensions: (time: 367439, feature_id: 2776738)\n",
427 "Coordinates:\n",
428 " * feature_id (feature_id) float64 101.0 179.0 181.0 ... 1.18e+09 1.18e+09\n",
429 " latitude (feature_id) float32 ...\n",
430 " longitude (feature_id) float32 ...\n",
431 " * time (time) datetime64[ns] 1979-02-01T01:00:00 ... 2020-12-31T...\n",
432 "Data variables:\n",
433 " elevation (time, feature_id) float32 ...\n",
434 " order (time, feature_id) float64 ...\n",
435 " qBtmVertRunoff (time, feature_id) float64 ...\n",
436 " qBucket (time, feature_id) float64 ...\n",
437 " qSfcLatRunoff (time, feature_id) float64 ...\n",
438 " q_lateral (time, feature_id) float64 ...\n",
439 " streamflow (time, feature_id) float64 ...\n",
440 " velocity (time, feature_id) float64 ...\n",
441 "Attributes: (12/19)\n",
442 " Conventions: CF-1.6\n",
443 " TITLE: OUTPUT FROM WRF-Hydro v5.2.0-beta2\n",
444 " _NCProperties: version=2,netcdf=4.7.4,hdf5=1.10.7,\n",
445 " cdm_datatype: Station\n",
446 " code_version: v5.2.0-beta2\n",
447 " dev: dev_ prefix indicates development/internal me...\n",
448 " ... ...\n",
449 " model_output_type: channel_rt\n",
450 " model_output_valid_time: 1979-02-01_01:00:00\n",
451 " model_total_valid_times: 1416\n",
452 " proj4: +proj=lcc +units=m +a=6370000.0 +b=6370000.0 ...\n",
453 " station_dimension: feature_id\n",
454 " stream_order_output: 1</pre><div class='xr-wrap' hidden><div class='xr-header'><div class='xr-obj-type'>xarray.Dataset</div></div><ul class='xr-sections'><li class='xr-section-item'><input id='section-56f5ce15-53cf-43d7-aba6-c33816137fe0' class='xr-section-summary-in' type='checkbox' disabled ><label for='section-56f5ce15-53cf-43d7-aba6-c33816137fe0' class='xr-section-summary' title='Expand/collapse section'>Dimensions:</label><div class='xr-section-inline-details'><ul class='xr-dim-list'><li><span class='xr-has-index'>time</span>: 367439</li><li><span class='xr-has-index'>feature_id</span>: 2776738</li></ul></div><div class='xr-section-details'></div></li><li class='xr-section-item'><input id='section-b3f72ac8-941b-42b8-adea-44eccaa9ac90' class='xr-section-summary-in' type='checkbox' checked><label for='section-b3f72ac8-941b-42b8-adea-44eccaa9ac90' class='xr-section-summary' >Coordinates: <span>(4)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>feature_id</span></div><div class='xr-var-dims'>(feature_id)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>101.0 179.0 ... 1.18e+09 1.18e+09</div><input id='attrs-f3668a03-3932-4260-bc13-313309f33476' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-f3668a03-3932-4260-bc13-313309f33476' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-0a9409b1-5308-4d0a-8f31-0ff0db4ba462' class='xr-var-data-in' type='checkbox'><label for='data-0a9409b1-5308-4d0a-8f31-0ff0db4ba462' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>NAME :</span></dt><dd>feature_id</dd><dt><span>_Netcdf4Dimid :</span></dt><dd>0</dd><dt><span>cf_role :</span></dt><dd>timeseries_id</dd><dt><span>comment :</span></dt><dd>NHDPlusv2 ComIDs within CONUS, arbitrary Reach IDs outside of CONUS</dd><dt><span>long_name :</span></dt><dd>Reach ID</dd></dl></div><div class='xr-var-data'><pre>array([1.010000e+02, 1.790000e+02, 1.810000e+02, ..., 1.180002e+09,\n",
455 " 1.180002e+09, 1.180002e+09])</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>latitude</span></div><div class='xr-var-dims'>(feature_id)</div><div class='xr-var-dtype'>float32</div><div class='xr-var-preview xr-preview'>...</div><input id='attrs-bf08cf8e-53e8-473f-b390-992f9b31528f' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-bf08cf8e-53e8-473f-b390-992f9b31528f' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-13538224-1cd1-49b4-87ad-1d8f0b12be47' class='xr-var-data-in' type='checkbox'><label for='data-13538224-1cd1-49b4-87ad-1d8f0b12be47' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>_Netcdf4Dimid :</span></dt><dd>0</dd><dt><span>long_name :</span></dt><dd>Feature latitude</dd><dt><span>standard_name :</span></dt><dd>latitude</dd><dt><span>units :</span></dt><dd>degrees_north</dd></dl></div><div class='xr-var-data'><pre>[2776738 values with dtype=float32]</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>longitude</span></div><div class='xr-var-dims'>(feature_id)</div><div class='xr-var-dtype'>float32</div><div class='xr-var-preview xr-preview'>...</div><input id='attrs-d1c2b135-dfdf-4356-aa30-6bc3b8a5d6c9' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-d1c2b135-dfdf-4356-aa30-6bc3b8a5d6c9' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-743de482-f441-496c-9608-7418336f6f21' class='xr-var-data-in' type='checkbox'><label for='data-743de482-f441-496c-9608-7418336f6f21' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>_Netcdf4Dimid :</span></dt><dd>0</dd><dt><span>long_name :</span></dt><dd>Feature longitude</dd><dt><span>standard_name :</span></dt><dd>longitude</dd><dt><span>units :</span></dt><dd>degrees_east</dd></dl></div><div class='xr-var-data'><pre>[2776738 values with dtype=float32]</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span class='xr-has-index'>time</span></div><div class='xr-var-dims'>(time)</div><div class='xr-var-dtype'>datetime64[ns]</div><div class='xr-var-preview xr-preview'>1979-02-01T01:00:00 ... 2020-12-...</div><input id='attrs-745f9609-4d6d-430b-a81c-877f5763d703' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-745f9609-4d6d-430b-a81c-877f5763d703' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-415a8a3d-8bdd-4eb5-80b0-755d368be12d' class='xr-var-data-in' type='checkbox'><label for='data-415a8a3d-8bdd-4eb5-80b0-755d368be12d' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>NAME :</span></dt><dd>time</dd><dt><span>_Netcdf4Dimid :</span></dt><dd>1</dd><dt><span>long_name :</span></dt><dd>valid output time</dd><dt><span>standard_name :</span></dt><dd>time</dd><dt><span>valid_max :</span></dt><dd>4862880</dd><dt><span>valid_min :</span></dt><dd>4777980</dd></dl></div><div class='xr-var-data'><pre>array([&#x27;1979-02-01T01:00:00.000000000&#x27;, &#x27;1979-02-01T02:00:00.000000000&#x27;,\n",
456 " &#x27;1979-02-01T03:00:00.000000000&#x27;, ..., &#x27;2020-12-31T21:00:00.000000000&#x27;,\n",
457 " &#x27;2020-12-31T22:00:00.000000000&#x27;, &#x27;2020-12-31T23:00:00.000000000&#x27;],\n",
458 " dtype=&#x27;datetime64[ns]&#x27;)</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-0b7d1138-3222-490b-be5a-4d1d8378c3ea' class='xr-section-summary-in' type='checkbox' checked><label for='section-0b7d1138-3222-490b-be5a-4d1d8378c3ea' class='xr-section-summary' >Data variables: <span>(8)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><ul class='xr-var-list'><li class='xr-var-item'><div class='xr-var-name'><span>elevation</span></div><div class='xr-var-dims'>(time, feature_id)</div><div class='xr-var-dtype'>float32</div><div class='xr-var-preview xr-preview'>...</div><input id='attrs-6e9b4965-91c4-4860-9e1f-14f6fa867a0b' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-6e9b4965-91c4-4860-9e1f-14f6fa867a0b' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-4971682e-8ece-4210-949d-a0524771f281' class='xr-var-data-in' type='checkbox'><label for='data-4971682e-8ece-4210-949d-a0524771f281' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>_Netcdf4Dimid :</span></dt><dd>0</dd><dt><span>long_name :</span></dt><dd>Feature Elevation</dd><dt><span>standard_name :</span></dt><dd>Elevation</dd><dt><span>units :</span></dt><dd>meters</dd></dl></div><div class='xr-var-data'><pre>[1020281833982 values with dtype=float32]</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>order</span></div><div class='xr-var-dims'>(time, feature_id)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>...</div><input id='attrs-7b1e1e41-047a-454e-8b47-fd6d4397e38b' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-7b1e1e41-047a-454e-8b47-fd6d4397e38b' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-eebe33ac-39f5-4080-a00d-8367176093e8' class='xr-var-data-in' type='checkbox'><label for='data-eebe33ac-39f5-4080-a00d-8367176093e8' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>_Netcdf4Dimid :</span></dt><dd>0</dd><dt><span>long_name :</span></dt><dd>Streamflow Order</dd><dt><span>standard_name :</span></dt><dd>order</dd></dl></div><div class='xr-var-data'><pre>[1020281833982 values with dtype=float64]</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>qBtmVertRunoff</span></div><div class='xr-var-dims'>(time, feature_id)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>...</div><input id='attrs-5d159a4c-b940-4d78-b0c6-e14ad4c5a18b' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-5d159a4c-b940-4d78-b0c6-e14ad4c5a18b' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-18bd8201-2e00-46f0-8b6e-6dc3acb8db13' class='xr-var-data-in' type='checkbox'><label for='data-18bd8201-2e00-46f0-8b6e-6dc3acb8db13' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>_Netcdf4Dimid :</span></dt><dd>0</dd><dt><span>grid_mapping :</span></dt><dd>crs</dd><dt><span>long_name :</span></dt><dd>Runoff from bottom of soil to bucket</dd><dt><span>units :</span></dt><dd>m3</dd><dt><span>valid_range :</span></dt><dd>[0, 20000000]</dd></dl></div><div class='xr-var-data'><pre>[1020281833982 values with dtype=float64]</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>qBucket</span></div><div class='xr-var-dims'>(time, feature_id)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>...</div><input id='attrs-d8931c37-f51d-4f39-b7a3-09a8934df3c4' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-d8931c37-f51d-4f39-b7a3-09a8934df3c4' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-59c6c288-8120-466c-94f9-537c0c97116b' class='xr-var-data-in' type='checkbox'><label for='data-59c6c288-8120-466c-94f9-537c0c97116b' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>_Netcdf4Dimid :</span></dt><dd>0</dd><dt><span>grid_mapping :</span></dt><dd>crs</dd><dt><span>long_name :</span></dt><dd>Flux from gw bucket</dd><dt><span>units :</span></dt><dd>m3 s-1</dd><dt><span>valid_range :</span></dt><dd>[0, 2000000000]</dd></dl></div><div class='xr-var-data'><pre>[1020281833982 values with dtype=float64]</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>qSfcLatRunoff</span></div><div class='xr-var-dims'>(time, feature_id)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>...</div><input id='attrs-ee333a50-ea6b-4f77-bb84-9860bd48e5f5' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-ee333a50-ea6b-4f77-bb84-9860bd48e5f5' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-7f1b3f8e-b772-4e6d-a28e-843dd41f9813' class='xr-var-data-in' type='checkbox'><label for='data-7f1b3f8e-b772-4e6d-a28e-843dd41f9813' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>_Netcdf4Dimid :</span></dt><dd>0</dd><dt><span>grid_mapping :</span></dt><dd>crs</dd><dt><span>long_name :</span></dt><dd>Runoff from terrain routing</dd><dt><span>units :</span></dt><dd>m3 s-1</dd><dt><span>valid_range :</span></dt><dd>[0, 2000000000]</dd></dl></div><div class='xr-var-data'><pre>[1020281833982 values with dtype=float64]</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>q_lateral</span></div><div class='xr-var-dims'>(time, feature_id)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>...</div><input id='attrs-ed8acfff-b081-4fe7-b99a-2a3e7fc0e98a' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-ed8acfff-b081-4fe7-b99a-2a3e7fc0e98a' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-1910f242-0328-4105-bdc1-3c65ae918f0c' class='xr-var-data-in' type='checkbox'><label for='data-1910f242-0328-4105-bdc1-3c65ae918f0c' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>_Netcdf4Dimid :</span></dt><dd>0</dd><dt><span>grid_mapping :</span></dt><dd>crs</dd><dt><span>long_name :</span></dt><dd>Runoff into channel reach</dd><dt><span>units :</span></dt><dd>m3 s-1</dd><dt><span>valid_range :</span></dt><dd>[0, 500000]</dd></dl></div><div class='xr-var-data'><pre>[1020281833982 values with dtype=float64]</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>streamflow</span></div><div class='xr-var-dims'>(time, feature_id)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>...</div><input id='attrs-a458dd3c-e7d2-41ef-8833-ecb157d8d387' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-a458dd3c-e7d2-41ef-8833-ecb157d8d387' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-71874e0c-a572-4f58-9095-678284fd0e85' class='xr-var-data-in' type='checkbox'><label for='data-71874e0c-a572-4f58-9095-678284fd0e85' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>_Netcdf4Dimid :</span></dt><dd>0</dd><dt><span>grid_mapping :</span></dt><dd>crs</dd><dt><span>long_name :</span></dt><dd>River Flow</dd><dt><span>units :</span></dt><dd>m3 s-1</dd><dt><span>valid_range :</span></dt><dd>[0, 5000000]</dd></dl></div><div class='xr-var-data'><pre>[1020281833982 values with dtype=float64]</pre></div></li><li class='xr-var-item'><div class='xr-var-name'><span>velocity</span></div><div class='xr-var-dims'>(time, feature_id)</div><div class='xr-var-dtype'>float64</div><div class='xr-var-preview xr-preview'>...</div><input id='attrs-b46430f3-f3dd-401e-b61e-4db688fcda7b' class='xr-var-attrs-in' type='checkbox' ><label for='attrs-b46430f3-f3dd-401e-b61e-4db688fcda7b' title='Show/Hide attributes'><svg class='icon xr-icon-file-text2'><use xlink:href='#icon-file-text2'></use></svg></label><input id='data-c41f32e0-619c-4273-a72f-0b3efbc2c533' class='xr-var-data-in' type='checkbox'><label for='data-c41f32e0-619c-4273-a72f-0b3efbc2c533' title='Show/Hide data repr'><svg class='icon xr-icon-database'><use xlink:href='#icon-database'></use></svg></label><div class='xr-var-attrs'><dl class='xr-attrs'><dt><span>_Netcdf4Dimid :</span></dt><dd>0</dd><dt><span>grid_mapping :</span></dt><dd>crs</dd><dt><span>long_name :</span></dt><dd>River Velocity</dd><dt><span>units :</span></dt><dd>m s-1</dd><dt><span>valid_range :</span></dt><dd>[0, 5000000]</dd></dl></div><div class='xr-var-data'><pre>[1020281833982 values with dtype=float64]</pre></div></li></ul></div></li><li class='xr-section-item'><input id='section-b5a48e23-3b48-487f-82a3-e7eb0a10ef20' class='xr-section-summary-in' type='checkbox' ><label for='section-b5a48e23-3b48-487f-82a3-e7eb0a10ef20' class='xr-section-summary' >Attributes: <span>(19)</span></label><div class='xr-section-inline-details'></div><div class='xr-section-details'><dl class='xr-attrs'><dt><span>Conventions :</span></dt><dd>CF-1.6</dd><dt><span>TITLE :</span></dt><dd>OUTPUT FROM WRF-Hydro v5.2.0-beta2</dd><dt><span>_NCProperties :</span></dt><dd>version=2,netcdf=4.7.4,hdf5=1.10.7,</dd><dt><span>cdm_datatype :</span></dt><dd>Station</dd><dt><span>code_version :</span></dt><dd>v5.2.0-beta2</dd><dt><span>dev :</span></dt><dd>dev_ prefix indicates development/internal meta data</dd><dt><span>dev_NOAH_TIMESTEP :</span></dt><dd>3600</dd><dt><span>dev_OVRTSWCRT :</span></dt><dd>1</dd><dt><span>dev_channelBucket_only :</span></dt><dd>0</dd><dt><span>dev_channel_only :</span></dt><dd>0</dd><dt><span>featureType :</span></dt><dd>timeSeries</dd><dt><span>model_configuration :</span></dt><dd>retrospective</dd><dt><span>model_initialization_time :</span></dt><dd>1979-02-01_00:00:00</dd><dt><span>model_output_type :</span></dt><dd>channel_rt</dd><dt><span>model_output_valid_time :</span></dt><dd>1979-02-01_01:00:00</dd><dt><span>model_total_valid_times :</span></dt><dd>1416</dd><dt><span>proj4 :</span></dt><dd>+proj=lcc +units=m +a=6370000.0 +b=6370000.0 +lat_1=30.0 +lat_2=60.0 +lat_0=40.0 +lon_0=-97.0 +x_0=0 +y_0=0 +k_0=1.0 +nadgrids=@</dd><dt><span>station_dimension :</span></dt><dd>feature_id</dd><dt><span>stream_order_output :</span></dt><dd>1</dd></dl></div></li></ul></div></div>"
459 ],
460 "text/plain": [
461 "<xarray.Dataset>\n",
462 "Dimensions: (time: 367439, feature_id: 2776738)\n",
463 "Coordinates:\n",
464 " * feature_id (feature_id) float64 101.0 179.0 181.0 ... 1.18e+09 1.18e+09\n",
465 " latitude (feature_id) float32 ...\n",
466 " longitude (feature_id) float32 ...\n",
467 " * time (time) datetime64[ns] 1979-02-01T01:00:00 ... 2020-12-31T...\n",
468 "Data variables:\n",
469 " elevation (time, feature_id) float32 ...\n",
470 " order (time, feature_id) float64 ...\n",
471 " qBtmVertRunoff (time, feature_id) float64 ...\n",
472 " qBucket (time, feature_id) float64 ...\n",
473 " qSfcLatRunoff (time, feature_id) float64 ...\n",
474 " q_lateral (time, feature_id) float64 ...\n",
475 " streamflow (time, feature_id) float64 ...\n",
476 " velocity (time, feature_id) float64 ...\n",
477 "Attributes: (12/19)\n",
478 " Conventions: CF-1.6\n",
479 " TITLE: OUTPUT FROM WRF-Hydro v5.2.0-beta2\n",
480 " _NCProperties: version=2,netcdf=4.7.4,hdf5=1.10.7,\n",
481 " cdm_datatype: Station\n",
482 " code_version: v5.2.0-beta2\n",
483 " dev: dev_ prefix indicates development/internal me...\n",
484 " ... ...\n",
485 " model_output_type: channel_rt\n",
486 " model_output_valid_time: 1979-02-01_01:00:00\n",
487 " model_total_valid_times: 1416\n",
488 " proj4: +proj=lcc +units=m +a=6370000.0 +b=6370000.0 ...\n",
489 " station_dimension: feature_id\n",
490 " stream_order_output: 1"
491 ]
492 },
493 "execution_count": 2,
494 "metadata": {},
495 "output_type": "execute_result"
496 }
497 ],
498 "source": [
499 "ds"
500 ]
501 },
502 {
503 "cell_type": "code",
504 "execution_count": 3,
505 "id": "e196d737-9c7c-48c3-a5f0-44e390375426",
506 "metadata": {
507 "pycharm": {
508 "is_executing": true
509 }
510 },
511 "outputs": [
512 {
513 "data": {
514 "text/plain": [
515 "(61.21695740624, 8.162254671856)"
516 ]
517 },
518 "execution_count": 3,
519 "metadata": {},
520 "output_type": "execute_result"
521 }
522 ],
523 "source": [
524 "ds.nbytes/1e12, ds.streamflow.nbytes/1e12 # How many terabytes total/in a single variable"
525 ]
526 },
527 {
528 "cell_type": "markdown",
529 "id": "fa498305-a6ad-419d-a2dc-a9584eb4510c",
530 "metadata": {},
531 "source": [
532 "#### Read and plot streamflow for a specific time \n",
533 "The local National Weather Service office in Houston observed all-time record daily rainfall accumulations on both August 26 and 27, measured at 14.4 in (370 mm) and 16.08 in (408 mm) respectively"
534 ]
535 },
536 {
537 "cell_type": "code",
538 "execution_count": null,
539 "id": "8b4117e1-7b6b-40bd-aa5c-1530828dd257",
540 "metadata": {
541 "pycharm": {
542 "is_executing": true
543 }
544 },
545 "outputs": [],
546 "source": [
547 "import hvplot.pandas\n",
548 "import geoviews as gv\n",
549 "from holoviews.operation.datashader import rasterize\n",
550 "import cartopy.crs as ccrs\n",
551 "import numpy as np\n",
552 "import pandas as pd"
553 ]
554 },
555 {
556 "cell_type": "code",
557 "execution_count": null,
558 "id": "d0de6dd8-9ec8-476e-bbee-59e433ec0017",
559 "metadata": {
560 "pycharm": {
561 "is_executing": true
562 }
563 },
564 "outputs": [],
565 "source": [
566 "ds1 = ds.sel(time='2017-08-27 18:00:00', method='nearest')"
567 ]
568 },
569 {
570 "cell_type": "code",
571 "execution_count": null,
572 "id": "d1b32143-bfa5-4803-922a-baf937840904",
573 "metadata": {
574 "pycharm": {
575 "is_executing": true
576 }
577 },
578 "outputs": [],
579 "source": [
580 "var = 'streamflow'"
581 ]
582 },
583 {
584 "cell_type": "code",
585 "execution_count": null,
586 "id": "ad8edc51-f843-4c5a-8207-d6d2e24676f0",
587 "metadata": {
588 "pycharm": {
589 "is_executing": true
590 }
591 },
592 "outputs": [],
593 "source": [
594 "df = ds1[var].to_pandas().to_frame()"
595 ]
596 },
597 {
598 "cell_type": "code",
599 "execution_count": null,
600 "id": "301888d3-a29d-4cf9-839c-a31ecdd88759",
601 "metadata": {
602 "pycharm": {
603 "is_executing": true
604 }
605 },
606 "outputs": [],
607 "source": [
608 "date_title = pd.to_datetime(ds1.time.values).strftime('%Y-%m-%d %H-%M-%D')\n",
609 "date_title = f'{var}: {date_title}'\n",
610 "date_title"
611 ]
612 },
613 {
614 "cell_type": "code",
615 "execution_count": null,
616 "id": "2ff4f769-e030-444e-a489-96075f7d478c",
617 "metadata": {
618 "pycharm": {
619 "is_executing": true
620 }
621 },
622 "outputs": [],
623 "source": [
624 "df = df.assign(latitude=ds.latitude)\n",
625 "df = df.assign(longitude=ds.longitude)\n",
626 "df.rename(columns={0: var}, inplace=True)"
627 ]
628 },
629 {
630 "cell_type": "code",
631 "execution_count": null,
632 "id": "fe8b09e6-dcab-4063-9778-67f6c1c2e938",
633 "metadata": {
634 "pycharm": {
635 "is_executing": true
636 }
637 },
638 "outputs": [],
639 "source": [
640 "p = df.hvplot.points(x='longitude', y='latitude', geo=True,\n",
641 " c=var, colorbar=True, size=14, label=date_title)\n",
642 "g = rasterize(p, aggregator='mean', x_sampling=0.02, \n",
643 " y_sampling=0.02, width=500).opts(tools=['hover'], \n",
644 " aspect='equal', logz=True, cmap='viridis', clim=(1e-2, np.nan))\n",
645 "g * gv.tile_sources.OSM"
646 ]
647 },
648 {
649 "cell_type": "code",
650 "execution_count": null,
651 "id": "c9b3f239",
652 "metadata": {
653 "pycharm": {
654 "is_executing": true
655 }
656 },
657 "outputs": [],
658 "source": []
659 }
660 ],
661 "metadata": {
662 "kernelspec": {
663 "display_name": "Python 3",
664 "language": "python",
665 "name": "python3"
666 },
667 "language_info": {
668 "codemirror_mode": {
669 "name": "ipython",
670 "version": 3
671 },
672 "file_extension": ".py",
673 "mimetype": "text/x-python",
674 "name": "python",
675 "nbconvert_exporter": "python",
676 "pygments_lexer": "ipython3",
677 "version": "3.8.8"
678 },
679 "widgets": {
680 "application/vnd.jupyter.widget-state+json": {
681 "state": {},
682 "version_major": 2,
683 "version_minor": 0
684 }
685 }
686 },
687 "nbformat": 4,
688 "nbformat_minor": 5
689 }