Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Procedure
Useful Tips
Claudia Vitolo1
1 Department of Civil and Environmental Engineering
Imperial College London
C.Vitolo R intro
Scope
Procedure
Useful Tips
Outline
1 Scope
What do you want to do?
What do you need?
2 Procedure
Data
Model
Results
3 Useful Tips
C.Vitolo R intro
Scope
What do you want to do?
Procedure
What do you need?
Useful Tips
Outline
1 Scope
What do you want to do?
What do you need?
2 Procedure
Data
Model
Results
3 Useful Tips
C.Vitolo R intro
Scope
What do you want to do?
Procedure
What do you need?
Useful Tips
Scope
C.Vitolo R intro
Scope
What do you want to do?
Procedure
What do you need?
Useful Tips
Scope
C.Vitolo R intro
Scope
What do you want to do?
Procedure
What do you need?
Useful Tips
Scope
C.Vitolo R intro
Scope
What do you want to do?
Procedure
What do you need?
Useful Tips
Outline
1 Scope
What do you want to do?
What do you need?
2 Procedure
Data
Model
Results
3 Useful Tips
C.Vitolo R intro
Scope
What do you want to do?
Procedure
What do you need?
Useful Tips
Let’s assume 1-4 are tables saved in text files, while parameters (5)
will be entered manually.
C.Vitolo R intro
Scope Data
Procedure Model
Useful Tips Results
Outline
1 Scope
What do you want to do?
What do you need?
2 Procedure
Data
Model
Results
3 Useful Tips
C.Vitolo R intro
Scope Data
Procedure Model
Useful Tips Results
Your data
Let’s say you have a text file (timeseries.csv) containing your time
series. . .
C.Vitolo R intro
Scope Data
Procedure Model
Useful Tips Results
Load data in R
R console
DATA <- read.csv("~/timeseries.csv",
header=TRUE,
sep=",")
Use the same command to read the tables containing delay function
and topographic index classes.
R console
parameters <- c("qs0"=,"lnTe"=,"m"=,"Sr0"=,"SrMax"=,
"td"=,"vch"=1000,"vr"=,"k0"=,"CD"=,"dt"=0.25)
C.Vitolo R intro
Scope Data
Procedure Model
Useful Tips Results
Plot data
R console
plot(DATA$rain,type="l",col="grey")
C.Vitolo R intro
Scope Data
Procedure Model
Useful Tips Results
Outline
1 Scope
What do you want to do?
What do you need?
2 Procedure
Data
Model
Results
3 Useful Tips
C.Vitolo R intro
Scope Data
Procedure Model
Useful Tips Results
R console
install.packages("topmodel")
library(topmodel)
Qsim <- topmodel(parameters, topidx, delay,
DATA$rain, DATA$ET0)
C.Vitolo R intro
Scope Data
Procedure Model
Useful Tips Results
Outline
1 Scope
What do you want to do?
What do you need?
2 Procedure
Data
Model
Results
3 Useful Tips
C.Vitolo R intro
Scope Data
Procedure Model
Useful Tips Results
C.Vitolo R intro
Scope Data
Procedure Model
Useful Tips Results
R console
write.csv(Qsim,
file="~/Qsim.csv",
row.names = FALSE)
C.Vitolo R intro
Scope
Procedure
Useful Tips
Useful Tips
Vectorization:
If your object ’parameters’ is a matrix rather than a vector, R will
run topmodel function as many times as the rows in the matrix.
Classes & Methods:
If Qobs is passed to the function, then NashSutcliffe efficiency is
automatically calculated.
R console
Qsim_mat <- topmodel(parameters, topidx,
delay, rain ,ET0)
NS <- topmodel(parameters, topidx,
delay, rain ,ET0, Qobs = Qobs)
C.Vitolo R intro
Appendix For Further Reading
Crawley, Michael J.
The R Book.
Wiley Publishing, 2007.
C.Vitolo R intro