Commit e8416966 authored by Dorchies David's avatar Dorchies David
Browse files

feat(calage perf): add map of QJXA10

Refs #5
parent 80b3f64a
Pipeline #31768 passed with stages
in 29 minutes and 45 seconds
......@@ -40,6 +40,7 @@ export(loadCalibrationParams)
export(loadConfig)
export(loadHydratecDB)
export(loadHypsoData)
export(max_na_rm)
export(mean_na_rm)
export(min_na_rm)
export(not_na_count)
......
......@@ -3,6 +3,7 @@
#' Calculation of Maximum daily flow per year.
#'
#' @param x [POSIXt] dates, or [data.frame] with a first column with dates, or \code{OutputsModel} produced by [airGR::RunModel]
#' @param threshold [numeric] minimum ratio of available data in a year to take it into account
#' @param flows [numeric] flows in l/s for use with x as a [POSIXt]
#' @param ... for S3 method compability
#'
......@@ -61,13 +62,20 @@ calcQJXA <- function(x, ...) {
#' @export
#' @rdname calcQJXA
calcQJXA.data.frame <- function(x, ...) {
if(ncol(x)<2) stop("x should have at least 2 columns")
apply(x[,-1, drop=F], 2, function(y) {
calcQJXA(x[,1], y)
})
}
calcQJXA.data.frame <- function(x, threshold = 0.8, ...) {
# Calculate monthly mean flow
QD <- suppressWarnings(
SeriesAggreg(x, Format = "%Y%m%d", rep("mean_na_rm", ncol(x)-1))
)
# 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[nDaysNotNA < threshold * 365] <- NA
return(QJXA)
}
#' @rdname calcQJXA
#' @export
......@@ -242,8 +250,8 @@ calcQJXAn.QJXA <- function(x, return_period) {
#' @rdname calcQJXAn
#' @export
calcQJXAn.data.frame <- function(x, return_period) {
QMNA <- calcQJXA(x)
apply(QMNA, 2, calcQJXAn.QJXA, return_period = return_period)
QJXA <- calcQJXA(x)
apply(QJXA, 2, calcQJXAn.QJXA, return_period = return_period)
}
......@@ -269,3 +277,16 @@ calcQJXAn.GumbelParams <- function(x, return_period) {
}
#' Maximum with NA stripped before computation
#'
#' @param x An R object.
#'
#' @return See [max]
#' @export
#'
#' @examples
#' max_na_rm(c(1, 2, 3, NA, 4))
#'
max_na_rm <- function(x) {
suppressWarnings(max(x, na.rm = TRUE))
}
......@@ -3,6 +3,7 @@
#' Calculation of QMNAs (annual minimum of mean monthly flows)
#'
#' @param x either [POSIXt] dates, or a [data.frame] with a first column of [POSIXt] dates and flows in the other columns, or a \code{airGR::OutputsModel} which is an output of [airGR::RunModel()]
#' @param threshold [numeric] minimum ratio of available data in a year or a month to take it into account
#' @param flows [numeric] flows in l/s
#'
#' @return [numeric] a numeric value of QMNA
......
......@@ -171,7 +171,7 @@ calcVCN30Y2 <- function(x) {
getMapRatio(Qsim, Qobs, calcVCN30Y2, "R-VCN30-2")
```
## QMNA5&nbsp;: Débit moyen mensuel minimum de période de retour 5 ans
## QMNA5&nbsp;: Débit moyen mensuel minimum annuel de période de retour 5 ans
```{r, fig.cap="Carte des R-QMNA5 des Bassins versants intermédiaires"}
calcQMNA5 <- function(x) {
......@@ -179,3 +179,12 @@ calcQMNA5 <- function(x) {
}
getMapRatio(Qsim, Qobs, calcQMNA5, "R-QMNA5")
```
## QJXA10&nbsp;: Débit moyen journalier maximum annuel de période de retour 10 ans
```{r, fig.cap="Carte des R-QMNA5 des Bassins versants intermédiaires"}
calcQJXA10 <- function(x) {
calcQJXAn(x, 10)
}
getMapRatio(Qsim, Qobs, calcQJXA10, "R-QJXA10")
```
......@@ -9,7 +9,7 @@
\usage{
calcQJXA(x, ...)
\method{calcQJXA}{data.frame}(x, ...)
\method{calcQJXA}{data.frame}(x, threshold = 0.8, ...)
\method{calcQJXA}{OutputsModel}(x, ...)
......@@ -20,6 +20,8 @@ calcQJXA(x, ...)
\item{...}{for S3 method compability}
\item{threshold}{\link{numeric} minimum ratio of available data in a year to take it into account}
\item{flows}{\link{numeric} flows in l/s for use with x as a \link{POSIXt}}
}
\value{
......
......@@ -18,6 +18,8 @@ calcQMNA(x, ...)
\arguments{
\item{x}{either \link{POSIXt} dates, or a \link{data.frame} with a first column of \link{POSIXt} dates and flows in the other columns, or a \code{airGR::OutputsModel} which is an output of \code{\link[airGR:RunModel]{airGR::RunModel()}}}
\item{threshold}{\link{numeric} minimum ratio of available data in a year or a month to take it into account}
\item{flows}{\link{numeric} flows in l/s}
}
\value{
......
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/calcQJXA.R
\name{max_na_rm}
\alias{max_na_rm}
\title{Maximum with NA stripped before computation}
\usage{
max_na_rm(x)
}
\arguments{
\item{x}{An R object.}
}
\value{
See \link{max}
}
\description{
Maximum with NA stripped before computation
}
\examples{
max_na_rm(c(1, 2, 3, NA, 4))
}
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