Postprocessing XBeach 2D#
Postprocessing 2D XBeach model output with the Python toolbox
[3]:
# import default modules
import matplotlib.pyplot as plt
import sys
import os
# method to import xbtools with try routine
try:
import xbTools
except ImportError:
print('**no xbTools installation found in environment, adding parent path of notebook to see if it works')
sys.path.append(os.path.abspath(os.path.join('..', '..', 'xbeach-toolbox')))
Import the toolbox and set the xbeach styleshoot for plotting
[4]:
## import xbeach tools
#sys.path.append(os.path.abspath(os.path.join('..')))
from xbTools.xbeachpost import XBeachModelAnalysis
Data#
Specify path and load model from folder, in this example the xb-2D model prepared by the xbeach-setup-2D is used!
Please note that you should run this model before this script can be executed.
[5]:
results = XBeachModelAnalysis('test_run_1', 'xb-2D\\')
Get metadata from XBlog#
[6]:
results.metadata
[6]:
{'wavemodel': 'surfbeat',
'cyclic': '0 (no record found, default value used)',
'swave': '1 (no record found, default value used)',
'single_dir': '1 (no record found, default value used)',
'lwave': '1 (no record found, default value used)',
'flow': '1 (no record found, default value used)',
'sedtrans': '1 (no record found, default value used)',
'morphology': '0',
'avalanching': '0 (no record found, default value used)',
'gwflow': '0 (no record found, default value used)',
'ships': '0 (no record found, default value used)',
'vegetation': '0 (no record found, default value used)',
'setbathy': '0 (no record found, default value used)',
'viscosity': '1 (no record found, default value used)',
'advection': '1 (no record found, default value used)',
'wind': '0 (no record found, default value used)',
'gridform': 'xbeach (no record found, default value used)',
'xori': '.0000',
'yori': '.0000',
'alfa': '10.0000',
'nx': '174',
'ny': '180',
'posdwn': '-1.0000',
'depfile': 'bed.dep',
'vardx': '1',
'dx': '-1.0000 (no record found, default value used)',
'dy': '-1.0000 (no record found, default value used)',
'xfile': 'x.grd',
'yfile': 'y.grd',
'nz': '1 (no record found, default value used)',
'thetamin': '-90.0000',
'thetamax': '90.0000',
'thetanaut': '0',
'r': ' 1',
'dtheta_s': '10.0000',
'CFL': '.7000 (no record found, default value used)',
'dtset': '.0000 (no record found, default value used)',
'tstop': '3600.0000',
'maxdtfac': '50.0000 (no record found, default value used)',
'rho': '1025.0000 (no record found, default value used)',
'g': '9.8100 (no record found, default value used)',
'depthscale': '1.0000 (no record found, default value used)',
'zsinitfile': ' None specified',
'wbctype': 'jonstable',
'bcfile': 'jonstable.txt',
'taper': '100.0000 (no record found, default value used)',
'nmax': '.8000 (no record found, default value used)',
'nonhspectrum': '0 (no record found, default value used)',
'Hrms': '1.0000 (no record found, default value used)',
'Tm01': '10.0000 (no record found, default value used)',
'Trep': '10.0000 (no record found, default value used)',
'dir0': '270.0000 (no record found, default value used)',
'm': '10 (no record found, default value used)',
'lateralwave': 'neumann (no record found, default value used)',
'random': '1 (no record found, default value used)',
'fcutoff': '.0000 (no record found, default value used)',
'trepfac': '.0100 (no record found, default value used)',
'sprdthr': '.0800 (no record found, default value used)',
'Tm01switch': '0 (no record found, default value used)',
'nspectrumloc': '1 (no record found, default value used)',
'wbcEvarreduce': '1.0000 (no record found, default value used)',
'front': 'abs_2d (no record found, default value used)',
'left': 'neumann (no record found, default value used)',
'right': 'neumann (no record found, default value used)',
'back': 'abs_2d (no record found, default value used)',
'ARC': '1 (no record found, default value used)',
'order': '2.0000 (no record found, default value used)',
'highcomp': '0 (no record found, default value used)',
'freewave': '0 (no record found, default value used)',
'epsi': '-1.0000 (no record found, default value used)',
'tidetype': 'velocity (no record found, default value used)',
'tideloc': '0 (no record found, default value used)',
'zs0': '.0000',
'disch_loc_file': ' None specified',
'disch_timeseries_file': ' None specified',
'ndischarge': '0 (no record found, default value used)',
'ntdischarge': '0 (no record found, default value used)',
'break': 'roelvink_daly (no record found, default value used)',
'gamma': '.4600 (no record found, default value used)',
'gamma2': '.3400 (no record found, default value used)',
'gammax': '2.0000 (no record found, default value used)',
'alpha': '1.3800 (no record found, default value used)',
'n': '10.0000 (no record found, default value used)',
'delta': '.0000 (no record found, default value used)',
'deltahmin': '.1000 (no record found, default value used)',
'fw': '.0000 (no record found, default value used)',
'fwfile': ' None specified',
'fwcutoff': '1000.0000 (no record found, default value used)',
'breakerdelay': '1.0000 (no record found, default value used)',
'roller': '1 (no record found, default value used)',
'rfb': '0 (no record found, default value used)',
'beta': '.0800 (no record found, default value used)',
'wci': '0 (no record found, default value used)',
'hwci': '.1000 (no record found, default value used)',
'hwcimax': '100.0000 (no record found, default value used)',
'cats': '4.0000 (no record found, default value used)',
'bedfriction': 'manning (no record found, default value used)',
'bedfricfile': ' None specified',
'bedfriccoef': '.0200 (no record found, default value used)',
'maxcf': '.0400 (no record found, default value used)',
'nuh': '.1000 (no record found, default value used)',
'nuhfac': '.0000 (no record found, default value used)',
'smag': '1 (no record found, default value used)',
'wearth': '.0417 (no record found, default value used)',
'lat': '.0000 (no record found, default value used)',
'form': 'vanthiel_vanrijn (no record found, default value use',
'waveform': 'vanthiel (no record found, default value used)',
'sws': '1 (no record found, default value used)',
'lws': '1 (no record found, default value used)',
'BRfac': '1.0000 (no record found, default value used)',
'facSk': '.1500 (no record found, default value used)',
'facAs': '.2000 (no record found, default value used)',
'facua': '.1750 (no record found, default value used)',
'Tbfac': '1.0000 (no record found, default value used)',
'turb': 'bore_averaged (no record found, default value used)',
'turbadv': 'none (no record found, default value used)',
'sus': '1 (no record found, default value used)',
'bed': '1 (no record found, default value used)',
'bulk': '0 (no record found, default value used)',
'facsl': '.1500 (no record found, default value used)',
'z0': '.0060 (no record found, default value used)',
'smax': '-1.0000 (no record found, default value used)',
'bdslpeffmag': 'roelvink_total (no record found, default value used)',
'bdslpeffini': 'none (no record found, default value used)',
'bdslpeffdir': 'none (no record found, default value used)',
'reposeangle': '30.0000 (no record found, default value used)',
'tsfac': '.1000 (no record found, default value used)',
'Tsmin': '.5000 (no record found, default value used)',
'facDc': '1.0000 (no record found, default value used)',
'lwt': '0 (no record found, default value used)',
'betad': '1.0000 (no record found, default value used)',
'fallvelred': '0 (no record found, default value used)',
'dilatancy': '0 (no record found, default value used)',
'alfaD50': '.4000 (no record found, default value used)',
'ngd': '1 (no record found, default value used)',
'nd': '3 (no record found, default value used)',
'por': '.4000 (no record found, default value used)',
'D50': '.0002 (no record found, default value used)',
'D90': '.0003 (no record found, default value used)',
'rhos': '2650.0000 (no record found, default value used)',
'dzg': '.1000 (no record found, default value used)',
'dzg1': '.1000 (no record found, default value used)',
'dzg2': '.1000 (no record found, default value used)',
'dzg3': '.1000 (no record found, default value used)',
'sedcal': '1.0000 (no record found, default value used)',
'ucrcal': '1.0000 (no record found, default value used)',
'timings': '1 (no record found, default value used)',
'tunits': ' None specified',
'tstart': '.0000 (no record found, default value used)',
'tint': '900.0000 (no record found, default value used)',
'tsglobal': ' None specified',
'tintg': '900.0000 (no record found, default value used)',
'tspoints': ' None specified',
'tintp': '1.0000 (no record found, default value used)',
'tsmean': ' None specified',
'tintm': '3600.0000 (no record found, default value used)',
'nglobalvar': '3',
'npoints': '4',
'nrugauge': '0 (no record found, default value used)',
'npointvar': '2',
'nrugdepth': '1 (no record found, default value used)',
'rugdepth': '.0000 (no record found, default value used)',
'nmeanvar': '1',
'outputformat': 'netcdf (no record found, default value used)',
'outputprecision': 'double (no record found, default value used)',
'ncfilename': ' None specified',
'remdryoutput': '1 (no record found, default value used)',
'projection': ' None specified',
'rotate': '1 (no record found, default value used)',
'scheme': 'warmbeam (no record found, default value used)',
'wavint': '600.0000 (no record found, default value used)',
'maxerror': '.0001 (no record found, default value used)',
'maxerror_angle': '1.0000 (no record found, default value used)',
'maxiter': '500 (no record found, default value used)',
'truncationtype': 'absolute (no record found, default value used)',
'eps': '.0050 (no record found, default value used)',
'eps_sd': '.5000 (no record found, default value used)',
'umin': '.0000 (no record found, default value used)',
'secorder': '0 (no record found, default value used)',
'thetanum': '1.0000 (no record found, default value used)',
'cmax': '.1000 (no record found, default value used)',
'dtlimTs': '5.0000 (no record found, default value used)'}
Additional settings#
Not necessary
[7]:
results.set_save_fig(False)
Coordinate settings#
Plot in local coords instead of global coords
[8]:
results.set_plot_localcoords(False)
Kilometer setting option#
plot in kilometers instead of m
[9]:
results.set_plot_km_coords(False)
Set starttime#
if not specified time from netcdf is used
[8]:
#results.set_globalstarttime('2021-10-11T13:00:00')
Change units#
m to m+msl / NAP etc.
[10]:
results.set_unitdict({'zb':['m+msl']})
Load the xbeach model set-up#
[11]:
results.load_model_setup()
Load XBeach model output#
[12]:
zs = results.load_modeloutput('zs')
ny, nx = results.var['globalx'].shape
results.load_modeloutput('point_zs')
zs = results.get_modeloutput('zs')
point_zs = results.get_modeloutput('point_zs')
[t, zs] = results.get_modeloutput_by_station('zs','point001')
#results.fig_check_tide_bc()
loading variable zs from file
loading variable point_zs from file
Plotting 2D fields and 1D transects#
[13]:
## change coordinates of plots to local coordinates:
#results.set_plot_localcoords(True)
## only plot a certain Area Of Interest of the complete grid
#results.set_aoi([20,445,20,220])
# example usage map plotting
fig, ax = results.fig_map_var('zb','[m]', it = 2)
#fig, ax = results.fig_map_diffvar('zb', '$\Delta z_b$ [m]')
fig, ax = results.fig_cross_var('H', 2, iy=5, coord=None, plot_ref_bathy=True, zmin=-25)
fig, ax = results.fig_profile_change(iy=5)
loading variable zb from file
loading variable H from file



Print params of xbeach run#
[14]:
results.params
[14]:
{'wavemodel': 'surfbeat',
'wbctype': 'jonstable',
'vardx': 1.0,
'posdwn': '-1',
'nx': 174.0,
'ny': 180.0,
'xori': 0.0,
'yori': 0.0,
'alfa': 10.0,
'xfile': 'x.grd',
'yfile': 'y.grd',
'depfile': 'bed.dep',
'thetamin': '-90',
'thetamax': 90.0,
'thetanaut': 0.0,
'dtheta': 10.0,
'dtheta_s': 10.0,
'Wavemodel': 'surfbeat',
'morphology': 0.0,
'tstop': 3600.0,
'zs0': 0.0,
'bcfile': 'jonstable.txt',
'nglobalvar': 3.0,
'npointvar': 2.0,
'nmeanvar': 1.0,
'npoints': 4.0,
'globalvar': ['zb', 'zs', 'H'],
'meanvar': ['zb'],
'pointvar': ['zs', 'H'],
'points': {'0': (6.0, 0.0), '': (12.0, 0.0)}}
[ ]: