netsse.analys.sawb
==================

.. py:module:: netsse.analys.sawb

.. autoapi-nested-parse::

   Python implementation of various algorithms for sea state estimation
   using the **wave-buoy analogy** (WBA), i.e. using the wave-induced
   responses of ships considered as sailing wave buoys (SAWB).

   .. 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.sawb.genspecres
   netsse.analys.sawb.specres


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

.. py:function:: genspecres(Rxy, Hxy, freq, beta, opt=None)

   Computes an estimate of the point wave spectrum using a generalised version of the
   spectral-residual method from Brodtkorb et al. (2017) and Nielsen et al. (2018).

   The cross-spectra from any number of responses are used as input.
   Using the motion transfer functions of the vessel, the wave spectrum is estimated
   through iteration.

   .. warning::
       Long-crested wave conditions are assumed in this sea state estimation method. The present
       version of the algorithm does not allow to distinguish waves coming from port and starboard
       sides.


   :param Rxy: The response cross-spectra.

               .. note::
                   The phase of the complex-valued response spectra is not important in this
                   implementation, and the amplitude (absolute value) alone can be provided without this affecting the estimation results.
   :type Rxy: array_like of shape (Nresp,Nfreq)
   :param Hxy: The RAO products for the ship, provided in the same order of response pairs as for the
               response cross-spectra `Rxy`.

               .. note::
                   The phase of the complex-valued transfer functions is not important in this
                   implementation, and the amplitude alone can be provided without this affecting
                   the estimation results.
   :type Hxy: array_like of shape (Nresp,Nbeta,Nfreq)
   :param freq: The frequencies of the response spectra and the transfer functions (should
                match).
   :type freq: array_like of shape (Nfreq,)
   :param beta: The discretized heading angles [deg] at which the transfer functions
                are known.

                .. tip::
                    For a port-starboard symmetric ship, directions from 0 deg to 180
                    deg only can be considered to lower the computational cost.
   :type beta: array_like of shape (Nbeta,)
   :param opt: Optional parameters controlling the SSE calculation. Available options are:

               - 'maxiter' : int, or array_like of shape (`Nresp`,)
                   Maximum number of iterations (default: 50).
               - 'tolCoef' : float, or array_like of shape (`Nresp`,)
                   Tolerance coefficient (default: 0.1).
               - 'gainFact' : float, or array_like of shape (`Nresp`,)
                   Gain factor, as a fraction of the maximum gain value (default: 0.5).
               - 'weights' : float, or array_like of shape (`Nresp`,)
                   Weights given to each response in the calculation of the final spectrum estimate
                   (default: equal weight for each response, i.e. wij = 1/`Nresp`).

               .. note::
                   `array_like` entries of the dictionary can be input for a response-specific option.
                   In such case, the array elements must be provided in the same order as for the response
                   spectra.
   :type opt: dict, optional

   :returns: * **S_wave** (*array_like of shape (Nfreq,)*) -- The estimated 1-D wave spectrum.
             * **beta_est** (*float*) -- The estimated relative wave heading [degrees].
             * **num_it** (*array_like of shape (Nresp,)*) -- The average number of iterations used per heading angle, for the individual
               response pairs.

   .. rubric:: References

   1. Brodtkorb, A. H., Nielsen, U. D., & Sørensen, A. J. (2018). Online wave estimation
      using vessel motion measurements. IFAC-PapersOnLine, 51(29), 244–249.
      https://doi.org/10.1016/j.ifacol.2018.09.510
   2. Brodtkorb, A. H., Nielsen, U. D., & Sørensen, A. J. (2018). Sea state estimation using
      vessel response in dynamic positioning. Applied Ocean Research, 70, 76–86.
      https://doi.org/10.1016/j.apor.2017.09.005
   3. Nielsen, U. D., Brodtkorb, A. H., & Sørensen, A. J. (2018). A brute-force spectral approach
      for wave estimation using measured vessel motions. Marine Structures, 60, 101–121.
      https://doi.org/10.1016/j.marstruc.2018.03.011
   4. Brodtkorb, A. H., & Nielsen, U. D. (2023). Automatic sea state estimation with online trust
      measure based on ship response measurements. Control Engineering Practice, 130.
      https://doi.org/10.1016/j.conengprac.2022.105375

   .. rubric:: Example

   >>> S_wave, beta_est, num_it = genspecres(Rxy, Hxy, freq, beta, opt=None)


