Skip to content

Commit a2a02fa

Browse files
Output visual output (#197)
* Clean-up of the Visualization function in inout.py * Added the variable "masstop" Added the option to export the mass of the toplayer exclusively to the *.nc file * Add SedTRAILS output Added the option the output SedTRAILS-required output for each timestep (MAT-files)
1 parent 34519a9 commit a2a02fa

File tree

4 files changed

+57
-6
lines changed

4 files changed

+57
-6
lines changed

aeolis/bed.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,9 @@ def update(s, p):
323323
# reshape mass matrix
324324
s['mass'] = m.reshape((ny+1,nx+1,nl,nf))
325325

326+
# Store toplayer of 'mass' variable (ilayer = 0)
327+
s['masstop'][:,:,:] = s['mass'][:,:,0,:].copy()
328+
326329
# update bathy
327330
if p['process_bedupdate']:
328331

aeolis/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@
138138
'u', # [m/s] Mean horizontal saltation velocity in saturated state
139139
'us', # [m/s] Component of the saltation velocity in x-direction
140140
'un', # [m/s] Component of the saltation velocity in y-direction
141+
'usST', # [NEW] [m/s] Component of the saltation velocity in x-direction for SedTRAILS
142+
'unST', # [NEW] [m/s] Component of the saltation velocity in y-direction for SedTRAILS
141143
'u0',
144+
'masstop', # [kg/m^2] Sediment mass in bed toplayer, only stored for output
142145
),
143146
('ny','nx','nlayers') : (
144147
'thlyr', # [m] Bed composition layer thickness
@@ -184,6 +187,8 @@
184187
'process_dune_erosion' : False, # Enable the process of wave-driven dune erosion
185188
'process_seepage_face' : False, # Enable the process of groundwater seepage (NB. only applicable to positive beach slopes)
186189
'visualization' : False, # Boolean for visualization of model interpretation before and just after initialization
190+
'output_sedtrails' : False, # NEW! [T/F] Boolean to see whether additional output for SedTRAILS should be generated
191+
'nfraction_sedtrails' : 0, # [-] Index of selected fraction for SedTRAILS (0 if only one fraction)
187192
'xgrid_file' : None, # Filename of ASCII file with x-coordinates of grid cells
188193
'ygrid_file' : None, # Filename of ASCII file with y-coordinates of grid cells
189194
'bed_file' : None, # Filename of ASCII file with bed level heights of grid cells

aeolis/inout.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
from webbrowser import UnixBrowser
3636
import numpy as np
3737
from matplotlib import pyplot as plt
38+
from scipy.io import savemat
3839

3940
# package modules
4041
from aeolis.utils import *
@@ -493,14 +494,17 @@ def visualize_spatial(s, p):
493494
fig, axs = plt.subplots(5, 3)
494495
pcs = [[None for _ in range(3)] for _ in range(5)]
495496

497+
# In the plotting below, prevent the UserWarning: The input coordinates to pcolormesh are interpreted as cell centers, but are not monotonically increasing or decreasing (...)
498+
import warnings
499+
warnings.filterwarnings("ignore", category=UserWarning)
500+
496501
# Plotting colormeshes
497502
if p['ny'] > 0:
498503
pcs[0][0] = axs[0,0].pcolormesh(x, y, s['zb'], cmap='viridis')
499504
pcs[0][1] = axs[0,1].pcolormesh(x, y, s['zne'], cmap='viridis')
500505
pcs[0][2] = axs[0,2].pcolormesh(x, y, s['rhoveg'], cmap='Greens', clim= [0, 1])
501506
pcs[1][0] = axs[1,0].pcolormesh(x, y, s['uw'], cmap='plasma')
502507
pcs[1][1] = axs[1,1].pcolormesh(x, y, s['ustar'], cmap='plasma')
503-
# pcs[1][2] = axs[1,2].pcolormesh(x, y, s['tau'], cmap='plasma')
504508
pcs[1][2] = axs[1,2].pcolormesh(x, y, s['u'][:, :, 0], cmap='plasma')
505509
pcs[2][0] = axs[2,0].pcolormesh(x, y, s['moist'], cmap='Blues', clim= [0, 0.4])
506510
pcs[2][1] = axs[2,1].pcolormesh(x, y, s['gw'], cmap='viridis')
@@ -528,11 +532,13 @@ def visualize_spatial(s, p):
528532
pcs[4][1] = axs[4,1].scatter(x, y, c=tide_mask_add, cmap='binary', clim= [0, 1])
529533
pcs[4][2] = axs[4,2].scatter(x, y, c=wave_mask_add, cmap='binary', clim= [0, 1])
530534

535+
# Re-allow the UserWarning
536+
warnings.filterwarnings("default", category=UserWarning)
537+
531538
# Quiver for vectors
532539
skip = 10
533540
axs[1,0].quiver(x[::skip, ::skip], y[::skip, ::skip], s['uws'][::skip, ::skip], s['uwn'][::skip, ::skip])
534541
axs[1,1].quiver(x[::skip, ::skip], y[::skip, ::skip], s['ustars'][::skip, ::skip], s['ustarn'][::skip, ::skip])
535-
# axs[1,2].quiver(x[::skip, ::skip], y[::skip, ::skip], s['taus'][::skip, ::skip], s['taun'][::skip, ::skip])
536542
axs[1,2].quiver(x[::skip, ::skip], y[::skip, ::skip], s['us'][::skip, ::skip, 0], s['un'][::skip, ::skip, 0])
537543

538544
# Adding titles to the plots
@@ -541,7 +547,6 @@ def visualize_spatial(s, p):
541547
axs[0,2].set_title('Vegetation density, rhoveg (-)')
542548
axs[1,0].set_title('Wind velocity, uw (m/s)')
543549
axs[1,1].set_title('Shear velocity, ustar (m/s)')
544-
# axs[1,2].set_title('Shear stress, tau (N/m2)')
545550
axs[1,2].set_title('Grain velocity, u (m/s)')
546551
axs[2,0].set_title('Soil moisture content, (-)')
547552
axs[2,1].set_title('Ground water level, gw (m)')
@@ -573,4 +578,29 @@ def visualize_spatial(s, p):
573578
fig.savefig('figure_params_initialization.png', dpi=300)
574579
plt.close()
575580

576-
return
581+
return
582+
583+
def output_sedtrails(s, p):
584+
'''Create additional output for SedTRAILS and save as mat-files.
585+
Chosen for seperate files, such that only relevant (Ct > 0) cells
586+
are exported for memory and speed efficiency'''
587+
588+
nf = p['nfraction_sedtrails']
589+
590+
# Speed and concetration: Only for the first fraction now
591+
x = s['x'].flatten()
592+
y = s['y'].flatten()
593+
us = s['usST'][:,:,nf].flatten()
594+
un = s['unST'][:,:,nf].flatten()
595+
pickup = s['pickup'][:,:,nf].flatten()
596+
dzb = s['dzb'].flatten() # Store the bed level change (AEOLIAN ONLY) for every timestep
597+
598+
os.makedirs('sedtrails_output', exist_ok=True)
599+
600+
time = p['_time']
601+
if time == 0: # Save the x and y coordinates only once to save memory
602+
mdic = {'x': x, 'y': y, 'us': us, 'un': un, 'dzb': dzb, 'pickup': pickup}
603+
savemat(os.path.join('sedtrails_output', str(int(time)).zfill(12) + '.mat'), mdic)
604+
else:
605+
mdic = {'us': us, 'un': un, 'dzb': dzb, 'pickup': pickup}
606+
savemat(os.path.join('sedtrails_output', str(int(time)).zfill(12) + '.mat'), mdic)

aeolis/transport.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ def duran_grainspeed(s, p):
7373
ustar0 = s['ustar0']
7474
uth = s['uth0'] # uth0 or uth???
7575
uth0 = s['uth0']
76+
uthST = s['uth']
7677

7778
# Wind input for filling up ets/ets (udir), where ustar == 0
7879
uw = s['uw']
@@ -97,6 +98,8 @@ def duran_grainspeed(s, p):
9798
u0 = np.zeros(uth.shape)
9899
us = np.zeros(uth.shape)
99100
un = np.zeros(uth.shape)
101+
usST = np.zeros(uth.shape)
102+
unST = np.zeros(uth.shape)
100103
u_approx = np.zeros(uth.shape)
101104
us_approx = np.zeros(uth.shape)
102105
un_approx = np.zeros(uth.shape)
@@ -209,7 +212,15 @@ def solve_u(u_i: complex, veff_i: complex, uf_i: float, alpha_i: float, dh_i: co
209212
else:
210213
logger.error('Grainspeed method not found!')
211214

212-
return u0, us, un, u
215+
# For SedTRAILS: Set grainspeed to 0 whenever uth > ustar
216+
usST[:,:,i] = us[:,:,i]
217+
unST[:,:,i] = un[:,:,i]
218+
219+
ix_no_speed = (uthST[:,:,i] > ustar[:,:,i])
220+
usST[ix_no_speed, i] *= 0.
221+
unST[ix_no_speed, i] *= 0.
222+
223+
return u0, us, un, u, usST, unST
213224

214225

215226

@@ -292,11 +303,13 @@ def equilibrium(s, p):
292303

293304
if p['method_grainspeed']=='duran' or p['method_grainspeed']=='duran_full':
294305
#the syntax inside grainspeed needs to be cleaned up
295-
u0, us, un, u = duran_grainspeed(s,p)
306+
u0, us, un, u, usST, unST = duran_grainspeed(s,p)
296307
s['u0'] = u0
297308
s['us'] = us
298309
s['un'] = un
299310
s['u'] = u
311+
s['usST'][:] = usST
312+
s['unST'][:] = unST
300313

301314
elif p['method_grainspeed']=='windspeed':
302315
s['u0'] = s['uw'][:,:,np.newaxis].repeat(nf, axis=2)

0 commit comments

Comments
 (0)