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:41, in Energyscope.es_model(self) 40 modules.activate(ampl_uuid) ---> 41 self.__es_model = AMPL() 42 except SystemError: 43 # 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 = 20260304; 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 69a7efba d362ffa5 e8d488bf 47a53b25 43e90abc 66122b4c 6db79539 34a8faf4 d7279046 4166f3f0 487a2c76 7192fddb e71d576d e4d0a535 3e6a49a5 c34aeda8 56de09ac c1b191ed 3a89864d 927b85ef 87197e5f 76c2fb23 bd776b5c a2c24394 a13d5011 a523df36 25b35ec8 d189957e 0712096b f3827b14 856221e5 b22d552b 0050c09c 5170d4c1 04e491a2 a7c44488 84a4f763 64554206 30640633 00af29d8 773f715e b57056e7 2c665072 73fd3062 87cb2d92 f206f5a0 7473c81b 15b56fbd 12f7d886 e2d3e8a7 b15c7dd0 d4ae139f 1366cf3f 16331f17 e0876b62 04bb6d1a 639b4f46 9210d1f2 c02f703e 4323883b 16289991 01c2d748 2132b456 c265a6c0 9712d957 87f4be00 194d6e10 67c807d4 31970c3d 73805296 dd6d5f33 e4e1bad2 54bcb3fe e0069c8c fcf5252e f0f3f05d a56a8dad 23b23d4b a38c7a92 708c73f5 6015caaf 75e24366 fdf13943 f582e56a a5b50edd a111e174 10754571 b7123bec d3a1ef9a 7345c205 f3 Computed 1-1-0-f7e71178 runner--pdbxrphm-project-62195384-concurrent-0 86:7E:05:99:9C:E4 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:83, in Energyscope.calc(self, ds, parser) 79 def calc(self, ds: Dataset = None, parser: Callable[[AMPL], Result] = parse_result) -> Result: 80 """ 81 Calls AMPL with `df` as .dat and returns the parsed result. 82 """ ---> 83 if self.es_model.getSets().__len__() == 0: # Check if AMPL instance is empty 84 self._initial_run(ds=ds) 86 # Solve the model File /builds/energyscope/energyscope/src/energyscope/energyscope.py:44, in Energyscope.es_model(self) 41 self.__es_model = AMPL() 42 except SystemError: 43 # Try to create the object a second time to prevent errors when starting `ampl_lic` ---> 44 self.__es_model = AMPL() 45 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 = 20260304; 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 69a7efba d362ffa5 e8d488bf 47a53b25 43e90abc 66122b4c 6db79539 34a8faf4 d7279046 4166f3f0 487a2c76 7192fddb e71d576d e4d0a535 3e6a49a5 c34aeda8 56de09ac c1b191ed 3a89864d 927b85ef 87197e5f 76c2fb23 bd776b5c a2c24394 a13d5011 a523df36 25b35ec8 d189957e 0712096b f3827b14 856221e5 b22d552b 0050c09c 5170d4c1 04e491a2 a7c44488 84a4f763 64554206 30640633 00af29d8 773f715e b57056e7 2c665072 73fd3062 87cb2d92 f206f5a0 7473c81b 15b56fbd 12f7d886 e2d3e8a7 b15c7dd0 d4ae139f 1366cf3f 16331f17 e0876b62 04bb6d1a 639b4f46 9210d1f2 c02f703e 4323883b 16289991 01c2d748 2132b456 c265a6c0 9712d957 87f4be00 194d6e10 67c807d4 31970c3d 73805296 dd6d5f33 e4e1bad2 54bcb3fe e0069c8c fcf5252e f0f3f05d a56a8dad 23b23d4b a38c7a92 708c73f5 6015caaf 75e24366 fdf13943 f582e56a a5b50edd a111e174 10754571 b7123bec d3a1ef9a 7345c205 f3 Computed 1-1-0-f7e71178 runner--pdbxrphm-project-62195384-concurrent-0 86:7E:05:99:9C:E4 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