-
Notifications
You must be signed in to change notification settings - Fork 0
/
modify-weather-file.Rmd
64 lines (50 loc) · 1.5 KB
/
modify-weather-file.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
---
title: "Modify Weather File"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{modify-weather-file}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
This vignette shows how to apply monthly changes into a weather file for climate scenarios.
```{r setup}
library(weaana)
```
The daily weather records are stored in the apsim format.
```{r read-weather-file}
file <- system.file("extdata/WeatherRecordsDemo1.met", package = "weaana")
# Read weather file
met <- readWeatherRecords(file)
# Get records in data.frame
records <- getWeatherRecords(met)
# Calculate month from weather records
month <- as.numeric(format(records$date, '%m'))
```
The monthly changes of future climate can be obtained from future climate scenarios.
```{r month-changes}
set.seed(1)
# maximum and minimum temperature changes are absolute values
tasmax <- (runif(12) - 0.5) * 2
tasmin <- (runif(12) - 0.5) * 2
# rain changes are a ratio
pr <- (runif(12) - 0.5) / 10
```
Add the monthly changes into weather records
```{r modify-weather-file}
new_maxt <- records$maxt + tasmax[month]
new_mint <- records$mint + tasmin[month]
new_rain <- records$rain * pr[month]
changeWeatherRecords(met, maxt = new_maxt)
changeWeatherRecords(met, mint = new_mint)
changeWeatherRecords(met, rain = new_rain)
```
Finally the new met file is saved into a new file
```{r save-file, eval=FALSE}
writeWeatherRecords(met, "new-file.met")
```