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()
--------------------------------------------------------------------------- KeyError 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:72, in Energyscope.calc(self, ds, parser) 68 def calc(self, ds: Dataset = None, parser: Callable[[AMPL], Result] = parse_result) -> Result: 69 """ 70 Calls AMPL with `df` as .dat and returns the parsed result. 71 """ ---> 72 if self.es_model.getSets().__len__() == 0: # Check if AMPL instance is empty 73 self._initial_run(ds=ds) 75 # Solve the model File /builds/energyscope/energyscope/src/energyscope/energyscope.py:30, in Energyscope.es_model(self) 28 else: 29 try: ---> 30 self.__es_model = AMPL(Environment(os.environ["AMPL_PATH"])) 31 except SystemError: 32 # Try to create the object a second time to prevent errors when starting `ampl_lic` 33 self.__es_model = AMPL() File /usr/local/lib/python3.10/os.py:680, in _Environ.__getitem__(self, key) 677 value = self._data[self.encodekey(key)] 678 except KeyError: 679 # raise KeyError with the original key value --> 680 raise KeyError(key) from None 681 return self.decodevalue(value) KeyError: 'AMPL_PATH'
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