Waves¶
The wave boundary sets how XBeach forces waves at the offshore boundary. rompy-xbeach has one class per XBeach boundary type (wbctype) and per kind of input data: constant parameters, wave spectra or integrated parameters from a dataset, or boundary files made elsewhere. A wave boundary goes in Config.input.wave. When the workspace is generated, its get(destdir, grid, period) method writes the boundary files and returns the parameters for params.txt. This page helps you choose a class and shows what each one writes.
The examples below use this grid, a 12-hour run period, and destdir, a temporary folder the boundary files are written to:
from rompy.core.time import TimeRange
from rompy_xbeach.grid import RegularGrid
grid = RegularGrid(
ori={"x": 115.594239, "y": -32.641104, "crs": "EPSG:4326"},
alfa=347.0,
dx=10.0,
dy=15.0,
nx=230,
ny=220,
crs="EPSG:28350",
)
period = TimeRange(start="2023-01-01T00", end="2023-01-01T12", interval="1h")
# The directional grid, relative to the grid x-axis (0 = shore-normal)
DIRECTIONS = {"thetamin": -90.0, "thetamax": 90.0, "dtheta": 10.0}
Wave boundary types¶
Each class writes the XBeach wbctype given by its id:
wbctype |
Classes | What XBeach gets |
|---|---|---|
params |
BoundaryParams |
Constant Hrms, Trep, dir0, m in params.txt, no file. Bichromatic wave groups when Tlong is set |
parametric |
Boundary{Station,Point,Grid}{Spectra,Param}Jons, BoundaryFileJons |
A file of JONSWAP parameters (Hm0, Tp, mainang, gammajsp, s), or a file list of them |
jonstable |
Boundary{Station,Point,Grid}{Spectra,Param}Jonstable, BoundaryFileJonstable |
One table with a row of JONSWAP parameters per time step |
swan |
BoundaryStationSpectraSwan, BoundaryFileSwan |
Full 2D spectra in SWAN format, or a file list of them |
ts_1, ts_2 |
BoundaryTs1, BoundaryTs2 |
An existing bc/gen.ezs time series of wave energy |
ts_nonh |
BoundaryTsNonh |
An existing non-hydrostatic time series (Boun_u.bcf format) |
reuse |
BoundaryReuse |
The boundary time series (.bcf files) generated by a previous XBeach run |
off |
BoundaryOff |
No wave forcing |
BoundaryStatTable writes wbctype = stat_table, which current XBeach versions do not accept, so it cannot be used yet.
Choosing a class¶
| Data you have | Class | Wave models |
|---|---|---|
| Nothing, just a sea state to test | BoundaryParams |
all |
| Nothing, idealised wave groups | BoundaryParams with Tlong |
surfbeat |
| 2D spectra at wave model output sites | BoundaryStationSpectraSwan (full spectrum), BoundaryStationSpectraJons or BoundaryStationSpectraJonstable (JONSWAP fit) |
swan, parametric: surfbeat, nonh; jonstable: all |
| Hs, Tp, direction at wave model sites | BoundaryStationParamJons, BoundaryStationParamJonstable |
as above |
| Gridded Hs, Tp, direction | BoundaryGridParamJons, BoundaryGridParamJonstable |
as above |
| One timeseries (buoy, CSV) | BoundaryPointParamJons, BoundaryPointParamJonstable |
as above |
| XBeach boundary files made elsewhere | BoundaryFileJons, BoundaryFileJonstable, BoundaryFileSwan |
as for their wbctype |
Time series files for ts_1, ts_2, ts_nonh |
BoundaryTs1, BoundaryTs2, BoundaryTsNonh |
ts_1, ts_2: surfbeat; ts_nonh: nonh |
| A previous XBeach run | BoundaryReuse |
surfbeat, nonh |
| No waves (tide or current only) | BoundaryOff |
all |
The JONSWAP classes differ in how they handle time. ...Jons writes one JONSWAP file for the start of the run, or with filelist=True one file per source time step. ...Jonstable always writes every time step into one table. ...Swan keeps the full frequency and direction spectrum, so XBeach sees multi-modal sea states (swell plus wind sea) that a JONSWAP fit cannot represent.
The wave model column is enforced by Config.
Constant waves¶
BoundaryParams applies the same root-mean-square wave height Hrms, representative period Trep and direction dir0 for the whole run. dir0 is nautical: the direction waves come from, clockwise from north. m is the power of the cosm directional spreading, so larger values give narrower spreading. No file is written; the values go straight into params.txt:
from rompy_xbeach.data.boundary import BoundaryParams
waves = BoundaryParams(Hrms=1.5, Trep=10.0, dir0=260.0, m=10, **DIRECTIONS)
print(waves.get(destdir))
{'wbctype': 'params', 'thetamin': -90.0, 'thetamax': 90.0, 'dtheta': 10.0, 'Hrms': 1.5, 'Trep': 10.0, 'dir0': 260.0, 'm': 10}
This is the simplest way to force the stationary wave model. With surfbeat, the wave energy at the boundary is then constant in time, without wave groups.
Bichromatic wave groups¶
Setting Tlong makes XBeach superimpose two wave trains that form regular wave groups with period Tlong. These groups drive infragravity waves, which is useful for idealised tests. XBeach only accepts bichromatic waves with the surfbeat wave model:
waves = BoundaryParams(Hrms=1.0, Trep=10.0, Tlong=80.0, dir0=270.0, m=20, **DIRECTIONS)
print(waves.get(destdir))
{'wbctype': 'params', 'thetamin': -90.0, 'thetamax': 90.0, 'dtheta': 10.0, 'Hrms': 1.0, 'Trep': 10.0, 'Tlong': 80.0, 'dir0': 270.0, 'm': 20}
Waves from spectra¶
The BoundaryStationSpectra... classes read 2D spectra at a set of sites, such as the spectral output of a regional wave model, through a SourceCRSWavespectra source and a wavespectra reader. The spectrum is taken at the middle of the offshore boundary, interpolated between the nearest sites.
from rompy_xbeach.source import SourceCRSWavespectra
spectra = SourceCRSWavespectra(
uri="tests/data/ww3-spectra-20230101-short.nc", reader="read_ww3"
)
JONSWAP parameters¶
BoundaryStationSpectraJons reduces the spectrum to JONSWAP parameters (significant wave height, peak period, mean direction, peak enhancement and spreading) and XBeach rebuilds a JONSWAP spectrum from them. By default it writes a single file with the conditions at the start of the run:
from rompy_xbeach.data.boundary import BoundaryStationSpectraJons
waves = BoundaryStationSpectraJons(source=spectra, **DIRECTIONS)
params = waves.get(destdir, grid, period)
print(params)
print((destdir / params["bcfile"]).read_text())
{'wbctype': 'parametric', 'bcfile': 'parametric-20230101T000000.txt', 'thetamin': -90.0, 'thetamax': 90.0, 'dtheta': 10.0, 'dtbc': 1.0}
mainang = 225.048
gammajsp = 1.56993
Tp = 14.4759
Hm0 = 2.95659
s = 7.79285
The directional spread is converted to the JONSWAP spreading coefficient s that XBeach expects.
Time-varying conditions: filelist¶
With filelist=True, the ...Jons and ...Swan classes write one boundary file per source time step within the run period, plus a FILELIST file that tells XBeach how long each file applies and at which time step (dtbc) to generate the boundary series. bcfile then points to the file list:
waves = BoundaryStationSpectraJons(source=spectra, filelist=True, **DIRECTIONS)
params = waves.get(destdir, grid, period)
print(params)
print((destdir / params["bcfile"]).read_text())
{'wbctype': 'parametric', 'bcfile': 'parametric-filelist.txt', 'thetamin': -90.0, 'thetamax': 90.0, 'dtheta': 10.0, 'dtbc': 1.0}
FILELIST
10800 1 parametric-20230101T000000.txt
10800 1 parametric-20230101T030000.txt
10800 1 parametric-20230101T060000.txt
10800 1 parametric-20230101T090000.txt
The spectra in this file are 3-hourly, so each file applies for 10800 s. If the run period does not start or end on a source time, the data are interpolated to the start and end times first.
JONSWAP table¶
BoundaryStationSpectraJonstable writes every time step into one table. The columns are Hm0, Tp, mainang, gammajsp, s, the duration of the row in seconds and dtbc:
from rompy_xbeach.data.boundary import BoundaryStationSpectraJonstable
waves = BoundaryStationSpectraJonstable(source=spectra, **DIRECTIONS)
params = waves.get(destdir, grid, period)
print(params)
print((destdir / params["bcfile"]).read_text())
{'wbctype': 'jonstable', 'bcfile': 'jonstable-20230101T000000-20230101T120000.txt', 'thetamin': -90.0, 'thetamax': 90.0, 'dtheta': 10.0, 'dtbc': 1.0}
2.95659 14.4759 225.048 1.56993 7.79284 10800 1
2.99656 14.5061 225.328 1.70814 9.87488 10800 1
3.06017 14.3689 225.606 1.77174 11.3748 10800 1
3.30915 14.2411 225.912 1.43912 11.0055 10800 1
3.63085 14.1611 226.41 1.07044 8.5548 10800 1
Full spectra¶
BoundaryStationSpectraSwan writes the spectrum as it is, in SWAN spectral format. filelist=True works as for JONSWAP. The first lines of the file:
from rompy_xbeach.data.boundary import BoundaryStationSpectraSwan
waves = BoundaryStationSpectraSwan(source=spectra, **DIRECTIONS)
params = waves.get(destdir, grid, period)
print(params)
print("\n".join((destdir / params["bcfile"]).read_text().splitlines()[:9]))
{'wbctype': 'swan', 'bcfile': 'swan-20230101T000000.txt', 'thetamin': -90.0, 'thetamax': 90.0, 'dtheta': 10.0, 'dtbc': 1.0}
SWAN 1 Swan standard spectral file
$ Created by wavespectra
$
LONLAT locations in spherical coordinates
1 number of locations
115.598402 -32.626715
AFREQ absolute frequencies in Hz
31 number of frequencies
0.03700
XBeach assumes the directions in a SWAN file are nautical. The spectra written here always are. dthetas_xb is only needed for SWAN files in the Cartesian convention (see existing boundary files).
Waves from parameters¶
When you only have integrated parameters, the ...Param... classes build JONSWAP boundaries from them. Each ..._var field takes either the name of a variable in the dataset or a constant number:
| Field | JONSWAP parameter |
|---|---|
hm0_var |
Significant wave height Hm0 (m) |
tp_var |
Peak period Tp (s) |
mainang_var |
Mean or peak direction, nautical (coming from) |
gammajsp_var |
Peak enhancement factor gamma (optional) |
dspr_var |
Directional spread in degrees, converted to s (optional) |
The ...Jons classes leave gammajsp or s out of the file when gammajsp_var or dspr_var is not set, so XBeach uses its defaults (3.3 and 10). The ...Jonstable classes need a value in every column and default to gammajsp_var=3.3 and a spread equivalent to s = 10.
At stations¶
BoundaryStationParamJons and BoundaryStationParamJonstable interpolate parameters between wave model sites. The dataset here has WAVEWATCH III partition parameters at sites along a seapoint dimension. The peak enhancement and spreading are given as constants:
from rompy_xbeach.data.boundary import BoundaryStationParamJons
from rompy_xbeach.source import SourceCRSFile
waves = BoundaryStationParamJons(
source=SourceCRSFile(uri="tests/data/smc-params-20230101.nc", crs=4326),
coords={"s": "seapoint"},
hm0_var="phs1",
tp_var="ptp1",
mainang_var="pdp1",
gammajsp_var=3.3,
dspr_var=20.0,
**DIRECTIONS,
)
params = waves.get(destdir, grid, period)
print(params)
print((destdir / params["bcfile"]).read_text())
{'wbctype': 'parametric', 'bcfile': 'parametric-20230101T000000.txt', 'thetamin': -90.0, 'thetamax': 90.0, 'dtheta': 10.0, 'dtbc': 1.0}
mainang = 254.158
gammajsp = 3.3
Tp = 13.1659
Hm0 = 0.875435
s = 15.414
On a grid¶
BoundaryGridParamJons and BoundaryGridParamJonstable take gridded fields. The source names the spatial dimensions:
from rompy_xbeach.data.boundary import BoundaryGridParamJonstable
waves = BoundaryGridParamJonstable(
source=SourceCRSFile(
uri="tests/data/gridded_wave_parameters.nc",
crs=4326,
x_dim="longitude",
y_dim="latitude",
),
hm0_var="phs1",
tp_var="ptp1",
mainang_var="pdp1",
gammajsp_var="ppe1",
dspr_var="pspr1",
**DIRECTIONS,
)
params = waves.get(destdir, grid, period)
print(params)
print((destdir / params["bcfile"]).read_text())
{'wbctype': 'jonstable', 'bcfile': 'jonstable-20230101T000000-20230101T120000.txt', 'thetamin': -90.0, 'thetamax': 90.0, 'dtheta': 10.0, 'dtbc': 1.0}
0.59286 15.326 256.055 3.61135 39.4458 3600 1
0.634844 15.24 256.115 3.71929 38.8198 3600 1
0.676148 15.1233 255.98 3.52664 39.3134 3600 1
0.701835 16.1724 259.39 3.69853 38.1915 3600 1
0.759703 15.9682 259.123 3.45387 37.5506 3600 1
0.873939 15.734 258.396 3.13726 34.7217 3600 1
0.909818 15.5477 258.148 3.04452 34.6838 3600 1
0.944898 15.3775 257.861 2.94178 34.9631 3600 1
0.971982 15.2133 257.593 2.84105 34.8189 3600 1
0.999866 15.053 257.326 2.73032 34.7809 3600 1
1.02135 14.8928 257.059 2.62559 35.0613 3600 1
1.04724 14.7305 256.771 2.50886 34.8105 3600 1
1.06753 14.5663 256.504 2.40013 34.5623 3600 1
From a single timeseries¶
BoundaryPointParamJons and BoundaryPointParamJonstable use a timeseries as it is, without spatial selection, for example a buoy record in a CSV file read with rompy's SourceTimeseriesCSV:
from rompy.core.source import SourceTimeseriesCSV
from rompy_xbeach.data.boundary import BoundaryPointParamJonstable
waves = BoundaryPointParamJonstable(
source=SourceTimeseriesCSV(filename="tests/data/wave-params-20230101.csv", tcol="time"),
hm0_var="phs1",
tp_var="ptp1",
mainang_var="pdp1",
gammajsp_var="ppe1",
dspr_var="pspr1",
**DIRECTIONS,
)
params = waves.get(destdir, grid, period)
print((destdir / params["bcfile"]).read_text())
1.01011 12.2993 244.342 2.52055 33.9251 3600 1
0.968176 13.7877 247.584 3.02407 41.2201 3600 1
0.994085 14.1542 248.386 3.02558 48.7203 3600 1
1.07939 13.5109 246.407 2.65635 46.7938 3600 1
1.13343 15.3336 250.89 2.79238 54.9961 3600 1
1.36986 15.4369 251.308 2.40611 50.0111 3600 1
1.46595 15.2322 251.179 2.30742 48.5546 3600 1
1.55301 15.0677 251.001 2.18789 47.001 3600 1
1.60305 14.9164 250.805 2.12522 46.4984 3600 1
1.63845 14.77 250.583 2.06828 46.1284 3600 1
1.66568 14.625 250.334 2.00733 45.8816 3600 1
1.68705 14.4773 250.034 1.94841 45.9753 3600 1
1.70383 14.321 249.769 1.89275 45.5342 3600 1
NetCDF timeseries work the same way through rompy's SourceFile.
Existing boundary files¶
The BoundaryFile... classes take a boundary file made elsewhere, as an XBeachDataBlob (a local path or a remote URI), copy it into the workspace and write the matching wbctype and bcfile. Here the JONSWAP file written above stands in for an existing file:
from rompy_xbeach.data.boundary import BoundaryFileJons
from rompy_xbeach.types import XBeachDataBlob
workspace = destdir / "workspace"
waves = BoundaryFileJons(
bcfile_source=XBeachDataBlob(source=destdir / "parametric-filelist.txt"),
filelist=True,
**DIRECTIONS,
)
print(waves.get(workspace))
print(sorted(p.name for p in workspace.iterdir()))
{'wbctype': 'parametric', 'bcfile': 'parametric-filelist.txt', 'thetamin': -90.0, 'thetamax': 90.0, 'dtheta': 10.0, 'dtbc': 1.0}
['parametric-20230101T000000.txt', 'parametric-20230101T030000.txt', 'parametric-20230101T060000.txt', 'parametric-20230101T090000.txt', 'parametric-filelist.txt']
With filelist=True the source is read as a FILELIST file, and every file it names is copied too, from the same folder. BoundaryFileSwan works the same way. BoundaryFileJonstable always takes a single table.
The time series boundaries BoundaryTs1, BoundaryTs2 and BoundaryTsNonh also take an existing file, in their source field. BoundaryTs1 and BoundaryTs2 copy it into a bc/ subfolder, as XBeach expects.
Reusing a previous run¶
XBeach converts a spectral boundary into wave energy and long-wave time series before it starts and saves them as .bcf files. BoundaryReuse copies these from the folder of a previous run, given as an XBeachDirectoryBlob, so a second run gets identical wave forcing. It copies the list files ebcflist.bcf and qbcflist.bcf (and esbcflist.bcf when the previous run used single_dir) and the series files they name, and writes no bcfile:
from rompy_xbeach.data.boundary import BoundaryReuse
from rompy_xbeach.types import XBeachDirectoryBlob
waves = BoundaryReuse(
previous_run=XBeachDirectoryBlob(source="path/to/first_run"), **DIRECTIONS
)
No waves¶
BoundaryOff switches wave forcing off, for tide- or current-only runs. The directional grid is still needed while short waves are enabled in Physics (the default), so either set it here or use Physics(swave=False):
Directional grid and shared settings¶
Every wave boundary class has the fields of WaveBoundaryParams. The classes that write or read spectral boundaries (parametric, jonstable, swan and reuse) have the extra fields of SpectralWaveBoundaryParams. Fields left as None are not written, so XBeach uses its defaults.
Directional grid. thetamin, thetamax and dtheta define the directional bins of the short-wave model. XBeach needs them whenever short waves are modelled. They are relative to the grid x-axis (0 is shore-normal, pointing onshore) unless thetanaut=True, in which case they are nautical directions. With surfbeat on a 2D grid, XBeach runs in single-direction mode by default and also needs dtheta_s, the directional resolution of its stationary refraction solver.
Other settings shared by all boundaries:
| Field | Meaning |
|---|---|
taper |
Spin-up time of the boundary forcing (s) |
order |
2 adds the bound long wave to the short-wave forcing, 1 forces short waves only |
nmax |
Maximum ratio of group to wave celerity used for the long-wave boundary |
ARC, freewave |
Absorbing-reflecting boundary settings |
wbcRemoveStokes, wbcScaleEnergy, wbcevarreduce, bclwonly, swkhmin, cyclicdiradjust |
Fine control of the generated boundary |
Settings for spectral boundaries only:
| Field | Meaning |
|---|---|
rt |
Duration of the boundary time series XBeach generates from each spectrum (s) |
dtbc |
Time step of that series (s). Defaults to 1.0 and is always written |
random |
Random wave phases; False makes runs repeatable |
fcutoff |
Low-frequency cut-off (Hz) |
dthetas_xb |
Rotation of the SWAN x-axis to east, for Cartesian SWAN files |
correcthm0, tm01switch, trepfac, sprdthr, nspr, nonhspectrum, nspectrumloc, wbcversion |
Fine control of the spectrum processing |
The JONSWAP classes also have fnyq and dfj, the highest frequency and frequency step XBeach uses to build the spectrum, which are written to the JONSWAP file.
For example, a repeatable boundary with a 10-minute spin-up and first-order forcing:
waves = BoundaryStationSpectraSwan(
source=spectra, random=False, taper=600.0, order=1, **DIRECTIONS
)
print(waves.get(destdir, grid, period))
{'wbctype': 'swan', 'bcfile': 'swan-20230101T000000.txt', 'taper': 600.0, 'thetamin': -90.0, 'thetamax': 90.0, 'dtheta': 10.0, 'order': 1, 'dtbc': 1.0, 'random': False}
Booleans such as random are written as 0 or 1 when Config renders params.txt.
Selecting data at the boundary¶
Wave boundaries always take data at the middle of the offshore boundary (location="offshore", the only value accepted). How that point is sampled depends on the data layout:
- Station classes (
...Station...) usesel_method="idw"by default: inverse distance weighting between the nearest sites.sel_method="nearest"takes the closest site. Options for the wavespectra selection functions, such astoleranceormax_sites, go insel_method_kwargs. Ifidwfinds no sites within tolerance, for example with a single-site dataset,get()raises an error suggestingnearest. - Grid classes (
...Grid...) usesel_method="sel"withsel_method_kwargs={"method": "nearest"}, the nearest grid cell.sel_method="interp"interpolates instead. - Point classes (
...Point...) use the timeseries as it is.
waves = BoundaryStationSpectraSwan(source=spectra, sel_method="nearest", **DIRECTIONS)
params = waves.get(destdir, grid, period)
print("\n".join((destdir / params["bcfile"]).read_text().splitlines()[3:6]))
The location written in the SWAN file is now that of the nearest site, rather than the boundary point.
The data interface fields inherited from rompy's DataGrid, such as crop_data and time_buffer, control how the source is cropped to the run period.
Wave model compatibility¶
XBeach refuses some combinations of boundary type and wave model at start-up. Config checks the same rules when it is created:
| Boundary | Allowed wave models |
|---|---|
params with Tlong (bichromatic) |
surfbeat |
parametric, swan, reuse |
surfbeat, nonh |
ts_1, ts_2 |
surfbeat |
ts_nonh |
nonh |
params, jonstable, off |
all |
from pydantic import ValidationError
from rompy_xbeach.components.physics import Physics
from rompy_xbeach.components.physics.wavemodel import Stationary
from rompy_xbeach.config import Config, DataInterface
from rompy_xbeach.data.bathy import XBeachBathy
from rompy_xbeach.source import SourceGeotiff
try:
Config(
grid=grid,
bathy=XBeachBathy(source=SourceGeotiff(filename="tests/data/bathy.tif")),
physics=Physics(wavemodel=Stationary()),
input=DataInterface(wave=BoundaryStationSpectraJons(source=spectra)),
)
except ValidationError as error:
print(error.errors()[0]["msg"])
Value error, wbctype=parametric from BoundaryStationSpectraJons cannot be used with the stationary wave model, XBeach requires nonh or surfbeat
In YAML¶
In YAML, the class is chosen by model_type, and the source by its own model_type:
import yaml
config_yaml = """
wave:
model_type: station_spectra_swan
source:
model_type: wavespectra
uri: tests/data/ww3-spectra-20230101-short.nc
reader: read_ww3
filelist: true
thetamin: -90.0
thetamax: 90.0
dtheta: 10.0
"""
data = DataInterface(**yaml.safe_load(config_yaml))
print(type(data.wave).__name__)
The model_type of each class is listed in the reference.
See it in the notebooks¶
See it in the notebooks
- 4. Adding forcing: waves, wind and water levels (tutorial)
- 5. Choosing model settings (tutorial)
- Constant and bichromatic wave boundaries (example)
- Flow and tide boundaries (example)
- Wave boundaries from spectra (example)
- Wave boundaries from wave parameters (example)
- Wave boundaries from existing files, and reuse (example)