Skip to content

Commit 9c572d9

Browse files
Vignettes updated (not knitted) and readme reduced
1 parent 14106f8 commit 9c572d9

File tree

8 files changed

+138
-505
lines changed

8 files changed

+138
-505
lines changed

README.md

Lines changed: 0 additions & 200 deletions
Original file line numberDiff line numberDiff line change
@@ -59,206 +59,6 @@ Alternatively, to install the latest version:
5959
1. Load the required packages using the R command: `library(c('Evapotranspiration', 'ncdf4', 'utils', 'raster', 'chron', 'maptools', 'sp', 'zoo', 'methods', 'xts')
6060
1. Install the AWAPer package using the following example R command (NOTE: use the full file path to the AWAPer folder). For example on a PC `install.packages("C:\MY_FOLDER\AWAPer\AWAPer_0.1.4.tar.gz", repos = NULL, type = "source")` and for Mac `install.packages(“~/Users/MyFolder/AWAPer/AWAPer_0.1.4.tar.gz", repos = NULL, type = "source")`
6161

62-
# Example 1. Build and then update netCDF files with the latest data
63-
64-
This example shows the steps required to build the two netCDF files, and then update the data to yesterday.
65-
66-
```R
67-
# Set dates for building netCDFs and extracting data from 15 to 5 days ago.
68-
startDate = as.Date(Sys.Date()-15,"%Y-%m-%d")
69-
endDate = as.Date(Sys.Date()-5,"%Y-%m-%d")
70-
71-
# Set names for netCDF files (in the system temp. directory).
72-
ncdfFilename = tempfile(fileext='.nc')
73-
ncdfSolarFilename = tempfile(fileext='.nc')
74-
75-
# Build netCDF grids for all met. data but only over the defined time period.
76-
file.names = makeNetCDF_file(ncdfFilename=ncdfFilename,
77-
ncdfSolarFilename=ncdfSolarFilename,
78-
updateFrom=startDate, updateTo=endDate)
79-
80-
# Now, to demonstrate updating the netCDF grids to one dat ago, rerun with
81-
# the same file names but updateFrom=NA.
82-
file.names = makeNetCDF_file(ncdfFilename=ncdfFilename,
83-
ncdfSolarFilename=ncdfSolarFilename,
84-
updateFrom=NA)
85-
```
86-
# Example 2. Extract point precip. data and check with osberved data.
87-
This example was developed by Ms Xinyang Fan (Uni. Melbourne) and shows how to extract point estimates of daily precipitation at four goundwater bore locations and at one rainfall gauge. The extracted data is then plotted. The rain gauge is also compared against the observed rain gauge. The latter shows that the results are unbiased, but minor differences do exist due to AWAP data having a 5x5 km grid-cell resolution. The plots below show (1) the locattions of the five sites (2) bar graphs of the daily precip. and (3) plots of the observed vs AWAPer estimated precip. at the rainfall gauge.
88-
89-
![Example 2. Site locations](https://user-images.githubusercontent.com/8623994/68077541-ee782700-fe19-11e9-93fa-c0eae4606af1.png)
90-
91-
![Example 2. Daily precip at sites](https://user-images.githubusercontent.com/8623994/68077652-9d693280-fe1b-11e9-9c2e-fbebce8013cd.png)
92-
93-
![Example 3. Obs. vs Est Precip](https://user-images.githubusercontent.com/8623994/68077658-c7baf000-fe1b-11e9-9074-10d22b1bf8cd.png)
94-
95-
```R
96-
# load all necessary packages
97-
library(AWAPer)
98-
99-
# Make the netCDF files of only AWAP precipitation data.
100-
fnames = makeNetCDF_file(ncdfFilename ='AWAP_demo.nc',
101-
updateFrom=as.Date("2010-08-01","%Y-%m-%d"),
102-
updateTo=as.Date("2010-10-01","%Y-%m-%d"),
103-
urlTmin=NA, urlTmax=NA, urlVprp=NA, urlSolarrad=NA)
104-
105-
# Set coordinates to four bores locations and one rainfall gauge.
106-
coordinates.data = data.frame( ID =c('Bore-70015656','Bore-50038039','Bore-20057861','Bore-10084446','Rain-63005'),
107-
Longitude = c(131.33588, 113.066933, 143.118263, 153.551875, 149.5559),
108-
Latitude = c(-12.660622, -25.860046, -38.668506,-28.517974,-33.4289))
109-
110-
# Convert the points to a spatial object
111-
sp::coordinates(coordinates.data) <- ~Longitude + Latitude
112-
113-
# Set projection to GDA94
114-
sp::proj4string(coordinates.data) = '+proj=longlat +ellps=GRS80'
115-
116-
# Plot coordinates
117-
sp::plot(coordinates.data, add =T)
118-
with(coordinates.data, text(sp::coordinates(coordinates.data)[,1],sp::coordinates(coordinates.data)[,2],
119-
labels = coordinates.data$ID, pos = 1))
120-
121-
# Extract time-series of daily precip data at all five sites
122-
climateData.data = extractCatchmentData(ncdfFilename='AWAP_demo.nc',
123-
extractFrom=as.Date("2010-08-01","%Y-%m-%d"),
124-
extractTo=as.Date("2010-10-01","%Y-%m-%d"),
125-
locations=coordinates.data,
126-
getTmin=F, getTmax=F, getVprp=F, getSolarrad=F, getET=F)
127-
128-
129-
# Plot the daily rainfall at each site
130-
par.default = par()
131-
par(mfrow=c(5,1), mar = c(4,5,3,0))
132-
for (i in 1:nrow(coordinates.data)){
133-
filt = climateData.data$CatchmentID.ID == coordinates.data$ID[i]
134-
135-
data2plot = climateData.data$precip_mm[filt]
136-
names(data2plot) = paste(climateData.data$day[filt],'/',climateData.data$month[filt],sep='')
137-
barplot(data2plot, main=coordinates.data$ID[i], ylab='Precip [mm/d]', xlab='Date [day/month]')
138-
139-
}
140-
141-
# The following is hard-coded observed rainfall for gauge 63005
142-
obsPrecip <- data.frame(
143-
year= c(2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010,
144-
2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010,
145-
2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010, 2010),
146-
month = c(8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
147-
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10),
148-
day = c(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, 1, 2, 3, 4, 5,
149-
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, 1),
150-
precip_mm = c(0.6, 5.2, 0.8, 0.4, 0.0, 0.0, 0.0, 0.0, 0.0, 15.8, 15.6, 7.6, 0.7, 0.4, 1.4, 1.0, 0.0, 0.0, 30.4, 1.0, 0.0,
151-
0.0, 5.0, 2.2, 0.3, 0.8, 13.8, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 13.8, 15.2, 0.4, 0.2, 0.0, 0.0, 12.4, 0.9,
152-
0.0, 0.0, 0.1, 13.0, 0.2, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.3, 0.0, 0.0, 0.0, 0.0))
153-
154-
# Plot the observed vs AWAPer rainfall at gauge ID 63005
155-
par(mfrow=c(1,2), mar = c(4,5,3,2))
156-
filt2 = climateData.data$CatchmentID.ID=='Rain-63005'
157-
plot(obsPrecip$precip_mm,climateData.data$precip_mm[filt2],
158-
xlim = c(0,35),ylim = c(0,35),
159-
main='Obs. vs. AWAPer precip. at 63005',
160-
xlab='Obs. precip [mm/d]', ylab='AWAPer Precip [mm/d]')
161-
abline(0,1, col='grey', lty=2)
162-
163-
# Plot the cumulative observed vs AWAPer rainfall at gauge ID 63005
164-
plot(cumsum(obsPrecip$precip_mm),cumsum(climateData.data$precip_mm[filt2]),
165-
xlim = c(0,175),ylim = c(0,175),
166-
main='Cumulative obs. vs. AWAPer precip. at 63005',
167-
xlab='Obs. precip. [mm]', ylab='AWAPer precip. [mm]', type='l')
168-
abline(0,1, col='grey', lty=2)
169-
170-
# Rest plotting parameters
171-
par(par.default)
172-
```
173-
174-
# Example 3. Calculate precip and evapotranspiration
175-
This example calculates the catchment weighted precipitation at Bet Bet Creek (Victoria, Australia), the spatial standard deviation in precipitation and two measures of potential evapotranspiration. The example was developed by Dr Conrad Wasko. Below is a plot of the output.
176-
177-
![Example 3. Calculate precip and evapotranspiration](https://user-images.githubusercontent.com/39328041/66539735-e14a7e00-eb74-11e9-9890-dc3bce4148f2.png)
178-
179-
```R
180-
# Make the netCDF files of AWAP data
181-
makeNetCDF_file(ncdfFilename ='AWAP_demo.nc',ncdfSolarFilename='AWAP_solar_demo.nc',
182-
updateFrom=as.Date("2010-1-1","%Y-%m-%d"),updateTo=as.Date("2011-12-1","%Y-%m-%d"))
183-
184-
# Load example catchment boundaries.
185-
data("catchments")
186-
187-
# Load the ET constants
188-
data(constants,package='Evapotranspiration')
189-
190-
# Extract catchment average data for Bet Bet Creek with
191-
# the Jensen Haise estimate of potential ET.
192-
climateData.ET.JensenHaise.var = extractCatchmentData(ncdfFilename='AWAP_demo.nc',
193-
ncdfSolarFilename='AWAP_solar_demo.nc', extractFrom=as.Date("2010-1-1","%Y-%m-%d"),
194-
extractTo=as.Date("2010-12-31","%Y-%m-%d"), locations=catchments[2,],
195-
ET.function='ET.JensenHaise', ET.timestep='daily', ET.constants=constants);
196-
197-
# Extract catchment average data for Bet Bet Creek with
198-
# the Mortons CRAE estimate of potential ET.
199-
climateData.ET.MortonCRAE.var = extractCatchmentData(ncdfFilename='AWAP_demo.nc',
200-
ncdfSolarFilename='AWAP_solar_demo.nc', extractFrom=as.Date("2010-1-1","%Y-%m-%d"),
201-
extractTo=as.Date("2010-12-31","%Y-%m-%d"), locations=catchments[2,],
202-
ET.function='ET.MortonCRAE', ET.timestep='monthly', ET.constants=constants);
203-
204-
# Set up start and end date indices for plotting
205-
srt.date = as.Date("2010-06-01","%Y-%m-%d")
206-
end.date = as.Date("2010-10-01","%Y-%m-%d")
207-
208-
# Convert year, month and day columns from extractions to a date.
209-
climateData.ET.JensenHaise.var.date = as.Date(paste0(climateData.ET.JensenHaise.var$catchmentTemporal.mean$year, "-",
210-
climateData.ET.JensenHaise.var$catchmentTemporal.mean$month, "-",
211-
climateData.ET.JensenHaise.var$catchmentTemporal.mean$day))
212-
213-
climateData.ET.MortonCRAE.var.date = as.Date(paste0(climateData.ET.MortonCRAE.var$catchmentTemporal.mean$year, "-",
214-
climateData.ET.MortonCRAE.var$catchmentTemporal.mean$month, "-",
215-
climateData.ET.MortonCRAE.var$catchmentTemporal.mean$day))
216-
217-
i1.s = match(srt.date, climateData.ET.JensenHaise.var.date)
218-
i1.e = match(end.date, climateData.ET.JensenHaise.var.date)
219-
i2.s = match(srt.date, climateData.ET.MortonCRAE.var.date)
220-
i2.e = match(end.date, climateData.ET.MortonCRAE.var.date)
221-
222-
# Plot rainfall and standard deviation against observations
223-
# ---------------------------------------------------------
224-
max.y = max(climateData.ET.JensenHaise.var$catchmentTemporal.mean$precip_mm[i1.s:i1.e] +
225-
sqrt(climateData.ET.JensenHaise.var$catchmentSpatial.var$precip_mm[i1.s:i1.e]))
226-
227-
# Change the plot margins
228-
par(mar = c(5, 7.5, 4, 2.7) + 0.1)
229-
230-
# Rainfall
231-
plot(climateData.ET.JensenHaise.var.date[i1.s:i1.e],
232-
climateData.ET.JensenHaise.var$catchmentTemporal.mean$precip_mm[i1.s:i1.e],
233-
type = "h", col = "#e31a1c", lwd = 3, mgp = c(2, 0.5, 0), ylim = c(0, 80),
234-
ylab = "", xlab = "2010", xaxs = "i", yaxt = "n", bty = "l", yaxs = "i")
235-
axis(side = 2, mgp = c(2, 0.5, 0), line = 0.5, at = seq(from = 0, to = 80, by = 20),
236-
labels = c("0", "20", "40", "60", "80mm"), col = "#e31a1c", col.axis = "#e31a1c")
237-
238-
# Standard deviation
239-
for (i in 1:length(climateData.ET.JensenHaise.var.date[i1.s:i1.e])) {
240-
x.plot = rep(climateData.ET.JensenHaise.var.date[i1.s:i1.e][i], 2)
241-
y.plot = c(climateData.ET.JensenHaise.var$catchmentTemporal.mean$precip_mm[i1.s:i1.e][i] +
242-
sqrt(climateData.ET.JensenHaise.var$catchmentSpatial.var$precip_mm[i1.s:i1.e][i]),
243-
climateData.ET.JensenHaise.var$catchmentTemporal.mean$precip_mm[i1.s:i1.e][i] -
244-
sqrt(climateData.ET.JensenHaise.var$catchmentSpatial.var$precip_mm[i1.s:i1.e][i]))
245-
lines(x.plot, y.plot, col = "black", lwd = 1.2)
246-
247-
}
248-
249-
# Plot evap data.
250-
par(new = TRUE)
251-
plot(climateData.ET.JensenHaise.var.date[i1.s:i1.e], climateData.ET.JensenHaise.var$catchmentTemporal.mean$ET_mm[i1.s:i1.e], col = "#bc80bd", lwd = 2, ylab = "",
252-
ylim = c(0, 4), lty = 1, xlab = "", xaxs = "i", yaxt = "n", xaxt = "n", type = "l", bty = "n", yaxs = "i")
253-
axis(side = 2, line = 2.3, mgp = c(2, 0.5, 0), labels = c("0", "1", "2", "3", "4mm"), at = seq(from = 0, to = 4, by = 1), col = "#bc80bd", col.axis = "#bc80bd")
254-
lines(climateData.ET.MortonCRAE.var.date[i2.s:i2.e], climateData.ET.MortonCRAE.var$catchmentTemporal.mean$ET_mm[i2.s:i2.e], col = "#bc80bd", lwd = 2, lty = 2)
255-
256-
# Legend
257-
legend("topleft", cex = 0.8, lwd = 2, bty = "n", inset = c(0.01, -0.01),
258-
lty = c(1, 1, 2), pch = c(NA, NA, NA),
259-
col = c("#e31a1c", "#bc80bd", "#bc80bd"),
260-
legend = c("Precipitation (bars +/- one standard dev.)", "Jensen-Haise PET", "Morton CRAE PET"), xpd = NA)
261-
```
26262

26363
# Example 4. Calculate evapotranspiration
26464

build_commands.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
path <- find.package("AWAPer")
66
system(paste(shQuote(file.path(R.home("bin"), "R")),"CMD", "Rd2pdf", shQuote(path)))
77

8-
# Pre-build the vignettes to avod their execuation during package installation.
8+
# Pre-build the vignettes to avoid their execution during package installation.
99
# NOTE: Must manually move image files from vignettes/figure/ to vignettes/ after knit
1010
# and remove figure/ from .Rmd
1111
library(knitr)
12-
knitr::knit("vignettes/Point_rainfall.Rmd.orig", output = "vignettes/Point_rainfall.Rmd")
13-
knitr::knit("vignettes/Catchment_avg_ET_rainfall.Rmd.orig", output = "vignettes/Catchment_avg_ET_rainfall.Rmd")
12+
library(rmarkdown)
13+
knitr::knit("vignettes/A_Make_data_grids.Rnw", output = "vignettes/A_Make_data_grids.Rmd")
14+
knitr::knit("vignettes/B_Point_rainfall.Rnw", output = "vignettes/B_Point_rainfall.Rmd")
15+
knitr::knit("vignettes/C_Catchment_avg_ET_rainfall.Rnw", output = "vignettes/C_Catchment_avg_ET_rainfall.Rmd")
1416
browseVignettes("AWAPer")
1517

1618
# Build the pavkage for CRAN

vignettes/A_Make_data_grids.Rmd

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: "Make and update source data grids"
3+
description: >
4+
This vignette shows how to build the netCDF data file and then
5+
update it to new start and end dates.
6+
output: rmarkdown::html_vignette
7+
vignette: >
8+
%\VignetteIndexEntry{Make source data grids}
9+
%\VignetteEngine{knitr::rmarkdown}
10+
%\usepackage[utf8]{inputenc}
11+
---
12+
13+
``` r
14+
library(AWAPer, warn.conflicts = FALSE)
15+
```
16+
This example shows how to build the required data files and then update them.
17+
18+
## Make netCDF file
19+
This example shows the steps required to build the netCDF data grid files.
20+
21+
First, let's define the dates for the data grids. Here the data grids are created for data between the dates _updateTo_ and _updateTo_. If the latter two dates were not input then data would be downloaded from 1/1/1900 to yesterday.
22+
23+
```{r}
24+
startDate = as.Date(Sys.Date()-15,"%Y-%m-%d")
25+
endDate = as.Date(Sys.Date()-5,"%Y-%m-%d")
26+
```
27+
28+
Next the file name for the netCDF grids need to be defined. Here we'll just use temporary files. You should change this to a non-temporary file name and folder.
29+
```{r}
30+
# Set names for netCDF files (in the system temp. directory).
31+
ncdfFilename = tempfile(fileext='.nc')
32+
ncdfSolarFilename = tempfile(fileext='.nc')
33+
```
34+
35+
Now we're ready to download and build the netCDF grids.
36+
37+
The netCDF data files contains grids of daily rainfall, temperature, vapour pressure deficit and solar radiation for all of Australia.
38+
```{r}
39+
file.names = makeNetCDF_file(ncdfFilename=ncdfFilename,
40+
ncdfSolarFilename=ncdfSolarFilename,
41+
updateFrom=startDate, updateTo=endDate)
42+
```
43+
44+
## Update existing data grids
45+
46+
Now that we've built the above files, the updating can be demonstrated. Here we'll updating the data grids to one day ago.
47+
48+
Often users run _makeNetCDF_file_ once to build netCDF data files that contain all variables over the entire record length (which requires ~5GB disk storage) and then use the netCDFs grids for multiple projects, rather than re-building the netCDF for each project.
49+
50+
Also, if _makeNetCDF_file_ is run with the the file names pointing to existing files and _updateFrom=NA_ then the netCDF files will be updated to yesterday.
51+
```{r}
52+
file.names = makeNetCDF_file(ncdfFilename=ncdfFilename,
53+
ncdfSolarFilename=ncdfSolarFilename,
54+
updateFrom=NA)
55+
```

vignettes/A_Make_data_grids.Rnw

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
title: "Make and update source data grids"
3+
description: >
4+
This vignette shows how to build the netCDF data file and then
5+
update it to new start and end dates.
6+
output: rmarkdown::html_vignette
7+
vignette: >
8+
%\VignetteIndexEntry{Make source data grids}
9+
%\VignetteEngine{knitr::rmarkdown}
10+
%\usepackage[utf8]{inputenc}
11+
---
12+
13+
``` r
14+
library(AWAPer, warn.conflicts = FALSE)
15+
```
16+
This example shows how to build the required data files and then update them.
17+
18+
## Make netCDF file
19+
This example shows the steps required to build the netCDF data grid files.
20+
21+
First, let's define the dates for the data grids. Here the data grids are created for data between the dates _updateTo_ and _updateTo_. If the latter two dates were not input then data would be downloaded from 1/1/1900 to yesterday.
22+
23+
```{r}
24+
startDate = as.Date(Sys.Date()-15,"%Y-%m-%d")
25+
endDate = as.Date(Sys.Date()-5,"%Y-%m-%d")
26+
```
27+
28+
Next the file name for the netCDF grids need to be defined. Here we'll just use temporary files. You should change this to a non-temporary file name and folder.
29+
```{r}
30+
# Set names for netCDF files (in the system temp. directory).
31+
ncdfFilename = tempfile(fileext='.nc')
32+
ncdfSolarFilename = tempfile(fileext='.nc')
33+
```
34+
35+
Now we're ready to download and build the netCDF grids.
36+
37+
The netCDF data files contains grids of daily rainfall, temperature, vapour pressure deficit and solar radiation for all of Australia.
38+
```{r}
39+
file.names = makeNetCDF_file(ncdfFilename=ncdfFilename,
40+
ncdfSolarFilename=ncdfSolarFilename,
41+
updateFrom=startDate, updateTo=endDate)
42+
```
43+
44+
## Update existing data grids
45+
46+
Now that we've built the above files, the updating can be demonstrated. Here we'll updating the data grids to one day ago.
47+
48+
Often users run _makeNetCDF_file_ once to build netCDF data files that contain all variables over the entire record length (which requires ~5GB disk storage) and then use the netCDFs grids for multiple projects, rather than re-building the netCDF for each project.
49+
50+
Also, if _makeNetCDF_file_ is run with the the file names pointing to existing files and _updateFrom=NA_ then the netCDF files will be updated to yesterday.
51+
```{r}
52+
file.names = makeNetCDF_file(ncdfFilename=ncdfFilename,
53+
ncdfSolarFilename=ncdfSolarFilename,
54+
updateFrom=NA)
55+
```

0 commit comments

Comments
 (0)