Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
menno94 committed Dec 21, 2023
2 parents fa05793 + f3cdb2b commit 0b3862c
Show file tree
Hide file tree
Showing 9 changed files with 302 additions and 56 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/xbTools/__pycache__
/xbTools/general/__pycache__
/xbTools/grid/__pycache__
/.idea
/examples/xb-2D/

2 changes: 1 addition & 1 deletion examples/xbeach-setup-1D.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@
"xb_setup.set_waves('parametric',{'Hm0':2, 'Tp':5, 'mainang':270, 'gammajsp':3.3, 's' : 10000, 'fnyq':1})\n",
"#xb_setup.set_waves('jonstable',{'Hm0':[1.5, 2, 1.5],'Tp':[4, 5, 4],'gammajsp':[3.3, 3.3, 3.3], 's' : [20,20,20], 'mainang':[270,280, 290],'duration':[3600, 3600, 3600],'dtbc':[1,1,1]})\n",
"\n",
"xb_setup.set_params({'Wavemodel':'surfbeat',\n",
"xb_setup.set_params({'wavemodel':'surfbeat',\n",
" 'morphology':0,\n",
" 'befriccoef':0.01,\n",
" 'tstop':3600,\n",
Expand Down
Binary file not shown.
4 changes: 2 additions & 2 deletions xbTools/general/executing_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"""
Created on Wed May 5 10:04:00 2023
@author: Cas van Bemmelen
collection containing executing run functionalities
"""
# import python modules
Expand Down Expand Up @@ -38,7 +37,7 @@ def xb_run_script_win(xb, N, maindir, xbeach_exe):
for item in xb:
path_sims.append(item.model_path)
elif isinstance(xb[0],str):
path_sims = [xb]
path_sims = xb
else:
print('Unvalid path')
else:
Expand All @@ -64,4 +63,5 @@ def xb_run_script_win(xb, N, maindir, xbeach_exe):
print(os.path.join(maindir,'run{}.bat'.format(run_number)))
with open(os.path.join(maindir,'run{}.bat'.format(run_number)), 'w') as f:
f.write(string)


4 changes: 3 additions & 1 deletion xbTools/general/visualize_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ def plot_mesh(mesh_x,mesh_y,thinning=1,ax=None,**kwargs):
# thin on y axis and then on x axis if value > 1
ax.plot(mesh_x[:,::thinning], mesh_y[:,::thinning], **kwargs)
ax.plot(mesh_x[::thinning,:].T, mesh_y[::thinning,:].T, **kwargs)

ax.plot(mesh_x[:,-1], mesh_y[:,-1], **kwargs)
ax.plot(mesh_x[-1,:].T, mesh_y[-1,:].T, **kwargs)

