forked from jwchang2/REoptLite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_loads.jl
90 lines (68 loc) · 2.41 KB
/
get_loads.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
using CPLEX
using JuMP
using REoptLite
using CSV, DataFrames
using JSON
# City names
cities = ["Albuquerque", "Atlanta", "Baltimore", "Boulder", "Chicago", "Duluth",
"Helena", "Houston", "LosAngeles", "Miami", "Minneapolis", "Phoenix", "SanFrancisco", "Seattle"]
function GenerateJSONs(city::String)
scenario_path = "/Users/amandafarthing1/.julia/dev/REoptLite/test/scenarios/get_loads/get_loads.json" #
# Open city name json
dict = Dict()
open(scenario_path, "r") do f
# global dict
dict=JSON.parse(f) # parse and transform data
end
# Update city name
dict["ElectricLoad"]["city"] = city
# Update building-specific values for each building type
hosp = deepcopy(dict)
school = deepcopy(dict)
warehouse = deepcopy(dict)
# DOE Reference Building name
hosp["ElectricLoad"]["doe_reference_name"]= "Hospital"
school["ElectricLoad"]["doe_reference_name"]= "SecondarySchool"
warehouse["ElectricLoad"]["doe_reference_name"]= "Warehouse"
# Critical load %
hosp["ElectricLoad"]["critical_load_pct"] = 0.85
school["ElectricLoad"]["critical_load_pct"] = 0.60
warehouse["ElectricLoad"]["critical_load_pct"] = 0.10
# Value of lost load
hosp["Financial"]["VoLL"] = 140.0
school["Financial"]["VoLL"] = 72.0
warehouse["Financial"]["VoLL"] = 4.0
# Write all dicts to json files
list_scenarios = [hosp, school, warehouse]
namez = ["hosp", "school", "warehouse"]
# Write each to json
for i in (1:length(list_scenarios))
n = namez[i]
scen = list_scenarios[i]
open("/Users/amandafarthing1/.julia/dev/REoptLite/test/scenarios/get_loads/$city $n.json", "w") do f
write(f, JSON.json(scen, 4))
end
end
end
function RunAndSaveLoads(city, bldg)
scenario_path = "/Users/amandafarthing1/.julia/dev/REoptLite/test/scenarios/get_loads/$city $bldg.json" #
m = Model(CPLEX.Optimizer)
results = run_reopt(m, "$scenario_path")
# Write loads_kw to file
building_load = results["building_load"]
df = DataFrame(BuildingLoad = building_load)
# Write results to csv
CSV.write("/Volumes/GoogleDrive/My Drive/0_Michigan/Master's Thesis/Results/USA/building_loads/$city$bldg.csv", df) # , header=false
end
# Generate JSONs
for i in (1:length(cities))
c = cities[i]
GenerateJSONs(c)
end
# Run (simplified) model and save bldg loads
for i in (1:length(cities))
city = cities[i]
for bldg in ["hosp", "school", "warehouse"]
RunAndSaveLoads(city, bldg)
end
end