Commit 81b83735 authored by Dorchies David's avatar Dorchies David
Browse files

feat(calage perf): add map of R-QMNA5

Refs #5
parent 2ea1ffd6
Pipeline #31766 passed with stages
in 30 minutes and 5 seconds
......@@ -41,6 +41,7 @@ export(loadConfig)
export(loadHydratecDB)
export(loadHypsoData)
export(mean_na_rm)
export(min_na_rm)
export(not_na_count)
export(readDrias2020)
export(readQsim)
......
......@@ -16,13 +16,13 @@
#'
#' @examples
calcQA <- function(x, threshold = 0.2, ...) {
calcQA <- function(x, threshold = 0.8, ...) {
UseMethod("calcQA", x)
}
#' @export
#' @rdname calcQA
calcQA.data.frame <- function(x, threshold = 0.2, ...) {
calcQA.data.frame <- function(x, threshold = 0.8, ...) {
QA <- SeriesAggreg(x, Format = "%Y", rep("mean_na_rm", ncol(x)-1))
nDaysNotNA <- SeriesAggreg(x, Format = "%Y", rep("not_na_count", ncol(x)-1))
QA <- QA[, -1]
......@@ -39,7 +39,7 @@ calcQA.data.frame <- function(x, threshold = 0.2, ...) {
#' @export
#'
#' @examples
#' not_na.count(c(1, 2, 3, NA, 4))
#' not_na_count(c(1, 2, 3, NA, 4))
#'
not_na_count <- function(x) {
sum(!is.na(x))
......@@ -53,7 +53,7 @@ not_na_count <- function(x) {
#' @export
#'
#' @examples
#' mean.na.rm(c(1, 2, 3, NA, 4))
#' mean_na_rm(c(1, 2, 3, NA, 4))
#'
mean_na_rm <- function(x) {
mean(x, na.rm = TRUE)
......
......@@ -54,17 +54,27 @@ calcQMNA <- function(x, ...) {
UseMethod("calcQMNA")
}
#' @export
#' @rdname calcQMNA
calcQMNA.data.frame <- function(x, ...) {
if(ncol(x)<2) stop("x should have at least 2 columns")
apply(x[, -1, drop=F], 2, function(y) {
calcQMNA(x[,1], y, ...)
})
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]
DatesR <- QM[, 1]
QM <- QM[, -1]
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[nDaysNotNA < threshold * 12] <- NA
return(QMNA)
}
#' @export
#' @rdname calcQMNA
calcQMNA.OutputsModel <- function(x, ...) {
......@@ -206,3 +216,17 @@ calcQLogNn <- function(x, return_period) {
}
xn
}
#' Minimum with NA stripped before computation
#'
#' @param x An R object.
#'
#' @return See [min]
#' @export
#'
#' @examples
#' min_na_rm(c(1, 2, 3, NA, 4))
#'
min_na_rm <- function(x) {
suppressWarnings(min(x, na.rm = TRUE))
}
......@@ -158,13 +158,13 @@ Qsim[is.na(Qobs)] <- NA
### Ratio débit moyen simulé et observé
```{r}
```{r, fig.cap="Carte des R-QA des Bassins versants intermédiaires"}
getMapRatio(Qsim, Qobs, calcQA, "R-QA")
```
## VCN30 de période de retour 2 ans
```{r}
```{r, fig.cap="Carte des R-VCN30-2 des Bassins versants intermédiaires"}
calcVCN30Y2 <- function(x) {
calcVCNn(x, 30, 2)
}
......@@ -173,11 +173,9 @@ getMapRatio(Qsim, Qobs, calcVCN30Y2, "R-VCN30-2")
## QMNA5&nbsp;: Débit moyen mensuel minimum de période de retour 5 ans
```{r}
```{r, fig.cap="Carte des R-QMNA5 des Bassins versants intermédiaires"}
calcQMNA5 <- function(x) {
calcQMNAn(x, 5)
}
getMapRatio(Qsim, Qobs, calcQMNA5, "R-QMNA5")
plot(gis_rivers[as.numeric(gis_rivers$classifica) < 5, "classifica"])
plot(gis_rivers[, "classifica"])
```
......@@ -8,9 +8,9 @@
Chazot, Sébastien, Perrin, Charles, Jean-Philippe Vidal, Eric Sauquet, Mathilde Chauveau, et Nathalie Rouchy. 2012. « Explore 2070 - Lot Hydrologie de surface - A2 - Résultats : Fiches, Cartes et Graphes ». Ministère de l’écologie, du développement durable, des transports et du logement.
}
\usage{
calcQA(x, threshold = 0.2, ...)
calcQA(x, threshold = 0.8, ...)
\method{calcQA}{data.frame}(x, threshold = 0.2, ...)
\method{calcQA}{data.frame}(x, threshold = 0.8, ...)
}
\arguments{
\item{x}{a \link{data.frame} with a first column containing dates in \link{POSIXt} format and one \link{numeric} column per gauging station}
......
......@@ -9,7 +9,7 @@
\usage{
calcQMNA(x, ...)
\method{calcQMNA}{data.frame}(x, ...)
\method{calcQMNA}{data.frame}(x, threshold = 0.8, ...)
\method{calcQMNA}{OutputsModel}(x, ...)
......
......@@ -16,6 +16,6 @@ See \link{mean}
Arithmetic Mean with NA stripped before computation
}
\examples{
mean.na.rm(c(1, 2, 3, NA, 4))
mean_na_rm(c(1, 2, 3, NA, 4))
}
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/calcQMNA.R
\name{min_na_rm}
\alias{min_na_rm}
\title{Minimum with NA stripped before computation}
\usage{
min_na_rm(x)
}
\arguments{
\item{x}{An R object.}
}
\value{
See \link{min}
}
\description{
Minimum with NA stripped before computation
}
\examples{
min_na_rm(c(1, 2, 3, NA, 4))
}
......@@ -16,6 +16,6 @@ The number of non-NA values
Count non-NA values in an object
}
\examples{
not_na.count(c(1, 2, 3, NA, 4))
not_na_count(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