Plot installed capacity
In [1]:
Copied!
"""
Installed Capacity
===================================
This is an example using the core model.
"""
"""
Installed Capacity
===================================
This is an example using the core model.
"""
Out[1]:
'\nInstalled Capacity\n===================================\n\nThis is an example using the core model.\n'
In [2]:
Copied!
import matplotlib.pyplot as plt
from energyscope.energyscope import Energyscope
from energyscope.models import core
import matplotlib.pyplot as plt
from energyscope.energyscope import Energyscope
from energyscope.models import core
In [3]:
Copied!
thresh = 1
figsize = (10, 6)
thresh = 1
figsize = (10, 6)
In [4]:
Copied!
# Create a model and calculate the results
es_core = Energyscope(model=core)
results = es_core.calc()
# Create a model and calculate the results
es_core = Energyscope(model=core)
results = es_core.calc()
[INFO] Activating AMPL license with UUID
--------------------------------------------------------------------------- SystemError Traceback (most recent call last) File /builds/energyscope/energyscope/src/energyscope/energyscope.py:40, in Energyscope.es_model(self) 39 modules.activate(ampl_uuid) ---> 40 self.__es_model = AMPL() 41 except SystemError: 42 # Try to create the object a second time to prevent errors when starting `ampl_lic` File ~/.local/share/hatch/env/virtual/energyscope/4BIeM0-F/docs/lib/python3.10/site-packages/amplpy/ampl.py:105, in AMPL.__init__(self, environment) 104 if environment is None: --> 105 self._impl = amplpython.AMPL() 106 else: SystemError: License not valid. Message: License file /root/.local/share/hatch/env/virtual/energyscope/4BIeM0-F/docs/lib/python3.10/site-packages/ampl_module_base/bin/ampl.lic: Today = 20261125; found license file "/root/.local/share/hatch/env/virtual/energyscope/4BIeM0-F/docs/lib/python3.10/site-packages/ampl_module_base/bin/ampl.lic": # Bundle #7221.7759 expiring 20260215: ME-409 Energy conversion and renewable energy, Prof. Fran?ois Mar?chal, EPFL 6b0715aa 75c1fae2 330d1c2a 3463b30c ef087175 a748694f c3a9dbf3 97b14187 cb303f4d 0785ebfb a67baad2 6393a598 f4ccca20 67efe305 668d2e67 e0fe22f2 8d022e34 038c38d6 a319fb92 d19e9001 c0d0741b f46a5191 51891c8d 81dc618d 1d964a21 05015bfd b1b08f7f 2746837e c4e73447 80165be6 61ae7914 f28f3242 69b0e208 d3f77672 718bc97d 11b61421 8b753224 55090f1d 70724303 0049003b c2a67ca8 7101f3b9 154325b2 b2ce36f6 0e10ff75 c7833b10 25544856 060f749b af24f779 e7b7f02b 93870814 22355000 8540b15c 368314b2 7302936f 45c7c6b8 6eadcbcb 96b43424 b0c1e916 f3f6b5fd 56fc47c5 31171143 43f6e792 f480d1d8 ee79e26a 554aa3c3 42b64614 e5bdf09a 69f4518d 3771af94 56d153b3 5251a276 8fefab82 d5fde20d a0935c3c f6afa65a 8f867c69 a11d3e5a 64508799 d5a225b8 e39a3cdb 51143eaa 35b14248 9045e4d1 ced7d5a7 021ad0e8 273494e3 b51a42cc 5c233475 05153abe 878da05d 32f504d4 ff8eb636 71b21d42 135f892b 459b36ba 3b23d155 adac43f9 03a14f9e 312dd164 3a Computed 1-1-0-1f286bcf runner--pdbxrphm-project-62195384-concurrent-0 36:BC:CA:46:B7:AA HOSTINFO.NPROC.4 HOSTINFO.CORES.4 HOSTINFO.PLATFORM.linux64 No ampl license for this machine. During handling of the above exception, another exception occurred: SystemError Traceback (most recent call last) Cell In[4], line 3 1 # Create a model and calculate the results 2 es_core = Energyscope(model=core) ----> 3 results = es_core.calc() File /builds/energyscope/energyscope/src/energyscope/energyscope.py:82, in Energyscope.calc(self, ds, parser) 78 def calc(self, ds: Dataset = None, parser: Callable[[AMPL], Result] = parse_result) -> Result: 79 """ 80 Calls AMPL with `df` as .dat and returns the parsed result. 81 """ ---> 82 if self.es_model.getSets().__len__() == 0: # Check if AMPL instance is empty 83 self._initial_run(ds=ds) 85 # Solve the model File /builds/energyscope/energyscope/src/energyscope/energyscope.py:43, in Energyscope.es_model(self) 40 self.__es_model = AMPL() 41 except SystemError: 42 # Try to create the object a second time to prevent errors when starting `ampl_lic` ---> 43 self.__es_model = AMPL() 44 return self.__es_model File ~/.local/share/hatch/env/virtual/energyscope/4BIeM0-F/docs/lib/python3.10/site-packages/amplpy/ampl.py:105, in AMPL.__init__(self, environment) 103 environment = Environment() 104 if environment is None: --> 105 self._impl = amplpython.AMPL() 106 else: 107 self._impl = amplpython.AMPL(environment._impl) SystemError: License not valid. Message: License file /root/.local/share/hatch/env/virtual/energyscope/4BIeM0-F/docs/lib/python3.10/site-packages/ampl_module_base/bin/ampl.lic: Today = 20261125; found license file "/root/.local/share/hatch/env/virtual/energyscope/4BIeM0-F/docs/lib/python3.10/site-packages/ampl_module_base/bin/ampl.lic": # Bundle #7221.7759 expiring 20260215: ME-409 Energy conversion and renewable energy, Prof. Fran?ois Mar?chal, EPFL 6b0715aa 75c1fae2 330d1c2a 3463b30c ef087175 a748694f c3a9dbf3 97b14187 cb303f4d 0785ebfb a67baad2 6393a598 f4ccca20 67efe305 668d2e67 e0fe22f2 8d022e34 038c38d6 a319fb92 d19e9001 c0d0741b f46a5191 51891c8d 81dc618d 1d964a21 05015bfd b1b08f7f 2746837e c4e73447 80165be6 61ae7914 f28f3242 69b0e208 d3f77672 718bc97d 11b61421 8b753224 55090f1d 70724303 0049003b c2a67ca8 7101f3b9 154325b2 b2ce36f6 0e10ff75 c7833b10 25544856 060f749b af24f779 e7b7f02b 93870814 22355000 8540b15c 368314b2 7302936f 45c7c6b8 6eadcbcb 96b43424 b0c1e916 f3f6b5fd 56fc47c5 31171143 43f6e792 f480d1d8 ee79e26a 554aa3c3 42b64614 e5bdf09a 69f4518d 3771af94 56d153b3 5251a276 8fefab82 d5fde20d a0935c3c f6afa65a 8f867c69 a11d3e5a 64508799 d5a225b8 e39a3cdb 51143eaa 35b14248 9045e4d1 ced7d5a7 021ad0e8 273494e3 b51a42cc 5c233475 05153abe 878da05d 32f504d4 ff8eb636 71b21d42 135f892b 459b36ba 3b23d155 adac43f9 03a14f9e 312dd164 3a Computed 1-1-0-1f286bcf runner--pdbxrphm-project-62195384-concurrent-0 36:BC:CA:46:B7:AA HOSTINFO.NPROC.4 HOSTINFO.CORES.4 HOSTINFO.PLATFORM.linux64 No ampl license for this machine.
In [5]:
Copied!
F = results.variables["F"]
storages = results.sets['STORAGE_TECH']["STORAGE_TECH"].values
F_storage = F[F.index.get_level_values(0).isin(storages)]
F_tech = F[~F.index.get_level_values(0).isin(storages)]
# Sort by size
F_storage = F_storage.sort_values(by=F_storage.columns[0], ascending=False)
F_storage = F_storage[F_storage.values[:,0]>thresh]
F_tech = F_tech[F_tech.values[:,0]>thresh]
F_tech = F_tech.sort_values(by=F_tech.columns[0], ascending=False)
# Calculate subplot widths proportional to number of bars
n_tech = len(F_tech)
n_storage = len(F_storage)
total = n_tech + n_storage
widths = [n_tech, n_storage] if total > 0 else [1, 1]
fig, axes = plt.subplots(1, 2, figsize=figsize, gridspec_kw={'width_ratios': widths})
# Technologies subplot (left)
axes[0].bar(x=range(n_tech), height=F_tech.values[:, 0])
axes[0].set_xticks(range(n_tech))
axes[0].set_xticklabels(F_tech.index, rotation=90)
axes[0].set_ylabel('Installed Capacity of Conversion Technologies [GW]')
axes[0].set_xlim(-1, n_tech)
axes[0].set_title('Conversion Technologies', fontsize=20)
# Storages subplot (right)
axes[1].bar(x=range(n_storage), height=F_storage.values[:, 0], color='orange')
axes[1].set_xticks(range(n_storage))
axes[1].set_xticklabels(F_storage.index, rotation=90)
axes[1].set_ylabel('Installed Capacity of Storages [GWh]')
axes[1].set_xlim(-1, n_storage)
axes[1].set_title('Storages', fontsize=20)
plt.tight_layout()
plt.show()
F = results.variables["F"]
storages = results.sets['STORAGE_TECH']["STORAGE_TECH"].values
F_storage = F[F.index.get_level_values(0).isin(storages)]
F_tech = F[~F.index.get_level_values(0).isin(storages)]
# Sort by size
F_storage = F_storage.sort_values(by=F_storage.columns[0], ascending=False)
F_storage = F_storage[F_storage.values[:,0]>thresh]
F_tech = F_tech[F_tech.values[:,0]>thresh]
F_tech = F_tech.sort_values(by=F_tech.columns[0], ascending=False)
# Calculate subplot widths proportional to number of bars
n_tech = len(F_tech)
n_storage = len(F_storage)
total = n_tech + n_storage
widths = [n_tech, n_storage] if total > 0 else [1, 1]
fig, axes = plt.subplots(1, 2, figsize=figsize, gridspec_kw={'width_ratios': widths})
# Technologies subplot (left)
axes[0].bar(x=range(n_tech), height=F_tech.values[:, 0])
axes[0].set_xticks(range(n_tech))
axes[0].set_xticklabels(F_tech.index, rotation=90)
axes[0].set_ylabel('Installed Capacity of Conversion Technologies [GW]')
axes[0].set_xlim(-1, n_tech)
axes[0].set_title('Conversion Technologies', fontsize=20)
# Storages subplot (right)
axes[1].bar(x=range(n_storage), height=F_storage.values[:, 0], color='orange')
axes[1].set_xticks(range(n_storage))
axes[1].set_xticklabels(F_storage.index, rotation=90)
axes[1].set_ylabel('Installed Capacity of Storages [GWh]')
axes[1].set_xlim(-1, n_storage)
axes[1].set_title('Storages', fontsize=20)
plt.tight_layout()
plt.show()
--------------------------------------------------------------------------- NameError Traceback (most recent call last) Cell In[5], line 1 ----> 1 F = results.variables["F"] 2 storages = results.sets['STORAGE_TECH']["STORAGE_TECH"].values 4 F_storage = F[F.index.get_level_values(0).isin(storages)] NameError: name 'results' is not defined