Skip to content

Instantly share code, notes, and snippets.

@seumasmorrison
Last active December 23, 2015 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seumasmorrison/6595733 to your computer and use it in GitHub Desktop.
Save seumasmorrison/6595733 to your computer and use it in GitHub Desktop.
Calculate significant wave height from a Datawell spt file with even bin spacings of 0.005hz using the zeroth spectral moment (m0) with trapezoid rule.
import pandas as pd
file_name = 'Bragar_HebMarine2$}2012-01-18T22h46Z.spt'
def calc_sig_wave_height(file_name):
max_psd = pd.read_csv(file_name, skiprows=range(12,200)).values[3][0]
spt_freq = pd.read_csv(file_name, skiprows=13, names=['frequency','psd','direction','spread','skew','kurtosis'])
psd = spt_freq.psd * max_psd
calc_sig_wave_height = 4 * np.sqrt(0.5 * 0.005 * ( psd[0] + psd[len(psd)-1] + 2 * psd[1:-1].sum()))
#sig_wave_height = pd.read_csv(file_name, skiprows=range(12,200)).values[1][0]
return calc_sig_wave_height
calc_sig_wave_height(file_name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment