Skip to content

Commit 73f40ff

Browse files
Merge pull request #91 from MET-OM/dev_cca
Dev cca
2 parents a0bec14 + e17374b commit 73f40ff

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

metocean_stats/plots/extreme.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,7 +1043,7 @@ def plot_storm_surge_for_given_hs(data: pd.DataFrame, var_surge: str, var_hs: st
10431043
return fig
10441044

10451045

1046-
def plot_cca_profiles(data,var='current_speed_',month=None,percentile=None,return_period=None,distribution='GUM',method='default',threshold='default',unit_var='m/s',unit_lev='m',output_file='plot_cca_profiles.png'):
1046+
def plot_cca_profiles(data,var='current_speed_',month=None,percentile=None,return_period=None,distribution='GUM',method='default',threshold='default',max='worst_case',unit_var='m/s',unit_lev='m',output_file='plot_cca_profiles.png'):
10471047
"""
10481048
This function plots the CCA profiles for a specific percentile or return period
10491049
data: dataframe
@@ -1052,18 +1052,20 @@ def plot_cca_profiles(data,var='current_speed_',month=None,percentile=None,retur
10521052
percentile: is the percentile associated with the worst case scenario
10531053
return_period: a return-period e.g., 10 for a 10-yr return period
10541054
distrbution, method, and threshold: only used if retrun_period is specified
1055+
max: by default, the highest curve will always be the worst-case scenario
10551056
unit_var: is a string with the unit of the variable var, default is m/s
10561057
unit_lev: is a string with the units of the vertical levels, default is m
10571058
output_file: name of the figure file
10581059
with the dimensions (vertical levels of the profile, vertical level of the worst case scenario)
1060+
Function written by clio-met
10591061
"""
10601062
if ((percentile is None) and (return_period is None)):
10611063
print('Please specify either a percentile or a return period in years')
10621064
sys.exit()
10631065
if not(percentile is None):
10641066
lev,woca,cca=cca_profiles(data,var=var,month=month,percentile=percentile)
10651067
if not(return_period is None):
1066-
lev,woca,cca=cca_profiles(data,var=var,month=month,return_period=return_period,distribution=distribution,method=method,threshold=threshold)
1068+
lev,woca,cca=cca_profiles(data,var=var,month=month,return_period=return_period,distribution=distribution,method=method,threshold=threshold,max=max)
10671069
import matplotlib as mpl
10681070
n_lines = len(lev)
10691071
cmap = mpl.colormaps['jet_r']

metocean_stats/stats/extreme.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,7 @@ def get_joint_2D_contour(data=pd.DataFrame,var1='hs', var2='tp', periods=[50,100
13261326
})
13271327
return contours, data_2D
13281328

1329-
def cca_profiles(data,var='current_speed_',month=None,percentile=None,return_period=None,distribution='GUM',method='default',threshold='default'):
1329+
def cca_profiles(data,var='current_speed_',month=None,percentile=None,return_period=None,distribution='GUM',method='default',threshold='default',max='worst_case'):
13301330
import sys
13311331
"""
13321332
This function calculates the CCA profiles for a specific percentile or return period
@@ -1335,7 +1335,8 @@ def cca_profiles(data,var='current_speed_',month=None,percentile=None,return_per
13351335
month: gives the month of interest (e.g. January or Jan), default (None) takes all months
13361336
percentile: is the percentile associated with the worst case scenario
13371337
return_period: a return-period e.g., 10 for a 10-yr return period
1338-
distrbution, method, and threshold: only used if retrun_period is specified
1338+
distrbution, method, and threshold: only used if return_period is specified
1339+
max: by default, if some points of the profile exceed the worst-case curve, they will be brought back down to the worst case value (if not wanted, write 'None')
13391340
output: list of vertical levels used, 1-d array for the worst case scenario (the percentiles or return values), the array with the profiles
13401341
with the dimensions (vertical levels of the profile, vertical level of the worst case scenario)
13411342
Function written by clio-met based on 'Turkstra models of current profiles by Winterstein, Haver and Nygaard (2009)'
@@ -1389,15 +1390,18 @@ def cca_profiles(data,var='current_speed_',month=None,percentile=None,return_per
13891390
nlevels=np.where(np.isnan(wcs))[0][0]
13901391
# Calculate the current at the other depths when curr_ref = percentile or return-period value
13911392
cca_prof=np.zeros((nlevels,nlevels))
1392-
for d in range(nlevels):
1393+
for d in range(nlevels): # Loop over the worst case level
13931394
prof_others=df_sel.drop(columns=[list_col[d]]).to_numpy() # extraxt currents as a matrix for all levels except the worst-case one
13941395
prof_wcd=df_sel[list_col[d]].to_numpy() # extract currents at the worst-case level
13951396
list_ind=np.arange(0,nlevels,1).tolist()
13961397
del list_ind[d] # remove the index of the worst-case level (index d)
13971398
cca_prof[d,d]=wcs[d]
13981399
i=0
1399-
for dd in list_ind:
1400+
for dd in list_ind: # Loop over the other levels
14001401
cca_prof[dd,d]=np.mean(prof_others[:,i],axis=0)+np.corrcoef(prof_wcd,prof_others[:,i])[0][1]*np.std(prof_others[:,i],axis=0)*((wcs[d]-np.mean(prof_wcd))/np.std(prof_wcd))
1402+
if max=='worst_case':
1403+
if cca_prof[dd,d]>wcs[dd]:
1404+
cca_prof[dd,d]=wcs[dd]
14011405
i=i+1
14021406
return levels[0:nlevels],wcs[0:nlevels],cca_prof
14031407

metocean_stats/tables/extreme.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ def table_storm_surge_for_rv_hs(data: pd.DataFrame, var_hs='HS',var_tp='TP',var_
733733
return df
734734

735735

736-
def table_cca_profiles(data,var='current_speed_',month=None,percentile=None,return_period=None,distribution='GUM',method='default',threshold='default',output_file='table_cca_profiles.csv'):
736+
def table_cca_profiles(data,var='current_speed_',month=None,percentile=None,return_period=None,distribution='GUM',method='default',threshold='default',max='worst_case',output_file='table_cca_profiles.csv'):
737737
"""
738738
This function returns a table containing the CCA profiles for a specific percentile or return period
739739
data: dataframe
@@ -742,16 +742,18 @@ def table_cca_profiles(data,var='current_speed_',month=None,percentile=None,retu
742742
percentile: is the percentile associated with the worst case scenario
743743
return_period: a return-period e.g., 10 for a 10-yr return period
744744
distrbution, method, and threshold: only used if retrun_period is specified
745+
max: by default, the highest curve will always be the worst-case scenario
745746
output_file: name of the csv file
746747
with the dimensions (vertical levels of the profile, vertical level of the worst case scenario)
748+
Function written by clio-met
747749
"""
748750
if ((percentile is None) and (return_period is None)):
749751
print('Please specify either a percentile or a return period in years')
750752
sys.exit()
751753
if not(percentile is None):
752754
lev,woca,cca=cca_profiles(data,var=var,month=month,percentile=percentile)
753755
if not(return_period is None):
754-
lev,woca,cca=cca_profiles(data,var=var,month=month,return_period=return_period,distribution=distribution,method=method,threshold=threshold)
756+
lev,woca,cca=cca_profiles(data,var=var,month=month,return_period=return_period,distribution=distribution,method=method,threshold=threshold,max=max)
755757
list_ind=[]
756758
columns=['Depth [m]']+[d for d in lev]+['Worst case']
757759
table = np.zeros((len(lev),len(lev)+2))

0 commit comments

Comments
 (0)