netsse.analys.enc_spec
======================

.. py:module:: netsse.analys.enc_spec

.. autoapi-nested-parse::

   Functions to compute spectra in a **body-fixed** reference system.

   .. 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.enc_spec.resp_spec_1d
   netsse.analys.enc_spec.resp_spec_2d


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

.. py:function:: resp_spec_1d(f0, ws, TRF1, TRF2, fe, U, beta)

   Computes a response cross-spectrum in both the absolute and encountered
   frequency domains, in a case of long-crested seas.

   :param f0: Vector of absolute frequencies [Hz].
   :type f0: array_like of shape (Nf0,1)
   :param ws: 1-D wave spectrum, as a function of (absolute) wave frequency ``f0`` [Hz].
   :type ws: array_like of shape (Nf0,1) in 1-D
   :param TRF1: Transfer functions of two response components, as a function of frequency
                ``f0`` [Hz].
   :type TRF1: array_like of shape (Nf0,1)
   :param TRF2: Transfer functions of two response components, as a function of frequency
                ``f0`` [Hz].
   :type TRF2: array_like of shape (Nf0,1)
   :param fe: Vector of encounter frequencies [Hz].
   :type fe: array_like of shape (Nfe,1)
   :param U: Ship speed [m/s].
   :type U: float
   :param beta: Ship heading, relative to the wave direction [deg].
   :type beta: float

   :returns: * **RspecAbs** (*array_like of shape (Nf0,1)*) -- Response spectrum, as a function of absolute wave frequency ``f0`` [Hz].
             * **RspecEnc** (*array_like of shape (Nfe,1)*) -- Response spectrum, as a function of encountered frequency ``fe`` [Hz].

   .. seealso::

      :py:obj:`resp_spec_2d`
          Computes a response cross-spectrum in the encounter-frequency domain, in case of short-crested sea.

   .. rubric:: Example

   >>> RspecAbs, RspecEnc = resp_spec_1d(f0,ws,TRF1,TRF2,fe,U,beta)


.. py:function:: resp_spec_2d(freq0, mu, ws0, beta_TRF, TRF1, TRF2, freqE, U, psi, conv='from', unit_freq='rad/s')

   Computes a response cross-spectrum in the encounter-frequency domain, in a case of
   short-crested seas.

   .. note::
       This is a Python implementation of the algorithm given in Nielsen et al. (2021).

   :param freq0: Vector of absolute frequencies, in which the wave spectrum and the
                 transfer functions are expressed.
   :type freq0: array_like of shape (Nf0,)
   :param mu: Vector of wave directions [deg], relative to North (in a NED-reference frame).
   :type mu: array_like of shape (Nmu,)
   :param ws0: 2-D wave spectrum, as a function of (absolute) wave frequency ``freq0`` and wave
               direction ``mu`` [rad].
   :type ws0: array_like of shape (Nf0,Nmu) in 2-D
   :param beta_TRF: Vector of relative wave headings [deg], in which the transfer functions
                    are expressed.
   :type beta_TRF: array_like of shape (Nbeta,)
   :param TRF1: Transfer function of the first and second response component, respectively, as a
                function of frequency ``freq0`` and relative wave heading.
   :type TRF1: array_like of shape (Nf0,Nbeta)
   :param TRF2: Transfer function of the first and second response component, respectively, as a
                function of frequency ``freq0`` and relative wave heading.
   :type TRF2: array_like of shape (Nf0,Nbeta)
   :param freqE: Vector of encounter frequencies for the output response spectrum.
   :type freqE: array_like of shape (Nfe,)
   :param U: Ship speed [m/s]
   :type U: float
   :param psi: Ship heading [deg], relative to North (in a NED-reference frame).
   :type psi: float
   :param conv: The convention that is used to express the direction ``mu`` of wave spectrum:

                - 'from' :
                    The naval architecture convention, indicating where the waves are COMING FROM.
                - 'to' :
                    The oceanographic convention, indicating where the waves are GOING TO.
                    The default is "from" direction.
   :type conv: {'from','to'}, optional
   :param unit_freq: Unit of the frequencies:

                     - 'rad/s' :
                         The variables ``freq0`` and ``freqE`` denote the angular frequencies in radians
                         per second.
                     - 'Hz' :
                         The 2-D wave spectrum ``ws0`` is expressed as a function of frequency in Hertz.
                         The default is 'rad/s'.
   :type unit_freq: {'rad/s','Hz'}, optional

   :returns: **RspecEnc** -- Response spectrum, as a function of encounter frequency ``freqE``.
   :rtype: array_like of shape (Nfe,)

   .. seealso::

      :py:obj:`resp_spec_1d`
          Computes a response cross-spectrum in both the absolute and encountered frequency domains, in a case of long-crested seas.

   .. rubric:: References

   Nielsen, U. D., Mounet, R. E. G., & Brodtkorb, A. H. (2021). Tuning of
   transfer functions for analysis of wave-ship interactions. Marine
   Structures, 79, 103029. https://doi.org/10.1016/j.marstruc.2021.103029

   .. rubric:: Example

   >>> RspecEnc =
   ...     resp_spec_2d(freq0,mu,ws0,beta_TRF,TRF1,TRF2,freqE,U,psi,'from','rad/s')


