Uncomment block that was accidentally committed
[notebooks.git] / tutorials / 04-mesowest_demo.ipynb
blobe5740a5e0d339c81f52d770a2744c5bb483f97fd
2  "cells": [
3   {
4    "cell_type": "markdown",
5    "metadata": {
6     "id": "NWVBxb_gnZEa"
7    },
8    "source": [
9     "### Python exercise - accessing weather station data by API, plus using dictionaries and jsons ###\n",
10     "See the [wrfxpy](https://github.com/openwfm/wrfxpy/blob/e5fa3fd5d67b4c3db493033f4940eda650ddc867/src/fmda/fuel_moisture_da.py#L124) code for a full version"
11    ]
12   },
13   {
14    "cell_type": "markdown",
15    "metadata": {
16     "id": "6uXVJj9koGF2"
17    },
18    "source": [
19     "First, make the API available"
20    ]
21   },
22   {
23    "cell_type": "code",
24    "execution_count": 1,
25    "metadata": {
26     "id": "w5I8Hz20nXMQ"
27    },
28    "outputs": [
29     {
30      "name": "stdout",
31      "output_type": "stream",
32      "text": [
33       "Collecting MesoPy\n",
34       "  Using cached MesoPy-2.0.3.tar.gz (7.2 kB)\n",
35       "Building wheels for collected packages: MesoPy\n",
36       "  Building wheel for MesoPy (setup.py) ... \u001b[?25ldone\n",
37       "\u001b[?25h  Created wheel for MesoPy: filename=MesoPy-2.0.3-py3-none-any.whl size=7793 sha256=9bfc494f18d1ac50e9a6c2eccbd4ac5b0ebd4f9178898e77988b3883e25feed4\n",
38       "  Stored in directory: /Users/jmandel/Library/Caches/pip/wheels/7f/80/61/2ee3a120b67e51c9355a931f83649887ae5fb349a4a996f1a1\n",
39       "Successfully built MesoPy\n",
40       "Installing collected packages: MesoPy\n",
41       "Successfully installed MesoPy-2.0.3\n"
42      ]
43     }
44    ],
45    "source": [
46     "!pip install MesoPy\n",
47     "from MesoPy import Meso"
48    ]
49   },
50   {
51    "cell_type": "markdown",
52    "metadata": {
53     "id": "s1HVOT-soL_e"
54    },
55    "source": [
56     "Specify the time interval and the bounding box to get the data from: "
57    ]
58   },
59   {
60    "cell_type": "code",
61    "execution_count": 2,
62    "metadata": {
63     "id": "uBp6J9gRc83D"
64    },
65    "outputs": [],
66    "source": [
67     "time_start = \"202006010800\"  # June 1 2020 08:00 in format yyyymmddHHMM \n",
68     "time_end   = \"202006010900\"  # June 1 2020 09:00 in format yyyymmddHHMM \n",
69     "bounding_box = \"-115, 38, -110, 40\"  # min longtitude, latitude\n"
70    ]
71   },
72   {
73    "cell_type": "markdown",
74    "metadata": {
75     "id": "U7-BOmVEokEj"
76    },
77    "source": [
78     "Call the API"
79    ]
80   },
81   {
82    "cell_type": "code",
83    "execution_count": 3,
84    "metadata": {
85     "id": "I8pZ1IYrqOxf"
86    },
87    "outputs": [],
88    "source": [
89     "meso_token=\"b40cb52cbdef43ef81329b84e8fd874f\"       # you should get your own if you do more of this\n",
90     "m = Meso(meso_token)                                     # create a Meso object\n",
91     "meso_obss = m.timeseries(time_start, time_end, bbox=bounding_box, showemptystations = '0', vars='fuel_moisture')   # ask the object for data"
92    ]
93   },
94   {
95    "cell_type": "markdown",
96    "metadata": {
97     "id": "VGv5pfNSrLce"
98    },
99    "source": [
100     "Print the result:"
101    ]
102   },
103   {
104    "cell_type": "code",
105    "execution_count": 4,
106    "metadata": {
107     "id": "aggTETGIrOyK"
108    },
109    "outputs": [
110     {
111      "name": "stdout",
112      "output_type": "stream",
113      "text": [
114       "{'UNITS': {'position': 'ft', 'fuel_moisture': 'gm', 'elevation': 'ft'}, 'QC_SUMMARY': {'QC_CHECKS_APPLIED': ['sl_range_check'], 'TOTAL_OBSERVATIONS_FLAGGED': 0.0, 'PERCENT_OF_TOTAL_OBSERVATIONS_FLAGGED': 0.0}, 'STATION': [{'STATUS': 'ACTIVE', 'MNET_ID': '2', 'PERIOD_OF_RECORD': {'start': '1997-01-01T00:00:00Z', 'end': '2021-10-23T19:27:00Z'}, 'ELEVATION': '6493', 'NAME': 'BLACK CEDAR', 'STID': 'BKCU1', 'SENSOR_VARIABLES': {'date_time': {'date_time': {}}, 'fuel_moisture': {'fuel_moisture_set_1': {'position': '0.98'}}}, 'ELEV_DEM': '6499.3', 'LONGITUDE': '-112.238864', 'STATE': 'UT', 'OBSERVATIONS': {'date_time': ['2020-06-01T08:27:00Z'], 'fuel_moisture_set_1': [4.5]}, 'RESTRICTED': False, 'QC_FLAGGED': False, 'LATITUDE': '38.979242', 'TIMEZONE': 'America/Denver', 'ID': '2328'}, {'STATUS': 'ACTIVE', 'MNET_ID': '2', 'PERIOD_OF_RECORD': {'start': '1998-07-30T00:00:00Z', 'end': '2021-10-23T19:12:00Z'}, 'ELEVATION': '8530', 'NAME': 'HORSE RIDGE', 'STID': 'HSRU1', 'SENSOR_VARIABLES': {'date_time': {'date_time': {}}, 'fuel_moisture': {'fuel_moisture_set_1': {'position': '0.98'}}}, 'ELEV_DEM': '8517.1', 'LONGITUDE': '-110.861944', 'STATE': 'UT', 'OBSERVATIONS': {'date_time': ['2020-06-01T08:12:00Z'], 'fuel_moisture_set_1': [8.7]}, 'RESTRICTED': False, 'QC_FLAGGED': False, 'LATITUDE': '39.933889', 'TIMEZONE': 'America/Denver', 'ID': '2341'}, {'STATUS': 'ACTIVE', 'MNET_ID': '2', 'PERIOD_OF_RECORD': {'start': '1997-01-01T00:00:00Z', 'end': '2021-10-23T19:16:00Z'}, 'ELEVATION': '8700', 'NAME': 'JOES VALLEY', 'STID': 'JVAU1', 'SENSOR_VARIABLES': {'date_time': {'date_time': {}}, 'fuel_moisture': {'fuel_moisture_set_1': {'position': '0.98'}}}, 'ELEV_DEM': '8710.6', 'LONGITUDE': '-111.322778', 'STATE': 'UT', 'OBSERVATIONS': {'date_time': ['2020-06-01T08:16:00Z'], 'fuel_moisture_set_1': [7.4]}, 'RESTRICTED': False, 'QC_FLAGGED': False, 'LATITUDE': '39.309444', 'TIMEZONE': 'America/Denver', 'ID': '2343'}, {'STATUS': 'ACTIVE', 'MNET_ID': '2', 'PERIOD_OF_RECORD': {'start': '2002-03-27T00:00:00Z', 'end': '2021-10-12T23:12:00Z'}, 'ELEVATION': '8625', 'NAME': 'H-T PORTABLE #3', 'STID': 'TR421', 'SENSOR_VARIABLES': {'date_time': {'date_time': {}}, 'fuel_moisture': {'fuel_moisture_set_1': {'position': '0.98'}}}, 'ELEV_DEM': '8638.5', 'LONGITUDE': '-114.669417', 'STATE': 'NV', 'OBSERVATIONS': {'date_time': ['2020-06-01T08:12:00Z'], 'fuel_moisture_set_1': [5.0]}, 'RESTRICTED': False, 'QC_FLAGGED': False, 'LATITUDE': '39.603583', 'TIMEZONE': 'America/Los_Angeles', 'ID': '3747'}, {'STATUS': 'ACTIVE', 'MNET_ID': '2', 'PERIOD_OF_RECORD': {'start': '2004-09-10T00:00:00Z', 'end': '2021-10-23T19:45:00Z'}, 'ELEVATION': '8112', 'NAME': 'ROCKY QD', 'STID': 'TS305', 'SENSOR_VARIABLES': {'date_time': {'date_time': {}}, 'fuel_moisture': {'fuel_moisture_set_1': {'position': '0.98'}}}, 'ELEV_DEM': '8123.4', 'LONGITUDE': '-110.950000', 'STATE': 'UT', 'OBSERVATIONS': {'date_time': ['2020-06-01T08:45:00Z'], 'fuel_moisture_set_1': [10.4]}, 'RESTRICTED': False, 'QC_FLAGGED': False, 'LATITUDE': '39.851083', 'TIMEZONE': 'America/Denver', 'ID': '11224'}, {'STATUS': 'ACTIVE', 'MNET_ID': '2', 'PERIOD_OF_RECORD': {'start': '2013-02-20T00:00:00Z', 'end': '2021-10-23T19:22:00Z'}, 'ELEVATION': '5790', 'NAME': 'FISHLAKE D1 PT #1', 'STID': 'TT156', 'SENSOR_VARIABLES': {'date_time': {'date_time': {}}, 'fuel_moisture': {'fuel_moisture_set_1': {'position': '0.98'}}}, 'ELEV_DEM': '5872.7', 'LONGITUDE': '-112.271383', 'STATE': 'UT', 'OBSERVATIONS': {'date_time': ['2020-06-01T08:22:00Z'], 'fuel_moisture_set_1': [4.3]}, 'RESTRICTED': False, 'QC_FLAGGED': False, 'LATITUDE': '38.941717', 'TIMEZONE': 'America/Denver', 'ID': '34260'}], 'SUMMARY': {'DATA_QUERY_TIME': '315.973997116 ms', 'RESPONSE_CODE': 1, 'RESPONSE_MESSAGE': 'OK', 'METADATA_RESPONSE_TIME': '105.997085571 ms', 'DATA_PARSING_TIME': '2.4139881134 ms', 'TOTAL_DATA_TIME': '318.388938904 ms', 'NUMBER_OF_OBJECTS': 6, 'FUNCTION_USED': 'time_data_parser'}}\n"
115      ]
116     }
117    ],
118    "source": [
119     "print(meso_obss)"
120    ]
121   },
122   {
123    "cell_type": "markdown",
124    "metadata": {
125     "id": "85Mx4ANVsAN1"
126    },
127    "source": [
128     "This long line does not look very good! But we see the structure: { key: value, key: value,...}. It is a **dictionary**. The value can be a dictionary itself, or a list, or some other kind of object. \n",
129     "First let's see if we can pretty print the dictionary in a more human friendly form: "
130    ]
131   },
132   {
133    "cell_type": "code",
134    "execution_count": 5,
135    "metadata": {
136     "id": "HE-r6GlnjWY7"
137    },
138    "outputs": [
139     {
140      "name": "stdout",
141      "output_type": "stream",
142      "text": [
143       "{\n",
144       "    \"UNITS\": {\n",
145       "        \"position\": \"ft\",\n",
146       "        \"fuel_moisture\": \"gm\",\n",
147       "        \"elevation\": \"ft\"\n",
148       "    },\n",
149       "    \"QC_SUMMARY\": {\n",
150       "        \"QC_CHECKS_APPLIED\": [\n",
151       "            \"sl_range_check\"\n",
152       "        ],\n",
153       "        \"TOTAL_OBSERVATIONS_FLAGGED\": 0.0,\n",
154       "        \"PERCENT_OF_TOTAL_OBSERVATIONS_FLAGGED\": 0.0\n",
155       "    },\n",
156       "    \"STATION\": [\n",
157       "        {\n",
158       "            \"STATUS\": \"ACTIVE\",\n",
159       "            \"MNET_ID\": \"2\",\n",
160       "            \"PERIOD_OF_RECORD\": {\n",
161       "                \"start\": \"1997-01-01T00:00:00Z\",\n",
162       "                \"end\": \"2021-10-23T19:27:00Z\"\n",
163       "            },\n",
164       "            \"ELEVATION\": \"6493\",\n",
165       "            \"NAME\": \"BLACK CEDAR\",\n",
166       "            \"STID\": \"BKCU1\",\n",
167       "            \"SENSOR_VARIABLES\": {\n",
168       "                \"date_time\": {\n",
169       "                    \"date_time\": {}\n",
170       "                },\n",
171       "                \"fuel_moisture\": {\n",
172       "                    \"fuel_moisture_set_1\": {\n",
173       "                        \"position\": \"0.98\"\n",
174       "                    }\n",
175       "                }\n",
176       "            },\n",
177       "            \"ELEV_DEM\": \"6499.3\",\n",
178       "            \"LONGITUDE\": \"-112.238864\",\n",
179       "            \"STATE\": \"UT\",\n",
180       "            \"OBSERVATIONS\": {\n",
181       "                \"date_time\": [\n",
182       "                    \"2020-06-01T08:27:00Z\"\n",
183       "                ],\n",
184       "                \"fuel_moisture_set_1\": [\n",
185       "                    4.5\n",
186       "                ]\n",
187       "            },\n",
188       "            \"RESTRICTED\": false,\n",
189       "            \"QC_FLAGGED\": false,\n",
190       "            \"LATITUDE\": \"38.979242\",\n",
191       "            \"TIMEZONE\": \"America/Denver\",\n",
192       "            \"ID\": \"2328\"\n",
193       "        },\n",
194       "        {\n",
195       "            \"STATUS\": \"ACTIVE\",\n",
196       "            \"MNET_ID\": \"2\",\n",
197       "            \"PERIOD_OF_RECORD\": {\n",
198       "                \"start\": \"1998-07-30T00:00:00Z\",\n",
199       "                \"end\": \"2021-10-23T19:12:00Z\"\n",
200       "            },\n",
201       "            \"ELEVATION\": \"8530\",\n",
202       "            \"NAME\": \"HORSE RIDGE\",\n",
203       "            \"STID\": \"HSRU1\",\n",
204       "            \"SENSOR_VARIABLES\": {\n",
205       "                \"date_time\": {\n",
206       "                    \"date_time\": {}\n",
207       "                },\n",
208       "                \"fuel_moisture\": {\n",
209       "                    \"fuel_moisture_set_1\": {\n",
210       "                        \"position\": \"0.98\"\n",
211       "                    }\n",
212       "                }\n",
213       "            },\n",
214       "            \"ELEV_DEM\": \"8517.1\",\n",
215       "            \"LONGITUDE\": \"-110.861944\",\n",
216       "            \"STATE\": \"UT\",\n",
217       "            \"OBSERVATIONS\": {\n",
218       "                \"date_time\": [\n",
219       "                    \"2020-06-01T08:12:00Z\"\n",
220       "                ],\n",
221       "                \"fuel_moisture_set_1\": [\n",
222       "                    8.7\n",
223       "                ]\n",
224       "            },\n",
225       "            \"RESTRICTED\": false,\n",
226       "            \"QC_FLAGGED\": false,\n",
227       "            \"LATITUDE\": \"39.933889\",\n",
228       "            \"TIMEZONE\": \"America/Denver\",\n",
229       "            \"ID\": \"2341\"\n",
230       "        },\n",
231       "        {\n",
232       "            \"STATUS\": \"ACTIVE\",\n",
233       "            \"MNET_ID\": \"2\",\n",
234       "            \"PERIOD_OF_RECORD\": {\n",
235       "                \"start\": \"1997-01-01T00:00:00Z\",\n",
236       "                \"end\": \"2021-10-23T19:16:00Z\"\n",
237       "            },\n",
238       "            \"ELEVATION\": \"8700\",\n",
239       "            \"NAME\": \"JOES VALLEY\",\n",
240       "            \"STID\": \"JVAU1\",\n",
241       "            \"SENSOR_VARIABLES\": {\n",
242       "                \"date_time\": {\n",
243       "                    \"date_time\": {}\n",
244       "                },\n",
245       "                \"fuel_moisture\": {\n",
246       "                    \"fuel_moisture_set_1\": {\n",
247       "                        \"position\": \"0.98\"\n",
248       "                    }\n",
249       "                }\n",
250       "            },\n",
251       "            \"ELEV_DEM\": \"8710.6\",\n",
252       "            \"LONGITUDE\": \"-111.322778\",\n",
253       "            \"STATE\": \"UT\",\n",
254       "            \"OBSERVATIONS\": {\n",
255       "                \"date_time\": [\n",
256       "                    \"2020-06-01T08:16:00Z\"\n",
257       "                ],\n",
258       "                \"fuel_moisture_set_1\": [\n",
259       "                    7.4\n",
260       "                ]\n",
261       "            },\n",
262       "            \"RESTRICTED\": false,\n",
263       "            \"QC_FLAGGED\": false,\n",
264       "            \"LATITUDE\": \"39.309444\",\n",
265       "            \"TIMEZONE\": \"America/Denver\",\n",
266       "            \"ID\": \"2343\"\n",
267       "        },\n",
268       "        {\n",
269       "            \"STATUS\": \"ACTIVE\",\n",
270       "            \"MNET_ID\": \"2\",\n",
271       "            \"PERIOD_OF_RECORD\": {\n",
272       "                \"start\": \"2002-03-27T00:00:00Z\",\n",
273       "                \"end\": \"2021-10-12T23:12:00Z\"\n",
274       "            },\n",
275       "            \"ELEVATION\": \"8625\",\n",
276       "            \"NAME\": \"H-T PORTABLE #3\",\n",
277       "            \"STID\": \"TR421\",\n",
278       "            \"SENSOR_VARIABLES\": {\n",
279       "                \"date_time\": {\n",
280       "                    \"date_time\": {}\n",
281       "                },\n",
282       "                \"fuel_moisture\": {\n",
283       "                    \"fuel_moisture_set_1\": {\n",
284       "                        \"position\": \"0.98\"\n",
285       "                    }\n",
286       "                }\n",
287       "            },\n",
288       "            \"ELEV_DEM\": \"8638.5\",\n",
289       "            \"LONGITUDE\": \"-114.669417\",\n",
290       "            \"STATE\": \"NV\",\n",
291       "            \"OBSERVATIONS\": {\n",
292       "                \"date_time\": [\n",
293       "                    \"2020-06-01T08:12:00Z\"\n",
294       "                ],\n",
295       "                \"fuel_moisture_set_1\": [\n",
296       "                    5.0\n",
297       "                ]\n",
298       "            },\n",
299       "            \"RESTRICTED\": false,\n",
300       "            \"QC_FLAGGED\": false,\n",
301       "            \"LATITUDE\": \"39.603583\",\n",
302       "            \"TIMEZONE\": \"America/Los_Angeles\",\n",
303       "            \"ID\": \"3747\"\n",
304       "        },\n",
305       "        {\n",
306       "            \"STATUS\": \"ACTIVE\",\n",
307       "            \"MNET_ID\": \"2\",\n",
308       "            \"PERIOD_OF_RECORD\": {\n",
309       "                \"start\": \"2004-09-10T00:00:00Z\",\n",
310       "                \"end\": \"2021-10-23T19:45:00Z\"\n",
311       "            },\n",
312       "            \"ELEVATION\": \"8112\",\n",
313       "            \"NAME\": \"ROCKY QD\",\n",
314       "            \"STID\": \"TS305\",\n",
315       "            \"SENSOR_VARIABLES\": {\n",
316       "                \"date_time\": {\n",
317       "                    \"date_time\": {}\n",
318       "                },\n",
319       "                \"fuel_moisture\": {\n",
320       "                    \"fuel_moisture_set_1\": {\n",
321       "                        \"position\": \"0.98\"\n",
322       "                    }\n",
323       "                }\n",
324       "            },\n",
325       "            \"ELEV_DEM\": \"8123.4\",\n",
326       "            \"LONGITUDE\": \"-110.950000\",\n",
327       "            \"STATE\": \"UT\",\n",
328       "            \"OBSERVATIONS\": {\n",
329       "                \"date_time\": [\n",
330       "                    \"2020-06-01T08:45:00Z\"\n",
331       "                ],\n",
332       "                \"fuel_moisture_set_1\": [\n",
333       "                    10.4\n",
334       "                ]\n",
335       "            },\n",
336       "            \"RESTRICTED\": false,\n",
337       "            \"QC_FLAGGED\": false,\n",
338       "            \"LATITUDE\": \"39.851083\",\n",
339       "            \"TIMEZONE\": \"America/Denver\",\n",
340       "            \"ID\": \"11224\"\n",
341       "        },\n",
342       "        {\n",
343       "            \"STATUS\": \"ACTIVE\",\n",
344       "            \"MNET_ID\": \"2\",\n",
345       "            \"PERIOD_OF_RECORD\": {\n",
346       "                \"start\": \"2013-02-20T00:00:00Z\",\n",
347       "                \"end\": \"2021-10-23T19:22:00Z\"\n",
348       "            },\n",
349       "            \"ELEVATION\": \"5790\",\n",
350       "            \"NAME\": \"FISHLAKE D1 PT #1\",\n",
351       "            \"STID\": \"TT156\",\n",
352       "            \"SENSOR_VARIABLES\": {\n",
353       "                \"date_time\": {\n",
354       "                    \"date_time\": {}\n",
355       "                },\n",
356       "                \"fuel_moisture\": {\n",
357       "                    \"fuel_moisture_set_1\": {\n",
358       "                        \"position\": \"0.98\"\n",
359       "                    }\n",
360       "                }\n",
361       "            },\n",
362       "            \"ELEV_DEM\": \"5872.7\",\n",
363       "            \"LONGITUDE\": \"-112.271383\",\n",
364       "            \"STATE\": \"UT\",\n",
365       "            \"OBSERVATIONS\": {\n",
366       "                \"date_time\": [\n",
367       "                    \"2020-06-01T08:22:00Z\"\n",
368       "                ],\n",
369       "                \"fuel_moisture_set_1\": [\n",
370       "                    4.3\n",
371       "                ]\n",
372       "            },\n",
373       "            \"RESTRICTED\": false,\n",
374       "            \"QC_FLAGGED\": false,\n",
375       "            \"LATITUDE\": \"38.941717\",\n",
376       "            \"TIMEZONE\": \"America/Denver\",\n",
377       "            \"ID\": \"34260\"\n",
378       "        }\n",
379       "    ],\n",
380       "    \"SUMMARY\": {\n",
381       "        \"DATA_QUERY_TIME\": \"315.973997116 ms\",\n",
382       "        \"RESPONSE_CODE\": 1,\n",
383       "        \"RESPONSE_MESSAGE\": \"OK\",\n",
384       "        \"METADATA_RESPONSE_TIME\": \"105.997085571 ms\",\n",
385       "        \"DATA_PARSING_TIME\": \"2.4139881134 ms\",\n",
386       "        \"TOTAL_DATA_TIME\": \"318.388938904 ms\",\n",
387       "        \"NUMBER_OF_OBJECTS\": 6,\n",
388       "        \"FUNCTION_USED\": \"time_data_parser\"\n",
389       "    }\n",
390       "}\n"
391      ]
392     }
393    ],
394    "source": [
395     "import json\n",
396     "print(json.dumps(meso_obss, indent=4))\n"
397    ]
398   },
399   {
400    "cell_type": "markdown",
401    "metadata": {
402     "id": "spCF7VdhvIIn"
403    },
404    "source": [
405     "Scrolling to the top, we see key \"STATION\". Try to retrieve its value:"
406    ]
407   },
408   {
409    "cell_type": "code",
410    "execution_count": 6,
411    "metadata": {
412     "id": "dPbrsJMtkiKx"
413    },
414    "outputs": [
415     {
416      "name": "stdout",
417      "output_type": "stream",
418      "text": [
419       "[{'STATUS': 'ACTIVE', 'MNET_ID': '2', 'PERIOD_OF_RECORD': {'start': '1997-01-01T00:00:00Z', 'end': '2021-10-23T19:27:00Z'}, 'ELEVATION': '6493', 'NAME': 'BLACK CEDAR', 'STID': 'BKCU1', 'SENSOR_VARIABLES': {'date_time': {'date_time': {}}, 'fuel_moisture': {'fuel_moisture_set_1': {'position': '0.98'}}}, 'ELEV_DEM': '6499.3', 'LONGITUDE': '-112.238864', 'STATE': 'UT', 'OBSERVATIONS': {'date_time': ['2020-06-01T08:27:00Z'], 'fuel_moisture_set_1': [4.5]}, 'RESTRICTED': False, 'QC_FLAGGED': False, 'LATITUDE': '38.979242', 'TIMEZONE': 'America/Denver', 'ID': '2328'}, {'STATUS': 'ACTIVE', 'MNET_ID': '2', 'PERIOD_OF_RECORD': {'start': '1998-07-30T00:00:00Z', 'end': '2021-10-23T19:12:00Z'}, 'ELEVATION': '8530', 'NAME': 'HORSE RIDGE', 'STID': 'HSRU1', 'SENSOR_VARIABLES': {'date_time': {'date_time': {}}, 'fuel_moisture': {'fuel_moisture_set_1': {'position': '0.98'}}}, 'ELEV_DEM': '8517.1', 'LONGITUDE': '-110.861944', 'STATE': 'UT', 'OBSERVATIONS': {'date_time': ['2020-06-01T08:12:00Z'], 'fuel_moisture_set_1': [8.7]}, 'RESTRICTED': False, 'QC_FLAGGED': False, 'LATITUDE': '39.933889', 'TIMEZONE': 'America/Denver', 'ID': '2341'}, {'STATUS': 'ACTIVE', 'MNET_ID': '2', 'PERIOD_OF_RECORD': {'start': '1997-01-01T00:00:00Z', 'end': '2021-10-23T19:16:00Z'}, 'ELEVATION': '8700', 'NAME': 'JOES VALLEY', 'STID': 'JVAU1', 'SENSOR_VARIABLES': {'date_time': {'date_time': {}}, 'fuel_moisture': {'fuel_moisture_set_1': {'position': '0.98'}}}, 'ELEV_DEM': '8710.6', 'LONGITUDE': '-111.322778', 'STATE': 'UT', 'OBSERVATIONS': {'date_time': ['2020-06-01T08:16:00Z'], 'fuel_moisture_set_1': [7.4]}, 'RESTRICTED': False, 'QC_FLAGGED': False, 'LATITUDE': '39.309444', 'TIMEZONE': 'America/Denver', 'ID': '2343'}, {'STATUS': 'ACTIVE', 'MNET_ID': '2', 'PERIOD_OF_RECORD': {'start': '2002-03-27T00:00:00Z', 'end': '2021-10-12T23:12:00Z'}, 'ELEVATION': '8625', 'NAME': 'H-T PORTABLE #3', 'STID': 'TR421', 'SENSOR_VARIABLES': {'date_time': {'date_time': {}}, 'fuel_moisture': {'fuel_moisture_set_1': {'position': '0.98'}}}, 'ELEV_DEM': '8638.5', 'LONGITUDE': '-114.669417', 'STATE': 'NV', 'OBSERVATIONS': {'date_time': ['2020-06-01T08:12:00Z'], 'fuel_moisture_set_1': [5.0]}, 'RESTRICTED': False, 'QC_FLAGGED': False, 'LATITUDE': '39.603583', 'TIMEZONE': 'America/Los_Angeles', 'ID': '3747'}, {'STATUS': 'ACTIVE', 'MNET_ID': '2', 'PERIOD_OF_RECORD': {'start': '2004-09-10T00:00:00Z', 'end': '2021-10-23T19:45:00Z'}, 'ELEVATION': '8112', 'NAME': 'ROCKY QD', 'STID': 'TS305', 'SENSOR_VARIABLES': {'date_time': {'date_time': {}}, 'fuel_moisture': {'fuel_moisture_set_1': {'position': '0.98'}}}, 'ELEV_DEM': '8123.4', 'LONGITUDE': '-110.950000', 'STATE': 'UT', 'OBSERVATIONS': {'date_time': ['2020-06-01T08:45:00Z'], 'fuel_moisture_set_1': [10.4]}, 'RESTRICTED': False, 'QC_FLAGGED': False, 'LATITUDE': '39.851083', 'TIMEZONE': 'America/Denver', 'ID': '11224'}, {'STATUS': 'ACTIVE', 'MNET_ID': '2', 'PERIOD_OF_RECORD': {'start': '2013-02-20T00:00:00Z', 'end': '2021-10-23T19:22:00Z'}, 'ELEVATION': '5790', 'NAME': 'FISHLAKE D1 PT #1', 'STID': 'TT156', 'SENSOR_VARIABLES': {'date_time': {'date_time': {}}, 'fuel_moisture': {'fuel_moisture_set_1': {'position': '0.98'}}}, 'ELEV_DEM': '5872.7', 'LONGITUDE': '-112.271383', 'STATE': 'UT', 'OBSERVATIONS': {'date_time': ['2020-06-01T08:22:00Z'], 'fuel_moisture_set_1': [4.3]}, 'RESTRICTED': False, 'QC_FLAGGED': False, 'LATITUDE': '38.941717', 'TIMEZONE': 'America/Denver', 'ID': '34260'}]\n"
420      ]
421     }
422    ],
423    "source": [
424     "stations=meso_obss['STATION']\n",
425     "print(stations)"
426    ]
427   },
428   {
429    "cell_type": "markdown",
430    "metadata": {
431     "id": "3bXopS3btyz0"
432    },
433    "source": [
434     "This is a list. Its first item is:"
435    ]
436   },
437   {
438    "cell_type": "code",
439    "execution_count": 9,
440    "metadata": {
441     "id": "FgKsHsDstoxg"
442    },
443    "outputs": [
444     {
445      "name": "stdout",
446      "output_type": "stream",
447      "text": [
448       "{'STATUS': 'ACTIVE', 'MNET_ID': '2', 'PERIOD_OF_RECORD': {'start': '1997-01-01T00:00:00Z', 'end': '2021-10-23T19:27:00Z'}, 'ELEVATION': '6493', 'NAME': 'BLACK CEDAR', 'STID': 'BKCU1', 'SENSOR_VARIABLES': {'date_time': {'date_time': {}}, 'fuel_moisture': {'fuel_moisture_set_1': {'position': '0.98'}}}, 'ELEV_DEM': '6499.3', 'LONGITUDE': '-112.238864', 'STATE': 'UT', 'OBSERVATIONS': {'date_time': ['2020-06-01T08:27:00Z'], 'fuel_moisture_set_1': [4.5]}, 'RESTRICTED': False, 'QC_FLAGGED': False, 'LATITUDE': '38.979242', 'TIMEZONE': 'America/Denver', 'ID': '2328'}\n"
449      ]
450     }
451    ],
452    "source": [
453     "print(stations[0])"
454    ]
455   },
456   {
457    "cell_type": "markdown",
458    "metadata": {
459     "id": "Qkkuse_UuiMH"
460    },
461    "source": [
462     "Looks like a dictionary.\n",
463     "**Exercise: pretty print this dictionary using json.dumps like above** "
464    ]
465   },
466   {
467    "cell_type": "code",
468    "execution_count": 10,
469    "metadata": {
470     "id": "3iWjymYMvWJM"
471    },
472    "outputs": [
473     {
474      "name": "stdout",
475      "output_type": "stream",
476      "text": [
477       "{\n",
478       "    \"STATUS\": \"ACTIVE\",\n",
479       "    \"MNET_ID\": \"2\",\n",
480       "    \"PERIOD_OF_RECORD\": {\n",
481       "        \"start\": \"1997-01-01T00:00:00Z\",\n",
482       "        \"end\": \"2021-10-23T19:27:00Z\"\n",
483       "    },\n",
484       "    \"ELEVATION\": \"6493\",\n",
485       "    \"NAME\": \"BLACK CEDAR\",\n",
486       "    \"STID\": \"BKCU1\",\n",
487       "    \"SENSOR_VARIABLES\": {\n",
488       "        \"date_time\": {\n",
489       "            \"date_time\": {}\n",
490       "        },\n",
491       "        \"fuel_moisture\": {\n",
492       "            \"fuel_moisture_set_1\": {\n",
493       "                \"position\": \"0.98\"\n",
494       "            }\n",
495       "        }\n",
496       "    },\n",
497       "    \"ELEV_DEM\": \"6499.3\",\n",
498       "    \"LONGITUDE\": \"-112.238864\",\n",
499       "    \"STATE\": \"UT\",\n",
500       "    \"OBSERVATIONS\": {\n",
501       "        \"date_time\": [\n",
502       "            \"2020-06-01T08:27:00Z\"\n",
503       "        ],\n",
504       "        \"fuel_moisture_set_1\": [\n",
505       "            4.5\n",
506       "        ]\n",
507       "    },\n",
508       "    \"RESTRICTED\": false,\n",
509       "    \"QC_FLAGGED\": false,\n",
510       "    \"LATITUDE\": \"38.979242\",\n",
511       "    \"TIMEZONE\": \"America/Denver\",\n",
512       "    \"ID\": \"2328\"\n",
513       "}\n"
514      ]
515     }
516    ],
517    "source": [
518     "print(json.dumps(stations[0], indent=4))"
519    ]
520   },
521   {
522    "cell_type": "code",
523    "execution_count": null,
524    "metadata": {},
525    "outputs": [],
526    "source": []
527   }
528  ],
529  "metadata": {
530   "colab": {
531    "collapsed_sections": [],
532    "name": "04-mesowest_demo.ipynb",
533    "provenance": []
534   },
535   "kernelspec": {
536    "display_name": "Python 3",
537    "language": "python",
538    "name": "python3"
539   },
540   "language_info": {
541    "codemirror_mode": {
542     "name": "ipython",
543     "version": 3
544    },
545    "file_extension": ".py",
546    "mimetype": "text/x-python",
547    "name": "python",
548    "nbconvert_exporter": "python",
549    "pygments_lexer": "ipython3",
550    "version": "3.8.5"
551   }
552  },
553  "nbformat": 4,
554  "nbformat_minor": 1