Skip to content

Commit

Permalink
climate vignette filled
Browse files Browse the repository at this point in the history
  • Loading branch information
biopsichas committed Apr 13, 2023
1 parent ebc9905 commit b402695
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 13 deletions.
123 changes: 110 additions & 13 deletions vignettes/climate.Rmd
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
---
title: "Climate data"
output: html_document
editor_options:
markdown:
wrap: 72
---

```{r setup, include=FALSE}
Expand All @@ -9,40 +12,134 @@ knitr::opts_chunk$set(echo = TRUE)

## Introduction

Text
Climate data in the [OPTAIN project](https://www.optain.eu/) for each
case study site could be obtained from
[UFZ-Cloud](https://nc.ufz.de/s/KA9Cr2bbtALGMHr/authenticate/showShare).
It is located under *WPs&Tasks\>WP3\>Task_3\_2\>data* path. Numbers are
referring to case study number and *gridded.zip* files contains `NetCDF`
files with climate data for the case study basin. Data are provided for
precipitation, solar radiation, relative humidity, min, max, mean
temperature and wind speed variables. Time period covered is from
1981-01-01 the end of this century with three representative
concentration pathways (RCPs) available (RCP2.6, RCP4.5, RCP8.5) and six
regional climate models (RCMs). Detained information about RCMs is
provided in Table \@ref(tab:rcms).

```{r fig-cloud, echo=FALSE, out.width='100%', fig.align = 'center'}
| Model number | Driving Model (GCM) | Ensemble | RCM | End date |
|:------------:|:-------------------:|:--------:|:----------:|:----------:|
| 1 | EC-EARTH | r12i1p1 | CCLM4-8-17 | 31.12.2100 |
| 2 | EC-EARTH | r3i1p1 | HIRHAM5 | 31.12.2100 |
| 3 | HadGEM2-ES | r1i1p1 | HIRHAM5 | 30.12.2099 |
| 4 | HadGEM2-ES | r1i1p1 | RACMO22E | 30.12.2099 |
| 5 | HadGEM2-ES | r1i1p1 | RCA4 | 30.12.2099 |
| 6 | MPI-ESM-LR | r2i1p1 | REMO2009 | 31.12.2100 |

: (#tab:rcms) RCMs models provided in OPTAIN.

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

Text
All RCMs data were bias-corrected to the
[ERA5-Land](https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-land?tab=overview)
climate data. Description of data preparation and analysis is provided
in the project deliverable [D3.1: Climate scenarios for integrated
modelling](https://www.optain.eu/sites/default/files/delivrables/OPTAIN%20D3.1%20-%20Climate%20scenarios%20for%20integrated%20modelling.pdf).

## NetCDF to SWAT+ input

There is no direct way of using `NetCDF` data in the SWAT model.
Therefore tools have been prepared for the users and provided with this
package.

```{r ext_cli, message = FALSE, warning = FALSE}
### Extraction from NetCDF

First step on a way to prepare SWAT+ climate input data is to download
*XX-gridded.zip* file for your case study site and to unzip it. Then
locate *CORDEX-BC* folder. Data extraction from `NetCDF` is done with
[load_climate_lst](../reference/load_climate_lst.html) function, which
needs path to your basin shape file and path to *CORDEX-BC* folder.

```{r ext_cli, eval = FALSE, 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)
basin_path <- "GIS/basin.shp"
cordex_path <- "climate/CORDEX-BC"
climate_lst <- load_climate_lst(cordex_path, basin_path)
```
Text

```{r plot_cli, message = FALSE, warning = FALSE}
This function creates virtual stations for each `NetCDF` grid cell,
which basin boundary touches. Virtual stations are defined and center of
grid cell. Then for each of this station data are extracted and saved in
list of list format.

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

### Evaluation

Extraction result is arranged in specific format. *RCP -\> RCM* are the top levels of the list format. Then format is same as with other meteorological data used in
this package.

- Meteo data list
- stations sf Data frame (ID, Name, Elevation, Source, geometry,
Long, Lat)
- data -\> Station ID -\> Variable -\> Data frame (DATE, Variable)


Therefore other package function as
[plot_weather](../reference/plot_weather.html) could be used to examine
function results or to compare to measurement data for example with
[plot_weather_compare](../reference/plot_weather_compare.html).

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

Text
```{r fig-temp, echo=FALSE, out.width='100%', out.height ='100%', fig.align = 'center'}
knitr::include_graphics('fig_temp.png')
```
[plot_wgn_comparison](../reference/plot_wgn_comparison.html) function might be useful to get climate set statistical comparison to motoring data.

```{r plot_wng, eval = FALSE, message = FALSE, warning = FALSE}
temp_path <- system.file("extdata", "weather_data.xlsx", package = "svatools")
met_lst <- load_template(temp_path, 4326)
plot_wgn_comparison(climate_lst[["rcp85"]][["1"]], met_lst, "ID4", "ID2", "Climate set", "Monitoring data", "comparison")
```

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

Other functions from [Weather data section](../articles/weather.html) are also applicable. This allows to update SWAT+ *.sqlite* [database](https://biopsichas.github.io/svatools/articles/weather.html#wgn-input-function) with climate data, prepare [weather generator](https://biopsichas.github.io/svatools/articles/weather.html#wgn-input-function) parameters, etc.

### Preparing all climate sets

Nevertheless [prepare_climate](../reference/prepare_climate.html) function could be used to directly prepare/update model input text files needed to run each climate scenario. Nothing else is needed just to overwrite model input files with prepared text files.

```{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="/")
Following lines runs [prepare_climate](../reference/prepare_climate.html) function in a loop and prepares all climate data input sets and folder stucture.

```{r get_cli, eval = FALSE, message = FALSE, warning = FALSE}
##Path to your SWAT+ model project directory
project_dir <- "../output/overwrite/tmp"
##These files will be copied from model directory and updated
files_to_copy <- paste(project_dir, c("aquifer.con", "chandeg.con", "hru.con", "reservoir.con", "rout_unit.con", "time.sim"), sep="/")
##Main loop to each rcp
for (rcp in c("rcp26", "rcp45", "rcp85")){
##Each rcm
for (rcm in as.character(c(1:6))){
##Each period
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"))){
##Creating new directory
cli_dir <- paste("../output/cli", rcp, paste0("rcm", rcm), p[1], sep = "/")
dir.create(cli_dir, recursive = TRUE)
##Coping files to update
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)
##Running function to prepare climate input for scenario
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/fig_basin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vignettes/fig_temp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vignettes/fig_wng.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 b402695

Please sign in to comment.