Download presentation
Presentation is loading. Please wait.
Published byHarold Grant Modified over 6 years ago
1
Lecture 19 Automating Preparing and Entering Model Data in WEAP
David E. Rosenberg CEE 6930 – Hydroinformatics Fall 2012 This work was funded by National Science Foundation Grant EPS
2
Learning Objectives Manipulate and transform data across file systems and formats Automate data entry to a water resources model Use the WEAP application programming interface (API) to enter Bear River flow data for ILO-9 CEE 6930
3
The Overarching Problem
ILO-9: What is the reliability of Bear River water to meet the water requirements of new, urban Cache County users considering (i) historical flows, or (ii) a warmer climate with reduced and time-shifted flows? Transform monthly flow data provided in the file P2009-T1.out to a CSV format WEAP can read Tell WEAP which CSV files to read in Repeat for a scenario representing future warmer climate CEE 6930
4
The Transformation ? P2009-T1.out Required WEAP Input
Monthly headflows and reach gains/losses Cross-tabulated by Water Year and Month ~100 locations (QX001, QX002,…) In acre-feet Required WEAP Input CSV (Calendar Year, Month, Value) Separate file for each location Separate file for reach gains and losses in a location In monthly average CFS ? CEE 6930
5
Steps to automate the transformation
Read in flow values for a desired location Convert to time-series format Convert Water Year to Calendar Year Covert monthly AF to period average CFS For reach gain/loss locations Separate positive values into reach gain time-series Separate negative values into reach loss time-series Write to CSV file Repeat #1-6 for next desired location Repeat #5-7 for climate change scenario CEE 6930
6
The Water Year Runs from October 1 to September 30
Shifts the start of the year by 3 months Group January, February, March, … September with the prior October, November, and December Is an accounting system to better group important hydrologic events in the same “year” See the Excel file for an example CEE 6930
7
Implement the Transformation in Code
Choose your language (Python, R, Matlab, C++, Database, Visual Basic, etc…) Comment each step of your code! CEE 6930
8
Automate Data Entry Using the Application Programming Interface
Scripts, Other Programs, Models, Remote Computers Methods Classes Properties Functions etc. API User Interface WEAP Model Prompts plots, etc. The User Mouse clicks keyboard etc. CEE 6930
9
Accessing the WEAP API Script Editor COM Automation Server
Advanced Menu=>Scripting) COM Automation Server Run WEAP from other software like Excel Install reference library and go! Make sure to check out the WEAP help on API!! Explains object libraries, methods, and properties CEE 6930
10
Example 1. 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 CEE 6930
11
Example 2. What CSV file is assigned to the Bear River headflow?
PRINT "Show the CSV file assigned as the Bear River Headflow” FOR EACH Riv IN WEAP.Branch("Supply and Resources\River").Children IF Riv.Name="Bear River" THEN PRINT Riv.Name & " " & Riv.Variables("Headflow").Expression End if Next CEE 6930
12
Example 3. Assign rivers the same headflow
PRINT "Set headflows for all the actual rivers to the same CSV file" SameHeadflow = "ReadFromFile(QX5-LowerBRInflow.csv, , 1967)" Dim ActualRivers(3) ActualRivers(0) = "Bear River" ActualRivers(1) = "Little Bear River" ActualRivers(2) = "Blacksmith Fork" ActualRivers(3) = "Malad" FOR EACH Riv IN ActualRivers Set CurrRiv = WEAP.Branch("Supply and Resources\River\" & Riv) PRINT "Updated " & CurrRiv.Name CurrRiv.Variables("Headflow").Expression = SameHeadflow Next CEE 6930
13
Example 4. Access Reaches and Diversions (to assign reach gains/losses)
PRINT "Show the CSV file assigned as inflow to a reach" SET Reach = WEAP.Branch("Supply and Resources\River\Bear River\Reaches\Below Withdrawal Node 2") PRINT Reach.Name & " " & Reach.Variables("Surface Water Inflow").Expression PRINT "Show the CSV file assigned as the required flow for a diversion" SET Div = WEAP.Branch("Supply and Resources\River\South Cache Reach Loss\Flow Requirements\South Cache Reach Loss") PRINT Div.name & " " & Div.Variables("Minimum Flow Requirement").Expression CEE 6930
14
Pull it all together in a single script
Loop to assign the 4 head flows Loop to assign the 2 reach gain/losses Reach gains to a reach Reach losses as a required flow on a diversion Consistently name the CSV files with flow values Use arrays to loop through the river elements and csv files CEE 6930
15
WEAP Scenario Explorer
What will happen if… [I change one or more inputs]?? Define and manage scenarios from the Data module Enter input data here too CEE 6930
16
WEAP Scenario Dashboard
Use Scenario Explorer icon to open scenario dashboard CEE 6930
17
WEAP Scenarios in the API
Check out the WEAPScenario class in the User’s Guide for more info! FOR EACH Scen in WEAP.Scenarios Scen.Activate PRINT Scen.Name & " is now active" 'Do some stuff Next CEE 6930
18
Example 5. What scenarios do you need for ILO-9?
How will you generate flow data for them? How will you use the WEAP API to injest the scenario flow data? CEE 6930
19
Wrap Up Often necessary to transform data to prepare it for input to a model Automate to speed up transformations, reduce errors, and document the process Use the Application Programming Interface to further automate data entry (and running) of a model Cache County seeks your hydroinformatics ninja skills to determine whether it should develop Bear River water! CEE 6930
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.