-
Notifications
You must be signed in to change notification settings - Fork 0
/
Simulatation.py
110 lines (90 loc) · 3.25 KB
/
Simulatation.py
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
import pysd
from pathlib import Path
import numpy as np
import matplotlib as mpl
from matplotlib import pyplot as plt
# import timeit
def Main():
model = ReadModel()
parameters = {
"time to adjust Prosumer Demand": 1,
"time to adjust Regular Consumer demand": 1,
"TIME STEP": 2 ** -10,
"SAVEPER": 2 ** -5,
"price elasticity of prosumers": -0.2,
'Initial Prosumer Demand':275,
"price elasticity of regular consumers": -0.1,
"Initial Electricity Tariff": 0.15,
"PV Potential": 0.3,
"FINAL TIME": 240
}
outputVariableList = [
"Regular Consumers",
"Prosumers",
"Defectors",
"Total Consumers",
"PV Cost",
"NPV PV",
"Battery Cost",
"Direct Defection NPV",
"Prosumer Average Demand",
"Regular Consumer Average Demand",
"Budget Deficit",
"Electricity Tariff",
"Monthly Income Shortfall",
"change in electricity tariff",
"Utility Energy Sale",
"Total Costs",
]
SimulateBaseCase(model, parameters, outputVariableList)
# SimulatePeriod(model)
# SimulatePopulation(model)
def ReadModel():
vensimDirectory = "./Simulation Files/Prosumers & defectors"
vensimFile = "net metering-no fixed tariff.mdl"
filepath = Path(vensimDirectory, vensimFile)
return pysd.read_vensim(str(filepath))
def SimulateBaseCase(model, params: dict, varList: list):
growthrate=0.2
params.update(
{"Tariff Correction Period": 12, "population growth rate": ((1+growthrate/100) ** (1 / 12)) - 1}
)
model.set_components(params=params)
variables = model.doc()
units = variables.loc[variables["Real Name"].isin(varList), ["Real Name", "Unit"]]
# units.loc[:, "Unit"] = units.loc[:, "Unit"].apply(lambda x: str(x)[2:-1])
units.to_csv("./Outputs/units.csv", index=False)
result = model.run(params=params, return_columns=varList)
result.to_csv("./Outputs/base.csv")
mpl.rc("lines", linewidth=3)
for v in result.columns:
plt.plot(result[v])
plt.grid(True, linestyle="--")
plt.title(v)
plt.xlabel("Time (Month)")
plt.ylabel(units.loc[units["Real Name"] == v, "Unit"].values[0])
plt.savefig(f"./Outputs/{v}.pdf", facecolor="w", bbox_inches="tight")
plt.clf()
def SimulatePeriod(model, params: dict, varList: list):
growthrate=0.2
params.update({"population growth rate": ((1+growthrate/100) ** (1 / 240)) - 1})
sensitivity_range = [1, 3] + list(range(6, 40, 6))
for s in sensitivity_range:
print(s)
result = model.run(
params={**params, "Tariff Correction Period": s},
return_columns=varList,
)
result.to_csv(f"./Outputs/period_{s}.csv")
def SimulatePopulation(model, params: dict, varList: list):
params.update({"Tariff Correction Period": 12})
sensitivity_range = [(1 + s) ** (1 / 240) - 1 for s in np.arange(0, 1, 0.1)]
for s in sensitivity_range:
print(s)
result = model.run(
params={**params, "population growth rate": s},
return_columns=varList,
)
result.to_csv(f"./Outputs/populationGrowth_{s}.csv")
if __name__ == "__main__":
Main()