Git Product home page Git Product logo

keys.lid's Introduction

R-CMD-check pkgdown codecov Project Status CRAN_Status_Badge

keys.lid

R Package for Simulating the Impact of Different LIDs (Low Impact Development) under Varying Climate Boundary Conditions in China on annual VRR (Volume Rainfall Retention).

Installation

For details on how to install KWB-R packages checkout our installation tutorial.

### Optionally: specify GitHub Personal Access Token (GITHUB_PAT)
### See here why this might be important for you:
### https://kwb-r.github.io/kwb.pkgbuild/articles/install.html#set-your-github_pat

# Sys.setenv(GITHUB_PAT = "mysecret_access_token")

# Install package "remotes" from CRAN
if (! require("remotes")) {
  install.packages("remotes", repos = "https://cloud.r-project.org")
}

# Install KWB package 'keys.lid' from GitHub
remotes::install_github("KWB-R/keys.lid")

Documentation

Release: https://kwb-r.github.io/keys.lid

Development: https://kwb-r.github.io/keys.lid/dev

keys.lid's People

Contributors

mrustl avatar robetatis avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

keys.lid's Issues

warning in makeRainfallRunoffEvent()

Running makeRainfallRunoffEvents https://github.com/KWB-R/LIDsensitivity/blob/clean/approachValidation.R#L73
produces the following warning:

> obs.neubrandenburg$rain_runoff <- makeRainfallRunoffEvents(
+   rainfalldata = obs.neubrandenburg$rain,
+   runoffdata = obs.neubrandenburg$runoff)
Warnmeldung:
In isValidTimestampSequence(timestamps, checks = c("timestep", "sorted")) :
  
*** The time step between timestamps is not unique: 5, 2, 3, 9, 1, 4 (mins)

Might this be somehow problematic or does this not impact the results?

fix "validation" vignette

