All Topics |
Topic: “Weap + R + WhatsApp”
Author | Message |
---|
Subject: Weap + R + WhatsApp
Posted: 4/15/2022 Viewed: 9215 times
Dears,
I beggan to use Weap recently in a project that aims to access water availability at Paracatu Basin, Brazil. I'm using WEAP to create Scenarios of irrigation water Demand with diferent crop time and type, areas size at planning units. All of these with rainfall forecast. It is a hard work to do without programming. So i started to code in R (my birth language) based on "WEAP_Calibration_and_Ensamble_with_R_Tool" and VBA Examples at WEAP help. I achieve some progress which will be enough to achieve our goals. But im very interested in learn more about it since im doing a almost "try and fail" method without theorical knowledge of "COM Automation Server", VBA structure.... To do so i will created a Whats App group (https://chat.whatsapp.com/EeWWyeRzU3bHc6XS88oTAg) and i'm sharing the basic newbie R/WEAP code that i wrote. Maybe we can achieve some progress together. For WEAP developers: If there is any problem with this post, please let me know and i delete this post. Best Wishes. Arthur. #######Code #remotes::install_github("BSchamberger/RDCOMClient", ref = "main") library(RDCOMClient) require(dplyr) # "COM Communication Server" #Open Weap WEAP <- COMCreate("WEAP.WEAPApplication") #Connect with WEAP.Application Library - OpenWEAP WEAPVariables <- COMCreate("WEAP.WEAPVariables") #Connect with WEAPVariables Library WEAPBranch <- COMCreate("WEAP.WEAPBranch") #Connect with WEAPBranch Library WEAPScenarios <- COMCreate("WEAP.WEAPScenarios") #Connect with WEAPBranch Library #Weap Area to Work WEAP[["ActiveArea"]] = "insert WEAP Area here" #Set Base Year if you Wish WEAP[["BaseYear"]] <- 2005 WEAP[["EndYear"]] <- 2015 WEAP[["Verbose"]] WEAP[["NumTimeSteps"]] #Scenario which changes will be done WEAP[["ActiveScenario"]] = "Current Accounts" WEAP[["ActiveScenario"]] = "Reference" #All tree Brenchs with ID BranchesID <- WEAP[["Branches"]][["FullNameList"]] %>% strsplit(",") %>% unlist() %>% as.data.frame() %>% bind_cols(NumberID = seq(1:nrow(.))) %>% setNames(c("Branches", "NumberID")) BranchesID #Branch "3" Variables VariablesID3Branch <- WEAPBranch[["Children"]][[3]][["Variables"]][["NameList"]] %>% strsplit(",") %>% unlist() %>% as.data.frame() %>% bind_cols(NumberID = seq(1:nrow(.))) %>% setNames(c("Variables", "NumberID")) #Calculate Variable "5", "7" and "2" of Branch "3" #Just Examples. R returns an Erros but it works fine at WEAP WEAPBranch[["Children"]][[3]][["Variables"]][[5]][["Expression"]] = 1000 #Irrigated Area WEAPBranch[["Children"]][[3]][["Variables"]][[7]][["Expression"]] = 1.2 #Kc WEAPBranch[["Children"]][[3]][["Variables"]][[2]][["Expression"]] = 4 #Branches ID = 12 (River 1) Variables VariablesID12Branch <- WEAPBranch[["Children"]][[12]][["Variables"]][["NameList"]] %>% strsplit(",") %>% unlist() %>% as.data.frame() %>% bind_cols(NumberID = seq(1:nrow(.))) %>% setNames(c("Variables", "NumberID")) #Calculate Variable "2" of Branch "4" with fixed value #Just Examples. R returns an Erros but it works fine at WEAP WEAPBranch[["Children"]][[14]][["Variables"]][[2]][["Expression"]] = 16 #Fixed HeadFlow #Calculate Variable "2" of Branch "4" with ReadFromFile expression. R returns an Erros but it works fine at WEAP WEAPBranch[["Children"]][[12]][["Variables"]][[2]][["Expression"]] = "ReadFromFile(C:\\Users\\arthur\\OneDrive\\projetoWeapDemanda\\resultados\\vazoes_est_select2.csv; 42250000_m3s; ; Minimum; ; Replace)" #Run Weap WEAP$Calculate() #Export results WEAP$LoadFavorite("Flow Requirement Coverage") #load result frame at WEAP WEAP$ExportResults("C:\\Users\\arthur\\Documents\\WEAP Areas\\demanda_weap\\results\\FRC.csv") #Export Table |
Subject: Re: Weap + R + WhatsApp
Posted: 4/28/2022 Viewed: 9040 times
Very cool, Arthur! Thanks for sharing your work and creating the WhatsApp group. I hope it produces some fruitful collaboration and advances!
(Please note that WEAP developers have not tested or verified the code contained in this post.) |
Topic: “Weap + R + WhatsApp”