-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeaveDoc.jmd
191 lines (147 loc) · 7.64 KB
/
WeaveDoc.jmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
---
title : DRIP Water Resource Allocation Tool
author : Lisa Rennels and Nick Depsky
date : 11th May 2018
---
# I. Intro
DRIP is a water resource allocation tool, modeled after [WEAP](http://weap21.org)
from the [Stockholm Environment Institute's U.S. Center](https://www.sei.org/centres/us/).
WEAP can be summarized as follows:
*WEAP ("Water Evaluation And Planning" system) is a user-friendly software tool
that takes an integrated approach to water resources planning.
Freshwater management challenges are increasingly common. Allocation of limited
water resources between agricultural, municipal and environmental uses now
requires the full integration of supply, demand, water quality and ecological
considerations. The Water Evaluation and Planning system, or WEAP, aims to
incorporate these issues into a practical yet robust tool for integrated water
resources planning. WEAP is developed by the Stockholm Environment Institute's
U.S. Center.*
The source code for DRIP is available on [GitHub](https://github.com/lrennels/ER290A-finalproject)
and includes several script files as well as input data files to run a small
example. In addition to the modeling in Julia, we created a small model in
`WEAP` for testing purposes. The required software is proprietary, so it is not
included in Github.
# II. User Guide and Example
#### 1. Setup
In order to use DRIP, you will first want to include the helper functions as
follows:
```{julia; eval=true}
using Weave
include("helper_functions.jl")
```
Next, set up some basic date information:
```{julia; eval=true}
const start_year = 1990
const stop_year = 2017
const tstep = 12
const modays = [31, 28, 31, 30 ,31, 30, 31, 31, 30 ,31, 30 , 31];
```
#### 2. Define Demand
The `DefineDemand.jl` script allows a user to define specific **demand** nodes
of which can be of several categories including agricultural, municipal, industrial,
and instream flow requirements (IFRs). Each demand nodes has several metadata
requirements including
- months - a list of months (*12 by 1 array of Strings*)
- node_type - type of node (*String*)
- name - name of the node (*String*)
- size - size of the node (*Float64*)
- rate - monthly rate of flow through node (*12 by 1 array of Float64*)
- size_units - units of size variable (*String*)
- demand_units = units of rate variable (*String*)
- priority - demand priority (*Int64*)
- Loc- location (or position) in list of all nodes (*Int64*)
Once all demand nodes are defined, you can create the structures with an
`include` statement and convert them to a DataFrame structure using the `rdf`
function as follows:
```{julia; eval=true}
include("DefineDemand.jl")
demand = ddf(demand_nodes, start_year, stop_year)
head(demand)
```
*The `include` call will return a list of dictionaries, one for each node,
and the `rdf` call will convert this data structure into a `DataFrame` for use
by the main DRIP script.*
You can also graphically view the demand time series using `dplot`
```{julia; eval=true}
dplot(demand,1990,1990)
```
#### 3. Define Supply
The `DefineSupply.jl` script allows a user to define specific **supply** nodes
of which can be of several categories including tributary inflow, catchment inflows,
return flows, and groundwater. Each supply nodes has several metadata
requirements including
- filepath - the file path of th e.csv file containing flow information (*String*)
- name - name of supply node (*String*)
- supply_units - units of rate variable (*String*)
- Loc- location (or position) in list of all nodes (*Int64*)
Note that supply information is assumed to be stored in a .csv file in the
format of month (Date format) in the first column and Supply (number format)
in the second column. Example files can be found in this folder eg.
*NYuba_Inflow_Month*.
Once all supply nodes are defined, you can create the structures with an
`include` statement and convert them to a DataFrame structure using the `rdf`
function as follows:
```{julia; eval=true}
include("DefineSupply.jl")
supply = sdf(supply_nodes, start_year, stop_year)
head(supply)
```
*The `include` call will return a list of dictionaries, one for each node,
and the `sdf` call will convert this data structure into a `DataFrame` for use
by the main DRIP script.*
You can also graphically view the demand time series using `splot`
```{julia; eval=true}
splot(supply,1990,2017)
```
#### 4. Define Infrastructure
The `DefineInfrastructure.jl` script allows a user to define specific **infrastructure**
nodes, which as of now are simply reservoirs. Each infrastructure node has
several metadata requirements including
- name - name of reservoir node (*String*)
- storage_capacity - capacity of reservoir (*Float64*)
- init_storage - initial storage of reservoir (*Float64*)
- top_of_conservation - (*12 by 1 array of Float64*)
- storage_units - units of storage (*String*)
- Loc - location (or position) in list of all nodes (*Int64*)
Note that supply information is assumed to be stored in a .csv file in the
format of month (Date format) in the first column and Supply (number format)
in the second column. Example files can be found in this folder eg.
*NYuba_Inflow_Month*.
Once all supply nodes are defined, you can create the structures with an
`include` statement and convert them to a DataFrame structure using the `rdf`
function as follows:
```{julia; eval=true}
include("DefineInfrastructure.jl")
reservoirs = rdf(reservoir_nodes, start_year, stop_year)
```
*The `include` call will return a list of dictionaries, one for each node,
and the `rdf` call will convert this data structure into a `DataFrame` for use
by the main DRIP script.*
#### 5. Run DRIP
Once you have set up the demand, supply, and reservoir nodes, you can run the
main DRIP allocation routine! This allocation script will run the allocation
algorithm and return `results`, which is a vector of values between 0 and 1
indicating the fraction of demand fulfilled for that specific demand node.
```{julia; eval=true}
include("DRIP_allocation_routine.jl")
results = DRIP_allocation_routine(demand_nodes, supply_nodes, reservoir_nodes,
(stop_year - start_year + 1))
results
```
# III. WEAP Model
In order to benchmark our model against the original WEAP software, we built a small dummy WEAP model of the system constructed in our model. It consists of a single river with headflow represented as a monthly average streamflow time series taken from the USGS hydrologic gauge data repository for the North Yuba River in the California Sierra Nevada. There is a single reservoir with a pre-defined storage capacity and initial storage. Currently there is also a single hydropower plant, a city (Berkeley) demand, a farm demand (Anaya's Farm), and a minimum instream flow requirement (IFR). A schema of the model in WEAP is shown below.
![](WEAP_schema1.png)
This model was run from 1990 to 2017 at a monthly timestep in order to produce result upon which we want to compare out model outputs. However, given the nascent stage of our model, we were yet unable to totally replicate the WEAP outputs, and are currently thinking through the ways in which WEAP likely obtains its optimzation outputs.
Some data inputs:
![](WEAP_input1.png)
Here are some results of the reservoir storage and demand shortage:
Reservoir Shortage
![](WEAP_results_res.png)
Demand Shortage
![](WEAP_results_shortage.png)
# IV. Future Work
Nick and I are interested in expanding upon this work, and have begun to do so
in the `DRIP_allocation_routine_WIP.jl` file. The most significant changes will
be to the the allocation algorithms, and include an optimisation component that
mirrors the one used in WEAP. A small model of the inner portion of this
optimisation can be found in `Excel_Optim_Model.xlsx`.