|
| 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 |
0 commit comments