This repository was archived by the owner on Dec 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataTweak.py
More file actions
617 lines (478 loc) · 22 KB
/
DataTweak.py
File metadata and controls
617 lines (478 loc) · 22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
import numpy as np
import pandas
import matplotlib.pyplot as plt
import os
import pandas
from statistics import mean
from functools import reduce
from sklearn.linear_model import LinearRegression
path = "\Datasets"
start_dir = os.getcwd() + path
snotel_sites = os.listdir(start_dir)
snotel_sites_withYampa = snotel_sites + ["Yampa River Basin.csv"]
full_data_sites = []
snotel_raw_data = {} #This is the accumulated swe of snotel sites
snotel_daily_swe = {} #This is the daily positive swe of snotel sites
snotel_normal_swe = {} #This is the daily non-extreme positive swe of snotel sites
snotel_ewe_swe = {} #This is the daily extreme swe of snotel sites
snotel_daily_swe_complete = {} #For sites that have the complete data for 31 years
snotel_daily_ewe_swe_complete = {} #For sites that have the complete data for 31 years
max_annual_swe = {} #This contains the maximum swe of each year for each snotel site
r_squared = {}
start_date = {} #This stores the start date of all of the datasets
total_swe = {} #This is the sum of daily swe of all of the years for each snotel site
total_ewe_swe = {} #This is the accumulated extreme weather swe for all the years combined
ewe_percentage_contribution = {} #Stores the ewe contribution percentage for each snotel site
average_annual_swe = {} #This is the average annual swe for each snotel site
average_annual_ewe_swe = {} #This is the average annual swe contributed by ewe's for each snotel site
#Reading DATA from Snotels
for site in snotel_sites:
file_path = start_dir + "\\" + site
file_dataframe = pandas.read_csv(file_path, parse_dates=["Date"], usecols=["Date", "Snow Water Equivalent (in) Start of Day Values"], index_col=["Date"])
file_dataframe = file_dataframe['10/1/1989' : '09/30/2020']
snotel_raw_data[site] = file_dataframe #Adding data to coin_datas
#Calculating Daily SWE from ACC SWE
diff_dataframe = file_dataframe.diff()
diff_dataframe = diff_dataframe.clip(lower=0)
diff_dataframe = diff_dataframe[diff_dataframe["Snow Water Equivalent (in) Start of Day Values"] > 0]
#print(diff_dataframe)
snotel_daily_swe[site] = diff_dataframe
#Finds missing datasets and also updates full_data_sites
def find_missing_datasets():
global start_date
global full_data_sites
startDate = {"Snotel Sites":[], "Start Year":[]}
for site in snotel_sites:
start_date[site] = snotel_raw_data[site].index.year[0]
date = "10/1/" + str(start_date[site])
startDate["Snotel Sites"].append(site[:-4])
startDate["Start Year"].append(date)
if start_date[site] == 1989:
full_data_sites.append(site)
#Adding the start date for Yampa River basin
start_date["Yampa River Basin.csv"] = 1989
#frame = pandas.DataFrame(startDate)
#frame = frame.set_index('Snotel Sites')
#frame.to_csv('start date.csv')
#Adds Yampa Data to snotel daily
def addYampa():
global snotel_daily_swe
#####Finding Yampa River Basin Mean EWE
yampa_river_basin = reduce(lambda x, y: x.add(y, fill_value=0), [snotel_daily_swe[site] for site in full_data_sites])
yampa_river_basin = yampa_river_basin/len(full_data_sites)
yampa_river_basin = yampa_river_basin[yampa_river_basin["Snow Water Equivalent (in) Start of Day Values"] > .05]
snotel_daily_swe["Yampa River Basin.csv"] = yampa_river_basin
def preprocessing():
global snotel_ewe_swe
global ewe_percentage_contribution
global average_annual_ewe_swe
global total_ewe_swe
global total_swe
global max_annual_swe
###Adding the average yampa river basin
for site in snotel_sites_withYampa:
########### Getting the snotel_positive values
curr_snotel = snotel_daily_swe[site]
######CALCULATING AND STORING ONLY THE 99th Percentile
percentile = curr_snotel.quantile(q = .99, axis = 0, numeric_only = True)
percentile_cutoff = percentile[0] #This is the value of our interest as all values >= are in the 99th percentile
curr_snotel_99percentile = curr_snotel[curr_snotel['Snow Water Equivalent (in) Start of Day Values'] >= percentile_cutoff]
snotel_ewe_swe[site] = curr_snotel_99percentile
### Saving to CSV ###
#curr_snotel_99percentile.to_csv("Dataset/EWE SWE/99 Percentile/"+ site[:-4] + ' 99th percentile.csv')
##### Calculating accumulated SWE for all 31 years
swe_total = curr_snotel.sum()[0]
total_swe[site] = swe_total
#######Calculating accumulated SWE for all 31 years contributed by EWE's
swe_99percentile_total = curr_snotel_99percentile.sum()[0]
total_ewe_swe[site] = swe_99percentile_total
####### Calculating percentage of accumulated SWE contributed by EWE's
swe_99percentile_contribution_percentage = swe_99percentile_total/swe_total*100
ewe_percentage_contribution[site] = swe_99percentile_contribution_percentage
############AVERAGES OF SWE's of previous step
### Calculating average accumulated SWE for a water year
average_annual_swe[site] = curr_snotel.sum()[0]/(2020-start_date[site])
### Calculating average accumulated SWE contributed by EWE's for a water year
average_annual_ewe_swe[site] = curr_snotel_99percentile.sum()[0]/(2020-start_date[site])
# Calculating maximum daily SWE recorded for each water year
maxByYear = {}
for year in range (1989, 2019):
max_val = curr_snotel['10/1/' + str(year): '12/31/' + str(year+1)].max()[0]
maxByYear[year] = max_val
max_annual_swe[site] = maxByYear
#Graphs Daily SWE of each snotel site
def graph_daily_swe():
for site in snotel_sites:
curr_snotel = snotel_daily_swe[site]
#GRAPHING
plt.title(site[:-4])
plt.xlabel('Date')
plt.ylabel('SWE (inches)')
plt.plot(curr_snotel,label= site[:-4])
axes = plt.gca()
axes.set_ylim([0.25,3.5])
plt.legend()
figure = plt.gcf()
figure.set_size_inches(19, 10)
### IF you want to save the graph uncomment this line
plt.savefig("Graphs/Daily SWE/" + site[:-4] + "SWE .png", bbox_inches='tight',dpi=120*2)
plt.show()
### Saving to CSV ###
curr_snotel.to_csv("CSVs for data/Daily SWE/" + site[:-4] + ' positive SWE.csv')
#Scatters Days with extreme SWE of each snotel site
def graph_daily_ewe_swe():
for site in snotel_sites_withYampa:
curr_snotel = snotel_ewe_swe[site]
#GRAPHING
plt.title(site[:-4])
plt.xlabel('Date')
plt.ylabel('SWE (inches)')
plt.scatter(x=snotel_ewe_swe[site].index.values, y = curr_snotel,label= site[:-4])
axes = plt.gca()
axes.set_ylim([0.25,3.5])
#Fitting a line
year = snotel_ewe_swe[site].index.year
month = snotel_ewe_swe[site].index.month
day =snotel_ewe_swe[site].index.day
x = year + month/12 + day/365
y = snotel_ewe_swe[site]["Snow Water Equivalent (in) Start of Day Values"]
fit = np.polyfit(x, y, deg = 1)
fit_fn = np.poly1d(fit)
plt.plot(snotel_ewe_swe[site].index.values, fit_fn(x), color = 'C3')
plt.legend()
figure = plt.gcf()
figure.set_size_inches(19, 10)
### IF you want to save the graph uncomment this line
plt.savefig("Graphs/Daily EWE SWE/" + site[:-4] + "99 Percentile EWE SWE.png", bbox_inches='tight',dpi=120*2)
plt.show()
### Saving to CSV ###
curr_snotel.to_csv("CSVs for data/Daily SWE/" + site[:-4] + ' positive SWE.csv')
#Scatters a multiplot extreme SWE
def graph_daily_ewe_swe_multiplot():
#First 9 sites
fig = plt.figure()
i=1
for site in snotel_sites_withYampa[:9]:
plt.subplot(3,3,i)
curr_snotel = snotel_ewe_swe[site]
#GRAPHING
plt.title(site[:-4])
plt.ylabel('SWE (inches)')
plt.scatter(x=snotel_ewe_swe[site].index.values, y = curr_snotel,label= site[:-4])
axes = plt.gca()
axes.set_ylim([0.25,3.5])
#Fitting a line
year = snotel_ewe_swe[site].index.year
month = snotel_ewe_swe[site].index.month
day =snotel_ewe_swe[site].index.day
x = year + month/12 + day/365
y = snotel_ewe_swe[site]["Snow Water Equivalent (in) Start of Day Values"]
fit = np.polyfit(x, y, deg = 1)
fit_fn = np.poly1d(fit)
plt.plot(snotel_ewe_swe[site].index.values, fit_fn(x), color = 'C3')
i+=1
plt.suptitle("EWE Days")
figure = plt.gcf()
figure.set_size_inches(19, 10)
plt.savefig("Graphs/Daily EWE SWE Multiplot/" + "EWE Multiplot(1).png", bbox_inches='tight', dpi=120*2)
plt.show()
#9-18 Sites
fig = plt.figure()
i=1
for site in snotel_sites_withYampa[9:18]:
plt.subplot(3,3,i)
curr_snotel = snotel_ewe_swe[site]
#GRAPHING
plt.title(site[:-4])
plt.ylabel('SWE (inches)')
plt.scatter(x=snotel_ewe_swe[site].index.values, y = curr_snotel,label= site[:-4])
axes = plt.gca()
axes.set_ylim([0.25,3.5])
#Fitting a line
year = snotel_ewe_swe[site].index.year
month = snotel_ewe_swe[site].index.month
day =snotel_ewe_swe[site].index.day
x = year + month/12 + day/365
y = snotel_ewe_swe[site]["Snow Water Equivalent (in) Start of Day Values"]
fit = np.polyfit(x, y, deg = 1)
fit_fn = np.poly1d(fit)
plt.plot(snotel_ewe_swe[site].index.values, fit_fn(x), color = 'C3')
i+=1
plt.suptitle("EWE Days")
figure = plt.gcf()
figure.set_size_inches(19, 10)
plt.savefig("Graphs/Daily EWE SWE Multiplot/" + "EWE Multiplot(2).png", bbox_inches='tight', dpi=120*2)
plt.show()
#18 onward Sites
#First 9 sites
fig = plt.figure()
i=1
for site in snotel_sites_withYampa[18:]:
plt.subplot(2,2,i)
curr_snotel = snotel_ewe_swe[site]
#GRAPHING
plt.title(site[:-4])
plt.ylabel('SWE (inches)')
plt.scatter(x=snotel_ewe_swe[site].index.values, y = curr_snotel,label= site[:-4])
axes = plt.gca()
axes.set_ylim([0.25,3.5])
#Fitting a line
year = snotel_ewe_swe[site].index.year
month = snotel_ewe_swe[site].index.month
day =snotel_ewe_swe[site].index.day
x = year + month/12 + day/365
y = snotel_ewe_swe[site]["Snow Water Equivalent (in) Start of Day Values"]
fit = np.polyfit(x, y, deg = 1)
fit_fn = np.poly1d(fit)
plt.plot(snotel_ewe_swe[site].index.values, fit_fn(x), color = 'C3')
i+=1
plt.suptitle("EWE Days")
figure = plt.gcf()
figure.set_size_inches(19, 10)
plt.savefig("Graphs/Daily EWE SWE Multiplot/" + "EWE Multiplot(3).png", bbox_inches='tight', dpi=120*2)
plt.show()
#Graphs the SWE Breakdown of the snotel sites + YAMPA river basin
def graph_swe_breakdown_percentage():
totalSWE = [None] * len(snotel_sites)
normalSWE = [None] * len(snotel_sites)
basin_total = []
basin_normal = []
for i in range(len(snotel_sites)):
site = snotel_sites_withYampa[i]
totalSWE[i] = average_annual_swe[site]
normalSWE[i] = average_annual_swe[site] - average_annual_ewe_swe[site]
if site in full_data_sites: #Appending to basin lists the sites that have full data
basin_total.append(totalSWE[i])
basin_normal.append(normalSWE[i])
#Taking mean of the lists to find the average SWE
totalSWE.append(mean(basin_total))
normalSWE.append(mean(basin_normal))
#GRAPHING
fig, ax = plt.subplots()
# creating the bar plot
first_bars = ax.barh([site[:-4] for site in snotel_sites_withYampa], totalSWE, label = "Extreme Weather SWE per Water Year", color = 'C1')
second_bars = ax.barh([site[:-4] for site in snotel_sites_withYampa], normalSWE, label = "Non-extreme SWE per Water Year", color = 'C0')
ax.set_xlabel("Total SWE (inches)")
ax.set_ylabel("Snotel Sites")
plt.title("SWE Breakdown of Yampa River Basin")
ax.legend()
#bars = plt.barh(x, height=y, width=.4)
for index in range (len(snotel_sites_withYampa)):
bar = first_bars[index]
w,h = bar.get_width(), bar.get_height()
x0, y0 = bar.xy
x3, y3 = x0+w, y0+h
plt.text(x3+.25,y3-.35, "{:.2f}".format((totalSWE[index]-normalSWE[index])*100/totalSWE[index]), color = "C0", va = 'center')
# yval = bar.get_height()
# plt.text(bar.get_x(), yval + .005, yval)
for index in range (len(snotel_sites_withYampa)):
bar = second_bars[index]
w,h = bar.get_width(), bar.get_height()
x0, y0 = bar.xy
plt.text(x0,y0+.33, "{:.2f}".format(normalSWE[index]*100/totalSWE[index]), color = "C1", va = 'center')
# yval = bar.get_height()
# plt.text(bar.get_x(), yval + .005, yval)
plt.legend(bbox_to_anchor=(1.05, 1))
figure = plt.gcf()
figure.set_size_inches(19, 10)
plt.savefig("Graphs/SWE Breakdown/" + "99 Percentile SWE Breakdown.png", bbox_inches='tight',dpi=120*2)
plt.show()
#Graphs the SWE Breakdown of the snotel sites + YAMPA river basin
def graph_breakdown_percentage():
totalSWE = [None] * len(snotel_sites)
normalSWE = [None] * len(snotel_sites)
basin_total = []
basin_normal = []
percentage_normalSWE = [None] * len(snotel_sites_withYampa)
percentage_totalSWE = [None] * len(snotel_sites_withYampa)
for i in range(len(snotel_sites)):
site = snotel_sites_withYampa[i]
totalSWE[i] = average_annual_swe[site]
normalSWE[i] = average_annual_swe[site] - average_annual_ewe_swe[site]
if site in full_data_sites: #Appending to basin lists the sites that have full data
basin_total.append(totalSWE[i])
basin_normal.append(normalSWE[i])
#Taking mean of the lists to find the average SWE
totalSWE.append(mean(basin_total))
normalSWE.append(mean(basin_normal))
#Calculating the percentages
for i in range(len(snotel_sites_withYampa)):
percentage_normalSWE[i] = normalSWE[i]*100/totalSWE[i]
percentage_totalSWE[i] = 100
#GRAPHING
fig, ax = plt.subplots()
# creating the bar plot
first_bars = ax.barh([site[:-4] for site in snotel_sites_withYampa], percentage_totalSWE, label = "Contribution of Extreme Weather", color = 'C1')
second_bars = ax.barh([site[:-4] for site in snotel_sites_withYampa], percentage_normalSWE, label = "Contribution of Normal Weather", color = 'C0')
ax.set_xlabel("Percentage of total SWE")
ax.set_ylabel("Snotel Sites")
plt.title("SWE Breakdown of Yampa River Basin")
ax.legend()
#bars = plt.barh(x, height=y, width=.4)
for index in range (len(snotel_sites_withYampa)):
bar = first_bars[index]
w,h = bar.get_width(), bar.get_height()
x0, y0 = bar.xy
x3, y3 = x0+w, y0+h
plt.text(x3+.25,y3-.35, "{:.2f}".format((totalSWE[index]-normalSWE[index])*100/totalSWE[index]), color = "C0", va = 'center')
# yval = bar.get_height()
# plt.text(bar.get_x(), yval + .005, yval)
for index in range (len(snotel_sites_withYampa)):
bar = second_bars[index]
w,h = bar.get_width(), bar.get_height()
x0, y0 = bar.xy
plt.text(x0,y0+.33, "{:.2f}".format(normalSWE[index]*100/totalSWE[index]), color = "C1", va = 'center')
# yval = bar.get_height()
# plt.text(bar.get_x(), yval + .005, yval)
plt.legend(bbox_to_anchor=(1.05, 1))
figure = plt.gcf()
figure.set_size_inches(19, 10)
plt.savefig("Graphs/SWE Breakdown/" + "99 Percentile SWE Percentage Breakdown.png", bbox_inches='tight',dpi=120*2)
plt.show()
#Graphs the maximum SWE recorded for each water Year for each snotel site
def graph_max_annual_swe():
#First 9 sites
fig = plt.figure()
i=1
for site in snotel_sites[:9]:
plt.subplot(3,3,i)
plt.scatter(max_annual_swe[site].keys(), max_annual_swe[site].values(), label= site[:-4])
axes = plt.gca()
axes.set_ylim([.5,3.5])
plt.title(site[:-4])
i+=1
plt.xlabel("Water Years")
plt.ylabel("SWE(inches)")
plt.suptitle("Annual Maximum SWE")
figure = plt.gcf()
figure.set_size_inches(19, 10)
plt.savefig("Graphs/Annual Maximum SWE/" + "Annual Maximum SWE(1).png", bbox_inches='tight', dpi=120*2)
plt.show()
#9-18 Sites
fig = plt.figure()
i=1
for site in snotel_sites[9:18]:
plt.subplot(3,3,i)
plt.scatter(max_annual_swe[site].keys(), max_annual_swe[site].values(), label= site[:-4])
axes = plt.gca()
axes.set_ylim([.5,3.5])
plt.title(site[:-4])
i+=1
plt.xlabel("Water Years")
plt.ylabel("SWE(inches)")
plt.suptitle("Annual Maximum SWE")
figure = plt.gcf()
figure.set_size_inches(19, 10)
plt.savefig("Graphs/Annual Maximum SWE/" + "Annual Maximum SWE(2).png", bbox_inches='tight', dpi=120*2)
plt.show()
#18 onward Sites
fig = plt.figure()
i=1
for site in snotel_sites[18:]:
plt.subplot(2,2,i)
plt.scatter(max_annual_swe[site].keys(), max_annual_swe[site].values(), label= site[:-4])
axes = plt.gca()
axes.set_ylim([.5,3.5])
plt.title(site[:-4])
i+=1
plt.xlabel("Water Years")
plt.ylabel("SWE(inches)")
plt.suptitle("Annual Maximum SWE")
figure = plt.gcf()
figure.set_size_inches(19, 10)
plt.savefig("Graphs/Annual Maximum SWE/" + "Annual Maximum SWE(3).png", bbox_inches='tight', dpi=120*2)
plt.show()
# Graphs the EWE events of each snotel site
def graph_ewe_days_all():
#GRAPHING ALL
fig = plt.figure()
for site in snotel_sites_withYampa:
df = snotel_ewe_swe[site].astype(str)
df['Snow Water Equivalent (in) Start of Day Values'] = df['Snow Water Equivalent (in) Start of Day Values'].replace([row[0] for _,row in df.iterrows()],site[:-4])
df = df['10/1/1989' : '09/30/2020']
plt.scatter(df.index.values, df["Snow Water Equivalent (in) Start of Day Values"], label= site[:-4], marker='x')
plt.xlabel("Water Years")
plt.ylabel("Snotel Sites")
plt.legend(bbox_to_anchor=(1.05, 1))
figure = plt.gcf()
figure.set_size_inches(19, 10)
#Uncomment to save plot
plt.savefig("Graphs/EWE Days All/" + "99 Percentile EWE Days.png", bbox_inches='tight', dpi=120*2)
plt.show()
#GRAPHING PART 1
fig = plt.figure()
for site in snotel_sites_withYampa:
df = snotel_ewe_swe[site].astype(str)
df['Snow Water Equivalent (in) Start of Day Values'] = df['Snow Water Equivalent (in) Start of Day Values'].replace([row[0] for _,row in df.iterrows()],site[:-4])
df = df['10/1/1989' : '09/30/2000']
plt.scatter(df.index.values, df["Snow Water Equivalent (in) Start of Day Values"], label= site[:-4], marker='x')
plt.xlabel("Water Years")
plt.ylabel("Snotel Sites")
plt.legend(bbox_to_anchor=(1.05, 1))
figure = plt.gcf()
figure.set_size_inches(19, 10)
#Uncomment to save plot
plt.savefig("Graphs/EWE Days All/" + "99 Percentile EWE Days(1).png", bbox_inches='tight', dpi=120*2)
plt.show()
#GRAPHING PART 2
fig = plt.figure()
for site in snotel_sites_withYampa:
df = snotel_ewe_swe[site].astype(str)
df['Snow Water Equivalent (in) Start of Day Values'] = df['Snow Water Equivalent (in) Start of Day Values'].replace([row[0] for _,row in df.iterrows()],site[:-4])
df = df['10/1/1999' : '09/30/2010']
plt.scatter(df.index.values, df["Snow Water Equivalent (in) Start of Day Values"], label= site[:-4], marker='x')
plt.xlabel("Water Years")
plt.ylabel("Snotel Sites")
plt.legend(bbox_to_anchor=(1.05, 1))
figure = plt.gcf()
figure.set_size_inches(19, 10)
#Uncomment to save plot
plt.savefig("Graphs/EWE Days All/" + "99 Percentile EWE Days(2).png", bbox_inches='tight', dpi=120*2)
plt.show()
#GRAPHING PART 3
fig = plt.figure()
for site in snotel_sites_withYampa:
df = snotel_ewe_swe[site].astype(str)
df['Snow Water Equivalent (in) Start of Day Values'] = df['Snow Water Equivalent (in) Start of Day Values'].replace([row[0] for _,row in df.iterrows()],site[:-4])
df = df['10/1/2009' : '09/30/2020']
plt.scatter(df.index.values, df["Snow Water Equivalent (in) Start of Day Values"], label= site[:-4], marker='x')
plt.xlabel("Water Years")
plt.ylabel("Snotel Sites")
plt.legend(bbox_to_anchor=(1.05, 1))
figure = plt.gcf()
figure.set_size_inches(19, 10)
#Uncomment to save plot
plt.savefig("Graphs/EWE Days All/" + "99 Percentile EWE Days(3).png", bbox_inches='tight', dpi=120*2)
plt.show()
def store_r_square():
global r_squared
for index in range(len(snotel_sites_withYampa)):
site = snotel_sites_withYampa[index]
year = snotel_ewe_swe[site].index.year
month = snotel_ewe_swe[site].index.month
day =snotel_ewe_swe[site].index.day
x = year + month/12 + day/365
fit = np.polyfit(x, snotel_ewe_swe[site]["Snow Water Equivalent (in) Start of Day Values"], deg = 1)
fit_fn = np.poly1d(fit)
#line_fit[site] = fit_fn
r_square_val = np.corrcoef(x,snotel_ewe_swe[site]["Snow Water Equivalent (in) Start of Day Values"])
r_squared[site] = r_square_val[0]
#line_fit_df = pandas.DataFrame(list(line_fit.items()),columns = ['Snotel Site', 'Line Fit'])
r_squared_df = pandas.DataFrame(list(r_squared.items()),columns = ['Snotel Site', 'R Square'])
#line_fit_df.to_csv('line fit.csv')
r_squared_df.to_csv('r_squared.csv')
#print(line_fit)
def main():
find_missing_datasets()
addYampa()
preprocessing()
#graph_daily_swe()
#graph_daily_ewe_swe()
graph_daily_ewe_swe_multiplot()
#graph_max_annual_swe()
#graph_swe_breakdown_percentage()
#graph_ewe_days_all()
#graph_breakdown_percentage()
#store_r_square()
if __name__ == "__main__":
main()