-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlincorr.py
73 lines (51 loc) · 2.02 KB
/
lincorr.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
import csv
import numpy as np
import matplotlib.pyplot as plt
from scipy import stats
import seaborn as sb
from sklearn.metrics import r2_score
import matplotlib as mpl
from matplotlib.ticker import FormatStrFormatter
def select_columns(m, combination):
return m[:, combination]
################
# Main program #
################
sb.set_style("dark")
path_in = r"M:\Documents\workspace\Special\IJGIS\data\new\random_FS_nymphs_with_zeros_raw.csv"
labels = ["tmin", "tmax", "prec", "ev", "rh", "sd", "vp", "min_ndvi", "range_ndvi", "min_evi", "range_evi", "min_ndwi", "range_ndwi"]
combination = (0,) + tuple(range(16, 23)) + tuple(range(93, 99))
# combination = (0,) + tuple(range(63, 82)) + tuple(range(93, 99))
l = []
with open(path_in, "r", newline="") as r:
reader = csv.reader(r, delimiter=";")
next(reader)
for row in reader:
floatify = [float(item) for item in row[3:]]
l.append(floatify)
mraw = np.array(l)
print(mraw.shape)
m = select_columns(mraw, combination)
r2_lbl = " (R2={0})"
target = m[:, 0]
for i in range(1, 14):
ax = plt.subplot(2, 7, i)
plt.subplots_adjust(hspace=.2)
plt.subplots_adjust(wspace=.3)
plt.suptitle("Linear fitting of AQT with each weather and vegetation features", size=18)
plt.ylim(0, 150)
plt.xticks(rotation=30)
if labels[i-1] == "prec":
plt.xlim(-0.5, 20)
variable = m[:, i]
sb.regplot(x=variable, y=target, color="grey", fit_reg=True, ci=None, line_kws={'color':'black'})
slope, intercept, r_value, p_value, std_err = stats.linregress(variable, target)
plt.title(labels[i-1].upper() + r2_lbl.format(np.round(r_value**2, decimals=2)), size=14)
plt.ylabel("AQT")
ax.get_xaxis().set_minor_locator(mpl.ticker.AutoMinorLocator())
ax.get_yaxis().set_minor_locator(mpl.ticker.AutoMinorLocator())
# ax.xaxis.set_major_formatter(FormatStrFormatter('%.1f'))
ax.grid(b=True, which='major', color='#A6A6A6', linewidth=0.5)
ax.grid(b=True, which='major', color='#A6A6A6', linewidth=0.5)
i += 1
plt.show()