From b548e8e642a29ddf1289275f39f0a7b119e3c7e3 Mon Sep 17 00:00:00 2001 From: Ryan Coe Date: Fri, 31 Mar 2017 17:24:11 -0600 Subject: [PATCH] remove depth from basic EA definition moved to steepness function --- WDRT/ESSC.py | 41 +++++++++++++++------------------ examples/example_envSampling.py | 15 ++++++------ 2 files changed, 25 insertions(+), 31 deletions(-) diff --git a/WDRT/ESSC.py b/WDRT/ESSC.py index c86005c..879341b 100644 --- a/WDRT/ESSC.py +++ b/WDRT/ESSC.py @@ -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 @@ -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 @@ -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) @@ -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) @@ -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 @@ -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 ___________ @@ -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 @@ -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 ___________ @@ -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 @@ -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 ___________ @@ -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 @@ -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 ___________ @@ -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 diff --git a/examples/example_envSampling.py b/examples/example_envSampling.py index 04ec237..2ea40e7 100644 --- a/examples/example_envSampling.py +++ b/examples/example_envSampling.py @@ -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 @@ -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)