Skip to content

Commit a4fce9c

Browse files
doc: update documentation for new functionality (#83)
1 parent d8b049f commit a4fce9c

7 files changed

Lines changed: 179 additions & 3 deletions

File tree

docs/api_ref/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ functions and methods.
1919
complex_to_polar
2020
CosineFullSpreading
2121
CosineHalfSpreading
22+
DirectionalBinSpectrum
2223
DirectionalSpectrum
2324
Grid
2425
JONSWAP
@@ -33,6 +34,7 @@ functions and methods.
3334
rigid_transform_heave
3435
rigid_transform_surge
3536
rigid_transform_sway
37+
WaveBinSpectrum
3638
WaveSpectrum
3739

3840

docs/user_guide/calculate_response.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ and provides useful spectrum operations, such as:
109109
.. math::
110110
S_x(\omega, \theta) = H_x(\omega, \theta)H_x^{*}(\omega, \theta) S_{\zeta}(\omega, \theta)
111111
112-
To obtain the one-dimentional spectrum (which is what you would measure with
113-
a sensor), you need to integrate over direction:
112+
To obtain the one-dimentional spectrum, you need to integrate over direction:
114113

115114
.. math::
116115
S_x(\omega) = \int S_x(\omega, \theta) d\theta
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
DirectionalBinSpectrum
2+
======================
3+
The :class:`~waveresponse.DirectionalBinSpectrum` class provides an interface for
4+
handling 2-D directional spectra. :class:`~waveresponse.DirectionalBinSpectrum`
5+
extends :class:`~waveresponse.Grid`, and contains spectrum density as a function
6+
of frequency, binned by direction.
7+
8+
.. math::
9+
\sum_{i=0}^n{S_i(\omega, \delta\left(\theta - \theta_i\right))}
10+
11+
The :class:`~waveresponse.DirectionalBinSpectrum` is initialized with a frequency
12+
list (1-D array), a direction list (1-D array) and corresponding spectrum
13+
density values, binned by direction (2-D array).
14+
15+
.. code-block:: python
16+
17+
import numpy as np
18+
from waveresponse as wr
19+
20+
21+
freq = np.linspace(0.0, 1.0, 50)
22+
dirs = np.linspace(0.0, 360.0, endpoint=False)
23+
vals = np.random.random((len(freq), len(dirs)))
24+
25+
spectrum = wr.DirectionalBinSpectrum(
26+
freq,
27+
dirs,
28+
vals,
29+
freq_hz=True,
30+
degrees=True,
31+
clockwise=False,
32+
waves_coming_from=False,
33+
)
34+
35+
The :class:`~waveresponse.DirectionalBinSpectrum` class extends the :class:`~waveresponse.Grid`
36+
class with the following:
37+
38+
Calculate the variance (i.e., integral) and standard deviation of the spectrum:
39+
40+
.. code-block:: python
41+
42+
# Variance
43+
var = spectrum.var()
44+
45+
# Standard deviation
46+
std = spectrum.std()
47+
48+
Integrate (or sum) over one of the axes to obtain a one-dimentional spectrum.
49+
You can specify whether to integrate over the frequency axis (``axis=0``), or
50+
sum over the direction axis (``axis=1``), by setting the appropriate `axis` parameter.
51+
52+
.. code-block:: python
53+
54+
# "Non-directional" spectrum
55+
spectrum_nondir = spectrum.spectrum1d(axis=1)
56+
57+
# Directional "histogram"
58+
spectrum_dir = spectrum.spectrum1d(axis=0)
59+
60+
Calculate spectral moments by calling the :meth:`~waveresponse.DirectionalBinSpectrum.moment`
61+
method with the desired order, `n`.
62+
63+
.. code-block:: python
64+
65+
# Zeroth-order moment
66+
m0 = spectrum.moment(0)
67+
68+
# First-order moment
69+
m1 = spectrum.moment(1)
70+
71+
# Second-order moment
72+
m2 = spectrum.moment(2)
73+
74+
# Etc.
75+
76+
Calculate the mean zero-crossing period, Tz:
77+
78+
.. code-block:: python
79+
80+
spectrum.tz
81+
82+
Calculate extreme values using the :meth:`~waveresponse.DirectionalSpectrum.extreme`
83+
method. The method takes three arguments: the duration of the process (in seconds),
84+
the quantile, ``q``, and a boolean flag, ``absmax``, determining whether to compute absolute
85+
value extremes (or only consider the maxima (`default`)).
86+
87+
.. code-block:: python
88+
89+
duration = 3 * 3600 # 3 hours
90+
91+
# Extreme maximum
92+
mpm = spectrum.extreme(duration, q=0.37) # most probable maximum (MPM)
93+
q90 = spectrum.extreme(duration, q=0.90) # 90-th quantile
94+
95+
# Extreme absolute value maximum (i.e., minima are taken into account)
96+
mpm = spectrum.extreme(duration, q=0.37, absmax=True) # most probable maximum (MPM)
97+
q90 = spectrum.extreme(duration, q=0.90, absmax=True) # 90-th quantile

docs/user_guide/concepts_utils/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@ This section will introduce concepts and utilites that are useful when working w
1111

1212
grid
1313
rao
14+
directional_bin_spectrum
1415
directional_spectrum
16+
wave_bin_spectrum
1517
wave_spectrum
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
WaveBinSpectrum
2+
===============
3+
The :class:`~waveresponse.WaveBinSpectrum` class provides an interface for handling
4+
2-D directional wave spectra. :class:`~waveresponse.WaveSpectrum` extends
5+
:class:`~waveresponse.DirectionalBinSpectrum`, and contains spectrum density as a function
6+
of frequency, binned by direction.
7+
8+
.. math::
9+
\sum_{i=0}^n{S_{\zeta, i}(\omega, \delta\left(\theta - \theta_i\right))}
10+
11+
The :class:`~waveresponse.WaveSpectrum` is initialized with a frequency
12+
list (1-D array), a direction list (1-D array) and corresponding spectrum
13+
density values, binned by direction (2-D array).
14+
15+
.. code-block:: python
16+
17+
import numpy as np
18+
import waveresponse as wr
19+
20+
21+
freq = np.linspace(0.0, 1.0, 50)
22+
dirs = np.linspace(0.0, 360.0, endpoint=False)
23+
vals = np.random.random((len(freq), len(dirs)))
24+
25+
wave = wr.WaveBinSpectrum(
26+
freq,
27+
dirs,
28+
vals,
29+
freq_hz=True,
30+
degrees=True,
31+
clockwise=False,
32+
waves_coming_from=False,
33+
)
34+
35+
36+
The :class:`~waveresponse.WaveBinSpectrum` class extends the
37+
:class:`~waveresponse.DirectionalBinSpectrum` class with the following:
38+
39+
Calculate the significant wave height, Hs:
40+
41+
.. code-block:: python
42+
43+
wave.hs
44+
45+
Calculate the wave peak period, Tp:
46+
47+
.. code-block:: python
48+
49+
wave.tp
50+
51+
Calculate the wave peak direction:
52+
53+
.. code-block:: python
54+
55+
wave.dirp()
56+
57+
Calculate the mean wave direction:
58+
59+
.. code-block::
60+
61+
wave.dirm()

docs/user_guide/standardized_spectra.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,18 @@ according to:
338338
339339
340340
where :math:`s` is a spreading coefficient, and :math:`\Gamma` is the Gamma function.
341+
342+
In addition, the spreading functions in ``waveresponse`` cand determine discrete
343+
direction bins with equal energy:
344+
345+
.. code:: python
346+
347+
import waveresponse as wr
348+
349+
350+
spread_fun = wr.CosineFullSpreading(s=2, degrees=True)
351+
discrete_dirs = spread_fun.discrete_directions(5, direction_offset=0.0)
352+
353+
354+
which may be used to spread 1-D 'non-directional' wave spectrum into waves
355+
with equal energy.

src/waveresponse/_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1833,7 +1833,7 @@ class DirectionalBinSpectrum(_SpectrumMixin, Grid):
18331833
"""
18341834
Directional binned spectrum.
18351835
1836-
The ``DirectionalBinSpectrum`` class extends the :class:`~waveresponse.BinGrid`
1836+
The ``DirectionalBinSpectrum`` class extends the :class:`~waveresponse.Grid`
18371837
class and represents a two-dimensional frequency/wave-direction grid. The spectrum values
18381838
represent spectral density as a function of frequency, binned by direction.
18391839

0 commit comments

Comments
 (0)