> obs.neubrandenburg <- keys.lid::readObservations(
+   subfolder = paths$green_roof_model_neubrandenburg,
+   rainFile = 'obs_rain_5min_Neubrandenburg.txt',
+   runoffFile = 'obs_runoff_5min_Neubrandenburg.txt',
+   temperatureFile = 'obs_temperature_10min_Neubrandenburg.txt',
+   dateTimetz = 'Etc/GMT-1', 
+   dateTimeformat = '%Y-%m-%d %H:%M:%S',
+   to_mmperhour = list(rain=1/(5/60), runoff=1/(5/60)), 
+   NAval = list(rain = -999, runoff = -999, temperature = -999))
Fehler in scan(file = file, what = what, sep = sep, quote = quote, dec = dec,  : 
  line 1 did not have 2 elements

feat: use rain data from satellite data

as BSWT data is lacking winter half year (no impact for Beijing, but for other cities!)

Either use:
GoogleEarthEngine: GSMaP Operational (1h rainfall 2000 - current)

https://developers.google.com/earth-engine/datasets/catalog/JAXA_GPM_L3_GSMaP_v6_operational
https://developers.google.com/earth-engine/datasets/catalog/JAXA_GPM_L3_GSMaP_v6_reanalysis

Or:
ERA-5 Copernicus Data
https://cds.climate.copernicus.eu/cdsapp#!/dataset/reanalysis-era5-single-levels?tab=overview.

R Package for Interfacting Copernicus Climate Store:
https://cran.r-project.org/web/packages/ecmwfr/v

feat: apply for 4 LIDs

  • bioretention-cell
  • green roof
  • permeable pavement
  • infiltration swale (soil, drainage mat, and so on ....)
  • rain barrel (typical size, extraction rate, overflow crest)

Literature: "scopus SWMM LID parameterisation"

bug: modified "BWSTI_Zone1.inp" not running in swmm 5.1.015

don`t know whether its due to wrong input file, newer swmm version or a real bug?

### install package dependencies
cran_pkgs <- c("gdata", "remotes", "swmmr", "sessioninfo", "xts")
install.packages(pkgs = cran_pkgs, repos = "https://cran.rstudio.com")
#> Installing packages into 'C:/Users/mrustl/Documents/R/win-library/4.0'
#> (as 'lib' is unspecified)
#> package 'gdata' successfully unpacked and MD5 sums checked
#> package 'remotes' successfully unpacked and MD5 sums checked
#> package 'swmmr' successfully unpacked and MD5 sums checked
#> package 'sessioninfo' successfully unpacked and MD5 sums checked
#> package 'xts' successfully unpacked and MD5 sums checked
#> 
#> The downloaded binary packages are in
#>  C:\Users\mrustl\AppData\Local\Temp\Rtmp4UTqOi\downloaded_packages

remotes::install_github("kwb-r/kwb.utils")
#> Using github PAT from envvar GITHUB_PAT
#> Skipping install of 'kwb.utils' from a github remote, the SHA1 (c9f447ab) has not changed since last install.
#>   Use `force = TRUE` to force installation

### Download "EPA SWMM 5.1.015.7z" from KWB cloud 
### "https://cloud.kompetenz-wasser.de/index.php/f/182136"
### and extract to "C:/_UserProg/EPA SWMM 5.1.015/"

### define paths
paths_list <- list(
  root_data = "//medusa/projekte$/WWT_Department/Projects/KEYS/Data-Work packages/WP1_sponge_city_elements/_DataAnalysis",
  root_swmm = "C:/_UserProg/",
  swmm_version = "5.1.015",
  swmm_exe = "<root_swmm>/EPA SWMM <swmm_version>/swmm5.exe",
  lid_models = "<root_data>/LIDmodels",
  green_roof = "<lid_models>/greenRoof"
)

### at kwb:
paths <- kwb.utils::resolve(paths_list)

### at home:
if (FALSE) {
paths <- kwb.utils::resolve(paths_list,   
                            root_data = "C:/kwb/projects/keys/data/_DataAnalysis")
}

# create swmm model


# read swmm model


# define parameter intervals


# run sensitivity analysis, input time series ideally should cover several years


# write out results


# plot results


# annual VRR vs weather vs. lid parameters



# read swmm input file
swmm_inp <- file.path(paths$green_roof, "BWSTI_Zone1/BWSTI_Zone1.inp")
swmm_inp
#> [1] "//medusa/projekte$/WWT_Department/Projects/KEYS/Data-Work packages/WP1_sponge_city_elements/_DataAnalysis/LIDmodels/greenRoof/BWSTI_Zone1/BWSTI_Zone1.inp"
input <- swmmr::read_inp(x = swmm_inp)
#> Warning: Expected 9 pieces. Additional pieces discarded in 1 rows [1].
summary(input)
#> 
#> ** summary of swmm model structure ** 
#> infiltration   :     horton 
#> flow_units     :        lps 
#> flow_routing   :    kinwave 
#> start_date     : 04/06/2014 
#> end_date       : 11/21/2016 
#> raingages      :          1 
#> subcatchments  :          1 
#> aquifers       :          0 
#> snowpacks      :          1 
#> junctions      :          0 
#> outfalls       :          1 
#> dividers       :          0 
#> storage        :          0 
#> conduits       :          0 
#> pumps          :          0 
#> orifices       :          0 
#> weirs          :          0 
#> outlets        :          0 
#> controls       :          0 
#> pollutants     :          0 
#> landuses       :          0 
#> lid_controls   :          1 
#> treatment      :          0 
#> *************************************

# length of the loop
l <- 1000

# data frame to write parameter values 
cal_names<-c("Run", "Soil_Thickness", "Porosity", "Field_Capacity", "Wilting_Point", "Conductivity", "Conductivity_Slope", "Suction_Head", # Soil Parameters
             "Drain_Thickness", "Void_Fraction", "Roughness", # Drainage Mat Parameters 
             "Sum_R"# Total Runoff
             )

cal_results <- data.frame(matrix(
  data = NA,
  ncol = length(cal_names),
  nrow = l))

cal_col <- colnames(cal_results)

cal_results <- gdata::rename.vars(cal_results,cal_col, cal_names)
#> 
#> Changing in cal_results                                                                           
#> From: X1  X2             X3       X4             X5            X6          
#> To:   Run Soil_Thickness Porosity Field_Capacity Wilting_Point Conductivity
#>                                                                              
#> From: X7                 X8           X9              X10           X11      
#> To:   Conductivity_Slope Suction_Head Drain_Thickness Void_Fraction Roughness
#>            
#> From: X12  
#> To:   Sum_R


# time period
seq <- seq.POSIXt(ISOdate(2008,4,30,00,05,tz="UTC"),
                  ISOdate(2019,10,15,23,00,tz="UTC"),
                  by="5 min")


# runoff results of the green roof
for (i in 1:l){
  
  # set parameters for simulation
  input$lid_controls$Par1[3] <- runif(n = 1, min = 80, max = 120) # Soil Thickness
  input$lid_controls$Par2[3] <- runif(n = 1, min = 0.45, max = 0.65) # Porosity
  input$lid_controls$Par3[3] <- runif(n = 1, min = 0.35, max = 0.55) # Field Capacity
  input$lid_controls$Par4[3] <- runif(n = 1, min = 0.05, max = 0.20) # Wilting Point
  input$lid_controls$Par5[3] <- runif(n = 1, min = 50, max = 350) # Conductivity
  input$lid_controls$Par6[3] <- runif(n = 1, min = 30, max = 55) # Conductivity Slope
  input$lid_controls$Par7[3] <- runif(n = 1, min = 50, max = 100) # Suction Head
  input$lid_controls$Par1[4] <- runif(n = 1, min = 10, max = 50) # Storage Thickness
  input$lid_controls$Par2[4] <- runif(n = 1, min = 0.3, max = 0.5) # Void Fraction
  input$lid_controls$Par3[4] <- runif(n = 1, min = 0.01, max = 0.03) # Roughness
  
  # write values in the dataframe
  cal_results$Run[i] <- i
  
  cal_results$Soil_Thickness[i] <- input$lid_controls$Par1[3]
  cal_results$Porosity[i] <- input$lid_controls$Par2[3]
  cal_results$Field_Capacity[i] <- input$lid_controls$Par3[3] 
  cal_results$Wilting_Point[i] <- input$lid_controls$Par4[3]
  cal_results$Conductivity[i] <- input$lid_controls$Par5[3]
  cal_results$Conductivity_Slope[i] <- input$lid_controls$Par6[3]
  cal_results$Suction_Head[i] <- input$lid_controls$Par7[3]
  cal_results$Drain_Thickness[i] <- input$lid_controls$Par1[4]
  cal_results$Void_Fraction[i] <- input$lid_controls$Par2[4]
  cal_results$Roughness[i] <- input$lid_controls$Par3[4]
  
  # save the changed input file
  swmmr::write_inp(input,"Validation_Beijing.inp") 
  
  # run swimm with changed input file
  files <- swmmr::run_swmm(inp = "Validation_Beijing.inp",
                           exec = paths$swmm_exe) 
  
  # read out results for itype 3 = system and vIndex 4 = runoff 
  results <- swmmr::read_out(files$out, iType = 3, vIndex = c(4)) 
  
  # change timezone to UTC
  xts::tzone(results$system_variable$total_runoff) <- "UTC"
  
  # write model runoff in data frame
  runoff_sim <- list()

  # extract model runoff of entire simulation period
  runoff_sim <- data.frame(matrix(
    data = NA,
    ncol = 1,
    nrow = length(seq)))
  
  colnames(runoff_sim)<-"sim" 
  
  runoff_sim$DateTime <- seq
  
  runoff_sim$sim <- (as.numeric(coredata(results$system_variable$total_runoff)))*300/65
  
  ### calculate sum of Runoff
  sum_sim <- sum(runoff_sim$sim) 
  
  cal_results$Sum_R[i] <- sum_sim
 
  print(paste("Run",i,"of",l,"finished"),sep=" ")
}

#o  Retrieving project data
#... EPA-SWMM 5.1 (Build 5.1.15)
#... EPA-SWMM completed in 0.00 seconds. There are errors.

#> Warning in normalizePath(path.expand(path), winslash, mustWork): path[1]="./
#> Validation_Beijing.out": Das System kann die angegebene Datei nicht finden
#> Warning in swmmr::read_out(files$out, iType = 3, vIndex = c(4)): error reading
#> out file
#> Error in attr(x, "tzone") <- value: Versuch ein Attribut von NULL zu setzen

paths$swmm_exe
#[1] "C:/_UserProg/EPA SWMM 5.1.015/swmm5.exe"

sessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value                       
#>  version  R version 4.0.2 (2020-06-22)
#>  os       Windows 10 x64              
#>  system   i386, mingw32               
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  German_Germany.1252         
#>  ctype    German_Germany.1252         
#>  tz       Europe/Berlin               
#>  date     2020-11-13                  
#> 
#> - Packages -------------------------------------------------------------------
#>  package     * version date       lib source                          
#>  assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.0.2)                  
#>  cli           2.1.0   2020-10-12 [1] CRAN (R 4.0.3)                  
#>  crayon        1.3.4   2017-09-16 [1] CRAN (R 4.0.2)                  
#>  curl          4.3     2019-12-02 [1] CRAN (R 4.0.2)                  
#>  digest        0.6.27  2020-10-24 [1] CRAN (R 4.0.3)                  
#>  dplyr         1.0.2   2020-08-18 [1] CRAN (R 4.0.3)                  
#>  ellipsis      0.3.1   2020-05-15 [1] CRAN (R 4.0.2)                  
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 4.0.2)                  
#>  fansi         0.4.1   2020-01-08 [1] CRAN (R 4.0.2)                  
#>  gdata         2.18.0  2017-06-06 [1] CRAN (R 4.0.3)                  
#>  generics      0.1.0   2020-10-31 [1] CRAN (R 4.0.3)                  
#>  glue          1.4.2   2020-08-27 [1] CRAN (R 4.0.2)                  
#>  gtools        3.8.2   2020-03-31 [1] CRAN (R 4.0.3)                  
#>  highr         0.8     2019-03-20 [1] CRAN (R 4.0.2)                  
#>  hms           0.5.3   2020-01-08 [1] CRAN (R 4.0.2)                  
#>  htmltools     0.5.0   2020-06-16 [1] CRAN (R 4.0.2)                  
#>  knitr         1.30    2020-09-22 [1] CRAN (R 4.0.2)                  
#>  kwb.utils     0.7.0   2020-10-05 [1] Github (kwb-r/kwb.utils@c9f447a)
#>  lattice       0.20-41 2020-04-02 [1] CRAN (R 4.0.3)                  
#>  lifecycle     0.2.0   2020-03-06 [1] CRAN (R 4.0.2)                  
#>  magrittr      1.5     2014-11-22 [1] CRAN (R 4.0.2)                  
#>  pillar        1.4.6   2020-07-10 [1] CRAN (R 4.0.2)                  
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.0.2)                  
#>  purrr         0.3.4   2020-04-17 [1] CRAN (R 4.0.2)                  
#>  R6            2.5.0   2020-10-28 [1] CRAN (R 4.0.3)                  
#>  Rcpp          1.0.5   2020-07-06 [1] CRAN (R 4.0.2)                  
#>  readr         1.4.0   2020-10-05 [1] CRAN (R 4.0.2)                  
#>  remotes       2.2.0   2020-07-21 [1] CRAN (R 4.0.3)                  
#>  rlang         0.4.8   2020-10-08 [1] CRAN (R 4.0.3)                  
#>  rmarkdown     2.4     2020-09-30 [1] CRAN (R 4.0.2)                  
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 4.0.3)                  
#>  stringi       1.5.3   2020-09-09 [1] CRAN (R 4.0.2)                  
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 4.0.3)                  
#>  swmmr         0.9.1   2020-03-02 [1] CRAN (R 4.0.3)                  
#>  tibble        3.0.4   2020-10-12 [1] CRAN (R 4.0.3)                  
#>  tidyr         1.1.2   2020-08-27 [1] CRAN (R 4.0.2)                  
#>  tidyselect    1.1.0   2020-05-11 [1] CRAN (R 4.0.2)                  
#>  vctrs         0.3.4   2020-08-29 [1] CRAN (R 4.0.2)                  
#>  withr         2.3.0   2020-09-22 [1] CRAN (R 4.0.2)                  
#>  xfun          0.18    2020-09-29 [1] CRAN (R 4.0.2)                  
#>  xts           0.12.1  2020-09-09 [1] CRAN (R 4.0.3)                  
#>  yaml          2.2.1   2020-02-01 [1] CRAN (R 4.0.2)                  
#>  zoo           1.8-8   2020-05-02 [1] CRAN (R 4.0.2)                  
#> 
#> [1] C:/Users/mrustl/Documents/R/win-library/4.0
#> [2] C:/Program Files/R/R-4.0.2/library

Created on 2020-11-13 by the reprex package (v0.3.0)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.