Update params.yaml
[notebooks.git] / fmda / visualizations.ipynb
blobbc6e429d5661f1898c89296e85dbf74abb20e351
2  "cells": [
3   {
4    "cell_type": "code",
5    "execution_count": null,
6    "id": "dd71eb39-f938-440e-99a8-3dc02ee55102",
7    "metadata": {},
8    "outputs": [],
9    "source": [
10     "from utils import read_pkl\n",
11     "from data_funcs import combine_nested\n",
12     "import pandas as pd\n",
13     "import matplotlib.pyplot as plt\n",
14     "import plotly.express as px\n",
15     "import plotly.graph_objects as go\n",
16     "import numpy as np\n",
17     "from mpl_toolkits.basemap import Basemap\n",
18     "from matplotlib.patches import Polygon"
19    ]
20   },
21   {
22    "cell_type": "code",
23    "execution_count": null,
24    "id": "4197b2ae-d8e3-4878-b87b-795f7622c753",
25    "metadata": {},
26    "outputs": [],
27    "source": [
28     "dat = read_pkl(\"train.pkl\")"
29    ]
30   },
31   {
32    "cell_type": "code",
33    "execution_count": null,
34    "id": "524d7d5f-7b07-4e9f-87e6-a1853bf4ef27",
35    "metadata": {},
36    "outputs": [],
37    "source": [
38     "list([*dat.keys()]).index('CHRO3_202401')"
39    ]
40   },
41   {
42    "cell_type": "code",
43    "execution_count": null,
44    "id": "df0ef300-c4d8-4120-889a-7765da096d9a",
45    "metadata": {},
46    "outputs": [],
47    "source": [
48     "d = combine_nested(dat)"
49    ]
50   },
51   {
52    "cell_type": "code",
53    "execution_count": null,
54    "id": "14b96f79-b8bd-403d-9a4a-8a3b9ae87ee6",
55    "metadata": {},
56    "outputs": [],
57    "source": [
58     "d.keys()"
59    ]
60   },
61   {
62    "cell_type": "code",
63    "execution_count": null,
64    "id": "116d180c-324a-4804-b5d4-28707aac7bc9",
65    "metadata": {},
66    "outputs": [],
67    "source": [
68     "locs = d['loc']\n",
69     "locs.keys()"
70    ]
71   },
72   {
73    "cell_type": "code",
74    "execution_count": null,
75    "id": "d28d3760-92ad-4e14-90fd-69020c2c4b56",
76    "metadata": {},
77    "outputs": [],
78    "source": [
79     "# NW GACC\n",
80     "bbox = [42, -124.6, 49, -116.4]"
81    ]
82   },
83   {
84    "cell_type": "code",
85    "execution_count": null,
86    "id": "eb6ad122-815b-4f83-8049-c3e28fb62c12",
87    "metadata": {},
88    "outputs": [],
89    "source": [
90     "df = pd.DataFrame({key: locs[key] for key in ['STID', 'lat', 'lon']})\n",
91     "df"
92    ]
93   },
94   {
95    "cell_type": "code",
96    "execution_count": null,
97    "id": "4c04a46d-7096-4fad-8c20-807e409f8f80",
98    "metadata": {},
99    "outputs": [],
100    "source": [
101     "def make_st_map_interactive(df):\n",
102     "    fig = go.Figure(go.Scattermapbox(\n",
103     "        lat=df['lat'],\n",
104     "        lon=df['lon'],\n",
105     "        mode='markers',\n",
106     "        marker=go.scattermapbox.Marker(\n",
107     "            size=10,\n",
108     "            opacity=0.7,\n",
109     "        ),\n",
110     "        text=df['STID'],\n",
111     "        name='',\n",
112     "        showlegend=False  # Turn off legend\n",
113     "    ))\n",
114     "\n",
115     "    # Add Points\n",
116     "    center_lon=df['lon'].median()\n",
117     "    center_lat=df['lat'].median()\n",
118     "    fig.update_layout(\n",
119     "        mapbox_style=\"open-street-map\",\n",
120     "        mapbox_center=dict(lat=center_lat, lon=center_lon)\n",
121     "    )\n",
122     "    # Add Lines for Bounding Box\n",
123     "    \n",
124     "    fig.add_trace(go.Scattermapbox(\n",
125     "        mode=\"lines\",\n",
126     "        lon=[df['lon'].min(), df['lon'].min(), df['lon'].max(), df['lon'].max(), df['lon'].min()],\n",
127     "        lat=[df['lat'].min(), df['lat'].max(), df['lat'].max(), df['lat'].min(), df['lat'].min()],\n",
128     "        marker=dict(size=5, color=\"black\"),\n",
129     "        line=dict(width=1.5, color=\"black\"),\n",
130     "        showlegend=False\n",
131     "    ))\n",
132     "    \n",
133     "    fig.update_layout(\n",
134     "        margin={\"r\":0,\"t\":0,\"l\":0,\"b\":0},\n",
135     "        mapbox_zoom =5,\n",
136     "        mapbox_center={\"lat\": np.median(df.lat), \"lon\": np.median(df.lon)},  # Center the map on desired location\n",
137     "        width=1000,\n",
138     "        height=800\n",
139     "    )\n",
140     "    return fig"
141    ]
142   },
143   {
144    "cell_type": "code",
145    "execution_count": null,
146    "id": "1fd6cfd9-8ce5-44a8-a618-fc06ba898666",
147    "metadata": {},
148    "outputs": [],
149    "source": [
150     "make_st_map_interactive(df)"
151    ]
152   },
153   {
154    "cell_type": "code",
155    "execution_count": null,
156    "id": "39374ba7-e4fb-4a7d-a9b0-7bca76e2f950",
157    "metadata": {},
158    "outputs": [],
159    "source": [
160     "st = \"HOOI1\"\n",
161     "ind = d['loc']['STID'].index(st)"
162    ]
163   },
164   {
165    "cell_type": "code",
166    "execution_count": null,
167    "id": "62053cfb-d882-4044-90c5-38165572596e",
168    "metadata": {},
169    "outputs": [],
170    "source": [
171     "fig, ax = plt.subplots()\n",
172     "plt.title(f\"RAWS Station {st}\")\n",
173     "ax.plot(d['y'][ind][3000:3500], linestyle='-',c='#468a29',label='FMC Observed')\n",
174     "plt.legend(loc='upper right')\n",
175     "ax.set_ylabel(\"Fuel Moisture Content (%)\")\n",
176     "ax.set_xlabel(\"Hour\")\n",
177     "plt.savefig(\"outputs/fmc_plot2.png\")\n",
178     "# Increase the thickness of the axis borders\n",
179     "ax.spines['top'].set_linewidth(1.5)\n",
180     "ax.spines['bottom'].set_linewidth(1.5)\n",
181     "ax.spines['left'].set_linewidth(1.5)\n",
182     "ax.spines['right'].set_linewidth(1.5)\n",
183     "\n",
184     "plt.savefig(\"outputs/fmc_plot2.png\")"
185    ]
186   },
187   {
188    "cell_type": "code",
189    "execution_count": null,
190    "id": "58961640-8836-4920-8a08-e891f5b17c34",
191    "metadata": {},
192    "outputs": [],
193    "source": []
194   },
195   {
196    "cell_type": "code",
197    "execution_count": null,
198    "id": "0dcdc7ca-da86-430f-a38b-ad5abe4abfe6",
199    "metadata": {},
200    "outputs": [],
201    "source": []
202   },
203   {
204    "cell_type": "code",
205    "execution_count": null,
206    "id": "86d94b91-fbb4-47fb-bba0-e41551f361b5",
207    "metadata": {},
208    "outputs": [],
209    "source": []
210   }
211  ],
212  "metadata": {
213   "kernelspec": {
214    "display_name": "Python 3 (ipykernel)",
215    "language": "python",
216    "name": "python3"
217   },
218   "language_info": {
219    "codemirror_mode": {
220     "name": "ipython",
221     "version": 3
222    },
223    "file_extension": ".py",
224    "mimetype": "text/x-python",
225    "name": "python",
226    "nbconvert_exporter": "python",
227    "pygments_lexer": "ipython3",
228    "version": "3.10.13"
229   }
230  },
231  "nbformat": 4,
232  "nbformat_minor": 5