Skip to content

Commit 229e38a

Browse files
committed
Add duramat workshop notebook skeleton
1 parent 18c20e5 commit 229e38a

1 file changed

Lines changed: 283 additions & 0 deletions

File tree

duramat-workshop.ipynb

Lines changed: 283 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,283 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 2,
6+
"id": "114cad4b",
7+
"metadata": {},
8+
"outputs": [
9+
{
10+
"name": "stdout",
11+
"output_type": "stream",
12+
"text": [
13+
"Starting Postgres subprocess...\n",
14+
"PostgreSQL connection established after 0.10 seconds.\n",
15+
"postgis already installed\n"
16+
]
17+
}
18+
],
19+
"source": [
20+
"import geogridfusion\n",
21+
"import pvdeg\n",
22+
"\n",
23+
"import numpy as np # range generation for bounding box\n",
24+
"\n",
25+
"conn = geogridfusion.start()"
26+
]
27+
},
28+
{
29+
"cell_type": "markdown",
30+
"id": "2ea71adc",
31+
"metadata": {},
32+
"source": [
33+
"Generate coordinate pairs to request"
34+
]
35+
},
36+
{
37+
"cell_type": "code",
38+
"execution_count": null,
39+
"id": "e12b7100",
40+
"metadata": {},
41+
"outputs": [],
42+
"source": [
43+
"longitude = [-109.060253, -102.041524]\n",
44+
"latitude = [36.992426, 41.003444]\n",
45+
"\n",
46+
"RESOLUTION = 5\n",
47+
"\n",
48+
"lats = np.linspace(latitude[0], latitude[1], RESOLUTION)\n",
49+
"lons = np.linspace(longitude[0], longitude[1], RESOLUTION)\n",
50+
"\n",
51+
"lat_grid, lon_grid = np.meshgrid(lats, lons, indexing='ij')\n",
52+
"pairs = np.column_stack((lat_grid.ravel(), lon_grid.ravel()))\n"
53+
]
54+
},
55+
{
56+
"cell_type": "markdown",
57+
"id": "240b7f97",
58+
"metadata": {},
59+
"source": [
60+
"option a: get weather and store for one location at a time."
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": null,
66+
"id": "e115207d",
67+
"metadata": {},
68+
"outputs": [],
69+
"source": [
70+
"for pair in pairs:\n",
71+
" single_weather, single_meta = pvdeg.weather.get(\n",
72+
" database=\"PVGIS\",\n",
73+
" id=tuple(pair)\n",
74+
" )\n",
75+
"\n",
76+
" geogridfusion.store_single(conn=conn, weather_df=single_weather, meta=single_meta, tmy=True, source_name=\"pvgis\")\n"
77+
]
78+
},
79+
{
80+
"cell_type": "markdown",
81+
"id": "a112e914",
82+
"metadata": {},
83+
"source": [
84+
"option b: get weather using dask for parallel speedup and write individually after all locations are loaded"
85+
]
86+
},
87+
{
88+
"cell_type": "code",
89+
"execution_count": null,
90+
"id": "a019046a",
91+
"metadata": {},
92+
"outputs": [
93+
{
94+
"name": "stderr",
95+
"output_type": "stream",
96+
"text": [
97+
"c:\\Users\\tford\\AppData\\Local\\miniconda3\\envs\\geogridfusion\\Lib\\site-packages\\distributed\\node.py:187: UserWarning: Port 8787 is already in use.\n",
98+
"Perhaps you already have a cluster running?\n",
99+
"Hosting the HTTP server on port 50853 instead\n",
100+
" warnings.warn(\n",
101+
"c:\\Users\\tford\\AppData\\Local\\miniconda3\\envs\\geogridfusion\\Lib\\contextlib.py:144: UserWarning: Creating scratch directories is taking a surprisingly long time. (1.68s) This is often due to running workers on a network file system. Consider specifying a local-directory to point workers to write scratch data to a local disk.\n",
102+
" next(self.gen)\n"
103+
]
104+
},
105+
{
106+
"name": "stdout",
107+
"output_type": "stream",
108+
"text": [
109+
"Dashboard: http://127.0.0.1:50853/status\n",
110+
"Connected to a Dask scheduler | Dashboard: http://127.0.0.1:50853/status\n"
111+
]
112+
}
113+
],
114+
"source": [
115+
"client = pvdeg.geospatial.start_dask()\n",
116+
"\n",
117+
"# this is a required step, otherwis4e the distrubted weather call will raise AttributeError: 'NoneType' object has no attribute 'sizes'\n",
118+
"pairs_tuples = [tuple(pair) for pair in pairs]\n",
119+
"\n",
120+
"try:\n",
121+
" geo_weather, geo_meta, failed_idx = pvdeg.weather.weather_distributed(\n",
122+
" database=\"PVGIS\",\n",
123+
" coords=pairs_tuples\n",
124+
" )\n",
125+
"\n",
126+
"except Exception as e:\n",
127+
" client.close()\n",
128+
" raise e\n",
129+
"\n",
130+
"\n",
131+
"# geo_weather\n",
132+
"\n",
133+
"for i, gid in enumerate(geo_weather.gid):\n",
134+
" geogridfusion.store_single(\n",
135+
" conn=conn,\n",
136+
" weather_df=geo_weather.sel(gid=gid).to_dataframe(),\n",
137+
" meta=geo_meta.iloc[i].to_dict(),\n",
138+
" tmy=True,\n",
139+
" source_name='pvgis'\n",
140+
" )"
141+
]
142+
},
143+
{
144+
"cell_type": "markdown",
145+
"id": "309774a1",
146+
"metadata": {},
147+
"source": [
148+
"Load all stored locations from dataset"
149+
]
150+
},
151+
{
152+
"cell_type": "code",
153+
"execution_count": null,
154+
"id": "6a136506",
155+
"metadata": {},
156+
"outputs": [],
157+
"source": [
158+
"loaded_weather, loaded_meta = geogridfusion.load_many(conn=conn, source_name=\"pvgis\")\n",
159+
"\n",
160+
"loaded_weather"
161+
]
162+
},
163+
{
164+
"cell_type": "markdown",
165+
"id": "77ce99fd",
166+
"metadata": {},
167+
"source": [
168+
"Run pvdeg geospatial degradation analysis"
169+
]
170+
},
171+
{
172+
"cell_type": "code",
173+
"execution_count": null,
174+
"id": "fe8213d8",
175+
"metadata": {},
176+
"outputs": [],
177+
"source": [
178+
"pvdeg.geospatial.analysis(...)"
179+
]
180+
},
181+
{
182+
"cell_type": "markdown",
183+
"id": "6cb4b57a",
184+
"metadata": {},
185+
"source": [
186+
"Plot result of small analysis"
187+
]
188+
},
189+
{
190+
"cell_type": "code",
191+
"execution_count": null,
192+
"id": "63c8dae9",
193+
"metadata": {},
194+
"outputs": [],
195+
"source": [
196+
"plt.plot(...)"
197+
]
198+
},
199+
{
200+
"cell_type": "markdown",
201+
"id": "7b201c21",
202+
"metadata": {},
203+
"source": [
204+
"### But wait, what if we want to do the entire country"
205+
]
206+
},
207+
{
208+
"cell_type": "code",
209+
"execution_count": null,
210+
"id": "108b2725",
211+
"metadata": {},
212+
"outputs": [],
213+
"source": [
214+
"# download 100 points for the rest of the country\n",
215+
"# should they be from pvgis or nsrdb, or others?\n",
216+
"...\n",
217+
"\n",
218+
"# store 100 points for the rest of the country"
219+
]
220+
},
221+
{
222+
"cell_type": "markdown",
223+
"id": "7f2ab408",
224+
"metadata": {},
225+
"source": [
226+
"Load whole country, (show how we can store more points over-time as needs change)\n",
227+
"\n",
228+
"Can demonstrate some downselection here? Or combining of different datasets?"
229+
]
230+
},
231+
{
232+
"cell_type": "code",
233+
"execution_count": null,
234+
"id": "d45d8790",
235+
"metadata": {},
236+
"outputs": [],
237+
"source": [
238+
"geogridfusion.load_many(conn=conn, source_name=\"pvgis\")"
239+
]
240+
},
241+
{
242+
"cell_type": "markdown",
243+
"id": "6948986f",
244+
"metadata": {},
245+
"source": [
246+
"Perform same analysis and create a plot for the whole country."
247+
]
248+
},
249+
{
250+
"cell_type": "code",
251+
"execution_count": null,
252+
"id": "8ee4ba94",
253+
"metadata": {},
254+
"outputs": [],
255+
"source": [
256+
"pvdeg.geospatial.analysis()\n",
257+
"\n",
258+
"plt.plot(...)"
259+
]
260+
}
261+
],
262+
"metadata": {
263+
"kernelspec": {
264+
"display_name": "geogridfusion",
265+
"language": "python",
266+
"name": "python3"
267+
},
268+
"language_info": {
269+
"codemirror_mode": {
270+
"name": "ipython",
271+
"version": 3
272+
},
273+
"file_extension": ".py",
274+
"mimetype": "text/x-python",
275+
"name": "python",
276+
"nbconvert_exporter": "python",
277+
"pygments_lexer": "ipython3",
278+
"version": "3.12.6"
279+
}
280+
},
281+
"nbformat": 4,
282+
"nbformat_minor": 5
283+
}

0 commit comments

Comments
 (0)