netsse.analys.spec
==================

.. py:module:: netsse.analys.spec

.. autoapi-nested-parse::

   Functions to compute sea state parameters from **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.spec.spec1d_to_params
   netsse.analys.spec.spec2d_to_params
   netsse.analys.spec.spec2d_to_spread_dist
   netsse.analys.spec.spread_dist_to_spec2d


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

.. py:function:: spec1d_to_params(S, freq, unit_freq='rad/s', smooth_Tp=False)

   Computes the main sea state parameters from a given 1-D wave spectrum.

   :param S: 1-D wave spectrum. If ``S`` has more than one dimension, then one axis must
             have a length Nfreq.
   :type S: array_like
   :param freq: Set of discretized frequencies.
   :type freq: array_like of shape (Nfreq,)
   :param unit_freq: Unit of the frequencies:

                     - 'rad/s' :
                         The variable ``freq`` denotes the circular frequencies in radians per second.
                     - 'Hz' :
                         The 1-D wave spectrum is expressed as a function of frequency in Hertz.
   :type unit_freq: {'rad/s','Hz'}, optional
   :param smooth_Tp: Specify whether the output ``Tp`` value should be smoothened by fitting
                     a polynomial of order 3 in the vicinity of the spectral peak and
                     estimating the peak period through the fitted polynomial.
   :type smooth_Tp: bool, default False

   :returns: * **m** (*array_like of shape (6,...,)*) -- Spectral moments :math:`[m_{-1},m_0,m_1,m_2,m_3,m_4]`.
             * **Hm0** (*float, or array_like*) -- Spectral significant wave height [m].
             * **Tp** (*float, or array_like*) -- Peak wave period [s].
             * **Tm01** (*float, or array_like*) -- Mean wave period [s].
             * **Tm02** (*float, or array_like*) -- Zero up-crossing period [s].
             * **Tm24** (*float, or array_like*) -- Mean crest period [s].
             * **TE** (*float, or array_like*) -- Mean energy period [s].
             * **Sm02** (*float, or array_like*) -- Significant wave steepness [-].
             * **epsilon** (*float, or array_like*) -- Spectral bandwidth [-].
             * **Qp** (*float, or array_like*) -- Goda's peakedness parameter [-].

   .. seealso::

      :py:obj:`spec2d_to_params`
          Computes a set of overall parameters characterizing the sea state from the 2-D wave spectrum.

   .. rubric:: Example

   >>> m, Hm0, Tp, Tm01, Tm02, Tm24, TE, Sm02, epsilon, Qp =
   ...     spec1d_to_params(S,freq,unit_freq='rad/s',smooth_Tp=False)


.. py:function:: spec2d_to_params(S2D, freq, theta, unit_theta='deg', smooth_peak=False)

   Computes a set of overall parameters characterizing the sea state from the
   2-D wave spectrum.

   :param S2D: Directional wave spectrum [m^2.s/``unit_theta``], as a function of frequency
               in Hertz and wave direction in specified unit (``unit_theta``).
   :type S2D: array_like of shape (...,Nf,Ntheta,...)
   :param freq: Vector of (discretized) wave frequencies [Hz] (must include :math:`f =` 0 Hz).
   :type freq: array_like of shape (Nf,)
   :param theta: Vector of wave headings [the unit is specified in ``unit_theta``].

                 .. attention::
                     ``theta`` must be in a wrapped format, i.e., corresponding to [0,360] deg.
   :type theta: array_like of shape (Ntheta,)
   :param unit_theta: Unit of the wave directions. This applies for the expression of the wave
                      spectrum too. Can be ``'deg'`` (for degrees), or ``'rad'`` (for radians).
                      ``'deg'`` is the default.
   :type unit_theta: {'deg','rad'}, optional
   :param smooth_peak: Specify whether the output ``Tp`` and ``theta_p`` values should be smoothened by
                       fitting a polynomial of order 3 in the vicinity of the spectral peak and
                       estimating the peak period and direction through the fitted polynomial.
                       The default is ``False``.
   :type smooth_peak: bool, optional

   :returns: * **m** (*array_like of shape (6,)*) -- Spectral moments :math:`[m_{-1},m_0,m_1,m_2,m_3,m_4]`.
             * **Hm0** (*float, or array_like*) -- Spectral significant wave height [m].
             * **Tp** (*float, or array_like*) -- Peak wave period [s].
             * **Tm01** (*float, or array_like*) -- Mean wave period [s].
             * **Tm02** (*float, or array_like*) -- Zero up-crossing period [s].
             * **Tm24** (*float, or array_like*) -- Mean crest period [s].
             * **TE** (*float, or array_like*) -- Mean energy period [s].
             * **Sm02** (*float, or array_like*) -- Significant wave steepness [-].
             * **epsilon** (*float, or array_like*) -- Spectral bandwidth [-].
             * **Qp** (*float, or array_like*) -- Goda's peakedness parameter [-].
             * **theta_p** (*float, or array_like*) -- Peak wave direction [deg].
             * **theta_m** (*float, or array_like*) -- Mean overall wave direction [deg].
             * **sigma_m** (*float, or array_like*) -- Mean directional spreading [deg].

   .. seealso::

      :py:obj:`spec1d_to_params`
          Computes the main sea state parameters from a given 1-D wave spectrum.

   .. rubric:: Example

   >>> m, Hm0, Tp, Tm01, Tm02, Tm24, TE, Sm02, epsilon, Qp, theta_p, theta_m, sigma_m =
   ...     spec2d_to_params(S2D, freq, theta, unit_theta='deg', smooth_peak=False)


.. py:function:: spec2d_to_spread_dist(S2D, theta)

   Converts the given 2-D wave spectrum into a directional spreading function
   and a 1-D wave spectrum.

   :param S2D: Directional wave spectrum, as a function of frequency and wave
               direction (with arbitrary units).
   :type S2D: array_like of shape (...,Nf,Ntheta,...)
   :param theta: Vector of wave headings (with arbitrary unit).
   :type theta: array_like of shape (Ntheta,)

   :returns: * **Sf** (*array_like of shape (...,Nf,...)*) -- One-sided variance spectrum of the waves, as a function of frequency.
             * **D** (*array_like of shape (...,Nf,Ntheta,...)*) -- Directional spreading function.

   .. seealso::

      :py:obj:`spread_dist_to_spec2d`
          Converts the given 1-D wave spectrum and directional spreading function into a 2-D wave spectrum.

   .. rubric:: Example

   >>> Sf, D = spec2d_to_spread_dist(S2D,theta)


.. py:function:: spread_dist_to_spec2d(Sf, D, theta)

   Converts the given 1-D wave spectrum and directional spreading function
   into a 2-D wave spectrum.

   :param Sf: One-sided variance spectrum of the waves, as a function of
              frequency.
   :type Sf: array_like of shape (...,Nf,...)
   :param D: Directional spreading function.
   :type D: array_like of shape (...,Nf,Ntheta,...)
   :param theta: Vector of wave headings (with arbitrary unit).
   :type theta: array_like of shape (Ntheta,)

   :returns: **S2D** -- Directional wave spectrum, as a function of frequency
             and wave direction (with arbitrary units).
   :rtype: array_like of shape (...,Nf,Ntheta,...)

   .. seealso::

      :py:obj:`spec2d_to_spread_dist`
          Converts the given 2-D wave spectrum into a directional spreading function and a 1-D wave spectrum.

   .. rubric:: Example

   >>> S2D = spread_dist_to_spec2d(Sf,D,theta)


