-
Notifications
You must be signed in to change notification settings - Fork 1
/
analyzeCorrelations.py
172 lines (155 loc) · 5.86 KB
/
analyzeCorrelations.py
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
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import matplotlib
# Prepare the dataframe ***************************************************************
df = pd.read_csv("correlations_between_fourier_and_cat_chars_mini.csv")
df.index = df[df.columns[0]]
df = df.drop(df.columns[0], axis=1)
# flow metric columns:
for index, col in enumerate(df.columns):
print(index, col)
corrDict = {}
maxes = []
absMaxes = []
for col in df.columns[113:]:
corrs = df[col]
maxes.append(np.max(corrs))
absMaxes.append(np.max(np.abs(corrs)))
plt.hist(maxes, bins=60)
plt.xlabel("coefficient of correlation")
plt.ylabel("count")
plt.title("Maximum Spearman Coefficient of Correlation between Flow Metrics and Spectral Power", wrap=True)
plt.tight_layout()
plt.show()
fig, ax = plt.subplots(figsize=(10,2))
for col in df.columns:
data = df[col]
data = [float(x) for x in data]
ax.plot(data, c="dimgrey", alpha=0.8)
rounded = []
for col in df.index:
rounded.append(format(float(col), ".2f"))
ax.set_ylabel("coefficient of correlation")
ax.set_xlabel("period length (days)")
ax.set_title("Spearman Correlations between Flow Metrics and Spectral Power (Fourier)")
ax.set_xticks(list(range(len(rounded))), rounded, rotation=90)
plt.tight_layout()
plt.show()
precSeen = False
summerPrecSeen = False
ordSeen = False
tempSeen = False
summerTempSeen = False
damSeen = False
hydroSeen = False
fig, ax = plt.subplots(figsize=(10,6))
for col in df.columns:
row = np.array(df[col])
#row = [float(x) for x in row]
if "prec" in col.lower() and not "cum" in col.lower() and not ("06" in col.lower() or "07" in col.lower() or "08" in col.lower()):
if not precSeen:
ax.plot(row, label="precipitation", c="b")
precSeen = True
else:
ax.plot(row,c="b")
if "prec" in col.lower() and not "cum" in col.lower() and ("06" in col.lower() or "07" in col.lower() or "08" in col.lower()):
if not summerPrecSeen:
ax.plot(row, label="summer precipitation", c="c")
summerPrecSeen = True
else:
ax.plot(row,c="c")
if "cum" in col.lower() or "ord" in col.lower() or "mag" in col.lower():
if not ordSeen:
ax.plot(row, label="catchment size", c="g")
ordSeen = True
else:
ax.plot(row, c="g")
if "temp" in col.lower() and not ("06" in col.lower() or "07" in col.lower() or "08" in col.lower()):
print("red: ", col)
if col == "tempcv":
ax.plot(row, label="temperature cv", c="tan")
tempSeen = True
elif not tempSeen:
ax.plot(row, label="temperature", c="r")
tempSeen = True
else:
ax.plot(row, c="r")
if "temp" in col.lower() and ("06" in col.lower() or "07" in col.lower() or "08" in col.lower()):
if not summerTempSeen:
ax.plot(row, label="summer temperature", c="orange")
summerTempSeen = True
else:
ax.plot(row, c="orange")
if "drain_den" == col:
ax.plot(row, label="drainage density", c="yellow")
if "strmDrop" == col:
ax.plot(row, label="stream drop", c="magenta")
# if "gelev_m" == col:
# ax.plot(row, label="elevation", c="k")
if "dam" in col.lower():
print(index)
if not damSeen:
ax.plot(row, label="dams", c="k", linestyle="--")
damSeen = True
else:
ax.plot(row, c="k", linestyle="--")
ax.set_ylim(-0.6,0.6)
ax.set_xticks(list(range(len(rounded))), rounded, rotation=90)
ax.set_ylabel("coefficient of correlation")
ax.set_xlabel("period length (days)")
ax.set_title("Spearman Correlations between Catchment Characteristics and Spectral Power (using fourier)", wrap=True)
plt.legend(bbox_to_anchor=(1.04, 0.5), loc="center left")
plt.tight_layout()
plt.savefig("cat_chars_1.png")
plt.show()
hydroSeen = False
fig, ax = plt.subplots(figsize=(10,6))
damSeen = False
for col in df.columns:
row = np.array(df[col])
if "cls1" == col.lower():
ax.plot(row, label="Evergreen Needle Trees", c="green")
if "cls2" == col.lower():
ax.plot(row, label="Evergreen Broadleaf", c="lime")
if "cls3" == col.lower():
ax.plot(row, label="Deciduous Broadleaf", c="fuchsia")
if "cls4" == col.lower():
ax.plot(row, label="Mixed Other Trees", c="cyan")
if "cls5" == col.lower():
ax.plot(row, label="Shrubs", c="darkorange")
if "cls6" == col.lower():
ax.plot(row, label="Herbaceous Vegetation", c="gold")
if "cls7" == col.lower():
ax.plot(row, label="Cultivated and Managed Vegetation", c="red")
if "cls8" == col.lower():
ax.plot(row, label="Regularly Flooded Vegetation", c="lightpink")
if "cls9" == col.lower():
ax.plot(row, label="Urban", c="grey")
if "cls10" == col.lower():
ax.plot(row, label="Snow Ice", c="lavender")
if "cls11" == col.lower():
ax.plot(row, label="Barren", c="tab:brown")
if "cls12" == col.lower() or "hydro" in col.lower():
if "hydro" in col.lower():
ax.plot(row, label="Open Water / lakes (not \nnormalized by catchment size)", c="blue")
else:
ax.plot(row, c="blue")
if "dam" in col.lower():
print(index)
if not damSeen:
ax.plot(row, label="dams", c="k", linestyle="--")
damSeen = True
else:
ax.plot(row, c="k", linestyle="--")
#plt.style.use("seaborn-poster")
#plt.legend()
ax.set_ylim(-0.6,0.6)
ax.set_xticks(list(range(len(rounded))), rounded, rotation=90)
ax.set_ylabel("coefficient of correlation")
ax.set_xlabel("period length (days)")
plt.legend(bbox_to_anchor=(1.04, 0.5), loc="center left")
ax.set_title("Spearman Correlations between Land Cover Characteristics and Spectral Power (using fourier)")
plt.tight_layout()
plt.savefig("cat_chars_2.png")
plt.show()