Skip to content

Commit

Permalink
Merge pull request #22 from indecis-eu/master
Browse files Browse the repository at this point in the history
1. Solve a problem with pze (probability of zero precipitation) when using user-provided parameters.
2. Allow time series with frequencies other than 12 (monthly).
  • Loading branch information
sbegueria authored Apr 25, 2022
2 parents f59bcb6 + 4b9ecd4 commit ad90915
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions R/spei.R
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,8 @@ spei <- function(data, scale, kernel=list(type='rectangular',shift=0),
dim_one = ifelse(distribution == "Gamma", 2, 3)

if (!is.null(params)) {
if (dim(params)[1]!=dim_one | dim(params)[2]!=m | dim(params)[3]!=12) {
stop(paste('parameters array should have dimensions (', dim_one, ', ', m, ', 12)',sep=' '))
if (dim(params)[1]!=dim_one | dim(params)[2]!=m | dim(params)[3]!=fr) {
stop(paste('parameters array should have dimensions (', dim_one, ', ', m, ', fr)',sep=' '))
}
}

Expand Down Expand Up @@ -344,18 +344,18 @@ spei <- function(data, scale, kernel=list(type='rectangular',shift=0),
next()
}

if(distribution != "log-Logistic"){
pze <- sum(month==0)/length(month)
month = month[month > 0]
}

if (is.null(params)) {
month_sd = sd(month,na.rm=TRUE)
if (is.na(month_sd) || (month_sd == 0)) {
std[f] <- NA
next
}

if(distribution != "log-Logistic"){
pze <- sum(month==0)/length(month)
month = month[month > 0]
}

# Stop early and assign NAs if month's data is length < 4
if(length(month) < 4){
std[ff,s] = NA
Expand Down

0 comments on commit ad90915

Please sign in to comment.