-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalc_qsh.r
33 lines (28 loc) · 969 Bytes
/
calc_qsh.r
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Function to calculate the shape parameter to fit
# a GPD distribution to given data. This parameter
# is calculated using function "fpot" of package 'evd'
# Input:
# u = threshold
# ws = clean vector of wind data
# yrs = No. of years in dataset
# quant = requested quantile (RP in years)
# Returns:
# zh = return value for the given quantile (input variable quant)
# shape = shape parameter for the fitted GPD
calc_qsh = function(u,ws,yrs,RP){
nopy <- length(ws)/yrs
#options(warn = -2) #Supress all warning messages
#print(paste("Trying to estimate GPD parameters with threshold=",toString(thres)," and RP=",toString(RP)))
qnt <- try(fpot(ws,u,mper=RP,npp=365.25,std.err=FALSE),silent=TRUE)
#print(qnt[[1]])
if(!is.numeric(qnt[[1]])){
#print(qnt[[1]])
#print(qnt[[1]]) #Trap errors
zh <- NA
shape <- NA
}else{
zh <- qnt$estimate[1]
shape <- qnt$estimate[2]
}
cbind(zh,shape)
}