Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
hydrocodes authored Aug 11, 2021
1 parent 4bb4189 commit 2a6e91c
Show file tree
Hide file tree
Showing 10 changed files with 385 additions and 0 deletions.
10 changes: 10 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Package: hydRopUrban
Type: Package
Title: hydRopUrban
Version: 1.0
Author: Pedro Rau
Maintainer: Pedro Rau <pedro.rau.ing@gmail.com>
Description: An R package for easy calculations in urban hydrology
License: GPL-2
Encoding: UTF-8
LazyData: true
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export(rational)
export(rationalm)
export(rationalu)
export(caquots)
export(caquotp)
export(mcunge)
227 changes: 227 additions & 0 deletions R/hydRopUrban.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
#' @title rational
#' @description Discharge time series by the rational method
#' @param data A dataframe containing drainage units parameters: Runoff coefficient (c), intensity in mm/hr (i), area in km2 (A) and time of concentration in hr (Tc)
#' @param dt A numeric value: Time interval in hours
#' @return Maximal discharges by drainage unit, hydrograph plots and output file with discharge series in m3/s
#' @examples rational(data, dt)
#' @export
rational <- function(data,dt)
{ Qp <- (data$c)*(data$i)*(data$A)/3.6
Tc <- data$Tc
q1 <- list()
q3 <- list()
qls <- list()
for (h in 1:length(Qp)){
q1[[h]] <- seq(0,Qp[h],dt*Qp[h]/Tc[h])
q3[[h]] <- seq(Qp[h]-dt*Qp[h]/(Tc[h]),0,-dt*Qp[h]/(Tc[h]))
qls[[h]] <- c(q1[[h]],q3[[h]])
}
n.obs <- sapply(qls, length)
seq.max <- seq_len(max(n.obs))
mat <- t(sapply(qls, "[", i = seq.max))
mat[is.na(mat)] <- 0
hydr <- colSums(mat)
x <- seq(0,dt*(length(hydr)-1),dt)
plot(x,hydr, type="l", lwd=2, xlab="Hours", ylab="Discharge (m3/s)")
for (g in 1:length(Qp)){
lines(x,mat[g,], type="l", lty=2)
print(max(mat[g,]))
}
df <- data.frame(Hours=x,Discharge=hydr)
write.table(df,file=output, sep = "\t", row.names = FALSE, col.names = TRUE)
sprintf("Qpeak = %f m3/s, Volume = %f m3", max(hydr), sum(hydr)*dt*60*60)
}

#' @title rationalm
#' @description Discharge time series by the modified rational method
#' @param data A dataframe containing drainage units parameters: Runoff coefficient (c), intensity in mm/hr (i), area in km2 (A) and time of concentration in hr (Tc)
#' @param D A numeric value: Event duration in hr
#' @param dt A numeric value: Time interval in hours
#' @return Maximal discharges by drainage unit, hydrograph plots and output file with discharge series in m3/s
#' @examples rationalm(data, D, dt)
#' @export
rationalm <- function(data,D,dt)
{ Qp <- (data$c)*(data$i)*(data$A)/3.6
Tc <- data$Tc
q1 <- list()
q2 <- list()
q3 <- list()
qls <- list()
j <- c()
D <- round(D,1)
for (h in 1:length(Qp)){
if (D > Tc[h]) {
q1[[h]] <- seq(0,Qp[h],dt*Qp[h]/Tc[h])
j[h] <- round((D-Tc[h]),1)/dt
q2[[h]] <- rep(Qp[h],j[h])
q3[[h]] <- seq(Qp[h],0,-dt*Qp[h]/(1.5*Tc[h]))
qls[[h]] <- c(q1[[h]],q2[[h]],q3[[h]])
} else {
if (D < Tc[h]){
q1[[h]] <- seq(0,Qp[h]*D/Tc[h],dt*Qp[h]/Tc[h])
q3[[h]] <- seq((Qp[h]*D/Tc[h])-dt*Qp[h]/(1.5*Tc[h]),0,-dt*Qp[h]/(1.5*Tc[h]))
qls[[h]] <- c(q1[[h]],q3[[h]])
}
else {
q1[[h]] <- seq(0,Qp[h],dt*Qp[h]/Tc[h])
q3[[h]] <- seq(Qp[h]-dt*Qp[h]/(1.5*Tc[h]),0,-dt*Qp[h]/(1.5*Tc[h]))
qls[[h]] <- c(q1[[h]],q3[[h]])
}
}
}
n.obs <- sapply(qls, length)
seq.max <- seq_len(max(n.obs))
mat <- t(sapply(qls, "[", i = seq.max))
mat[is.na(mat)] <- 0
hydr <- colSums(mat)
x <- seq(0,dt*(length(hydr)-1),dt)
plot(x,hydr, type="l", lwd=2, xlab="Hours", ylab="Discharge (m3/s)")
for (g in 1:length(Qp)){
lines(x,mat[g,], type="l", lty=2)
print(max(mat[g,]))
}
df <- data.frame(Hours=x,Discharge=hydr)
write.table(df,file=output, sep = "\t", row.names = FALSE, col.names = TRUE)
sprintf("Qpeak = %f m3/s, Volume = %f m3", max(hydr), sum(hydr)*dt*60*60)
}

#' @title rationalu
#' @description Discharge time series by the universal rational method
#' @param data A dataframe containing drainage units parameters: Runoff coefficient (c), intensity in mm/hr (i), area in Km2 (A) and time of concentration in hr (Tc)
#' @param dt A numeric value: Time interval in hours
#' @return Maximal discharges by drainage unit, hydrograph plots and output file with discharge series in m3/s
#' @examples rationalu(data, dt)
#' @export
rationalu <- function(data,dt)
{ Qp <- (data$c)*(data$i)*(data$A)/3.6
Tc <- data$Tc
q1 <- list()
q2 <- list()
q3 <- list()
q4 <- list()
q5 <- list()
q6 <- list()
q7 <- list()
q8 <- list()
q9 <- list()
q10 <- list()
q11 <- list()
qls <- list()
for (h in 1:length(Qp)){
q1[[h]] <- seq(0,0.21*Qp[h],dt*0.21*Qp[h]/Tc[h])
q2[[h]] <- seq(0.21*Qp[h]+dt*0.09*Qp[h]/Tc[h],0.3*Qp[h],dt*0.09*Qp[h]/Tc[h])
q3[[h]] <- seq(0.3*Qp[h]+dt*0.7*Qp[h]/Tc[h],Qp[h],dt*0.7*Qp[h]/Tc[h])
q4[[h]] <- seq(Qp[h]-dt*0.46*Qp[h]/Tc[h],0.54*Qp[h],-dt*0.46*Qp[h]/Tc[h])
q5[[h]] <- seq(0.54*Qp[h]-dt*0.15*Qp[h]/Tc[h],0.39*Qp[h],-dt*0.15*Qp[h]/Tc[h])
q6[[h]] <- seq(0.39*Qp[h]-dt*0.14*Qp[h]/Tc[h],0.25*Qp[h],-dt*0.14*Qp[h]/Tc[h])
q7[[h]] <- seq(0.25*Qp[h]-dt*0.07*Qp[h]/Tc[h],0.18*Qp[h],-dt*0.07*Qp[h]/Tc[h])
q8[[h]] <- seq(0.18*Qp[h]-dt*0.03*Qp[h]/Tc[h],0.15*Qp[h],-dt*0.03*Qp[h]/Tc[h])
q9[[h]] <- seq(0.15*Qp[h]-dt*0.01*Qp[h]/Tc[h],0.14*Qp[h],-dt*0.01*Qp[h]/Tc[h])
q10[[h]] <- seq(0.14*Qp[h]-dt*0.01*Qp[h]/Tc[h],0.13*Qp[h],-dt*0.01*Qp[h]/Tc[h])
q11[[h]] <- seq(0.13*Qp[h]-dt*0.13*Qp[h]/Tc[h],0,-dt*0.13*Qp[h]/Tc[h])
qls[[h]] <- c(q1[[h]],q2[[h]],q3[[h]],q4[[h]],q5[[h]],q6[[h]],q7[[h]],q8[[h]],q9[[h]],q10[[h]],q11[[h]])
}
n.obs <- sapply(qls, length)
seq.max <- seq_len(max(n.obs))
mat <- t(sapply(qls, "[", i = seq.max))
mat[is.na(mat)] <- 0
hydr <- colSums(mat)
x <- seq(0,dt*(length(hydr)-1),dt)
plot(x,hydr, type="l", lwd=2, xlab="Hours", ylab="Discharge (m3/s)")
for (g in 1:length(Qp)){
lines(x,mat[g,], type="l", lty=2)
print(max(mat[g,]))
}
df <- data.frame(Hours=x,Discharge=hydr)
write.table(df,file=output, sep = "\t", row.names = FALSE, col.names = TRUE)
sprintf("Qpeak = %f m3/s, Volume = %f m3", max(hydr), sum(hydr)*dt*60*60)
}

