Skip to main content

Ocean wave 2D spectrum partitioning and fitting JONSWAP spectrum

Project description

Ocean Wave Spectra 2D Splitting/Fitting

Introduction

The main purpose of this package is to find parameters of JONSWAP wave spectra with spreading that, when recombined, best match the input 2D frequency direction wave spectra. Given a 2D wave spectrum S(f,theta), the package finds parameters of multiple JONSWAP partitions including wave spreading (i.e. Hs, Tp, Gamma, Tail exponent, ThetaP).

The aim of the package is to provide an industry wide approach to derive usable wave spectral parameters that provide the best possible reconstruction of the input wave spectrum. The method is designed to be tunable, but robust in the default configuration. A large number of observed and numerically modelled datasets have been tested during the creation and validation of the method.

It is the intention that the package will be used by consultants and weather forecastors to improve the descriptions of the ocean wave partitions for use in operations and engineering applications. It provides the metocean engineer with a robust way to separate swells and wind seas.

Usage

Import the waveSpec class

import numpy as np
from wavespectra2dsplitfit.S2DFit import readWaveSpectrum_mat
filename = 'data/ExampleWaveSpectraObservations.mat'
f, th, S, sDate = readWaveSpectrum_mat(filename)
S = S * np.pi/180 # convert from m^2/(Hz.rad) to m^2/(Hz.deg)
   
# Setup fitting configuration - simple example with no wind (also usually best setup with no wind)    
tConfig = {
    'maxPartitions': 3,
    'useClustering': True,
    'useWind': False,
    'useFittedWindSea': False, 
    'useWindSeaInClustering': False,
}

# Just do the first spectrum
from wavespectra2dsplitfit.S2DFit import fit2DSpectrum
specParms, fitStatus, diagOut = fit2DSpectrum(f[0], th[0], S[0,:,:], **tConfig)
print(specParms, fitStatus)

for tSpec in specParms:
    print("===== PARTITION =====")
    print("Hs = ",tSpec[0])
    print("Tp = ",tSpec[1])
    print("Gamma = ",tSpec[2])
    print("Sigma A = ",tSpec[3])
    print("Sigma B = ",tSpec[4])
    print("Tail Exp = ",tSpec[5])
    print("ThetaP = ",tSpec[6])
print("===== FITTING OUTCOME =====")
print(f"Fitting successful: ",fitStatus[0])
print(f"RMS error of fit: ",fitStatus[1])
print(f"Number of function evalutions: ",fitStatus[2])

from wavespectra2dsplitfit.S2DFit import plot2DFittingDiagnostics
f, th, S, f_sm, th_sm, S_sm, wsMask, Tp_pk, ThetaP_pk, Tp_sel, ThetaP_sel, whichClus = diagOut
plot2DFittingDiagnostics(
    specParms, 
    f, th, S, 
    f_sm, th_sm, S_sm, 
    wsMask,
    Tp_pk, ThetaP_pk, Tp_sel, ThetaP_sel, whichClus,
    tConfig['useWind'], tConfig['useClustering'],
    saveFigFilename = 'test',  
    tag = "S2DFit Simple Test"  
)

Example Result

Check out the test.py script as an example with data.

$ python test.py
Optimization terminated successfully.
         Current function value: 0.082135
         Iterations: 1082
         Function evaluations: 1733
[[0.5859285326910995, 4.716981132075468, 1.0000053476007895, 0.07, 0.09, -4.234276488479486, 300.0, 4.716981132075468], [0.6129423521749234, 7.812499999999995, 5.970526837658344, 0.07, 0.09, -5.140143260428807, 290.0, 7.812499999999995], [0.4047506936099149, 10.869565217391298, 1.0000041524068202, 0.07, 0.09, -15.401874257914326, 240.0, 10.869565217391298]] [True, 0.08213522716322981, 1733]
===== PARTITION =====
Hs =  0.5859285326910995
Tp =  4.716981132075468
Gamma =  1.0000053476007895
Sigma A =  0.07
Sigma B =  0.09
Tail Exp =  -4.234276488479486
ThetaP =  300.0
===== PARTITION =====
Hs =  0.6129423521749234
Tp =  7.812499999999995
Gamma =  5.970526837658344
Sigma A =  0.07
Sigma B =  0.09
Tail Exp =  -5.140143260428807
ThetaP =  290.0
===== PARTITION =====
Hs =  0.4047506936099149
Tp =  10.869565217391298
Gamma =  1.0000041524068202
Sigma A =  0.07
Sigma B =  0.09
Tail Exp =  -15.401874257914326
ThetaP =  240.0
===== FITTING OUTCOME =====
Fitting successful:  True
RMS error of fit:  0.08213522716322981
Number of function evalutions:  1733

An example of the input and output reconstructed spectrum are shown in the image below.

This is an example output image

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

wavespectra2dsplitfit-0.5.5.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

wavespectra2dsplitfit-0.5.5-py3-none-any.whl (18.9 kB view details)

Uploaded Python 3

File details

Details for the file wavespectra2dsplitfit-0.5.5.tar.gz.

File metadata

  • Download URL: wavespectra2dsplitfit-0.5.5.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.13

File hashes

Hashes for wavespectra2dsplitfit-0.5.5.tar.gz
Algorithm Hash digest
SHA256 df388c29764056aeeeeeb4ab97dd8e812ad6e7a6a935ce495f87198cffc6fae4
MD5 4319620e8a7c3f34eaea76f2ba8e2d91
BLAKE2b-256 03fe228757c1dfd619b0c1eacf8b3a40adce7c3027eec101b2f78829abdce02c

See more details on using hashes here.

File details

Details for the file wavespectra2dsplitfit-0.5.5-py3-none-any.whl.

File metadata

File hashes

Hashes for wavespectra2dsplitfit-0.5.5-py3-none-any.whl
Algorithm Hash digest
SHA256 9a05c3d323df9f5d0cb856893272efdbd2ba6320ddcc536e1699d4e2c634d5ed
MD5 87ab703b6f1dbb7cd60aa9fd9e45d973
BLAKE2b-256 00511adac2b4c2d7ed2a9776e18badde0a9e4335126409a5165991d16a2b0bbe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page