-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
324 lines (232 loc) · 10.5 KB
/
main.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
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
# Script to make a Taylor diagram from LEM inputs
# Geo.X hackathon 13/03/18
import gdalio as gdal_io
import numpy as np
import matplotlib.pyplot as plt
from differences import *
from input_dem import *
from correlation import *
from taylorDiagram import *
from glob import glob
def test1():
"""
Test 1: Taylor diagram for a single initial condition compared to a single reference case.
"""
# parameters
Normalize = 0
markersize = 8
markerstyle = 'o'
# define the FileNames
DataDirectory = '../Caesar-Ddata/'
InitialFileName = 'DEM_init.txt'
RefFileName = 'A1-210.txt'
# get the initial DEM
InitialDEM = ReadInitialDEM(DataDirectory+InitialFileName)
# get the reference DoD and std
RefDod, RefStd = ReadReference(InitialDEM,DataDirectory+RefFileName)
#print(RefDod)
#print(RefStd)
#create figure
fig = plt.figure(figsize=(7, 5))
if (Normalize == 1):
dia = TaylorDiagram(RefStd/RefStd, fig=fig, rect=111, label="Reference")
else:
dia = TaylorDiagram(RefStd, fig=fig, rect=111, label="Reference")
# Add grid
dia.add_grid()
# Add RMS contours, and label them
contours = dia.add_contours(colors='0.5')
PLT.clabel(contours, inline=1, fontsize=10, fmt='%.2f')
# now for each other DEM, calculate the pearson correlation and standard deviation
# for each model run, get all the files and plot them onto the diagram
# D1
color = plt.matplotlib.cm.Reds(0.9)
DEMFileName = DataDirectory+'D1-210.txt'
pointcp, pointsd = CalculateTaylorPoint(DEMFileName,InitialDEM,RefDod)
if (Normalize == 1):
pointsd = pointsd/RefStd
dia.add_sample(pointsd, pointcp, marker=markerstyle, ms=markersize, ls='', mfc=color, mec='k', label=DEMFileName[len(DataDirectory):len(DEMFileName)-4])
# D2
color = plt.matplotlib.cm.Greens(0.9)
DEMFileName = DataDirectory+'D2-210.txt'
pointcp, pointsd = CalculateTaylorPoint(DEMFileName,InitialDEM,RefDod)
if (Normalize == 1):
pointsd = pointsd/RefStd
dia.add_sample(pointsd, pointcp, marker=markerstyle, ms=markersize, ls='', mfc=color, mec='k', label=DEMFileName[len(DataDirectory):len(DEMFileName)-4])
# D3
color = plt.matplotlib.cm.Blues(0.9)
DEMFileName = DataDirectory+'D3-210.txt'
pointcp, pointsd = CalculateTaylorPoint(DEMFileName,InitialDEM,RefDod)
if (Normalize == 1):
pointsd = pointsd/RefStd
dia.add_sample(pointsd, pointcp, marker=markerstyle, ms=markersize, ls='', mfc=color, mec='k', label=DEMFileName[len(DataDirectory):len(DEMFileName)-4])
# D3
color = plt.matplotlib.cm.Wistia(0.9)
DEMFileName = DataDirectory+'D4-210.txt'
pointcp, pointsd = CalculateTaylorPoint(DEMFileName,InitialDEM,RefDod)
if (Normalize == 1):
pointsd = pointsd/RefStd
dia.add_sample(pointsd, pointcp, marker=markerstyle, ms=markersize, ls='', mfc=color, mec='k', label=DEMFileName[len(DataDirectory):len(DEMFileName)-4])
# add legend
fig.legend(dia.samplePoints,
[ p.get_label() for p in dia.samplePoints ],
numpoints=1, prop=dict(size='small'), loc='center left')
plt.savefig(DataDirectory+"fig1.png",format="png",dpi=300)
return fig
def test2():
"""
Test 2: Taylor diagram for a time series compared to a single reference case.
"""
# define the FileNames
DataDirectory = '../Caesar-Ddata/'
InitialFileName = 'DEM_init.txt'
RefFileName = 'A1-210.txt'
# parameters
Normalize = 0
markersize = 8
markerstyle = 'o'
# get the initial DEM
InitialDEM = ReadInitialDEM(DataDirectory+InitialFileName)
# get the reference DoD and std
RefDod, RefStd = ReadReference(InitialDEM,DataDirectory+RefFileName)
#print(RefDod)
#print(RefStd)
#create figure
fig = plt.figure(figsize=(12, 5))
if (Normalize == 1):
dia1 = TaylorDiagram(RefStd/RefStd, fig=fig, rect=121, label="Reference")
dia2 = TaylorDiagram(RefStd/RefStd, fig=fig, rect=122, label="Reference")
else:
dia1 = TaylorDiagram(RefStd, fig=fig, rect=121, label="Reference")
dia2 = TaylorDiagram(RefStd, fig=fig, rect=122, label="Reference")
# Add grid
dia1.add_grid()
dia2.add_grid()
# Add RMS contours, and label them
contours = dia.add_contours(colors='0.5')
PLT.clabel(contours, inline=1, fontsize=10, fmt='%.2f')
contours = dia1.add_contours(colors='0.5')
PLT.clabel(contours, inline=1, fontsize=10, fmt='%.2f')
contours = dia2.add_contours(colors='0.5')
PLT.clabel(contours, inline=1, fontsize=10, fmt='%.2f')
# now for each other DEM, calculate the pearson correlation and standard deviation
# for each model run, get all the files and plot them onto the diagram
# D1
files = sorted(glob(DataDirectory+'D1*.txt'))
n_files = len(files)
colors = plt.matplotlib.cm.Reds(np.linspace(0.1, 0.9, n_files))
for i, DEMFileName in enumerate(files):
pointcp, pointsd = CalculateTaylorPoint(DEMFileName,InitialDEM,RefDod)
if (Normalize == 1):
pointsd = pointsd/RefStd
dia1.add_sample(pointsd, pointcp, marker=markerstyle, ms=markersize, ls='', mfc=colors[i], mec='k', label=DEMFileName[len(DataDirectory):len(DEMFileName)-4])
# D3
files = sorted(glob(DataDirectory+'D3*.txt'))
colors = plt.matplotlib.cm.Blues(np.linspace(0.1, 0.9, n_files))
for i, DEMFileName in enumerate(files):
pointcp, pointsd = CalculateTaylorPoint(DEMFileName,InitialDEM,RefDod)
if (Normalize == 1):
pointsd = pointsd/RefStd
dia1.add_sample(pointsd, pointcp, marker=markerstyle, ms=markersize, ls='', mfc=colors[i], mec='k', label=DEMFileName[len(DataDirectory):len(DEMFileName)-4])
# D2
files = sorted(glob(DataDirectory+'D2*.txt'))
colors = plt.matplotlib.cm.Greens(np.linspace(0.3, 0.7, n_files))
for i, DEMFileName in enumerate(files):
pointcp, pointsd = CalculateTaylorPoint(DEMFileName,InitialDEM,RefDod)
if (Normalize == 1):
pointsd = pointsd/RefStd
dia2.add_sample(pointsd, pointcp, marker=markerstyle, ms=markersize, ls='', mfc=colors[i], mec='k', label=DEMFileName[len(DataDirectory):len(DEMFileName)-4])
# D4
files = sorted(glob(DataDirectory+'D4*.txt'))
colors = plt.matplotlib.cm.Wistia(np.linspace(0.3, 0.7, n_files))
for i, DEMFileName in enumerate(files):
pointcp, pointsd = CalculateTaylorPoint(DEMFileName,InitialDEM,RefDod)
if (Normalize == 1):
pointsd = pointsd/RefStd
dia2.add_sample(pointsd, pointcp, marker=markerstyle, ms=markersize, ls='', mfc=colors[i], mec='k', label=DEMFileName[len(DataDirectory):len(DEMFileName)-4])
# add legend
fig.legend(dia1.samplePoints,
[ p.get_label() for p in dia1.samplePoints ],
numpoints=1, prop=dict(size='small'), loc='center left')
plt.savefig(DataDirectory+"fig2.png",format="png",dpi=300)
return fig
def test3():
"""
Test 3: Taylor diagram for a different initial conditions compared to different reference cases.
"""
# parameters
Normalize = 1
markersize = 8
markerstyle = 'o'
# define the FileNames
DataDirectory = '../Caesar-Ddata/'
InitialFileName = 'DEM_init.txt'
RefFileName = 'A1-210.txt'
# get the initial DEM
InitialDEM = ReadInitialDEM(DataDirectory+InitialFileName)
# get the reference DoD and std
RefDod, RefStd = ReadReference(InitialDEM,DataDirectory+RefFileName)
#print(RefDod)
#print(RefStd)
#create figure
fig = plt.figure(figsize=(7, 5))
if (Normalize == 1):
dia = TaylorDiagram(RefStd/RefStd, fig=fig, rect=111, label="Reference")
else:
dia = TaylorDiagram(RefStd, fig=fig, rect=111, label="Reference")
# Add grid
dia.add_grid()
# Add RMS contours, and label them
contours = dia.add_contours(colors='0.5')
PLT.clabel(contours, inline=1, fontsize=10, fmt='%.2f')
# now for each other DEM, calculate the pearson correlation and standard deviation
# for each model run, get all the files and plot them onto the diagram
# D1
color = plt.matplotlib.cm.Reds(0.9)
DEMFileName = DataDirectory+'D1-210.txt'
pointcp, pointsd = CalculateTaylorPoint(DEMFileName,InitialDEM,RefDod)
if (Normalize == 1):
pointsd = pointsd/RefStd
dia.add_sample(pointsd, pointcp, marker=markerstyle, ms=markersize, ls='', mfc=color, mec='k', label=DEMFileName[len(DataDirectory):len(DEMFileName)-4])
# D2
color = plt.matplotlib.cm.Greens(0.9)
DEMFileName = DataDirectory+'D2-210.txt'
pointcp, pointsd = CalculateTaylorPoint(DEMFileName,InitialDEM,RefDod)
if (Normalize == 1):
pointsd = pointsd/RefStd
dia.add_sample(pointsd, pointcp, marker=markerstyle, ms=markersize, ls='', mfc=color, mec='k', label=DEMFileName[len(DataDirectory):len(DEMFileName)-4])
# now the other ones
markerstyle = 's'
# define the FileNames
DataDirectory = '../MuddPILE_data/'
InitialFileName = 'Initial_topography.bil'
RefFileName = 'Reference_TS60.bil'
# get the initial DEM
InitialDEM = ReadInitialDEM(DataDirectory+InitialFileName)
# get the reference DoD and std
RefDod, RefStd = ReadReference(InitialDEM,DataDirectory+RefFileName)
# n = 1.5
color = plt.matplotlib.cm.Wistia(0.9)
DEMFileName = DataDirectory+'movern_0p35_n_is_one_and_half60.bil'
pointcp, pointsd = CalculateTaylorPoint(DEMFileName,InitialDEM,RefDod)
if (Normalize == 1):
pointsd = pointsd/RefStd
dia.add_sample(pointsd, pointcp, marker=markerstyle, ms=markersize, ls='', mfc=color, mec='k', label='MUDD n=1.5')
# n = 2.0
color = plt.matplotlib.cm.Blues(0.9)
DEMFileName = DataDirectory+'movern_0p35_n_is_two60.bil'
pointcp, pointsd = CalculateTaylorPoint(DEMFileName,InitialDEM,RefDod)
if (Normalize == 1):
pointsd = pointsd/RefStd
dia.add_sample(pointsd, pointcp, marker=markerstyle, ms=markersize, ls='', mfc=color, mec='k', label='MUDD n=2.0')
# add legend
fig.legend(dia.samplePoints,
[ p.get_label() for p in dia.samplePoints ],
numpoints=1, prop=dict(size='small'), loc='center left')
plt.savefig(DataDirectory+"fig3.png",format="png",dpi=300)
return fig
if __name__ == '__main__':
test1()
test2()
test3()
plt.show()