netsse.model.envir_cond
=======================

.. py:module:: netsse.model.envir_cond

.. autoapi-nested-parse::

   Relevant functions for **environmental conditions**.

   .. 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.model.envir_cond.JONSWAP_DNV
   netsse.model.envir_cond.fit_spec_tail
   netsse.model.envir_cond.lin_disprel
   netsse.model.envir_cond.wavespec1dto2d


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

.. py:function:: JONSWAP_DNV(Tp, Hs, omega, gamma='standard', h=0)

   Computes the JONSWAP spectrum corresponding to the input sea state
   parameters.

   The JONSWAP spectrum is formulated as a modification of
   a Pierson-Moskowitz spectrum for a developing sea state in a fetch
   limited situation.

   :param Tp: Peak period [s].
   :type Tp: float
   :param Hs: Significant wave height [m].
   :type Hs: float
   :param omega: Vector of angular frequencies [rad/s].
   :type omega: array_like of shape (Nfreq,)
   :param gamma: Peak shape parameter [-]. The value can be user-provided as a float.
                 Alternatively, if ``'standard'`` is input, then ``gamma`` will take the
                 standard value of 3.3., while a value ``'DNV'`` as input leads to
                 following the procedure 3.5.5.5 described in DNV-RP-C205.

                 .. tip::
                     Use ``gamma = 1`` to output a standard Pierson-Moskowitz spectrum.
   :type gamma: {'standard','DNV',float}, optional
   :param h: Water depth [m]. If ``h`` is specified as input argument, then the output
             JONSWAP spectrum is corrected to account for finite water depth, becoming
             a standard TMA spectrum as per Bouws et al. (1985).
   :type h: float, default 0

   :returns: **S_J** -- Standard wave spectrum [m^2.s/rad].
   :rtype: array_like of shape (Nfreq,)

   .. rubric:: References

   1. DNV-RP-C205, "Environmental Conditions and Environmental Loads,
      April 2007.
   2. Bouws, E., Gunther, H., Rosenthal, W., & Vincent, C. L. (1985).
      *Similarity of the wind wave spectrum in finite depth water. 1. Spectral form*.
      Journal of Geophysical Research-Oceans, 90(NC1), 975–986.
      https://doi.org/10.1029/JC090iC01p00975

   .. seealso::

      :py:obj:`lin_disprel`
          A fast and accurate approximation of the linear wave dispersion relationship in finite water depth.

   .. rubric:: Example

   >>> S_J = JONSWAP_DNV(Tp,Hs,omega,gamma='standard',h=0)


.. py:function:: fit_spec_tail(f, S, fc, exponent=5, fmax=None, n_tail=256, amplitude_mode='match_fc', transition_width=0.0)

   Extend a 1-D wave spectrum :math:`S(f)` with an :math:`f^{-n}` tail beyond :math:`f_c`.

   :param f: 1-D array of frequencies [Hz], strictly increasing.
   :type f: array_like
   :param S: 1-D array of spectral densities [m^2/Hz], same length as ``f``.
   :type S: array_like
   :param fc: Cutoff frequency :math:`f_c` [Hz]; must be within the range of ``f``.
   :type fc: float
   :param exponent: Exponent :math:`n` of the power-law tail to fit beyond :math:`f_c`. Default is ``5`` for a typical high-frequency wave spectrum tail.
   :type exponent: float
   :param fmax: Maximum frequency for the extended tail. If ``None`` (default), set to ``2fc``.
   :type fmax: float or None
   :param n_tail: Number of points to generate in :math:`(f_c, f_{\max}]`. Default is ``256``.
   :type n_tail: int
   :param amplitude_mode: How to estimate the tail amplitude :math:`C` in :math:`S(f) \sim C f^{-n}` beyond :math:`f_c`.

                          Options are:

                          - `match_fc` (default): :math:`C = S(f_c) \cdot f_c^n` using interpolation at :math:`f_c`.

                          - `least_squares`: fit :math:`C` by minimizing :math:`\sum (S - C f^{-n})^2` over a band near :math:`f_c`.

                          - `median`: :math:`C = \mathrm{median}(S \cdot f^n)` over a band near :math:`f_c` (robust to outliers).
   :type amplitude_mode: {"match_fc", "least_squares", "median"}
   :param transition_width: Width of cosine blend band [Hz] below :math:`f_c` to smoothly transition
                            from original spectrum to the tail. If set to ``0`` (default), hard splice at :math:`f_c`.
   :type transition_width: float

   :returns: * **f_ext** (*ndarray*) -- Extended frequency vector including original ``f`` and new tail points.
             * **S_ext** (*ndarray*) -- Spectrum values aligned with ``f_ext``.
             * **C** (*float*) -- Tail amplitude used in :math:`S_{tail} = C \cdot f^{-n}`.

   .. rubric:: Example

   >>> f = np.linspace(0.05, 1.0, 100)
   >>> S = 0.1 * f**-3 * np.exp(- (f / 0.3)**2)  # Example spectrum
   >>> fc = 0.5
   >>> f_ext, S_ext, C = fit_spec_tail(f, S, fc, exponent=5, amplitude_mode="least_squares", transition_width=0.1)


.. py:function:: lin_disprel(input, h=None, direction='om2k')

   Computes the wavenumbers from wave angular frequencies, or vice-versa, using the linear dispersion relationship.

   If the water depth is specified, then the finite water depth is accounted for. Otherwise, deep water is assumed.

   In the "om2k" direction in finite water depth, this function implements a fast and accurate approximation of the linear wave dispersion relationship. In the "k2om" direction, the function always uses the exact linear dispersion relationship.

   :param input: The input, which can either be the wave angular frequencies [rad/s] or the wavenumbers [1/m], depending on the ``direction``.
   :type input: array_like or float
   :param h: Mean water depth [m]
   :type h: array_like or float, optional
   :param direction: Direction of the dispersion relation to be solved. If ``'om2k'``, then the function
                     computes the wavenumbers from the angular frequencies. If ``'k2om'``, then the function
                     computes the angular frequencies from the wavenumbers.
   :type direction: {'om2k','k2om'}, optional

   :returns: **output** -- The corresponding wavenumbers [1/m] or wave angular frequencies [rad/s] to input, depending on the ``direction``.
   :rtype: array_like or float

   .. rubric:: Example

   >>> k = lin_disprel(omega, h)


.. py:function:: wavespec1dto2d(S1d, theta, theta0, s)

   Transforms a 1-D wave spectrum into a 2-D wave spectrum.

   A cosine-2s function is used for the directional spreading distribution.

   :param S1d: 1-D wave spectrum.
   :type S1d: array_like of shape (Nfreq,)
   :param theta: Vector of wave headings [deg] at which the 2-D spectrum must be computed.
   :type theta: array_like of shape (Ntheta,)
   :param theta0: Mean wave direction [deg].
   :type theta0: float
   :param s: Spreading parameter [-], related to the exponent of the cosine function.
   :type s: float

   :returns: * **S2d** (*array_like of shape (Nfreq,Ntheta)*) -- 2-D wave spectrum, as a function of both the frequency and the wave
               heading [deg].
             * **D_theta** (*array_like of shape (1,Ntheta)*) -- Directional spreading function, as a function of the wave heading [deg].

   .. rubric:: References

   Naess, Arvid, and Torgeir Moan. 2010. Stochastic Dynamics of
   Marine Structures. Stochastic Dynamics of Marine Structures. Vol.
   9780521881555. Cambridge University Press.
   https://doi.org/10.1017/CBO9781139021364.

   .. rubric:: Example

   >>> S2d = wavespec1dto2d(S1d,theta,theta0,s)