#' @title caquots
#' @description Maximal discharge by Caquot for serial drainage units
#' @param data A dataframe containing drainage units parameters: Runoff coefficient (c), slope (S), area in Ha (A) and travel length in m (L)
#' @param a A numeric value: Exponent from Montana IDF equation a*D^b
#' @param b A numeric value: Exponent from Montana IDF equation a*D^b
#' @return Maximal discharge by drainage unit, total discharge and equivalent values
#' @examples caquots(data,a,b)
#' @export
caquots <- function(data, a, b)
{ k <- (0.5^b)*a/6.6
u <- 1 + 0.287*b
v <- -0.41*b
w <- 0.95 + 0.507*b
E <- (data$L)/sqrt(data$A*10000)
m <- (E/2)^(0.7*b)
Qp <- m*(k^(1/u))*((data$S)^(v/u))*((data$c)^(1/u))*((data$A)^(w/u))
A <- sum(data$A)
c <- sum((data$c)*(data$A))/sum(data$A)
S <- (sum(data$L)/sum((data$L)/sqrt(data$S)))^2
Es <- sum(data$L)/sqrt(sum(data$A*10000))
ms <- (Es/2)^(0.7*b)
Qps <- ms*(k^(1/u))*(S^(v/u))*(c^(1/u))*(A^(w/u))
df <- data.frame(c,S,A,L=max(data$L))
print(Qp)
print(df)
sprintf("Qpeak = %f m3/s", Qps)
}

#' @title caquotp
#' @description Maximal discharge by Caquot for parallel drainage units
#' @param data A dataframe containing drainage units parameters: Runoff coefficient (c), slope (S), area in Ha (A) and travel length in m (L)
#' @param a A numeric value: Exponent from Montana IDF equation a*D^b
#' @param b A numeric value: Exponent from Montana IDF equation a*D^b
#' @return Maximal discharge by drainage unit, total discharge and equivalent values
#' @examples caquotp(data,a,b)
#' @export
caquotp <- function(data, a, b)
{ k <- (0.5^b)*a/6.6
u <- 1 + 0.287*b
v <- -0.41*b
w <- 0.95 + 0.507*b
E <- (data$L)/sqrt(data$A*10000)
m <- (E/2)^(0.7*b)
Qp <- m*(k^(1/u))*((data$S)^(v/u))*((data$c)^(1/u))*((data$A)^(w/u))
A <- sum(data$A)
c <- sum((data$c)*(data$A))/sum(data$A)
S <- sum((data$S)*Qp)/sum(Qp)
df1 <- data.frame(L=data$L,Qp)
Es <- df1$L[df1$Qp==max(Qp)]/sqrt(sum(data$A*10000))
ms <- (Es/2)^(0.7*b)
Qps <- ms*(k^(1/u))*(S^(v/u))*(c^(1/u))*(A^(w/u))
df <- data.frame(c,S,A,L=sum(data$L))
print(Qp)
print(df)
sprintf("Qpeak = %f m3/s", Qps)
}

#' @title mcunge
#' @description Hydrograph routing through an open urban drainage channel
#' @param inflow A vector: Input hydrograph in m3/s
#' @param Qo A numeric value: Reference discharge in m3/s
#' @param To A numeric value: Reference open width in m
#' @param Vo A numeric value: Reference velocity in m/s
#' @param L A numeric value: Travel length in m
#' @param m A numeric value: Q-A relationship exponent of the hydraulic section Q=e*A^m
#' @param dt A numeric value: Time interval in hours
#' @param init A numeric value: Initial outflow discharge
#' @return Routed hydrograph and discharge time series
#' @examples mcunge(inflow, Qo, To, Vo, L, m, dt, init)
#' @export
mcunge <- function(inflow, Qo, To, Vo, L, m, dt, init){
x <- 0.5*(1-(Qo/To)/(So*m*Vo*L))
K <- L/(m*Vo)
c0 <- (-K*x + 0.5*dt*3600)/(K - K*x + 0.5*dt*3600)
c1 <- (K*x + 0.5*dt*3600)/(K - K*x + 0.5*dt*3600)
c2 <- (K - K*x - 0.5*dt*3600)/(K - K*x + 0.5*dt*3600)
outflow <- rep(0, length(inflow))
outflow[1] <- init
for (i in 2:length(inflow)){
outflow[i] <- c0*inflow[i] + c1*inflow[i-1] + c2*outflow[i-1]
}
time <- seq(0,(length(inflow)-1)*dt,dt)
df <- data.frame(Hours=time, Outflow=outflow)
write.table(df,file=output, sep = "\t", row.names = FALSE, col.names = TRUE)
plot(time,inflow,type="l", lwd=2, xlab="Hours", ylab="Discharge (m3/s)")
lines(time,outflow,type="l", lwd=2, lty=3)
sprintf("Qpeak_in = %f m3/s, Qpeak_out = %f m3/s", max(inflow), max(outflow))
}
22 changes: 22 additions & 0 deletions hydRopUrban.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Version: 1.0

RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8

RnwWeave: knitr
LaTeX: pdfLaTeX

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageCheckArgs: --as-cran
PackageRoxygenize: rd,collate,namespace
19 changes: 19 additions & 0 deletions man/caquotp.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
\name{caquotp}
\alias{caquotp}
\title{caquotp: Method of Caquot for parallel drainage units}
\usage{
caquotp(data, a, b)
}
\description{
Maximal discharge by Caquot's method for parallel drainage units and equivalent values for unit drainage resulting.
}
\arguments{
data: A dataframe: containing drainage units parameters: Runoff coefficient (c), slope (S), area in Ha (A) and travel length in m (L)
a: A numeric value: Exponent from Montana IDF equation: a*Duration^b
b: A numeric value: Exponent from Montana IDF equation: a*Duration^b
}
\examples{
caquotp(data=database2, a=3.1, b=-0.64)
}
19 changes: 19 additions & 0 deletions man/caquots.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
\name{caquots}
\alias{caquots}
\title{caquots: Method of Caquot for serial drainage units}
\usage{
caquots(data, a, b)
}
\description{
Maximal discharge by Caquot's method for serial drainage units and equivalent values for unit drainage resulting.
}
\arguments{
data: A dataframe: containing drainage units parameters: Runoff coefficient (c), slope (S), area in Ha (A) and travel length in m (L)
a: A numeric value: Exponent from Montana IDF equation: a*Duration^b
b: A numeric value: Exponent from Montana IDF equation: a*Duration^b
}
\examples{
caquots(data=database2, a=3.1, b=-0.64)
}
29 changes: 29 additions & 0 deletions man/mcunge.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
\name{mcunge}
\alias{mcunge}
\title{mcunge: Method of Muskingum-Cunge for urban channel routing}
\usage{
mcunge(inflow, Qo, To, Vo, L, m, dt, init)
}
\description{
Outflow discharge through a channel routing by the method of Muskingum-Cunge.
}
\arguments{
inflow: A vector: Input hydrograph in m3/s

Qo: A numeric value: Reference discharge in m3/s

To: A numeric value: Reference open width in m

Vo: A numeric value: Reference velocity in m/s

L: A numeric value: Travel length in m

m: A numeric value: Q-A relationship exponent of the hydraulic section Q=e*A^m

dt: A numeric value: Time interval in hours

init: A numeric value: Initial outflow discharge
}
\examples{
mcunge(inflow=database3, Qo, To, Vo, L, m=1.33, dt=0.05, init)
}
17 changes: 17 additions & 0 deletions man/rational.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
\name{rational}
\alias{rational}
\title{rational: Standard rational method}
\usage{
rational(data, dt)
}
\description{
Estimation of discharges time series by the standard rational method with a triangular hydrograph with a recession of 1xTc, without considering a storm duration
}
\arguments{
data: A dataframe: containing drainage units parameters: Runoff coefficient (c), intensity in mm/hr (i), area in km2 (A) and time of concentration in hr (Tc)

dt: A numeric value: Time interval in hours for plotting (e.g. 3-min as 0.05)
}
\examples{
rational(data=database1, dt=0.05)
}
19 changes: 19 additions & 0 deletions man/rationalm.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
\name{rationalm}
\alias{rationalm}
\title{rationalm: Modified rational method}
\usage{
rationalm(data, D, dt)
}
\description{
Estimation of discharges time series by the modified rational method with a triangular hydrograph with a recession of 1.5xTc, and considering a storm event duration.
}
\arguments{
data: A dataframe: containing drainage units parameters: Runoff coefficient (c), intensity in mm/hr (i), area in km2 (A) and time of concentration in hr (Tc)

D: A numeric value: Event duration in hr

dt: A numeric value: Time interval in hours for plotting (e.g. 3-min as 0.05)
}
\examples{
rationalm(data=database1, D=1, dt=0.05)
}
17 changes: 17 additions & 0 deletions man/rationalu.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
\name{rationalu}
\alias{rationalu}
\title{rationalu: Universal rational method}
\usage{
rationalu(data, dt)
}
\description{
Estimation of discharges time series by the universal rational method with a synthetic hydrograph for urban catchments.
}
\arguments{
data: A dataframe: containing drainage units parameters: Runoff coefficient (c), intensity in mm/hr (i), area in km2 (A) and time of concentration in hr (Tc)

dt: A numeric value: Time interval in hours for plotting (e.g. 3-min as 0.05)
}
\examples{
rationalu(data=database1, dt=0.05)
}

0 comments on commit 2a6e91c

Please sign in to comment.