Subject: Weap + R + WhatsApp Posted: 4/15/2022 Viewed: 5244 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.
#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"]]
#Calculate Variable "5", "7" and "2" of Branch "3" #Just Examples. R returns an Erros but it works fine at WEAP
#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
Ms. Anne Hereford
Subject: Re: Weap + R + WhatsApp Posted: 4/28/2022 Viewed: 5080 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.)