def write_mesh_to_shp(mesh_x,mesh_y,file_name,modelnr,EPSG=3844):
'''
Function to write mesh to shapefile
Expand Down
7 changes: 6 additions & 1 deletion xbTools/grid/extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,16 @@ def seaward_extend(x,y,z,slope=1/20,depth=-20):

## maximum distance
distance = (z0max - depth)/slope

## prevent very small grid sizes!
distance = np.ceil(distance/dx_grid) * dx_grid

## dummy array
x_dummy = np.arange(x[0, 0]-distance, x[0, 0], dx_grid)

# prevent very small grid sizes when floating point zero goes wrong for computing var distance!
if (x_dummy[-1]-x[0, 0])< 0.01:
x_dummy = x_dummy[:-1]

x_extend = np.ones((x.shape[0], len(x_dummy) ))
x_extend = x_extend * x_dummy
z_extend = np.ones_like(x_extend)
Expand Down
180 changes: 159 additions & 21 deletions xbTools/par.json
Original file line number Diff line number Diff line change
@@ -1,21 +1,159 @@
{"Physical processes":["wavemodel","sedtrans","morphology","vegetation","spongelength","ships","wind","viscosity","swrunup","swave","snells","single_dir","setbathy","gwflow","avalanching","nonhq3d"],
"Initial conditions":["zs0","zsinitfile","hotstartflow"],
"Model time":["tstop","CFL"],
"Grid parameters":["thetamin","thetamax","dtheta","dtheta_s","thetanaut","posdwn"],
"Flow boundary condition parameters":["front","back","left","right"],
"Flow parameters":["tidetype","epsi","bedfriction","bedfriccoef","nuhfac","bedfricfile"],
"Flow numerics parameters" : ["eps","eps_sd"],
"Tide boundary conditions":["zs0file","tideloc","paulrevere"],
"Wave boundary condition parameters":["Hrms","Tlong","Trep","dir0","m","taper","Tm01"],
"Wave-spectrum boundary condition parameters":["wbctype","rt","Tm01switch","correctHm0","dtbc","dthetaS_XB","fcutoff","nonhspectrum","nspectrumloc","nspr","random","sprdthr","trepfac","wbcEvarreduce","wbcScaleEnergy","wbcRemoveStokes","wbcversion"],
"Wave breaking parameters":["break","gamma","gamma2","alpha","deltahmin","fwfile"],
"Roller parameters":["beta"],
"Morphology parameters":["morstart","morfac","wetslp","struct","ne_layer","Hswitch"],
"Sediment input":["por","ws","rhos","ngd"],
"Bed composition parameters":["D50","D90"],
"Bed update numerics parameters":["nTrepavaltime"],
"Sediment transport parameters":["form","waveform","facSk","facAs","bulk","alfaD50","oldTsmin","oldhmin","bulk"],
"Sediment transport numerics parameters":["dtlimTs"],
"Avalanching":["wetslp","dryslp","fixedavaltime"],
"Output":["outputformat","tintg","tintm","tstart","tintp","tintc","nrugdepth","outputprecision","timings"],
"_Output": ["nglobalvar","nmeanvar","npointvar","npoints"]}
{
"_General": [
"wavemodel",
"wbctype"
],
"Physical processes": [
"sedtrans",
"morphology",
"vegetation",
"spongelength",
"ships",
"wind",
"viscosity",
"swrunup",
"swave",
"snells",
"single_dir",
"setbathy",
"gwflow",
"avalanching",
"cyclic",
"nonhq3d"
],
"Initial conditions": [
"zs0",
"zsinitfile",
"hotstartflow"
],
"Model time": [
"tstop",
"CFL"
],
"Grid parameters": [
"thetamin",
"thetamax",
"dtheta",
"dtheta_s",
"thetanaut",
"posdwn"
],
"Flow boundary condition parameters": [
"front",
"back",
"left",
"right"
],
"Flow parameters": [
"tidetype",
"epsi",
"bedfriction",
"bedfriccoef",
"nuhfac",
"bedfricfile"
],
"Flow numerics parameters": [
"eps",
"eps_sd"
],
"Tide boundary conditions": [
"zs0file",
"tideloc",
"paulrevere"
],
"Wave boundary condition parameters": [
"Hrms",
"Tlong",
"Trep",
"dir0",
"m",
"taper",
"Tm01"
],
"Wave-spectrum boundary condition parameters": [
"rt",
"Tm01switch",
"correctHm0",
"dtbc",
"dthetaS_XB",
"fcutoff",
"nonhspectrum",
"nspectrumloc",
"nspr",
"random",
"sprdthr",
"trepfac",
"wbcEvarreduce",
"wbcScaleEnergy",
"wbcRemoveStokes",
"wbcversion"
],
"Wave breaking parameters": [
"break",
"gamma",
"gamma2",
"alpha",
"deltahmin",
"fwfile"
],
"Roller parameters": [
"beta"
],
"Morphology parameters": [
"morstart",
"morfac",
"wetslp",
"struct",
"ne_layer",
"Hswitch"
],
"Sediment input": [
"por",
"ws",
"rhos",
"ngd"
],
"Bed composition parameters": [
"D50",
"D90"
],
"Bed update numerics parameters": [
"nTrepavaltime"
],
"Sediment transport parameters": [
"form",
"waveform",
"facSk",
"facAs",
"bulk",
"alfaD50",
"oldTsmin",
"oldhmin",
"bulk"
],
"Sediment transport numerics parameters": [
"dtlimTs"
],
"Avalanching": [
"wetslp",
"dryslp",
"fixedavaltime"
],
"Output": [
"outputformat",
"tintg",
"tintm",
"tstart",
"tintp",
"tintc",
"nrugdepth",
"outputprecision",
"timings"
],
"_Output": [
"nglobalvar",
"nmeanvar",
"npointvar",
"npoints"
]
}
24 changes: 15 additions & 9 deletions xbTools/xbeachpost.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""
Created on Fri Aug 11 14:10:02 2023
@author: MarliesA
@author: Marlies van der Lugt
main collection for the postprocessing of XBeach models
module contains class for analysis of 2D XBeach models
note that output and input must be available in directory
Expand Down Expand Up @@ -52,7 +52,7 @@ def __init__(self, fname, model_path):
self.plot_km_coords = False
self.AOI = []
self.globalstarttime = None
self.unitdict = {'Hm0': ' [m]', 'H': ' [m]', 'zs': ' [m+NAP]', 'u': ' [m/s]', 'v': ' [m/s]',
self.unitdict = {'Hm0': ' [m]', 'H': ' [m]', 'zs': ' [m]', 'u': ' [m/s]', 'v': ' [m/s]',
'zb': ' [m]', 'thetamean': ' [deg]', 'beta': '[-]'}

def get_metadata(self):
Expand Down Expand Up @@ -312,7 +312,7 @@ def load_output_coordinates(self):
x = ds.variables['globalx'][:]
y = ds.variables['globaly'][:]
if len(self.AOI) > 0:
assert len(self.AOI) == 4, 'AOI should be specified as [x0, xend, y0, yend]'
assert len(self.AOI) == 4, 'AOI should be specified as [i_y0, i_yend, i_x0, i_xend]'

x = x[self.AOI[0]:self.AOI[1], self.AOI[2]:self.AOI[3]]
y = y[self.AOI[0]:self.AOI[1], self.AOI[2]:self.AOI[3]]
Expand Down Expand Up @@ -426,6 +426,8 @@ def load_modeloutput(self, var):

if '_mean' in var:
assert sum([var[:-5] in x for x in self.params['meanvar']]) > 0, '{} not in xb output'
elif '_var' in var:
assert sum([var[:-4] in x for x in self.params['meanvar']]) > 0, '{} not in xb output'
elif '_min' in var:
assert sum([var[:-4] in x for x in self.params['meanvar']]) > 0, '{} not in xb output'
elif '_max' in var:
Expand Down Expand Up @@ -540,8 +542,8 @@ def fig_check_tide_bc(self):
assert 'zs0file' in self.params, 'No tidal signal available'

# get model output
self.load_modeloutput('zs')
zs = self.var['zs']
self.load_modeloutput('zs_mean')
zs = self.var['zs_mean']

# get model input
if self.tide == {}:
Expand Down Expand Up @@ -624,7 +626,7 @@ def _fig_map_var(self, dat, label, figsize=None, **kwargs):
divider = make_axes_locatable(ax)
cax = divider.append_axes('right', size='5%', pad=0.05)

if np.max(np.abs(dat))<0.001:
if np.max(np.abs(dat))<0.01:
fmt = lambda x, pos: '{:.1e}'.format(x)
else:
fmt = lambda x, pos: '{:.1f}'.format(x)
Expand Down Expand Up @@ -656,7 +658,7 @@ def _fig_map_var(self, dat, label, figsize=None, **kwargs):

return fig, ax

def fig_map_var(self, var, label, it=np.inf, figsize=None, **kwargs):
def fig_map_var(self, var, label=None, it=np.inf, figsize=None, **kwargs):
"""_summary_
Args:
Expand All @@ -675,6 +677,8 @@ def fig_map_var(self, var, label, it=np.inf, figsize=None, **kwargs):
assert it <= len(self.var['globaltime']) - 1, 'it should be <= {}'.format(len(self.var['globaltime']) - 1)

data = self.var[var][it, :, :]
if label is None:
label = str(var)
fig, ax = self._fig_map_var(data, label, figsize, **kwargs)

if self.globalstarttime is None:
Expand Down Expand Up @@ -758,7 +762,7 @@ def fig_cross_var(self,var, it, iy=None, coord=None, plot_ref_bathy=True, zmin=-
self.load_modeloutput(var)
except:
print('var not found as output specified in params. Will try to continue to see if computed earlier')
self.load_modeloutput('zb')


x = self.var['globalx']
y = self.var['globaly']
Expand All @@ -768,7 +772,6 @@ def fig_cross_var(self,var, it, iy=None, coord=None, plot_ref_bathy=True, zmin=-
iy, _ = np.unravel_index(((x - coord[0]) ** 2 + (y - coord[1]) ** 2).argmin(), x.shape)

data = self.var[var][it, iy, :]
z = self.var['zb'][it, iy, :]
cross = self.var['cross']

fig, ax1 = plt.subplots(figsize=[5, 3])
Expand All @@ -781,6 +784,9 @@ def fig_cross_var(self,var, it, iy=None, coord=None, plot_ref_bathy=True, zmin=-
ax1.set_xlabel('cross shore [m]')

if plot_ref_bathy:
self.load_modeloutput('zb')
z = self.var['zb'][it, iy, :]

ax2 = ax1.twinx()
ax1.set_zorder(ax2.get_zorder() + 1) # move ax in front
ax1.patch.set_visible(False)
Expand Down
Loading

0 comments on commit 0b3862c

Please sign in to comment.