4 "cell_type": "markdown",
5 "id": "b1100419-e2ec-46b6-89d3-327421288025",
8 "## Find Data Availability for Stations\n",
10 "Find which RAWS stations in given state have data availability for variables of interest to fuel moisture model.\n",
12 "See available Mesonet variables [here](https://developers.synopticdata.com/mesonet/v2/api-variables/)."
18 "id": "edb47918-af48-4002-8a66-7e78c7d10c77",
22 "# !pip install MesoPy\n",
24 "from MesoPy import Meso\n",
25 "import os.path as osp\n",
27 "import pandas as pd\n",
28 "import numpy as np\n",
32 "meso_token=\"4192c18707b848299783d59a9317c6e1\" # Get your own token...\n",
39 "id": "fe4c6fbf-0242-4345-9fc5-38cdb5628861",
44 "output_type": "stream",
46 "C:\\Users\\jhirs\\anaconda3\\lib\\site-packages\\requests\\__init__.py:109: RequestsDependencyWarning: urllib3 (1.26.15) or chardet (5.1.0)/charset_normalizer (2.0.12) doesn't match a supported version!\n",
53 "from data_funcs import format_raws"
59 "id": "37683794-406d-4524-99d3-2c167ff444ea",
63 "time_start = \"202306010800\" # June 1 2022 08:00 in format yyyymmddHHMM\n",
64 "time_s2 = \"202306010900\" # small time to get station ids\n",
65 "time_end = \"202306300900\" # June 30 2022 09:00 in format yyyymmddHHMM\n",
66 "state_str = \"CO\"\n",
68 "vars='air_temp,relative_humidity,precip_accum,fuel_moisture,wind_speed,solar_radiation'"
74 "id": "7dfb0387-6535-4976-9e9a-62e3cf9a69cd",
78 "meso_obss = m.timeseries(start=time_start,end=time_s2, state=state_str, \n",
79 " showemptystations = '0', vars=vars)"
85 "id": "2255f323-2685-47b1-b862-f86eca6a3991",
89 "station_df = pd.DataFrame(columns=['STID', 'air_temp', 'relative_humidity', 'precip_accum', 'fuel_moisture', 'wind_speed', 'solar_radiation'],\n",
90 " index=range(0, len(meso_obss[\"STATION\"])))"
96 "id": "6f4fbe0d-dd16-4c1c-950e-97e23e5a1918",
100 "for i in range(0, station_df.shape[0]):\n",
101 " station_df[\"STID\"][i] = meso_obss[\"STATION\"][i][\"STID\"]\n",
102 " station_df[\"air_temp\"][i] = int(\"air_temp\" in meso_obss[\"STATION\"][i][\"SENSOR_VARIABLES\"].keys())\n",
103 " station_df[\"relative_humidity\"][i] = int(\"relative_humidity\" in meso_obss[\"STATION\"][i][\"SENSOR_VARIABLES\"].keys())\n",
104 " station_df[\"precip_accum\"][i] = int(\"precip_accum\" in meso_obss[\"STATION\"][i][\"SENSOR_VARIABLES\"].keys())\n",
105 " station_df[\"fuel_moisture\"][i] = int(\"fuel_moisture\" in meso_obss[\"STATION\"][i][\"SENSOR_VARIABLES\"].keys())\n",
106 " station_df[\"wind_speed\"][i] = int(\"wind_speed\" in meso_obss[\"STATION\"][i][\"SENSOR_VARIABLES\"].keys())\n",
107 " station_df[\"solar_radiation\"][i] = int(\"solar_radiation\" in meso_obss[\"STATION\"][i][\"SENSOR_VARIABLES\"].keys())"
112 "execution_count": 7,
113 "id": "99938a78-4cac-440b-a2d8-6509b30f8c31",
119 "# Filter to stations with complete observations over time period\n",
120 "station_df = station_df[\n",
121 " (station_df[\"fuel_moisture\"]==1) & \n",
122 " (station_df[\"relative_humidity\"]==1) &\n",
123 " (station_df[\"precip_accum\"]==1) &\n",
124 " (station_df[\"air_temp\"]==1) &\n",
125 " (station_df[\"wind_speed\"]==1) &\n",
126 " (station_df[\"solar_radiation\"]==1)\n",
128 "# Extract station IDs\n",
130 "ids = station_df['STID'].tolist()"
135 "execution_count": 8,
136 "id": "5492a962-b3da-4407-86d9-8ba35d004c29",
143 "output_type": "stream",
145 "Number of RAWS Stations: 47\n"
150 "print('Number of RAWS Stations: ',station_df.shape[0])"
155 "execution_count": 9,
156 "id": "99dde77e-5f6f-4e45-babf-f7599e8fca14",
161 "# station_df.to_csv(osp.join(outpath, 'station_df_co.csv'), index=False)"
165 "cell_type": "markdown",
166 "id": "1d92fcdb-afaa-4048-848e-e201b29040c4",
169 "## Get Observations"
174 "execution_count": 10,
175 "id": "5ca1523d-b381-457c-9051-d2352144a666",
181 "# Queuery all stations with complete vars\n",
182 "meso_ts = m.timeseries(time_start, time_end, stid=ids, showemptystations = '0', vars=vars) # ask the object for data"
187 "execution_count": null,
188 "id": "7abd402f-af58-46ce-8cb6-6854201f9d31",
194 "# Dictionary to be saved for testing\n",
200 "execution_count": null,
201 "id": "86e20fc8-f935-4577-83d7-ac188739698d",
207 "for i in range(0, len(meso_ts['STATION'])):\n",
208 " raws1 = format_raws(meso_ts['STATION'][i])\n",
210 " 'id': 'case'+str(i+1),\n",
211 " 'time': raws1['time'],\n",
212 " 'rain': raws1['rain'],\n",
213 " 'fm' : raws1['fm'],\n",
214 " 'rh' : raws1['rh'],\n",
215 " 'temp' : raws1['temp'],\n",
216 " 'Ed' : raws1['Ed'],\n",
217 " 'Ew' : raws1['Ew'],\n",
218 " 'wind' : raws1['wind_speed'],\n",
219 " 'solar' : raws1['solar'],\n",
220 " 'STID' : raws1['STID'],\n",
221 " 'title' : 'RAWS Station '+raws1['STID'],\n",
222 " 'descr' : 'RAWS sensor data, Colorado',\n",
223 " 'hours':len(raws1['time']),\n",
224 " 'h2':int(24*20),\n",
225 " 'other': {'lon': raws1['lon'], 'lat': raws1['lat']}\n",
227 " test_dict['case'+str(i+1)] = dict1 # save to test dictionary"
231 "cell_type": "markdown",
232 "id": "35ab9bfc-1773-4d50-a83c-69780945245b",
240 "execution_count": null,
241 "id": "5f0f7cff-96bb-4b1e-a2b7-3fc2afcf5770",
247 "# Create file name from environment vars\n",
248 "filename = \"testing_dict\"+\"_\"+state_str+\"_\"+time_start[0:6:1]\n",
254 "execution_count": null,
255 "id": "6aac2c25-b605-4437-b1de-f0f46cbba308",
261 "os.chdir('data')\n",
262 "with open(filename+'.pickle', 'wb') as handle:\n",
263 " pickle.dump(test_dict, handle, protocol=pickle.HIGHEST_PROTOCOL)"
268 "execution_count": null,
269 "id": "a6bdb681-0843-4dac-be53-e45aa0f4b991",
277 "display_name": "Python 3 (ipykernel)",
278 "language": "python",
286 "file_extension": ".py",
287 "mimetype": "text/x-python",
289 "nbconvert_exporter": "python",
290 "pygments_lexer": "ipython3",