Commit 33bcb7a7 authored by Dorchies David's avatar Dorchies David
Browse files

fix(calcQLXA, calcQMNA): crash with one column of data

parent 335f313f
......@@ -71,8 +71,8 @@ calcQJXA.data.frame <- function(x, threshold = 0.8, ...) {
# Calculate maximum of daily mean flow
QJXA <- SeriesAggreg(QD, Format = "%Y", rep("max_na_rm", ncol(x)-1))
nDaysNotNA <- SeriesAggreg(QD, Format = "%Y", rep("not_na_count", ncol(x)-1))
QJXA <- QJXA[, -1]
nDaysNotNA <- nDaysNotNA[, -1]
QJXA <- QJXA[, -1, drop = FALSE]
nDaysNotNA <- nDaysNotNA[, -1, drop = FALSE]
QJXA[nDaysNotNA < threshold * 365] <- NA
return(QJXA)
}
......@@ -220,22 +220,18 @@ getGumbelParams <- function(x) {
#' #! load data
#' data(L0123001, package = "airGR")
#'
#' #! define vector of flows, time step is the day
#' flows <- BasinObs$Qls / 1000
#'
#' #! define vector of dates
#' dates <- BasinObs$DatesR
#'
#' #! define return period
#' return_period <- 10
#'
#' # Calculation in detail#'
#' QJXA <- calcQJXA(x = dates, flows = flows)
#' # Calculation in detail
#' QJXA <- calcQJXA(x = BasinObs$DatesR, flows = BasinObs$Qls / 1000)
#' gumbel <- getGumbelParams(QJXA)
#' calcQJXAn(gumbel, return_period)
#'
#' # Or directly
#' calcQJXAn(QJXA, return_period)
#' dfQ <- data.frame(DatesR = BasinObs$DatesR, Q = BasinObs$Qls / 1000)
#' calcQJXAn(dfQ, return_period)
#'
calcQJXAn <- function(x, return_period) {
UseMethod("calcQJXAn", x)
}
......
......@@ -61,17 +61,17 @@ calcQMNA.data.frame <- function(x, threshold = 0.8, ...) {
# Calculate monthly mean flow
QM <- SeriesAggreg(x, Format = "%Y%m", rep("mean_na_rm", ncol(x)-1))
nDaysNotNA <- SeriesAggreg(x, Format = "%Y%m", rep("not_na_count", ncol(x)-1))
nDaysNotNA <- nDaysNotNA[, -1]
nDaysNotNA <- nDaysNotNA[, -1, drop = FALSE]
DatesR <- QM[, 1]
QM <- QM[, -1]
QM <- QM[, -1, drop = FALSE]
QM[nDaysNotNA < threshold * 31] <- NA
QM <- cbind(DatesR, QM)
# Calculate minimum of monthly mean flow
QMNA <- SeriesAggreg(QM, Format = "%Y", rep("min_na_rm", ncol(x)-1))
nDaysNotNA <- SeriesAggreg(QM, Format = "%Y", rep("not_na_count", ncol(x)-1))
QMNA <- QMNA[, -1]
nDaysNotNA <- nDaysNotNA[, -1]
QMNA <- QMNA[, -1, drop = FALSE]
nDaysNotNA <- nDaysNotNA[, -1, drop = FALSE]
QMNA[nDaysNotNA < threshold * 12] <- NA
return(QMNA)
}
......
......@@ -30,20 +30,16 @@ Compute the flow for a given Gumbel law
#! load data
data(L0123001, package = "airGR")
#! define vector of flows, time step is the day
flows <- BasinObs$Qls / 1000
#! define vector of dates
dates <- BasinObs$DatesR
#! define return period
return_period <- 10
# Calculation in detail#'
QJXA <- calcQJXA(x = dates, flows = flows)
# Calculation in detail
QJXA <- calcQJXA(x = BasinObs$DatesR, flows = BasinObs$Qls / 1000)
gumbel <- getGumbelParams(QJXA)
calcQJXAn(gumbel, return_period)
# Or directly
calcQJXAn(QJXA, return_period)
dfQ <- data.frame(DatesR = BasinObs$DatesR, Q = BasinObs$Qls / 1000)
calcQJXAn(dfQ, return_period)
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment