wecopttool.waves.spectrum

spectrum(f1, nfreq, directions, spectrum_func, spread_func, spectrum_name='', spread_name='')[source]

Create the xarray.DataArray for an irregular wave in the wavespectra.SpecArray format.

Examples

Define the desired spectrum parameters.

>>> import wecopttool as wot
>>> import numpy as np
>>> Hs = 5
>>> Tp = 6
>>> fp = 1/Tp
>>> directions = np.linspace(0, 360, 36, endpoint=False)

Create a function handle to define the spectral density,

>>> def spectrum_func(f):
...    return wot.waves.pierson_moskowitz_spectrum(freq=f,
...                                                fp=fp,
...                                                hs=Hs)

and a spreading function handle for spreading.

>>> def spread_func(f, d):
...     return wot.waves.spread_cos2s(freq=f,
...                                   directions=d,
...                                   dm=10,
...                                   fp=fp,
...                                   s_max=10)

Generate the spectrum.

>>> wave = wot.waves.spectrum(f1=fp/10,
...                           nfreq=20,
...                           directions=directions,
...                           spectrum_func=spectrum_func,
...                           spread_func=spread_func,
...                           spectrum_name="Pierson-Moskowitz",
...                           spread_name="cosine-2s",)
Parameters:
  • f1 (float) – Fundamental frequency f1 [Hz].

  • nfreq (int) – Number of frequencies (not including zero frequency), i.e., freq = [0, f1, 2*f1, ..., nfreq*f1].

  • directions (float | ArrayLike) – Wave directions in degrees. 1D array, evenly spaced.

  • spectrum_func (Callable) – Wave spectrum function. Maps frequencies to amplitude spectrum. Union[float, ArrayLike] -> Union[float, np.ndarray]. Units: \(m^2/Hz\).

  • spread_func (Callable) – Wave spreading function. Maps wave frequencies and directions to spread value. tuple[ Union[float, ArrayLike], Union[float, ArrayLike]] -> ndarray. Units: \(1/degree\).

  • spectrum_name (str) – Name of the spectrum function.

  • spread_name (str) – Name of the spread function.

Return type:

DataArray