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

refactor: change output folder structure

Fix #16
parent 386521f6
Pipeline #33737 failed with stages
in 31 minutes and 45 seconds
......@@ -7,7 +7,7 @@
#'
#' @examples
#' cfg <- loadConfig()
#' df <- readQsim(cfg$Qnat$path, "Qnat-v1")
#' df <- readQsim(cfg$Qnat$path, "historical/data")
#' summary(df)
readQsim <- function(..., cfg = loadConfig()) {
file <- getDataPath(..., "ts_Qsim.tsv")
......
......@@ -37,14 +37,14 @@ indicators_periods <- list(
calage = as.POSIXct(c(cfg$calibration$date$start, cfg$calibration$date$end), tz = "UTC"),
reference = as.POSIXct(cfg$hydroclim$drias$periods$ref, tz = "UTC")
)
saveFlowDB(path = getDataPath(cfg$Qnat$path, "Qnat-v1", cfg = cfg),
saveFlowDB(path = getDataPath(cfg$Qnat$path, "historical/data", cfg = cfg),
InputsModel = InputsModel,
OutputsModel = OutputsModel,
indicators_periods = indicators_periods,
cfg = cfg)
```
Les fichiers au format [Tab-separated values (TSV)](https://fr.wikipedia.org/wiki/Tabulation-separated_values) sont téléchargeables à l'adresse : https://nextcloud.inrae.fr/s/adinzGa3AmLEXnZ?path=%2F03-naturalised_flows%2FQnat-v1
Les fichiers au format [Tab-separated values (TSV)](https://fr.wikipedia.org/wiki/Tabulation-separated_values) sont téléchargeables à l'adresse : https://nextcloud.inrae.fr/s/adinzGa3AmLEXnZ?path=%2F03-naturalised_flows%2Fv1.0%2Fhistorical%2Fdata
## Comparaison des données simulées avec d'autres bases de données
......@@ -113,7 +113,7 @@ Enregistrement des graphiques pour toutes les stations sur le cloud&nbsp;:
apply(hydratec$stations, 1, function(station) {
CdSiteHydro <- station["CdSiteHydro"]
p <- plotVCN(CdSiteHydro, dfVCN10)
path <- getDataPath(cfg$Qnat$path, "Analyses/Qnat-v1", cfg = cfg)
path <- getDataPath(cfg$Qnat$path, "historical/VCN10", cfg = cfg)
filename <- paste0(
paste("VCN10",
CdSiteHydro,
......@@ -124,6 +124,6 @@ apply(hydratec$stations, 1, function(station) {
})
```
Les graphiques sont téléchargeables à l'adresse&nbsp;: https://nextcloud.inrae.fr/s/adinzGa3AmLEXnZ?path=%2F03-naturalised_flows%2FAnalyses%2FQnat-v1
Les graphiques sont téléchargeables à l'adresse&nbsp;: https://nextcloud.inrae.fr/s/adinzGa3AmLEXnZ?path=%2F03-naturalised_flows%2FQnat-v1%2Fhistorical%2Fplots
......@@ -18,7 +18,7 @@ LoadRunSave <- function(rcp, scenario) {
BasinsObs <- loadBasinsObs(file, cfg = cfg)
InputsModel <- suppressMessages(CreateInputsModel(BasinsObs))
OutputsModel <- RunModel(BasinsObs, "calibration_with_reservoirs.txt", InputsModel = InputsModel)
path <- getDataPath(cfg$Qnat$path, "Drias2020/Qnat-v1", rcp, scenario, cfg = cfg)
path <- getDataPath(cfg$Qnat$path, rcp, "data", scenario, cfg = cfg)
indicators_periods <- lapply(cfg$hydroclim$drias$periods, as.POSIXct, tz = "UTC")
saveFlowDB(path = path,
InputsModel = InputsModel,
......@@ -41,9 +41,10 @@ scenarios <- rep(scenarios, each = length(rcps))
mapply(LoadRunSave, rcp = rcps, scenario = scenarios)
```
Les données de débits naturels simulés avec les forçages climatiques du DRIAS 2020 créées par le script ci-dessus sont téléchargeables à l'adresse :
Les données de débits naturels simulés avec les forçages climatiques du DRIAS 2020 créées par le script ci-dessus sont téléchargeables aux adresses suivantes :
https://nextcloud.inrae.fr/s/adinzGa3AmLEXnZ?path=%2F03-naturalised_flows%2FDrias2020%2FQnat-v1
- https://nextcloud.inrae.fr/s/adinzGa3AmLEXnZ?path=%2F03-naturalised_flows%2Fv1.0%2Frcp4.5%2Fdata
- https://nextcloud.inrae.fr/s/adinzGa3AmLEXnZ?path=%2F03-naturalised_flows%2Fv1.0%2Frcp8.5%2Fdata
## Comparaison des débits naturels sous forçage climatique avec les données historiques
......@@ -58,19 +59,19 @@ hydratec <- loadHydratecDB(cfg = cfg)
#### Débits simulés sur le climat historique
```{r}
Qnat <- readQsim(cfg$Qnat$path, "Qnat-v1", cfg = cfg)
Qnat <- readQsim(cfg$Qnat$path, "v1.0/historical/data", cfg = cfg)
Qnat <- Qnat[, names(hydratec$Q)]
```
#### Débits simulés sur le climat passé et futur avec les projections climatiques DRIAS 2020
```{r}
loadDriasQsim <- function(rcp_scenario) {
message("Read Qsim for ", rcp_scenario)
Qsim <- readQsim(cfg$Qnat$path, "Drias2020/Qnat-v1", rcp_scenario, cfg = cfg)
loadDriasQsim <- function(rcp, scenario) {
message("Read Qsim for ", rcp, "/", scenario)
Qsim <- readQsim(cfg$Qnat$path, rcp, "data", scenario, cfg = cfg)
Qsim[, names(hydratec$Q)]
}
QsimDrias <- lapply(paste(rcps, scenarios, sep="/"), loadDriasQsim)
QsimDrias <- mapply(loadDriasQsim, rcp = rcps, scenario = scenarios, SIMPLIFY = FALSE)
names(QsimDrias) <- paste(rcps, scenarios, sep = " - ")
```
......@@ -126,7 +127,7 @@ plotVCN <- function(CdSiteHydro, df) {
plotVCN("H5920010", dfVCN10[grep("Hydratec|Inrae|rcp4\\.5", dfVCN10$source), ])
```
```{r, fig.cap="VCN10 annuel et moyenne mobile sur 5 ans des débits naturels historiques des bases Hydratec et Inrae et des projections Drias 2020 historiques et futures du scénario d'émission RCP 4.5 du modèle Inrae sur la Seine à Paris"}
```{r, fig.cap="VCN10 annuel et moyenne mobile sur 5 ans des débits naturels historiques des bases Hydratec et Inrae et des projections Drias 2020 historiques et futures du scénario d'émission RCP 8.5 du modèle Inrae sur la Seine à Paris"}
plotVCN("H5920010", dfVCN10[grep("Hydratec|Inrae|rcp8\\.5", dfVCN10$source), ])
```
......@@ -138,7 +139,7 @@ apply(hydratec$stations, 1, function(station) {
lapply(cfg$hydroclim$drias$rcp[-1], function(rcp) {
p <- plotVCN(CdSiteHydro,
dfVCN10[grep(paste0("Hydratec|Inrae|", gsub("\\.", "\\\\.", rcp)), dfVCN10$source), ])
path <- getDataPath(cfg$Qnat$path, "Analyses/Drias2020/Qnat-v1", rcp)
path <- getDataPath(cfg$Qnat$path, rcp, "plots/VCN10")
filename <- paste0(
paste("VCN10",
CdSiteHydro,
......
......@@ -94,16 +94,16 @@ loadIndicators <- function(rcp, scenario, indicator) {
periods <- names(cfg$hydroclim$drias$periods)
names(periods) <- periods
lapply(periods, function(period) {
file <- paste0(indicator, "_",
file <- paste0(indicator, "_",
substr(cfg$hydroclim$drias$periods[[period]][1], 1, 4),
"-",
substr(cfg$hydroclim$drias$periods[[period]][2], 1, 4),
".tsv")
path <- getDataPath(
cfg$Qnat$path,
"Drias2020/Qnat-v1",
rcp,
scenario,
cfg$Qnat$path,
rcp,
"data",
scenario,
file,
cfg = cfg
)
......@@ -112,11 +112,13 @@ loadIndicators <- function(rcp, scenario, indicator) {
}
loadAllIndicators <- function(indicator) {
ind <- mapply(rcp = rcpsX,
scenario = scenariosX,
indicator = indicator,
loadIndicators,
SIMPLIFY = FALSE)
ind <- mapply(
rcp = rcpsX,
scenario = scenariosX,
indicator = indicator,
loadIndicators,
SIMPLIFY = FALSE
)
names(ind) <- paste(rcpsX, scenariosX, sep = " - ")
return(ind)
}
......@@ -132,12 +134,12 @@ historiQ <- list(
period = c(cfg$calibration$date$start, cfg$calibration$date$end)),
sim = list(path = file.path(cfg$calibration$path, "Qsim"),
period = c(cfg$calibration$date$start, cfg$calibration$date$end)),
nat = list(path = file.path(cfg$Qnat$path, "Qnat-v1"),
nat = list(path = file.path(cfg$Qnat$path, "historical/data"),
period = cfg$hydroclim$drias$periods$ref)
)
loadHistoriQ <- function(l, indicator) {
file <- paste0(indicator, "_",
file <- paste0(indicator, "_",
substr(l$period[1], 1, 4),
"-",
substr(l$period[2], 1, 4),
......@@ -215,7 +217,7 @@ calcDelta <- function(ind, rcp, period, delta = "*") {
names(scenarios) <- scenarios
ind <- lapply(scenarios, function(x) {
if (grepl(rcp, x, fixed = TRUE)) {
ind[[x]]
} else {
NULL
......@@ -278,21 +280,21 @@ knitr::kable(tableDeltaStation("H5920010", deltaIndicators, Qhist_indicators), d
## Cartes d'évolutions
```{r, fig.asp = 1}
plot_map_delta <- function(r, title,
breaks = c(-60, -30, -20, -10, -5,
plot_map_delta <- function(r, title,
breaks = c(-60, -30, -20, -10, -5,
5, 10, 20, 30, 1.6, 100)) {
plot_seine_map(r, breaks, title)
}
```
```{r, fig.asp = 1}
plot_map_delta(deltaIndicators$med[, "QA"], "QA - évolution RCP4.5 scénario médian (%)")
plot_map_delta(deltaIndicators$med[, "QA"], "QA - évolution RCP8.5 scénario médian (%)")
```
```{r, fig.asp = 1}
plot_map_delta(deltaIndicators$med[, "QMNA5"], "QMNA5 - évolution RCP4.5 scénario minimum (%)")
plot_map_delta(deltaIndicators$med[, "QMNA5"], "QMNA5 - évolution RCP8.5 scénario minimum (%)")
```
```{r, fig.asp = 1}
plot_map_delta(deltaIndicators$med[, "QJXA10"], "QJXA10 - évolution RCP4.5 scénario maximum (%)")
plot_map_delta(deltaIndicators$med[, "QJXA10"], "QJXA10 - évolution RCP8.5 scénario maximum (%)")
```
......@@ -19,7 +19,7 @@ id_Paris <- "H5920010"
```{r load_Q}
# Débit simulé période historique
Qnat <- readQsim(cfg$Qnat$path, "Qnat-v1", cfg = cfg)
Qnat <- readQsim(cfg$Qnat$path, "historical/data", cfg = cfg)
iCol <- which(names(Qnat) == id_Paris)
Qnat <- Qnat[, c(1, iCol)]
......@@ -28,13 +28,13 @@ rcps <- "rcp8.5"
scenarios <- gsub("/", "_", cfg$hydroclim$drias$scenarios)
scenariosX <- rep(scenarios, length(rcps))
rcpsX <- rep(rcps, each = length(scenarios))
loadDriasQsim <- function(rcp_scenario) {
message("Read Qsim for ", rcp_scenario)
Qsim <- readQsim(cfg$Qnat$path, "Drias2020/Qnat-v1", rcp_scenario, cfg = cfg)
loadDriasQsim <- function(rcp, scenario) {
message("Read Qsim for ", rcp, "/", scenario)
Qsim <- readQsim(cfg$Qnat$path, rcp, "data", scenario, cfg = cfg)
iCol <- which(names(Qnat) == id_Paris)
Qsim[, c(1, iCol)]
}
QsimDrias <- lapply(paste(rcps, scenarios, sep="/"), loadDriasQsim)
QsimDrias <- mapply(loadDriasQsim, rcp = rcps, scenario = scenarios, SIMPLIFY = FALSE)
names(QsimDrias) <- paste(rcps, scenarios, sep = " - ")
QsimAll <- c(list(hist = Qnat), QsimDrias)
```
......@@ -87,7 +87,7 @@ plotReturnPeriods(QJXA_end, "Période 2071-2100")
```{r}
period <- c(cfg$hydroclim$drias$periods$ref[1], cfg$hydroclim$drias$periods$end[2])
QJXA_all <- statQJXA(QsimDrias, period)
plotReturnPeriods(QJXA_all,
plotReturnPeriods(QJXA_all,
"Période 1976-2100")
```
......@@ -98,7 +98,7 @@ return.level.ci <- function(fit, t_max, alpha = 0.05) {
return.period <- seq(2, t_max)
estimate <- return.level(fit, return.period = return.period)
estimate[estimate < 0] <- 0
l <- lapply(alpha, function(a) {
rl <- return.level(fit, return.period = return.period, do.ci = TRUE, alpha = a)
class(rl) <- "matrix"
......@@ -119,12 +119,12 @@ bilan_scenario <- function(scenario, QJXA, t_max = 100, alphas) {
QJXA <- QJXA[QJXA$scenario == scenario, ]
fit <- fevd(x = Q, data = QJXA, type = "Gumbel", time.units = "years")
dfRl <- return.level.ci(fit, t_max, alphas)
p <- ggplot(dfRl,
aes(x = return.period)) +
p <- ggplot(dfRl,
aes(x = return.period)) +
geom_ribbon(aes(ymin = p02, ymax = p98, fill = "Incertitude 95%"), fill = "#66c1bf", alpha = 0.3, show.legend = T) +
geom_ribbon(aes(ymin = p15, ymax = p85), fill = "#008c8e", alpha = 0.3) +
geom_line(aes(y = estimate, color = "Estimation"), color = "#423089") +
geom_point(data = QJXA,
geom_line(aes(y = estimate, color = "Estimation"), color = "#423089") +
geom_point(data = QJXA,
aes(x = t, y = Q, color = "Observations"), color = "#ed6e6c") +
labs(x = "Période de retour (années)",
y = "Débit (m3/s)",
......
......@@ -52,4 +52,4 @@ default:
- 0.9
- 2.3
Qnat:
path: 03-naturalised_flows
path: 03-naturalised_flows/v1.0
......@@ -19,6 +19,6 @@ Load simulated flows recorded with \link{saveFlowDB}
}
\examples{
cfg <- loadConfig()
df <- readQsim(cfg$Qnat$path, "Qnat-v1")
df <- readQsim(cfg$Qnat$path, "historical/data")
summary(df)
}
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