-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdrt_plotting.py
More file actions
333 lines (279 loc) · 13.3 KB
/
drt_plotting.py
File metadata and controls
333 lines (279 loc) · 13.3 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
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 24 11:03:28 2025
@author: sdevo
"""
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from matplotlib import gridspec
def drt_plotting(scenario):
# drt_plotting: code to plot basic model output for deterministic run
# fig, axs = plt.subplots(2, 3, figsize=(16, 9))
# fig.subplots_adjust(wspace=0.25, hspace=0.35)
fig = plt.figure(figsize=(16, 9))
gs = gridspec.GridSpec(2, 3, figure=fig, wspace=0.25, hspace=0.35)
# Top row (3 subplots)
ax1 = fig.add_subplot(gs[0, 0])
ax2 = fig.add_subplot(gs[0, 1])
ax3 = fig.add_subplot(gs[0, 2])
# Bottom row:
ax5 = fig.add_subplot(gs[1, 0:2]) # spans bottom-left two columns
ax4 = fig.add_subplot(gs[1, 2]) # bottom-right panel
# figure('units','normalized','outerposition',[0 0 1 1])
# ---- COMMON time limits ----
times = scenario['timing']['times']
xlims = [np.min(times), np.max(times)]
xpts = np.linspace(xlims[0].toordinal(), xlims[1].toordinal(), 5)
xpts = np.unique(np.floor(xpts))
# Format x-axis for date ticks
date_fmt = mdates.DateFormatter('%Y-%m-%d')
# # Subplot for Wind Time Series
# ax1 = axs[0,0]
ax1.plot(times, scenario['env']['winds']['windSpeed'],'k-',linewidth=3)
ax1.set_ylabel('Wind Speed [m/s]')
ax1.grid(True)
ax1.set_title('Winds', fontweight='bold')
ax1.set_xlim(xlims)
ax1.xaxis.set_major_formatter(date_fmt)
ax1.tick_params(axis='x',rotation=30)
ax1.tick_params(width=1.5)
ax1.spines[:].set_linewidth(1.5)
ax1b = ax1.twinx()
ax1b.plot(times,scenario['env']['winds']['windDirection'],'.',linewidth=0.5,color=[0.5, 0.5, 0.5],markersize=6)
ax1b.set_ylabel(r'Wind Direction $[^{\circ}]$')
ax1b.set_ylim([0,360])
ax1.yaxis.label.set_color('k')
ax1b.yaxis.label.set_color([0.5, 0.5, 0.5])
# # Subplot for Wave Time Series
# ax2 = axs[0,1]
ax2.plot(times, scenario['env']['waves']['Hs_deepwater'],'k-',linewidth=3)
ax2.set_ylabel(r'$H_s$ [m]')
ax2.grid(True)
ax2.set_title('Waves',fontweight='bold')
ax2.set_xlim(xlims)
ax2.xaxis.set_major_formatter(date_fmt)
ax2.tick_params(axis='x',rotation=30)
ax2.spines[:].set_linewidth(1.5)
ax2b = ax2.twinx()
ax2b.plot(times,scenario['env']['waves']['D_deepwater'],'.',color=[0.5, 0.5, 0.5],markersize=6)
ax2b.set_ylabel(r'Wave Direction $[^{\circ}]$')
ax2b.set_ylim([0,360])
ax2.yaxis.label.set_color('k')
ax2b.yaxis.label.set_color([0.5, 0.5, 0.5])
# # Subplot for Water Level Time Series
# ax3 = axs[0,2]
ax3.plot(times, scenario['env']['tides']['wl'],color=[0.5, 0.5, 0.5], linewidth=3,label='SWL')
ax3.plot(times,scenario['erosion']['TWL'],'k-',linewidth=3,label='TWL')
dtoe = scenario['grids']['morphometrics']['dtoe']
dhigh = scenario['grids']['morphometrics']['dhigh']
ax3.plot(xlims,[dtoe, dtoe],'--',color=[0.9, 0.3, 0.3],linewidth=2)
ax3.plot(xlims,[dhigh, dhigh],'--',color=[0.3, 0.1, 0.1],linewidth=2)
xo = xlims[0] + (xlims[1]-xlims[0])*0.05
ax3.text(xo, dhigh+0.25,'Dune Crest',fontweight='bold',color=[0.3, 0.1, 0.1])
ax3.text(xo, dtoe+0.25,'Dune Toe',fontweight='bold',color=[0.9, 0.3, 0.3])
ax3.set_ylabel('SWL & TWL [m]')
ax3.set_title('Water Levels',fontweight='bold')
ax3.grid(True)
ax3.set_xlim(xlims)
ax3.spines[:].set_linewidth(1.5)
ax3.xaxis.set_major_formatter(date_fmt)
ax3.tick_params(axis='x',rotation=30)
ylims = [np.min((np.min(scenario['env']['tides']['wl']),dtoe)) - 1, np.max((np.max(scenario['erosion']['TWL']),dhigh)) + 1]
ax3.set_ylim(ylims)
# # Subplot for Morphology Change
# ax4 = axs[1,2]
cmap = plt.colormaps['viridis'].resampled(lutsize=len(scenario['erosion']['zmat_times']))
colors = cmap(np.linspace(0, 1, len(scenario['erosion']['zmat_times'])+1))
cumDV_erosion = -np.cumsum(scenario['erosion']['dV'])
cumDV_accretion = np.cumsum(scenario['accretion']['dV'])
cumDV_net = cumDV_accretion + cumDV_erosion
ylims4 = [np.min(cumDV_erosion)-0.5, np.max(cumDV_accretion)+0.5]
ax4.plot(times, cumDV_erosion, 'b-',linewidth=3, label='Erosion (Waves)')
ax4.plot(times, cumDV_accretion, 'r-',linewidth=3, label='Accretion (Winds)')
ax4.plot(times, cumDV_net, 'k--', linewidth=4, label='Net')
for i, t in enumerate(scenario['erosion']['zmat_times']):
ax4.plot([t, t], ylims4, '--', linewidth=2, color=colors[i])
ax4.set_xlim(xlims)
ax4.set_ylim(ylims4)
ax4.set_ylabel(r'$\Delta V_{dune}\ [m^3/m]$')
ax4.set_title('Dune Volume Change',fontweight='bold')
ax4.legend(loc='best')
ax4.grid(True)
ax4.spines[:].set_linewidth(1.5)
ax4.xaxis.set_major_formatter(date_fmt)
ax4.tick_params(axis='x',rotation=30)
# # Subplot for profile change
# ax5 = axs[1,0:2]
for i, t in enumerate(scenario['erosion']['zmat_times']):
ax5.plot(scenario['grids']['XGrid'],scenario['erosion']['Z'][i],'-',color=colors[i],linewidth=3)
ylims5 = [0, np.nanmax(np.nanmax(scenario['erosion']['Z']))+1]
ax5.set_ylim(ylims5)
ax5.set_ylabel('Z [m, NAVD]')
ax5.set_xlabel('Cross-Shore Disntance [m]')
ax5.grid(True)
ax5.set_title('Dune Profile Change (Erosion Only)', fontweight='bold')
ax5.spines[:].set_linewidth(1.5)
# erosion category:
if cumDV_net[-1]>-0.5:
col = [0.2, 0.9, 0.2]
tex = 'No or Minimal Net Dune Erosion Predicted'
elif cumDV_net[-1]>-5:
col = [1, 0, 1]
tex = 'Minor Dune Erosion Predicted'
else:
col = [1, 0, 0]
tex = 'Substantial Dune erosion predicted'
# add background patch:
xgrid = scenario['grids']['XGrid']
ax5.fill_between(xgrid, ylims5[0], ylims5[1], color=col, alpha=0.075)
if np.min(scenario['grids']['ZGrid'])>0:
x0 = np.min(scenario['grids']['XGrid'])
else:
x0 = np.interp(0,scenario['grids']['XGrid'],scenario['grids']['ZGrid'])
xlim = [x0, np.max(scenario['grids']['XGrid'])]
# Add additional info onto plot
xlims5 = xlim
ax5.set_xlim(xlims5)
xo = xlims5[0] + (xlims5[1] - xlims5[0])*0.05
xo2 = xlims5[0] + (xlims5[1] - xlims5[0])*0.5
yo2 = ylims5[0] + (ylims5[1] - ylims5[0])*0.08
ax5.plot(xgrid, np.full_like(xgrid, dtoe), '--', color=[0.9, 0.3, 0.3], linewidth=2)
ax5.plot(xgrid, np.full_like(xgrid, dhigh), '--', color=[0.3, 0.1, 0.1], linewidth=2)
ax5.text(xo, dhigh+0.25, 'Dune Crest', fontweight='bold',color=[0.3, 0.1, 0.1])
ax5.text(xo, dtoe+0.25, 'Dune Toe', fontweight='bold',color=[0.9, 0.3, 0.3])
ax5.text(xo2, yo2, tex, fontweight='bold', color=col)
def drt_frf_plotting(scenario,lidar_dat):
# drt_plotting: code to plot basic model output for deterministic run
fig = plt.figure(figsize=(16, 9))
gs = gridspec.GridSpec(2, 3, figure=fig, wspace=0.25, hspace=0.35)
# Top row (3 subplots)
ax1 = fig.add_subplot(gs[0, 0])
ax2 = fig.add_subplot(gs[0, 1])
ax3 = fig.add_subplot(gs[0, 2])
# Bottom row:
ax5 = fig.add_subplot(gs[1, 0:2]) # spans bottom-left two columns
ax4 = fig.add_subplot(gs[1, 2]) # bottom-right panel
# figure('units','normalized','outerposition',[0 0 1 1])
# ---- COMMON time limits ----
times = scenario['timing']['times']
xlims = [np.min(times), np.max(times)]
xpts = np.linspace(xlims[0].toordinal(), xlims[1].toordinal(), 5)
xpts = np.unique(np.floor(xpts))
# Format x-axis for date ticks
date_fmt = mdates.DateFormatter('%Y-%m-%d')
# # Subplot for Wind Time Series
# ax1 = axs[0,0]
ax1.plot(times, scenario['env']['winds']['windSpeed'],'k-',linewidth=3)
ax1.set_ylabel('Wind Speed [m/s]')
ax1.grid(True)
ax1.set_title('Winds', fontweight='bold')
ax1.set_xlim(xlims)
ax1.xaxis.set_major_formatter(date_fmt)
ax1.tick_params(axis='x',rotation=30)
ax1.tick_params(width=1.5)
ax1.spines[:].set_linewidth(1.5)
ax1b = ax1.twinx()
ax1b.plot(times,scenario['env']['winds']['windDirection'],'.',linewidth=0.5,color=[0.5, 0.5, 0.5],markersize=6)
ax1b.set_ylabel(r'Wind Direction $[^{\circ}]$')
ax1b.set_ylim([0,360])
ax1.yaxis.label.set_color('k')
ax1b.yaxis.label.set_color([0.5, 0.5, 0.5])
# # Subplot for Wave Time Series
# ax2 = axs[0,1]
ax2.plot(times, scenario['env']['waves']['Hs_deepwater'],'k-',linewidth=3)
ax2.set_ylabel(r'$H_s$ [m]')
ax2.grid(True)
ax2.set_title('Waves',fontweight='bold')
ax2.set_xlim(xlims)
ax2.xaxis.set_major_formatter(date_fmt)
ax2.tick_params(axis='x',rotation=30)
ax2.spines[:].set_linewidth(1.5)
ax2b = ax2.twinx()
ax2b.plot(times,scenario['env']['waves']['D_deepwater'],'.',color=[0.5, 0.5, 0.5],markersize=6)
ax2b.set_ylabel(r'Wave Direction $[^{\circ}]$')
ax2b.set_ylim([0,360])
ax2.yaxis.label.set_color('k')
ax2b.yaxis.label.set_color([0.5, 0.5, 0.5])
# # Subplot for Water Level Time Series
# ax3 = axs[0,2]
ax3.plot(times, scenario['env']['tides']['wl'],color=[0.5, 0.5, 0.5], linewidth=3,label='SWL')
ax3.plot(times,scenario['erosion']['TWL'],'k-',linewidth=3,label='TWL')
dtoe = scenario['grids']['morphometrics']['dtoe']
dhigh = scenario['grids']['morphometrics']['dhigh']
ax3.plot(xlims,[dtoe, dtoe],'--',color=[0.9, 0.3, 0.3],linewidth=2)
ax3.plot(xlims,[dhigh, dhigh],'--',color=[0.3, 0.1, 0.1],linewidth=2)
xo = xlims[0] + (xlims[1]-xlims[0])*0.05
ax3.text(xo, dhigh+0.25,'Dune Crest',fontweight='bold',color=[0.3, 0.1, 0.1])
ax3.text(xo, dtoe+0.25,'Dune Toe',fontweight='bold',color=[0.9, 0.3, 0.3])
ax3.set_ylabel('SWL & TWL [m]')
ax3.set_title('Water Levels',fontweight='bold')
ax3.grid(True)
ax3.set_xlim(xlims)
ax3.spines[:].set_linewidth(1.5)
ax3.xaxis.set_major_formatter(date_fmt)
ax3.tick_params(axis='x',rotation=30)
ylims = [np.min((np.min(scenario['env']['tides']['wl']),dtoe)) - 1, np.max((np.max(scenario['erosion']['TWL']),dhigh)) + 1]
ax3.set_ylim(ylims)
# # Subplot for Morphology Change
# ax4 = axs[1,2]
cmap = plt.colormaps['viridis'].resampled(lutsize=len(scenario['erosion']['zmat_times']))
colors = cmap(np.linspace(0, 1, len(scenario['erosion']['zmat_times'])+1))
cumDV_erosion = -np.cumsum(scenario['erosion']['dV'])
cumDV_accretion = np.cumsum(scenario['accretion']['dV'])
cumDV_net = cumDV_accretion + cumDV_erosion
ylims4 = [np.min(cumDV_erosion)-0.5, np.max(cumDV_accretion)+0.5]
ax4.plot(times, cumDV_erosion, 'b-',linewidth=3, label='Erosion (Waves)')
ax4.plot(times, cumDV_accretion, 'r-',linewidth=3, label='Accretion (Winds)')
ax4.plot(times, cumDV_net, 'k--', linewidth=4, label='Net')
for i, t in enumerate(scenario['erosion']['zmat_times']):
ax4.plot([t, t], ylims4, '--', linewidth=2, color=colors[i])
ax4.set_xlim(xlims)
ax4.set_ylim(ylims4)
ax4.set_ylabel(r'$\Delta V_{dune}\ [m^3/m]$')
ax4.set_title('Dune Volume Change',fontweight='bold')
ax4.legend(loc='best')
ax4.grid(True)
ax4.spines[:].set_linewidth(1.5)
ax4.xaxis.set_major_formatter(date_fmt)
ax4.tick_params(axis='x',rotation=30)
# # Subplot for profile change
# ax5 = axs[1,0:2]
for i, t in enumerate(scenario['erosion']['zmat_times']):
ax5.plot(scenario['grids']['XGrid'],scenario['erosion']['Z'][i],'-',color=colors[i],linewidth=3)
ylims5 = [0, np.nanmax(np.nanmax(scenario['erosion']['Z']))+1]
ax5.set_ylim(ylims5)
ax5.set_ylabel('Z [m, NAVD]')
ax5.set_xlabel('Cross-Shore Disntance [m]')
ax5.grid(True)
ax5.set_title('Dune Profile Change (Erosion Only)', fontweight='bold')
ax5.spines[:].set_linewidth(1.5)
# erosion category:
if cumDV_net[-1]>-0.5:
col = [0.2, 0.9, 0.2]
tex = 'No or Minimal Net Dune Erosion Predicted'
elif cumDV_net[-1]>-5:
col = [1, 0, 1]
tex = 'Minor Dune Erosion Predicted'
else:
col = [1, 0, 0]
tex = 'Substantial Dune erosion predicted'
# add background patch:
xgrid = scenario['grids']['XGrid']
ax5.fill_between(xgrid, ylims5[0], ylims5[1], color=col, alpha=0.075)
if np.min(scenario['grids']['ZGrid'])>0:
x0 = np.min(scenario['grids']['XGrid'])
else:
x0 = np.interp(0,scenario['grids']['XGrid'],scenario['grids']['ZGrid'])
xlim = [x0, np.max(scenario['grids']['XGrid'])]
# Add additional info onto plot
xlims5 = xlim
ax5.set_xlim(xlims5)
xo = xlims5[0] + (xlims5[1] - xlims5[0])*0.05
xo2 = xlims5[0] + (xlims5[1] - xlims5[0])*0.5
yo2 = ylims5[0] + (ylims5[1] - ylims5[0])*0.08
ax5.plot(xgrid, np.full_like(xgrid, dtoe), '--', color=[0.9, 0.3, 0.3], linewidth=2)
ax5.plot(xgrid, np.full_like(xgrid, dhigh), '--', color=[0.3, 0.1, 0.1], linewidth=2)
ax5.text(xo, dhigh+0.25, 'Dune Crest', fontweight='bold',color=[0.3, 0.1, 0.1])
ax5.text(xo, dtoe+0.25, 'Dune Toe', fontweight='bold',color=[0.9, 0.3, 0.3])
ax5.text(xo2, yo2, tex, fontweight='bold', color=col)