WaveSpectrum#
The WaveSpectrum class provides an interface for handling
2-D directional wave spectra. WaveSpectrum extends
DirectionalSpectrum, and contains spectrum density values on
a two-dimensional frequency/(wave)direction grid.
The WaveSpectrum is initialized with a frequency
list (1-D array), a direction list (1-D array) and corresponding wave spectrum density
values (2-D array).
import numpy as np
import waveresponse as wr
freq = np.linspace(0.0, 1.0, 50)
dirs = np.linspace(0.0, 360.0, endpoint=False)
vals = np.random.random((len(freq), len(dirs)))
wave = wr.WaveSpectrum(
freq,
dirs,
vals,
freq_hz=True,
degrees=True,
clockwise=False,
waves_coming_from=False,
)
Alternatively, you can construct a WaveSpectrum from a ‘non-directional’
spectrum (1-D array), a directional spreading function and a peak direction:
import numpy as np
import waveresponse as wr
freq = np.linspace(0.0, 1.0, 50)
dirs = np.linspace(0.0, 360.0, endpoint=False)
spectrum1d = np.random.random(len(freq))
dirp = 45.0
def spread_fun(f, d):
return (1.0 / 180.0) * np.cos(np.radians(d / 2)) ** 2
wave = wr.WaveSpectrum.from_spectrum1d(
freq,
dirs,
spectrum1d,
spread_fun,
dirp,
freq_hz=True,
degrees=True,
clockwise=False,
waves_coming_from=False,
)
Tip
Two standardized (cosine-based) spreading functions, CosineFullSpreading
and CosineHalfSpreading, are provided by waveresponse.
The WaveSpectrum class extends the
DirectionalSpectrum class with the following:
Calculate the significant wave height, Hs:
wave.hs
Calculate the wave peak period, Tp:
wave.tp
Calculate the wave peak direction:
wave.dirp()
Calculate the mean wave direction:
wave.dirm()