27 March 2014

[R] Hydromad Cikapundung (1)

(the output: P=precipitation (mm), Q=river discharge (L/sec), E=Max daily temp (oC) from 2007-2010)


This will be the first post on the Hydromad Package Practice
The analysis used Cikapundung dataset and R code from Willem Vervoort's Class (http://sydney.edu.au/agriculture/staff/vervoort/index.shtml)

-------------------------------------

# Hydromad practical (based on Cikapundung data and Willem's code)

setwd("C:/Users/dira0651/Downloads/week3lwsc3007")

# load the hydromad package
library(hydromad)

# read flow data
Flow <- read.csv("flowlembang.csv")
head(Flow)

# Convert the date column
Flow$Date <- as.Date(Flow[,1], "%m/%d/%Y")

# Choose my flow (use only st1 dataset)
My.Flow <- dat
a.frame(Date=Flow$Date,
                      Flow=Flow$st1)
head(My.Flow)

# convert flow in ML/day to mm using
# Hydromad tool
# My.Flow$Flow <- convertFlow(My.Flow$Flow,
                            from="ML",area.km2=0.147)
# head(My.Flow)

# load in the rainfall (with no missing data)
Rain <- read.csv("rainlembang.csv")
head(Rain)

# force colnames
colnames(Rain) <- c("Date", "Rain")
Rain$Date <- as.Date(Rain[,1],"%m/%d/%Y")
head(Rain)

# same thing with temperature
Temp <- read.csv("templembang.csv")
Temp$Date <- as.Date(Temp[,1],"%m/%d/%Y")
head(Temp)

# use package zoo
library(zoo)
tsQ <- zoo(My.Flow$Flow,
           order.by=My.Flow$Date,frequency=1)
tsP <- zoo(Rain$Rain,
           order.by=Rain$Date,frequency=1)
tsT <- zoo(Temp$MaxT,
           order.by=Temp$Date,frequency=1)

# merge
Cikapundung <- merge(P=tsP, Q=tsQ, E=tsT, all=F)

# make a quick plot
xyplot(Cikapundung)
---------------------------

@dasaptaerwin

No comments: