Skip to content
This repository has been archived by the owner on May 4, 2023. It is now read-only.

Commit

Permalink
remove depth from basic EA definition
Browse files Browse the repository at this point in the history
moved to steepness function
  • Loading branch information
ryancoe committed Mar 31, 2017
1 parent feff6f2 commit b548e8e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 31 deletions.
41 changes: 18 additions & 23 deletions WDRT/ESSC.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def getContourPoints(self, T_Sample):
self.Hs_SampleCA = Hs_SampleCA
return Hs_SampleCA

def steepness(self, SteepMax, T_vals):
def steepness(self, depth, SteepMax, T_vals):
'''This function calculates a steepness curve to be plotted on an H vs. T
diagram. First, the function calculates the wavelength based on the
depth and T. The T vector can be the input data vector, or will be
Expand All @@ -164,6 +164,8 @@ def steepness(self, SteepMax, T_vals):
Parameters
----------
depth: float
Depth at site
SteepMax: float
Wave breaking steepness estimate (e.g., 0.07).
T_vals :np.array
Expand Down Expand Up @@ -210,19 +212,19 @@ def steepness(self, SteepMax, T_vals):

for i in range(len(T_vals)):
# Initialize kh using Eckert 1952 (mentioned in Holthuijsen pg. 124)
kh = (omega[i]**2) * self.depth / \
(g * (np.tanh((omega[i]**2) * self.depth / g)**0.5))
kh = (omega[i]**2) * depth / \
(g * (np.tanh((omega[i]**2) * depth / g)**0.5))
# Find solution using the Newton-Raphson Method
for j in range(1000):
kh0 = kh
f0 = (omega[i]**2) * self.depth / g - kh0 * np.tanh(kh0)
f0 = (omega[i]**2) * depth / g - kh0 * np.tanh(kh0)
df0 = -np.tanh(kh) - kh * (1 - np.tanh(kh)**2)
kh = -f0 / df0 + kh0
f = (omega[i]**2) * self.depth / g - kh * np.tanh(kh)
f = (omega[i]**2) * depth / g - kh * np.tanh(kh)
if abs(f0 - f) < 10**(-6):
break

lambdaT.append((2 * np.pi) / (kh / self.depth))
lambdaT.append((2 * np.pi) / (kh / depth))
del kh, kh0

lambdaT = np.array(lambdaT, dtype=np.float)
Expand Down Expand Up @@ -262,15 +264,15 @@ def bootStrap(self, boot_size=1000, plotResults=True):
buoycopy.Hs = copy.deepcopy(self.buoy.Hs[boot_inds])
buoycopy.T = copy.deepcopy(self.buoy.T[boot_inds])
if self.method == "PCA":
essccopy = PCA(self.depth, buoycopy, self.size_bin)
essccopy = PCA(buoycopy, self.size_bin)
elif self.method == "GaussianCopula":
essccopy = GaussianCopula(self.depth, buoycopy, self.n_size, self.bin_1_limit, self.bin_step)
essccopy = GaussianCopula(buoycopy, self.n_size, self.bin_1_limit, self.bin_step)
elif self.method == "Rosenblatt":
essccopy = Rosenblatt(self.depth, buoycopy, self.n_size, self.bin_1_limit, self.bin_step)
essccopy = Rosenblatt(buoycopy, self.n_size, self.bin_1_limit, self.bin_step)
elif self.method == "ClaytonCopula":
essccopy = ClaytonCopula(self.depth, buoycopy, self.n_size, self.bin_1_limit, self.bin_step)
essccopy = ClaytonCopula(buoycopy, self.n_size, self.bin_1_limit, self.bin_step)
elif self.method == "GumbelCopula":
essccopy = GumbelCopula(self.depth, buoycopy, self.n_size, self.bin_1_limit, self.bin_step, self.Ndata)
essccopy = GumbelCopula(buoycopy, self.n_size, self.bin_1_limit, self.bin_step, self.Ndata)
Hs_Return_Boot[:,i],T_Return_Boot[:,i] = essccopy.getContours(self.time_ss, self.time_r, self.nb_steps)

contour97_5_Hs = np.percentile(Hs_Return_Boot,97.5,axis=1)
Expand Down Expand Up @@ -354,19 +356,16 @@ def __getCopulaParams(self,n_size,bin_1_limit,bin_step):

class PCA(EA):

def __init__(self, depth, buoy, size_bin=250.):
def __init__(self, buoy, size_bin=250.):
'''
Parameters
___________
depth : int
Depth at measurement point (m)
size_bin : float
chosen bin size
buoy : NDBCData
ESSC.Buoy Object
'''
self.method = "Principle component analysis"
self.depth = depth
self.buoy = buoy
self.size_bin = size_bin

Expand Down Expand Up @@ -915,7 +914,7 @@ def __sigma_fits(self, Comp1_mean, sigma_vals):

class GaussianCopula(EA):

def __init__(self, depth, buoy, n_size=40., bin_1_limit=1., bin_step=0.25):
def __init__(self, buoy, n_size=40., bin_1_limit=1., bin_step=0.25):
'''
Parameters
___________
Expand All @@ -931,7 +930,6 @@ def __init__(self, depth, buoy, n_size=40., bin_1_limit=1., bin_step=0.25):
overlap interval for each bin
'''
self.method = "Gaussian Copula"
self.depth = depth
self.buoy = buoy
self.n_size = n_size
self.bin_1_limit = bin_1_limit
Expand Down Expand Up @@ -1042,7 +1040,7 @@ def _saveParams(self, groupObj):


class Rosenblatt(EA):
def __init__(self, depth, buoy, n_size=40., bin_1_limit=1., bin_step=0.25):
def __init__(self, buoy, n_size=40., bin_1_limit=1., bin_step=0.25):
'''
Parameters
___________
Expand All @@ -1058,7 +1056,6 @@ def __init__(self, depth, buoy, n_size=40., bin_1_limit=1., bin_step=0.25):
overlap interval for each bin
'''
self.method = "Rosenblatt"
self.depth = depth
self.buoy = buoy
self.n_size = n_size
self.bin_1_limit = bin_1_limit
Expand Down Expand Up @@ -1169,7 +1166,7 @@ def _saveParams(self, groupObj):


class ClaytonCopula(EA):
def __init__(self, depth, buoy, n_size=40., bin_1_limit=1., bin_step=0.25):
def __init__(self, buoy, n_size=40., bin_1_limit=1., bin_step=0.25):
'''
Parameters
___________
Expand All @@ -1185,7 +1182,6 @@ def __init__(self, depth, buoy, n_size=40., bin_1_limit=1., bin_step=0.25):
overlap interval for each bin
'''
self.method = "Clayton Copula"
self.depth = depth
self.buoy = buoy
self.n_size = n_size
self.bin_1_limit = bin_1_limit
Expand Down Expand Up @@ -1297,7 +1293,7 @@ def _saveParams(self, groupObj):


class GumbelCopula(EA):
def __init__(self, depth, buoy, n_size=40., bin_1_limit=1., bin_step=0.25,Ndata = 1000):
def __init__(self, buoy, n_size=40., bin_1_limit=1., bin_step=0.25,Ndata = 1000):
'''
Parameters
___________
Expand All @@ -1313,7 +1309,6 @@ def __init__(self, depth, buoy, n_size=40., bin_1_limit=1., bin_step=0.25,Ndata
overlap interval for each bin
'''
self.method = "Gumbel Copula"
self.depth = depth
self.buoy = buoy
self.n_size = n_size
self.bin_1_limit = bin_1_limit
Expand Down
15 changes: 7 additions & 8 deletions examples/example_envSampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@

# Declare required parameters
depth = 391.4 # Depth at measurement point (m)
size_bin = 250. # Enter chosen bin size

# # Create EA object using above parameters
pca46022 = ESSC.PCA(depth, buoy46022, size_bin)
Gauss46022 = ESSC.GaussianCopula(depth, buoy46022)
Gumbel46022 = ESSC.GumbelCopula(depth, buoy46022)
cc46022 = ESSC.ClaytonCopula(depth, buoy46022)
rosen46022 = ESSC.Rosenblatt(depth, buoy46022)
pca46022 = ESSC.PCA(buoy46022)
Gauss46022 = ESSC.GaussianCopula(buoy46022)
Gumbel46022 = ESSC.GumbelCopula(buoy46022)
cc46022 = ESSC.ClaytonCopula(buoy46022)
rosen46022 = ESSC.Rosenblatt(buoy46022)

Time_SS = 1. # Sea state duration (hrs)
Time_R = 100 # Return periods (yrs) of interest
Expand Down Expand Up @@ -67,8 +66,8 @@
SteepMax = 0.07 # Optional: enter estimate of breaking steepness
T_vals = np.arange(0.1, np.amax(buoy46022.T), 0.1)

SteepH = pca46022.steepness(SteepMax, T_vals)
SteepH_Return = pca46022.steepness(SteepMax, pca46022.T_ReturnContours)
SteepH = pca46022.steepness(depth, SteepMax, T_vals)
SteepH_Return = pca46022.steepness(depth, SteepMax, pca46022.T_ReturnContours)

Steep_correction = np.where(SteepH_Return < pca46022.Hs_ReturnContours)
Hs_Return_Steep = copy.deepcopy(pca46022.Hs_ReturnContours)
Expand Down

0 comments on commit b548e8e

Please sign in to comment.