This repository has been archived by the owner on Jul 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspatial_plots.py
134 lines (86 loc) · 2.91 KB
/
spatial_plots.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
import os
import pandas as pd
import geopandas as gpd
import matplotlib as mpl
import matplotlib.pyplot as plt
import contextily as ctx
mpl.use('TkAgg')
"""
script to plot average error at all save points
"""
sp2coord = os.path.join(os.getcwd(), '..', 'data',
'NACCS_SavePts_18977_ConversionKey_MSL_to_NAVD_meters.csv')
sp2coord = pd.read_csv(sp2coord, skiprows=[1])
sp2coord['SP_Longitude'] = pd.to_numeric(sp2coord['SP_Longitude'])
sp2coord['SP_Latitude'] = pd.to_numeric(sp2coord['SP_Latitude'])
path_to_models = os.path.join(os.getcwd(), 'LSTM_training_results',
'Model_results')
models = [
"LSTM_B15_h100_l1_bbS",
"LSTM_LL1_B15_h256_l1_bbS",
"LSTM_LL2_B15_h256_l1_bbS",
# "LSTM_LL1_B15_h100_l1_bbM",
# "LSTM_LL2_B15_h100_l1_bbM",
# "LSTM_LL1_B15_h100_l1_bbL",
# "LSTM_LL2_B15_h100_l1_bbL",
]
model_names = [
'LSTM',
'LSTM + Linear Layer',
'LSTM + Norm Layer + Linear Layer',
'LSTM + Linear Layer',
'LSTM + Norm Layer + Linear Layer',
'LSTM + Linear Layer',
'LSTM + Norm Layer + Linear Layer'
]
bb = ['Small', 'Small', 'Small',
'Medium', 'Medium',
'Large', 'Large' ]
cbar_axes = [
[0.92, 0.105, 0.02, 0.78], # small bounding box
[0.92, 0.105, 0.02, 0.78],
[0.92, 0.105, 0.02, 0.78],
[0.92, 0.25, 0.02, 0.5], # med bounding box
[0.92, 0.25, 0.02, 0.5],
[0.83, 0.105, 0.02, 0.78], # lg. bounding box
[0.83, 0.105, 0.02, 0.78]
]
cbar_max = [1.0, 1.0, 1.0,
1.0, 1.0,
1.0, 1.0
]
for i, model in enumerate(models):
predict = model + '_predict.csv'
predict = os.path.join(path_to_models, predict)
predict = pd.read_csv(predict).mean(axis=0)
target = model + '_target.csv'
target = os.path.join(path_to_models, target)
target = pd.read_csv(target).mean(axis=0)
error = predict-target
print(error.max(), error.min())
sp = error.index.to_list()
sp = [(i.split('_')[1]) for i in sp]
sp2coord_temp = sp2coord[sp2coord['SavePointID'].isin(sp)]
sp2coord_temp['error'] = error.values
gdf = gpd.GeoDataFrame(sp2coord_temp,
geometry=gpd.points_from_xy(
sp2coord_temp.SP_Longitude,
sp2coord_temp.SP_Latitude
)
)
gdf.crs = {'init': 'epsg:4326'}
gdf = gdf.to_crs({'init': 'epsg:3857'})
fig, axes = plt.subplots(1,1, figsize = (12, 10))
gdf.plot(column=error, cmap = 'bwr', vmin=-cbar_max[i], vmax=cbar_max[i],
ax=axes, legend = False, edgecolor = 'k', linewidth = 0.3)
ctx.add_basemap(axes, url=ctx.providers.Stamen.TonerLite)
axes.set_xticks([])
axes.set_yticks([])
axes.set_title('Model: {}\nBounding Box: {}' .format(model_names[i], bb[i]))
cbar_ax = fig.add_axes(cbar_axes[i])
norm = mpl.colors.Normalize(vmin=-cbar_max[i],vmax=cbar_max[i])
sm = plt.cm.ScalarMappable(cmap='bwr', norm=norm)
sm.set_array([])
plt.colorbar(sm, cax=cbar_ax)
path_out = os.path.join(os.getcwd(), 'spatial_plots', model)
plt.savefig(path_out)