-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper_functions.jl
123 lines (112 loc) · 3.73 KB
/
helper_functions.jl
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
## function to add a demand node to the list of demand nodes
##
## arguments: name, size, rate, size_units, rate_units
## output: the node dictionary
using Queryverse
function res_init(reservoir_nodes)
res_inits = fill(0,length(reservoir_nodes))
for r = 1:length(reservoir_nodes)
res_inits[r] = reservoir_nodes[r]["init_storage"]
end
return res_inits
end
function create_demand_node(;
demand_type::String = "default_type",
name::String = "default_name",
size::Float64= -999.,
rate::Array{} = [],
size_units::String = "default_units",
demand_units::String = "demand_units",
priority::Int64 = 999,
Loc::Int64 = 999,
months::Array{} = []);
return Dict("demand_type" => demand_type, "name" => name, "size" => size, "rate" => rate,
"size_units" => size_units, "demand_units" => demand_units, "priority" => priority,
"Loc" => Loc, "months" => months);
end
## function to add a supply node to the list of supply nodes
##
## arguments: name, size, rate, size_units, rate_units
## output: the node dictionary
function create_supply_node(;
filepath::String = "filepath",
name::String = "default_name",
supply_units::String = "supply_units",
Loc::Int64 = 999)
inflow = DataFrame(load(filepath))
return Dict("name" => name, "inflow" => inflow, "supply_units" => supply_units,
"Loc" => Loc)
end
## function to add a reservoir to the list of objects
##
## arguments: name, storage capacity, top of conservation
## output: the node dictionary
function create_reservoir(;
name::String = "default_name",
storage_capacity::Float64 = -999.,
init_storage::Float64 = -999.,
top_of_conservation::Array = fill(-999.,12),
storage_units::String = "storage_units",
Loc::Int64 = -999);
return Dict("name" => name, "storage_capacity" => storage_capacity, "init_storage" => init_storage,
"top_of_conservation" => top_of_conservation, "storage_units" => storage_units,
"Loc" => Loc);
end
###----------------------- PLOTTING FUNCTIONS ------------------------###
# Supply Plot (supply_nodes)
splot = function(sup,year1,year2)
sup2 = deepcopy(sup[(Dates.year(sup[:Date]).>=year1)&(Dates.year(sup[:Date]).<=year2),:])
sup2 |> vl"""
{
"title": "Streamflow",
"mark": "area",
"background": "white",
"encoding": {
"x": {"field": "Date","type": "temporal"},
"y": {"field": "Quantity","type": "Quantitative"},
"color": {"field": "Name", "type": "nominal"},
"opacity":{"value": 0.8}
},
"width": 500,
"height": 300
}
"""
end
#Demand Plot (demand_nodes)
dplot = function(dem,year1,year2)
dem2 = deepcopy(dem[(Dates.year(dem[:Date]).>=year1)&(Dates.year(dem[:Date]).<=year2),:])
dem2 |> vl"""
{
"title": "Demand",
"mark": "area",
"background": "white",
"encoding": {
"x": {"field": "Date", "type": "temporal"},
"y": {"field":"Quantity", "type": "Quantitative"},
"color": {"field": "Name", "type": "nominal"},
"opacity":{"value": 0.8}
},
"width": 500,
"height": 300
}
"""
end
# Reservoir Plots
rplot = function(res,year1,year2)
res2 = deepcopy(res[(Dates.year(res[:Date]).>=year1)&(Dates.year(res[:Date]).<=year2),:])
res2 |> vl"""
{
"title": "Demand",
"mark": "area",
"background": "white",
"encoding": {
"x": {"field": "Date", "type": "temporal"},
"y": {"field":"Quantity", "type": "Quantitative"},
"color": {"field": "Name", "type": "nominal"},
"opacity":{"value": 0.8}
},
"width": 500,
"height": 300
}
"""
end