netsse.analys.buoy
==================

.. py:module:: netsse.analys.buoy

.. autoapi-nested-parse::

   Functions to **process wave buoy** motion signals into directional wave
   spectra.

   .. dropdown:: Copyright (C) 2023-2026 Technical University of Denmark, R.E.G. Mounet
       :color: primary
       :icon: law

       *This code is part of the NetSSE software.*

       NetSSE is free software: you can redistribute it and/or modify it under
       the terms of the GNU General Public License as published by the Free
       Software Foundation, either version 3 of the License, or (at your
       option) any later version.

       NetSSE is distributed in the hope that it will be useful, but WITHOUT
       ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       for more details.

       You should have received a copy of the GNU General Public License along
       with this program.  If not, see https://www.gnu.org/licenses/.

       To credit the author, users are encouraged to use below reference:

       .. code-block:: text

           Mounet, R. E. G., & Nielsen, U. D. NetSSE: An open-source Python package
           for network-based sea state estimation from ships, buoys, and other
           observation platforms (version 2.2). Technical University of Denmark,
           GitLab. February 2026. https://doi.org/10.11583/DTU.26379811.

   *Last updated on 20-02-2026 by R.E.G. Mounet*



Functions
---------

.. autoapisummary::

   netsse.analys.buoy.Fourier2spread_dist_params
   netsse.analys.buoy.Shannon_MEMII_Newton
   netsse.analys.buoy.cross_spec2Fourier_coef
   netsse.analys.buoy.spread_dist_params2Fourier


Module Contents
---------------

.. py:function:: Fourier2spread_dist_params(a1, b1, a2, b2)

   Infers the parameters of the directional spreading distribution function
   from the Fourier coefficients, as per Kuik et al. (1988).

   :param a1: First four Fourier coefficients of the directional wave spectrum.
   :type a1: array_like of shape (Nf,)
   :param b1: First four Fourier coefficients of the directional wave spectrum.
   :type b1: array_like of shape (Nf,)
   :param a2: First four Fourier coefficients of the directional wave spectrum.
   :type a2: array_like of shape (Nf,)
   :param b2: First four Fourier coefficients of the directional wave spectrum.
   :type b2: array_like of shape (Nf,)

   :returns: * **alpha** (*array_like of shape (Nf,)*) -- Wave direction [rad].
             * **sigma** (*array_like of shape (Nf,)*) -- Directional spread [rad].
             * **gamma** (*array_like of shape (Nf,)*) -- Skewness of the directional distribution [-].
             * **delta** (*array_like of shape (Nf,)*) -- Kurtosis of the directional distribution [-].

   .. seealso::

      :py:obj:`spread_dist_params2Fourier`
          Infers the Fourier coefficients from the parameters of the directional spreading distribution function.

   .. rubric:: References

   Kuik, A. J., van Vledder, G. P., & Holthuijsen, L. H. (1988). *A Method for
   the Routine Analysis of Pitch-and-Roll Buoy Wave Data*. Journal of Physical
   Oceanography, 18(7), 1020–1034.

   .. rubric:: Example

   >>> [alpha, sigma, gamma, delta] = Fourier2spread_dist_params(a1,b1,a2,b2)


