4 "cell_type": "markdown",
5 "id": "b1100419-e2ec-46b6-89d3-327421288025",
8 "## Find Data Availability for Stations\n",
10 "Find which RAWS stations in Colorado have data availability for variables of interest to fuel moisture model."
16 "id": "edb47918-af48-4002-8a66-7e78c7d10c77",
21 "output_type": "stream",
23 "Requirement already satisfied: MesoPy in /Users/jmandel/miniconda3/lib/python3.9/site-packages (2.0.3)\r\n"
28 "!pip install MesoPy\n",
29 "from MesoPy import Meso\n",
33 "# bounding_box = \"-115, 38, -110, 40\"\n",
34 "meso_token=\"4192c18707b848299783d59a9317c6e1\"\n",
41 "id": "37683794-406d-4524-99d3-2c167ff444ea",
45 "time_start = \"201806010800\" # June 1 2018 08:00 in format yyyymmddHHMM\n",
46 "time_s2 = \"201806010900\" # June 1 2018 09:00 in format yyyymmddHHMM \n",
47 "time_end = \"201907200900\" # June 20 2018 09:00 in format yyyymmddHHMM\n",
49 "vars='air_temp,relative_humidity,precip_accum,fuel_moisture'"
55 "id": "7dfb0387-6535-4976-9e9a-62e3cf9a69cd",
59 "meso_obss = m.timeseries(time_start, time_s2, state=\"CO\", \n",
60 " showemptystations = '0', vars=vars)"
66 "id": "2255f323-2685-47b1-b862-f86eca6a3991",
70 "import pandas as pd\n",
71 "import numpy as np\n",
73 "station_df = pd.DataFrame(columns=['STID', 'air_temp', 'relative_humidity', 'precip_accum', 'fuel_moisture'],\n",
74 " index=range(0, len(meso_obss[\"STATION\"])))"
80 "id": "6f4fbe0d-dd16-4c1c-950e-97e23e5a1918",
84 "for i in range(0, station_df.shape[0]):\n",
85 " station_df[\"STID\"][i] = meso_obss[\"STATION\"][i][\"STID\"]\n",
86 " station_df[\"air_temp\"][i] = int(\"air_temp\" in meso_obss[\"STATION\"][i][\"SENSOR_VARIABLES\"].keys())\n",
87 " station_df[\"relative_humidity\"][i] = int(\"relative_humidity\" in meso_obss[\"STATION\"][i][\"SENSOR_VARIABLES\"].keys())\n",
88 " station_df[\"precip_accum\"][i] = int(\"precip_accum\" in meso_obss[\"STATION\"][i][\"SENSOR_VARIABLES\"].keys())\n",
89 " station_df[\"fuel_moisture\"][i] = int(\"fuel_moisture\" in meso_obss[\"STATION\"][i][\"SENSOR_VARIABLES\"].keys())"
95 "id": "de8ec8c9-4af7-4bdc-9dbc-1b361d011654",
103 " .dataframe tbody tr th:only-of-type {\n",
104 " vertical-align: middle;\n",
107 " .dataframe tbody tr th {\n",
108 " vertical-align: top;\n",
111 " .dataframe thead th {\n",
112 " text-align: right;\n",
115 "<table border=\"1\" class=\"dataframe\">\n",
117 " <tr style=\"text-align: right;\">\n",
120 " <th>air_temp</th>\n",
121 " <th>relative_humidity</th>\n",
122 " <th>precip_accum</th>\n",
123 " <th>fuel_moisture</th>\n",
172 " STID air_temp relative_humidity precip_accum fuel_moisture\n",
173 "123 CPTC2 1 1 1 1\n",
174 "124 CHAC2 1 1 1 1\n",
175 "125 CHRC2 1 1 1 1\n",
176 "144 LKGC2 1 1 1 1\n",
180 "execution_count": 6,
182 "output_type": "execute_result"
186 "station_df[station_df[\"fuel_moisture\"]==1].head()"
191 "execution_count": 7,
192 "id": "99dde77e-5f6f-4e45-babf-f7599e8fca14",
197 "station_df.to_csv(outpath+\"/station_df_co.csv\", index=False)"
201 "cell_type": "markdown",
202 "id": "8f63bc34-6deb-48bd-9aa9-c2f5a4cc293e",
205 "## Plot Timeseries for a Station\n",
207 "Visualize the available data."
212 "execution_count": 8,
213 "id": "d45d76e5-ccb1-45b6-a187-25d0d1f91b8e",
217 "ename": "NameError",
218 "evalue": "name 'lon' is not defined",
219 "output_type": "error",
221 "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
222 "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
223 "Input \u001b[0;32mIn [8]\u001b[0m, in \u001b[0;36m<cell line: 2>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m e \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m0.01\u001b[39m \u001b[38;5;66;03m# tolerance\u001b[39;00m\n\u001b[0;32m----> 2\u001b[0m bb \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m, \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m, \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m, \u001b[39m\u001b[38;5;132;01m%s\u001b[39;00m\u001b[38;5;124m'\u001b[39m \u001b[38;5;241m%\u001b[39m (\u001b[43mlon\u001b[49m \u001b[38;5;241m-\u001b[39m e, lat \u001b[38;5;241m-\u001b[39m e, lon \u001b[38;5;241m+\u001b[39m e, lat \u001b[38;5;241m+\u001b[39m e)\n\u001b[1;32m 3\u001b[0m meso_ts \u001b[38;5;241m=\u001b[39m m\u001b[38;5;241m.\u001b[39mtimeseries(time_start, time_end, stid\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mCPTC2\u001b[39m\u001b[38;5;124m\"\u001b[39m, showemptystations \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m0\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;28mvars\u001b[39m\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mvars\u001b[39m)\n",
224 "\u001b[0;31mNameError\u001b[0m: name 'lon' is not defined"
229 "e = 0.01 # tolerance\n",
230 "bb = '%s, %s, %s, %s' % (lon - e, lat - e, lon + e, lat + e)\n",
231 "meso_ts = m.timeseries(time_start, time_end, stid=\"CPTC2\", showemptystations = '0', vars=vars) # ask the object for data"
236 "execution_count": null,
237 "id": "05e37b54-e014-44e8-b0f4-e3d53b5dbf86",
241 "from datetime import datetime, timedelta, time\n",
242 "import numpy as np\n",
243 "import matplotlib.pyplot as plt\n",
245 "station = meso_ts['STATION'][0]\n",
246 "time_str = station['OBSERVATIONS']['date_time']\n",
247 "obs_time = [datetime.strptime(t, '%Y-%m-%dT%H:%M:%SZ').replace(tzinfo=pytz.UTC) for t in time_str]\n",
248 "start_time = obs_time[0].replace(minute=0) # remember obs_time and start_time for later\n",
249 "end_time = obs_time[-1]\n",
250 "obs_data = np.array(station['OBSERVATIONS'][\"fuel_moisture_set_1\"])\n",
253 "%matplotlib inline\n",
254 "plt.figure(figsize=(16,4))\n",
255 "plt.plot(obs_data,linestyle='-',c='k',label='10-h fuel data')\n",
256 "plt.title(station['STID'] + ' 10 h fuel moisture data')\n",
257 "plt.xlabel('Time (hours)') \n",
258 "plt.ylabel('Fuel moisture content (%)')\n",
264 "execution_count": null,
265 "id": "d58d9cb6-f87f-47a2-8845-97c6d6c15358",
269 "obs_data = np.array(station['OBSERVATIONS'][\"relative_humidity_set_1\"])\n",
272 "%matplotlib inline\n",
273 "plt.figure(figsize=(16,4))\n",
274 "plt.plot(obs_data,linestyle='-',c='k')\n",
275 "plt.title(station['STID'] + ' relative humidity data')\n",
276 "plt.xlabel('Time (hours)') \n",
277 "plt.ylabel('Relative Humidity (%)')"
282 "execution_count": null,
283 "id": "20176db9-997d-4a46-8d73-f2e7a08ee9d4",
287 "obs_data = np.array(station['OBSERVATIONS'][\"precip_accum_set_1\"])\n",
290 "%matplotlib inline\n",
291 "plt.figure(figsize=(16,4))\n",
292 "plt.plot(obs_data,linestyle='-',c='k')\n",
293 "plt.title(station['STID'] + ' precip accum data')\n",
294 "plt.xlabel('Time (hours)') \n",
295 "plt.ylabel('Precipitation Accumulated (mm)')"
300 "execution_count": null,
301 "id": "2cf93527-578c-4ce2-b4f6-1508b9dbfa7c",
305 "obs_data = np.array(station['OBSERVATIONS'][\"air_temp_set_1\"])\n",
308 "%matplotlib inline\n",
309 "plt.figure(figsize=(16,4))\n",
310 "plt.plot(obs_data,linestyle='-',c='k')\n",
311 "plt.title(station['STID'] + ' air temp data')\n",
312 "plt.xlabel('Time (hours)') \n",
313 "plt.ylabel('Air Temp (C)')"
318 "execution_count": null,
319 "id": "45264085-d516-4803-bcc6-d0a64cc7e1c9",
326 "execution_count": null,
327 "id": "0730d61b-6d71-407a-a31b-8b16494f1921",
335 "display_name": "Python 3 (ipykernel)",
336 "language": "python",
344 "file_extension": ".py",
345 "mimetype": "text/x-python",
347 "nbconvert_exporter": "python",
348 "pygments_lexer": "ipython3",