Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.93 KB | None | 0 0
  1. library(tidyverse)
  2.  
  3. rain_design <- 90.9
  4. t_pattern <- c(4.1, 8.0, 11.0, 23.3, 15.3, 8.1, 7.0, 7.0, 5.1, 6.1, 3.1, 1.9)
  5. t_step <- 0.5
  6. t_step_count <- 1:length(t_pattern)
  7. t_hour <- t_step_count * t_step
  8. hyeto <- t_pattern * rain_design/100
  9.  
  10. hyeto_df <- data_frame(t_step_count, t_hour, rain = hyeto)
  11. hyeto_df
  12.  
  13.  
  14. # Chart the hyetograph
  15.  
  16. hyeto_df %>%
  17. ggplot(aes( x = t_step_count )) +
  18. geom_bar(aes(y = rain), stat = 'identity', fill = 'blue', width = 1, colour = 'black') +
  19. ylab("Rainfall (mm)") +
  20. scale_x_continuous(name = "Time (hours)",
  21. breaks = c(t_step, t_step_count + t_step),
  22. labels = c(0, t_hour)) + # some fiddling here to get the x-axis labelling correct
  23. theme_gray(base_size = 14)
  24.  
  25.  
  26. # Function to remove initial loss from a hyetograph
  27. #
  28. # Arguments
  29.  
  30. # Hyeto = hyetograph (mm of rain for 1 or more time steps)
  31. # IL = Initial Loss (mm)
  32.  
  33. Remove_IL <- function(Hyeto, IL){
  34.  
  35. # IL <- 1
  36. # Hyeto <- c(30, 7, 4, 3, 7, 20, 15, 3)
  37. # #
  38. if(sum(Hyeto) < IL) {
  39. warning('Initial loss is not satisfied')
  40. Hyeto[] <- 0
  41. return(Hyeto)
  42. }
  43.  
  44. rain_cum <- cumsum(Hyeto)
  45.  
  46. tzero <- min(which(rain_cum > IL)) - 1
  47.  
  48. if(tzero == 0) {
  49. Hyeto[1] <- Hyeto[1] - IL
  50. return(Hyeto)
  51. }
  52.  
  53. Hyeto[tzero + 1] <- Hyeto[tzero + 1] - (IL - rain_cum[tzero])
  54. Hyeto[1:tzero] <- 0
  55. Hyeto
  56.  
  57. }
  58.  
  59. # Function to remove continuing loss from a hyetograph
  60.  
  61. # Arguments
  62. # Hyetograph - rainfall for each time step
  63. # CL - continuing loss in mm/h
  64. # t_step - length of each time step in hours
  65.  
  66. Remove_CL <- function(Hyeto, CL, t_step) {
  67.  
  68. CL_t_step = CL * t_step # Continuing loss per time step
  69. Hyeto <- Hyeto - CL_t_step
  70. Hyeto[Hyeto < 0] <- 0
  71. Hyeto
  72.  
  73.  
  74. }
  75.  
  76.  
  77. # Plot rainfall excess hyetograph
  78.  
  79. hyeto_df %>%
  80. mutate(rain_IL = Remove_IL(rain, 10),
  81. rain_ILCL = Remove_CL(rain_IL, 2, 0.5)) %>%
  82. ggplot(aes( x = t_step_count)) +
  83. geom_bar(aes(y = rain), stat = 'identity', fill = 'white', width = 1, colour = 'black') +
  84. geom_bar(aes(y = rain_IL), stat = 'identity', fill = 'yellow', width = 1, colour = 'black') +
  85. geom_bar(aes(y = rain_ILCL), stat = 'identity', fill = 'blue', width = 1, colour = 'black') +
  86. ylab("Rainfall (mm)") +
  87. scale_x_continuous(name = "Time (hours)",
  88. breaks = c(t_step, t_step_count + t_step),
  89. labels = c(0, t_hour)) + # some fiddling here to get the x-axis labelling correct
  90. annotate(geom = 'rect', xmin = 8, xmax = 8.5, ymin = 20, ymax = 21, fill = 'white', colour = 'black') +
  91. annotate(geom = 'text', x = 8.6, y = 20.5, hjust = 0, label = 'Initial Loss' ) +
  92. annotate(geom = 'rect', xmin = 8, xmax = 8.5, ymin = 18.5, ymax = 19.5, fill = 'yellow', colour = 'black') +
  93. annotate(geom = 'text', x = 8.6, y = 19, hjust = 0, label = 'Continuing loss' ) +
  94. theme_gray(base_size = 14)
  95.  
  96. # Convert to a hydrograph
  97.  
  98. sub_area <- 78.7
  99. t_step = 0.5 # time step in hours
  100.  
  101. # Example calculation
  102.  
  103. hyeto_df %>%
  104. mutate(rain_IL = Remove_IL(rain, 10),
  105. rain_ILCL = Remove_CL(rain_IL, 2, 0.5)) %>%
  106. select(rain_ILCL) %>%
  107. unlist(use.names = FALSE) # pull out the rainfall excess
  108.  
  109. # [1] 0.0000 0.0000 8.9990 20.1797 12.9077 6.3629 5.3630 5.3630 3.6359 4.5449 1.8179 0.7271
  110.  
  111. # Rainfall in the 3rd time step is 8.9 mm
  112.  
  113. (8.999 / 0.5) * 1e-3 * 78.7 * 1e+6 / 3600
  114.  
  115. # Calculate the rainfall excess hydrograph
  116.  
  117. # Add an extra row to the bottom of the data frame so the flow returns to zero
  118. # and plot hydrograph
  119.  
  120. hyeto_df %>%
  121. mutate(rain_excess = Remove_CL(Remove_IL(rain, 10), 2, 0.5)) %>%
  122. add_row(t_step_count = 13,
  123. t_hour = 6.5,
  124. rain = 0,
  125. rain_excess = 0 ) %>%
  126. mutate(flow = (rain_excess/t_step) * sub_area * 1e3/3600) %>%
  127. ggplot(aes(x = t_hour, y = flow)) +
  128. geom_line(alpha = 0.5) +
  129. geom_point(shape = 21, color = 'grey', fill = 'blue', size = 3) +
  130. ylab(bquote('Flow ('*m^-3~s^-1*')')) +
  131. xlab('Time (hour)') +
  132. theme_gray(base_size = 14)
  133.  
  134.  
  135.  
  136. hyeto_df %>%
  137. mutate(rain_excess = Remove_CL(Remove_IL(rain, 10), 2, 0.5)) %>%
  138. add_row(t_step_count = 13,
  139. t_hour = 6.5,
  140. rain = 0,
  141. rain_excess = 0 ) %>%
  142. mutate(flow = (rain_excess/t_step) * sub_area * 1e3/3600)
  143.  
  144. # # A tibble: 13 × 5
  145. # t_step_count t_hour rain rain_excess flow
  146. # <dbl> <dbl> <dbl> <dbl> <dbl>
  147. # 1 1 0.5 3.7269 0.0000 0.00000
  148. # 2 2 1.0 7.2720 0.0000 0.00000
  149. # 3 3 1.5 9.9990 8.9990 393.45628
  150. # 4 4 2.0 21.1797 20.1797 882.30133
  151. # 5 5 2.5 13.9077 12.9077 564.35333
  152. # 6 6 3.0 7.3629 6.3629 278.20013
  153. # 7 7 3.5 6.3630 5.3630 234.48228
  154. # 8 8 4.0 6.3630 5.3630 234.48228
  155. # 9 9 4.5 4.6359 3.6359 158.96963
  156. # 10 10 5.0 5.5449 4.5449 198.71313
  157. # 11 11 5.5 2.8179 1.8179 79.48263
  158. # 12 12 6.0 1.7271 0.7271 31.79043
  159. # 13 13 6.5 0.0000 0.0000 0.00000
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement