Merge pull request #17 from openwfm/restructure
[notebooks.git] / fmda / data / synopticpy_tutorial.ipynb
blobd6342c067c1432ed7582408c0a11ac23b0965987
2  "cells": [
3   {
4    "cell_type": "markdown",
5    "id": "f1f4cc18-d23f-48ea-84dc-b0328a65e8e5",
6    "metadata": {},
7    "source": [
8     "# Collect RAWS Data with SynopticPy"
9    ]
10   },
11   {
12    "cell_type": "markdown",
13    "id": "84ed774d-7bef-48e7-b9a6-8f4ba4e17d81",
14    "metadata": {},
15    "source": [
16     "## Setup"
17    ]
18   },
19   {
20    "cell_type": "code",
21    "execution_count": null,
22    "id": "509b32fd-9d6b-4582-b724-4d2a094a6832",
23    "metadata": {},
24    "outputs": [],
25    "source": [
26     "import matplotlib.pyplot as plt\n",
27     "from datetime import datetime\n",
28     "\n",
29     "from synoptic.services import stations_timeseries"
30    ]
31   },
32   {
33    "cell_type": "markdown",
34    "id": "4fbefa25-ac25-4164-adbc-187f9740b6b8",
35    "metadata": {},
36    "source": [
37     "## Station Time Series"
38    ]
39   },
40   {
41    "cell_type": "code",
42    "execution_count": null,
43    "id": "8f05be2b-0120-4637-b5d2-a258211b2650",
44    "metadata": {},
45    "outputs": [],
46    "source": [
47     "params = dict(\n",
48     "    stid=[\"PLFI1\"],\n",
49     "    vars=[\"air_temp\", \"relative_humidity\", \"precip_accum\", \"fuel_moisture\", \"wind_speed\", \"solar_radiation\", \"soil_moisture\"],\n",
50     "    start=datetime(2024, 1, 1),\n",
51     "    end=datetime(2024, 6, 1),\n",
52     ")\n",
53     "\n",
54     "a = stations_timeseries(verbose=\"HIDE\", **params)\n",
55     "\n",
56     "a"
57    ]
58   },
59   {
60    "cell_type": "code",
61    "execution_count": null,
62    "id": "8ce7b02c-4149-443e-b29d-da8cdf12583e",
63    "metadata": {},
64    "outputs": [],
65    "source": [
66     "type(a)"
67    ]
68   },
69   {
70    "cell_type": "code",
71    "execution_count": null,
72    "id": "880122b3-f947-4d0f-b391-841db74c8eef",
73    "metadata": {},
74    "outputs": [],
75    "source": [
76     "import numpy as np\n",
77     "np.diff(a.precip_accum, 1)"
78    ]
79   },
80   {
81    "cell_type": "code",
82    "execution_count": null,
83    "id": "7068d270-d6e8-4afc-9bfe-881e8d7d4c6f",
84    "metadata": {},
85    "outputs": [],
86    "source": [
87     "a.precip_accum"
88    ]
89   },
90   {
91    "cell_type": "code",
92    "execution_count": null,
93    "id": "e711774a-f8be-4f60-ac8c-8908f5c192ec",
94    "metadata": {},
95    "outputs": [],
96    "source": [
97     "print(f'Station Elevation: {a.attrs[\"ELEVATION\"]}')\n",
98     "print(f'Lat: {a.attrs[\"latitude\"]}')\n",
99     "print(f'Lon: {a.attrs[\"longitude\"]}')\n",
100     "print(f'Temp Units: {a.attrs[\"UNITS\"][\"air_temp\"]}')\n",
101     "print(f'Wind Units: {a.attrs[\"UNITS\"][\"wind_speed\"]}')\n",
102     "# print(f'Solar Rad. Units: {a.attrs[\"UNITS\"][\"solar_radiation\"]}')"
103    ]
104   },
105   {
106    "cell_type": "code",
107    "execution_count": null,
108    "id": "2058d705-a2d3-48d9-9151-a4536512057e",
109    "metadata": {},
110    "outputs": [],
111    "source": [
112     "a.attrs"
113    ]
114   },
115   {
116    "cell_type": "code",
117    "execution_count": null,
118    "id": "ccddffba-f785-4fb8-a053-b87ad648ef9c",
119    "metadata": {},
120    "outputs": [],
121    "source": [
122     "plt.plot(a.fuel_moisture)"
123    ]
124   },
125   {
126    "cell_type": "code",
127    "execution_count": null,
128    "id": "6901c78a-8f6f-4af7-8fbe-e0e15dea0b6c",
129    "metadata": {},
130    "outputs": [],
131    "source": []
132   }
133  ],
134  "metadata": {
135   "kernelspec": {
136    "display_name": "Python 3 (ipykernel)",
137    "language": "python",
138    "name": "python3"
139   },
140   "language_info": {
141    "codemirror_mode": {
142     "name": "ipython",
143     "version": 3
144    },
145    "file_extension": ".py",
146    "mimetype": "text/x-python",
147    "name": "python",
148    "nbconvert_exporter": "python",
149    "pygments_lexer": "ipython3",
150    "version": "3.12.5"
151   }
152  },
153  "nbformat": 4,
154  "nbformat_minor": 5