.. py:function:: specres(Rxy, TRF, freq, beta, opt=None)

   Computes an estimate of the sea state using the spectral-residual method
   from Brodtkorb et al. (2017) and Nielsen et al. (2018).

   The heave, roll, and pitch response cross-spectra are used as input.
   Using the motion transfer functions of the vessel, the wave spectrum is estimated
   through iteration.

   .. warning::
       Long-crested wave conditions are assumed in this sea state estimation method.

   .. note::
       This Python code is based on a MATLAB/Simulink implementation by
       Astrid H. Brodtkorb.

   :param Rxy: The complex-valued response spectra, given as in:
               ``Rxy = [heaveheave, rollroll, pitchpitch, heaveroll, heavepitch, rollpitch]``.
   :type Rxy: array_like of shape (Nfreq,6)
   :param TRF: The transfer functions of the ship, in heave, roll, and pitch, concatenated
               along the second axis as in:
               ``TRF = [heave_TF,roll_TF,pitch_TF]``

               .. note::
                   The phase of the complex transfer functions is not important in this
                   implementation, and the amplitude alone can be provided without this affecting
                   the estimation results.
   :type TRF: array_like of shape (Nfreq,3*Nbeta)
   :param freq: The frequencies of the response spectra and the transfer functions (should
                match).
   :type freq: array_like of shape (Nfreq,)
   :param beta: The discretized heading angles [deg] at which the transfer functions
                are known.

                .. tip::
                    For a port-starboard symmetric ship, directions from 0 deg to 180
                    deg only can be considered to lower the computational cost.
   :type beta: array_like of shape (Nbeta,)
   :param opt: Optional parameters controlling the SSE calculation. Available options are:

               - 'maxiter' : int, or array_like of shape (6,)
                   Maximum number of iterations (default: 50).
               - 'tolCoef' : float, or array_like of shape (6,)
                   Tolerance coefficient (default: 0.1).
               - 'gainFact' : float, or array_like of shape (6,)
                   Gain factor, as a fraction of the maximum gain value (default: 0.5).
               - 'weights' : float, or array_like of shape (6,)
                   Weights given to each response in the calculation of the final spectrum estimate
                   (default: equal weight for each response, i.e. wij = 1/6).

               .. note::
                   `array_like` entries of the dictionary can be input for a response-specific option.
                   In such case, the array elements must be provided in the same order as for the response
                   spectra.
   :type opt: dict, optional

   :returns: * **S_wave** (*array_like of shape (Nfreq,)*) -- The estimated 1-D wave spectrum.
             * **beta_est** (*float*) -- The estimated relative wave heading [degrees].
             * **num_it** (*array_like of shape (6,)*) -- The average number of iterations used per heading angle, for the individual
               response pairs organised as:
               ``num_it = [it3, it4, it5, it34, it35, it45]``.

   .. rubric:: References

   1. Brodtkorb, A. H., Nielsen, U. D., & Sørensen, A. J. (2018). Online wave estimation
      using vessel motion measurements. IFAC-PapersOnLine, 51(29), 244–249.
      https://doi.org/10.1016/j.ifacol.2018.09.510
   2. Brodtkorb, A. H., Nielsen, U. D., & Sørensen, A. J. (2018). Sea state estimation using
      vessel response in dynamic positioning. Applied Ocean Research, 70, 76–86.
      https://doi.org/10.1016/j.apor.2017.09.005
   3. Nielsen, U. D., Brodtkorb, A. H., & Sørensen, A. J. (2018). A brute-force spectral approach
      for wave estimation using measured vessel motions. Marine Structures, 60, 101–121.
      https://doi.org/10.1016/j.marstruc.2018.03.011
   4. Brodtkorb, A. H., & Nielsen, U. D. (2023). Automatic sea state estimation with online trust
      measure based on ship response measurements. Control Engineering Practice, 130.
      https://doi.org/10.1016/j.conengprac.2022.105375

   .. rubric:: Example

   >>> S_wave, beta_est, num_it = specres(Rxy, TRF, freq, beta, opt=None)