.. py:function:: Shannon_MEMII_Newton(a1, a2, b1, b2, freq, theta, maxiter, tol_error, miniter=50, approx=False)

   Reconstructs the directional spreading function based on the first four Fourier
   coefficients of a directional wave spectrum.

   The function implements the Maximum Entropy Principle (Hashimoto, 1997), either via
   running the Newton local linearisation method or following the approximation method
   by Kim et al. (1994).

   :param a1: First four Fourier coefficients of the directional wave spectrum.
   :type a1: array_like of shape (Nf,)
   :param a2: First four Fourier coefficients of the directional wave spectrum.
   :type a2: array_like of shape (Nf,)
   :param b1: First four Fourier coefficients of the directional wave spectrum.
   :type b1: array_like of shape (Nf,)
   :param b2: First four Fourier coefficients of the directional wave spectrum.
   :type b2: array_like of shape (Nf,)
   :param freq: Vector of (discretized) wave frequencies [Hz].
   :type freq: array_like of shape (Nf,)
   :param theta: Vector of wave headings [deg].
   :type theta: array_like of shape (Ntheta,)
   :param maxiter: Maximum number of iterations.
   :type maxiter: int
   :param tol_error: Tolerance in the relative error.
   :type tol_error: float
   :param miniter: Minimum number of iterations.
   :type miniter: int, default 50
   :param approx: Boolean which indicates whether the approximation method should be
                  used for finding the Lagrangian multipliers.
   :type approx: bool, default False

   :returns: * **D** (*array_like of shape (Nf,Ntheta)*) -- Directional spreading function.
             * **flag** (*array_like of shape (Nf,)*) -- Boolean flag indicating unconverged frequencies
               (``flag = 0`` for unconverged)
             * **L1, L2, L3, L4** (*array_like of shape (Nf,)*) -- Optimized Lagrange multipliers.

   .. seealso::

      :py:obj:`cross_spec2Fourier_coef`
          Computes the Fourier coefficients from the cross-spectra of a heave-East-North wave buoy.

      :py:obj:`netsse.analys.emep.emep`
          Extended Maximum Entropy Principle (EMEP) method for reconstructing the directional spreading function based on the cross-power spectra of measured wave-induced responses.

   .. rubric:: References

   1. Benoit, M., Frigaard, P., & Schäffer, H. A. (1997). *Analysing Multidirectional
      Wave Spectra: A tentative classification of available methods*. Proceedings of
      the 27th IAHR Congress, San Francisco, CA, USA (pp. 131–158).
      Canadian Government Publishing.
   2. Hashimoto, N. (1997). *Analysis of the Directional Wave Spectrum from Field
      Data*. Advances in coastal and ocean engineering. 3:103-44.
   3. Kim, T., Lin, L.-H., & Wang, H. (1994). *Application of Maximum Entropy Method
      to the Real Sea Data*. In Coastal Engineering (pp. 340–355).

   .. rubric:: Example

   >>> D, flag, L1, L2, L3, L4 =
   ...     Shannon_MEMII_Newton(a1,a2,b1,b2,freq,theta,maxiter,tol_error,miniter=50,False)


.. py:function:: cross_spec2Fourier_coef(Gf)

   Computes the Fourier coefficients from the cross-spectra of a
   heave-East-North wave buoy, as per Benoit et al. (1997).

   :param Gf: Cross-spectra (Heave-East-North), as a function of frequency in Hertz.
   :type Gf: array_like of shape (3,3,Nf)

   :returns: * **Sf** (*array_like of shape (Nf,)*) -- One-sided variance spectrum of the waves [m^2.s], as a function of
               frequency in Hertz.
             * **a1, a2, b1, b2** (*array_like of shape (Nf,)*) -- Frequency-dependent Fourier coefficients of the directional wave
               spectrum.

   .. seealso::

      :py:obj:`Shannon_MEMII_Newton`
          Reconstructs the directional spreading function based on the first four Fourier coefficients of a directional wave spectrum.

   .. rubric:: References

   Benoit, M., Frigaard, P., & Schäffer, H. A. (1997). *Analysing Multidirectional
   Wave Spectra: A tentative classification of available methods*. Proceedings of
   the 27th IAHR Congress, San Francisco, CA, USA (pp. 131–158). Canadian
   Government Publishing.

   .. rubric:: Example

   >>> Sf, a1, a2, b1, b2 = cross_spec2Fourier_coef(Gf)


.. py:function:: spread_dist_params2Fourier(alpha, sigma, gamma, delta, unit='rad')

   Infers the Fourier coefficients from the parameters of the directional
   spreading distribution function, as per Kuik et al. (1988).

   :param alpha: Wave direction [rad, or deg].
   :type alpha: array_like of shape (Nf,)
   :param sigma: Directional spread [rad, or deg].
   :type sigma: array_like of shape (Nf,)
   :param gamma: Skewness of the directional distribution [-].
   :type gamma: array_like of shape (Nf,)
   :param delta: Kurtosis of the directional distribution [-].
   :type delta: array_like of shape (Nf,)
   :param unit: Unit of the wave direction and directional spread: ``'deg'`` or ``'rad'``
                (default).
   :type unit: {'rad','deg'}, optional

   :returns: **a1, b1, a2, b2** -- First four Fourier coefficients of the directional wave spectrum.
   :rtype: array_like of shape (Nf,)

   .. seealso::

      :py:obj:`Fourier2spread_dist_params`
          Infers the parameters of the directional spreading distribution function from the Fourier coefficients.

      :py:obj:`Shannon_MEMII_Newton`
          Reconstructs the directional spreading function based on the first four Fourier coefficients of a directional wave spectrum.

   .. rubric:: References

   Kuik, A. J., van Vledder, G. P., & Holthuijsen, L. H. (1988). *A Method for
   the Routine Analysis of Pitch-and-Roll Buoy Wave Data*. Journal of Physical
   Oceanography, 18(7), 1020–1034.

   .. rubric:: Example

   >>> [a1,b1,a2,b2] = spread_dist_params2Fourier(alpha,sigma,gamma,delta,unit)


