Presentation is loading. Please wait.

Presentation is loading. Please wait.

Automating Entering Data in WEAP and Scenario Analysis Erfan Goharian Hydroinformatics Fall 2013.

Similar presentations


Presentation on theme: "Automating Entering Data in WEAP and Scenario Analysis Erfan Goharian Hydroinformatics Fall 2013."— Presentation transcript:

1 Automating Entering Data in WEAP and Scenario Analysis Erfan Goharian Hydroinformatics Fall 2013

2 Learning Objectives Automate data entry to a water resources model Use the WEAP application programming interface (API) to enter climate data Analyze different scenarios in WEAP

3 Steps to automate the transformation 1.Read precipitation values for a desired location 2.Convert Water Year to Calendar Year (if it’s needed) 3.Covert units (if it’s needed) 4.Write to CSV file 5.Repeat #1-4 for next desired location 6.Repeat #1-5 for climate change scenario

4 WEAP Scenario Explorer First, a “Current Accounts” year is chosen to serve as the base year of the model A “Reference” scenario is established from the Current Accounts to simulate likely evolution of the system without intervention. Finally, “what-if” scenarios can be created to alter the “Reference Scenario” and evaluate the effects of changes in policies and/or technologies.

5 Automate Data Entry Using the Application Programming Interface WEAP Model The User User Interface Prompts plots, etc. Mouse clicks keyboard etc. Scripts, Other Programs, Models, Remote Computers Methods Classes Properties Functions etc. API

6 Scripting in WEAP 1.Internally: create more powerful expressions and functions e.g., create a script to calculate reservoir water quality, and Call the script from a WEAP expression 2.Externally: to automate WEAP via its Application Programming Interface (API) to perform a sequence of actions e.g., create and run 100 WEAP scenarios by varying the value of several parameters (sensitivity analysis)

7 Accessing the WEAP API Script Editor: edit, interactively debug and run scripts main menu: Advanced, Scripting, Run. Script: VBScript and JScript come with Windows other scripting languages must be installed (like Perl, Python, Ruby and PHP) COM Automation Server Run WEAP from other software like Excel Install reference library and go!

8 List the names of the demand sites in the current WEAP Area WEAP. is an object with numerous properties including all the branches of the data tree We loop through all the elements of Demand Sites Enter “WEAP.” to see the available properties/methods FOR EACH Br IN WEAP.Branch("\Demand Sites").Children PRINT Br.Name NEXT

9 What CSV file is assigned to the precipitation? PRINT "Show the CSV file assigned as the precipitation" FOR EACH br IN WEAP.Branch("\Demand Sites").Children PRINT br.Name & " " & br.Variables("precipitation").Expression Next

10 Connecting to Database Const adOpenStatic = 3 Const adLockOptimistic = 3 Set objConnection = CreateObject("ADODB.Connection") Set objRecordSet = CreateObject("ADODB.Recordset") objConnection.Open "DSN=your data source name;UID=root;PWD=YOUR PASSWORD;Database=weap" Set WshShell = CreateObject("WScript.Shell") Set fso = CreateObject("Scripting.FileSystemObject")

11 Query from Database SQL_Command_String1 = " Select f_airport.`Date`, rcp26 from f_airport WHERE" & _ " '2010-01-01' <=f_airport.`Date` and f_airport.`Date`<='2039- 01-01' INTO OUTFILE 'C:/ProgramData/MySQL/MySQL Server 5.7/Uploads/airport_rcp26.csv'" & _ "FIELDS TERMINATED BY ','" & _ "ENCLOSED BY ' '" & _ "LINES TERMINATED BY '\n';" Set Rs2 = objConnection.Execute(SQL_Command_String1)

12 Assign scenarios the precipitation 'Define the scenarios' Dim ScenInfo(1,3) 'WEAP Scenario name in column 1 (index 0)' ScenInfo(0,0) = "Current Accounts" 'Represents first base year. Data is defined' ScenInfo(0,1) = "Reference" 'Historical conditions provided in previous class' ScenInfo(0,2) = "rcp26" 'rcp26' ScenInfo(0,3) = "rcp85" 'rcp85' 'CSV file name affix in column 2 (index 1)' ScenInfo(1,0) = "" ScenInfo(1,1) = "" ScenInfo(1,2) = "" ScenInfo(1,3) = ""

13 Assign watersheds the precipitation 'Define watersheds' Dim WatershedInfo(1,3) 'WEAP watershed name in Column 1 (index 0)' WatershedInfo(0,0) = "City Creek Watershed" WatershedInfo(0,1) = "Dell Creek Watershed" WatershedInfo(0,2) = "Lamb Creek Watershed" WatershedInfo(0,3) = "Big Cottonwood Watershed" 'CSV data file name in Column 2 that goes with watershed name' 'in Column 1 (index 1)' WatershedInfo(1,0) = "airport" ' CSV file name ' WatershedInfo(1,1) = "parleys" WatershedInfo(1,2) = "parleys" WatershedInfo(1,3) = "parleys"

14 Assign precipitation from database Dim i 'watershed index' Dim s 'Scenario index' 'Loop over the scenarios' FOR s = 2 to ubound(ScenInfo,2) 'we already defined' 'the historical CSV files for Current and Reference scenarios' Set Sc = WEAP.Scenarios("" & ScenInfo(0,s)) 'The first double quotes forces the parameter to a text string' PRINT "" PRINT SC.Name & " is now active" Sc.Activate 'Activate the scenario so data inputs are for that scenario only' 'Work on the watersheds' FOR i=0 to ubound( WatershedInfo,2) Set CurrWts = WEAP.Branch("\Demand Sites\" & WatershedInfo(0,i)) CurrWts.Variables("Precipitation").Expression = "ReadFromFile(C:\ProgramData\MySQL\MySQL Server 5.7\Uploads\" & WatershedInfo(1,i) & "_" & SC.Name & ".csv,,2010, SUM)" PRINT "Updated " & CurrWts.Name & " with Precipitation " & CurrWts.Variables("Precipitation").Expression Next NEXT

15 Assignment #9 Change factor charts (from 6 tables: 2 stations and 3 time slices) Reliability of historical period (from WEAP) Comparison between streamflow and reliability of system between reference period and RCP26 and RCP 85 (for 2010-2039) Optional: Compare historical period with all RCPs and over next 100years


Download ppt "Automating Entering Data in WEAP and Scenario Analysis Erfan Goharian Hydroinformatics Fall 2013."

Similar presentations


Ads by Google