Skip to content

Commit

Permalink
some bugs in prepare_climate and climate vignette (+script) added
Browse files Browse the repository at this point in the history
  • Loading branch information
biopsichas committed Apr 12, 2023
1 parent 17938a4 commit ebc9905
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 8 deletions.
11 changes: 3 additions & 8 deletions R/preparing.R
Original file line number Diff line number Diff line change
Expand Up @@ -785,16 +785,12 @@ prepare_climate <- function(meteo_lst, write_path, period_starts = NA, period_en
warning(paste("'time.sim' file was not found in", write_path, "and was not updated.
Please make sure 'yrc_start' is", year(period_starts), "and 'yrc_end' is", year(period_ends), "."))
} else {
if(!file.exists(f_write)){
file.create(f_write)
} else {
unlink(f_write)
invisible(file.create(f_write))
}
f_write <- paste(f_dir, fname, sep = "/")
file.create(f_write)
time_sim <- read.delim(paste(write_path, fname, sep = "/"))
write.table(paste0(fname, hd_txt), f_write, append = FALSE, sep = "\t", dec = ".", row.names = FALSE, col.names = FALSE, quote = FALSE)
st_hd <- c(rep('%10s', 5))
write.table(paste(sprintf(st_hd, unlist(strsplit(time_sim[1,1], "\\s+"))[-1]), collapse = ' '), f_write, append = TRUE, sep = "\t", dec = ".", row.names = FALSE, col.names = FALSE, quote = FALSE)
write.table(paste(sprintf(st_hd, unlist(strsplit(time_sim[1,1], "\\s+"))), collapse = ' '), f_write, append = TRUE, sep = "\t", dec = ".", row.names = FALSE, col.names = FALSE, quote = FALSE)
time_sim_v <- as.numeric(unlist(strsplit(time_sim[2,1], "\\s+"))[-1])
time_sim_v[c(2, 4)] <- c(year(period_starts), year(period_ends))
write.table(paste(sprintf(st_hd, time_sim_v), collapse = ' '), f_write, append = TRUE, sep = "\t", dec = ".", row.names = FALSE, col.names = FALSE, quote = FALSE)
Expand Down Expand Up @@ -945,7 +941,6 @@ get_usersoil_table <- function(csv_path, hsg = FALSE, keep_values = FALSE, nb_ly
df_hsg[i,c(paste0("SOL_Z", 1:df_hsg$NLAYERS[i]),paste0("SOL_K", 1:df_hsg$NLAYERS[i]))]))
}
soilp$HYDGRP <- c
soilp <- soilp[,!(names(soilp) %in% c("Impervious", "Depth", "Drained"))]
print("Soil hydrological groups were calculated.")
}

Expand Down
48 changes: 48 additions & 0 deletions vignettes/climate.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
title: "Climate data"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Introduction

Text

```{r fig-cloud, echo=FALSE, out.width='100%', fig.align = 'center'}
knitr::include_graphics('cloud.png')
```

Text

```{r ext_cli, message = FALSE, warning = FALSE}
library(svatools)
basin_path <- system.file("extdata", "GIS/basin.shp", package = "svatools")
climate_lst <- load_climate_lst("../output/climate/CORDEX-BC", basin_path)
```
Text

```{r plot_cli, message = FALSE, warning = FALSE}
plot_weather(climate_lst[["rcp85"]][["1"]],"TMP_MAX", "year", "max")
```

Text

```{r get_cli, message = FALSE, warning = FALSE}
f_dir <- "../output/overwrite/tmp"
files_to_copy <- paste(f_dir, c("aquifer.con", "chandeg.con", "hru.con", "reservoir.con", "rout_unit.con", "time.sim"), sep="/")
for (rcp in c("rcp26", "rcp45", "rcp85")){
for (rcm in as.character(c(1:6))){
for(p in list(c("H", "1988-01-01", "2020-12-31"), c("N", "2032-01-01", "2065-12-31"), c("E", "2067-01-01", "2099-12-31"))){
cli_dir <- paste("../output/cli", rcp, paste0("rcm", rcm), p[1], sep = "/")
dir.create(cli_dir, recursive = TRUE)
file.copy(files_to_copy, paste(cli_dir, c("aquifer.con", "chandeg.con", "hru.con", "reservoir.con", "rout_unit.con", "time.sim"), sep = "/"), overwrite = TRUE)
prepare_climate(climate_lst[[rcp]][[rcm]], cli_dir, p[2], p[3])
print(paste(rcp, "rcm", rcm, p[1], p[2], "-", p[3], "set prepared."))
}
}
}
```
Binary file added vignettes/cloud.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ebc9905

Please sign in to comment.