Skip to content

Commit

Permalink
Upgrade oemof to 0.5.1
Browse files Browse the repository at this point in the history
- Change import statements
- Add period in constraint flows as per
https://oemof-solph.readthedocs.io/en/v0.5.1/changelog.html#new-features
- Update attributes
  • Loading branch information
Bachibouzouk committed Sep 12, 2023
1 parent d167536 commit 9bd5b1e
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 127 deletions.
5 changes: 1 addition & 4 deletions requirements/default.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
oemof.solph==0.4.4
pandas>=0.24.0,!=1.1.0,!=1.1.1,!=1.1.2
pyomo!=5.7.3,!=6.0 # version 5.7.3 and 6.0 make mvs very slow
graphviz>=0.14.1
plotly
psutil
kaleido>=0.0.2
openpyxl>=3.0.5
xlrd==1.2.0
numpy>=1.21.0
oemof.solph==0.5.1
2 changes: 1 addition & 1 deletion src/multi_vector_simulator/A0_initialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ def process_user_arguments(
logger.define_logging(
logpath=path_output_folder,
logfile=LOGFILE,
file_level=logging.DEBUG,
file_level=logging.INFO,
screen_level=screen_level,
)

Expand Down
7 changes: 4 additions & 3 deletions src/multi_vector_simulator/D0_modelling_and_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import timeit
import warnings

from oemof.solph import processing, network
import oemof.solph as solph
from oemof.solph import processing
from oemof import solph

import multi_vector_simulator.D1_model_components as D1
import multi_vector_simulator.D2_model_constraints as D2
Expand Down Expand Up @@ -142,7 +142,8 @@ def initialize(dict_values):
"""
logging.info("Initializing oemof simulation.")
model = solph.EnergySystem(
timeindex=dict_values[SIMULATION_SETTINGS][TIME_INDEX]
timeindex=dict_values[SIMULATION_SETTINGS][TIME_INDEX],
infer_last_interval=True,
)

# this dictionary will include all generated oemof objects
Expand Down
64 changes: 38 additions & 26 deletions src/multi_vector_simulator/D1_model_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import logging

import oemof.solph as solph
from oemof import solph

from multi_vector_simulator.utils.constants_json_strings import (
VALUE,
Expand Down Expand Up @@ -326,6 +326,7 @@ def sink(model, dict_asset, **kwargs):
"""
if TIMESERIES in dict_asset:
sink_non_dispatchable(model, dict_asset, **kwargs)

else:
sink_dispatchable_optimize(model, dict_asset, **kwargs)

Expand Down Expand Up @@ -629,7 +630,7 @@ def transformer_constant_efficiency_fix(model, dict_asset, **kwargs):
}

if missing_dispatch_prices_or_efficiencies is None:
t = solph.Transformer(
t = solph.components.Transformer(
label=dict_asset[LABEL],
inputs=inputs,
outputs=outputs,
Expand Down Expand Up @@ -806,7 +807,7 @@ def transformer_constant_efficiency_optimize(model, dict_asset, **kwargs):
}

if missing_dispatch_prices_or_efficiencies is None:
t = solph.Transformer(
t = solph.components.Transformer(
label=dict_asset[LABEL],
inputs=inputs,
outputs=outputs,
Expand Down Expand Up @@ -991,15 +992,16 @@ def source_non_dispatchable_fix(model, dict_asset, **kwargs):
"""
outputs = {
kwargs[OEMOF_BUSSES][dict_asset[OUTFLOW_DIRECTION]]: solph.Flow(
label=dict_asset[LABEL],
fix=dict_asset[TIMESERIES],
nominal_value=dict_asset[INSTALLED_CAP][VALUE],
variable_costs=dict_asset[DISPATCH_PRICE][VALUE],
emission_factor=dict_asset[EMISSION_FACTOR][VALUE],
custom_attributes=dict(emission_factor=dict_asset[EMISSION_FACTOR][VALUE]),
)
}

source_non_dispatchable = solph.Source(label=dict_asset[LABEL], outputs=outputs)
source_non_dispatchable = solph.components.Source(
label=dict_asset[LABEL], outputs=outputs
)

model.add(source_non_dispatchable)
kwargs[OEMOF_SOURCE].update({dict_asset[LABEL]: source_non_dispatchable})
Expand Down Expand Up @@ -1034,7 +1036,6 @@ def source_non_dispatchable_optimize(model, dict_asset, **kwargs):
existing = dict_asset[INSTALLED_CAP][VALUE]
outputs = {
kwargs[OEMOF_BUSSES][dict_asset[OUTFLOW_DIRECTION]]: solph.Flow(
label=dict_asset[LABEL],
fix=dict_asset[TIMESERIES_NORMALIZED],
investment=solph.Investment(
ep_costs=dict_asset[SIMULATION_ANNUITY][VALUE]
Expand All @@ -1046,11 +1047,13 @@ def source_non_dispatchable_optimize(model, dict_asset, **kwargs):
variable_costs=dict_asset[DISPATCH_PRICE][VALUE]
/ dict_asset[TIMESERIES_PEAK][VALUE],
# add emission_factor for emission contraint
emission_factor=dict_asset[EMISSION_FACTOR][VALUE],
custom_attributes=dict(emission_factor=dict_asset[EMISSION_FACTOR][VALUE]),
)
}

source_non_dispatchable = solph.Source(label=dict_asset[LABEL], outputs=outputs)
source_non_dispatchable = solph.components.Source(
label=dict_asset[LABEL], outputs=outputs
)

model.add(source_non_dispatchable)
kwargs[OEMOF_SOURCE].update({dict_asset[LABEL]: source_non_dispatchable})
Expand Down Expand Up @@ -1079,7 +1082,6 @@ def source_dispatchable_optimize(model, dict_asset, **kwargs):
if TIMESERIES_NORMALIZED in dict_asset:
outputs = {
kwargs[OEMOF_BUSSES][dict_asset[OUTFLOW_DIRECTION]]: solph.Flow(
label=dict_asset[LABEL],
max=dict_asset[TIMESERIES_NORMALIZED],
investment=solph.Investment(
ep_costs=dict_asset[SIMULATION_ANNUITY][VALUE]
Expand All @@ -1091,10 +1093,14 @@ def source_dispatchable_optimize(model, dict_asset, **kwargs):
variable_costs=dict_asset[DISPATCH_PRICE][VALUE]
/ dict_asset[TIMESERIES_PEAK][VALUE],
# add emission_factor for emission contraint
emission_factor=dict_asset[EMISSION_FACTOR][VALUE],
custom_attributes=dict(
emission_factor=dict_asset[EMISSION_FACTOR][VALUE]
),
)
}
source_dispatchable = solph.Source(label=dict_asset[LABEL], outputs=outputs,)
source_dispatchable = solph.components.Source(
label=dict_asset[LABEL], outputs=outputs,
)
else:
if TIMESERIES in dict_asset:
logging.info(
Expand All @@ -1107,18 +1113,22 @@ def source_dispatchable_optimize(model, dict_asset, **kwargs):
)
outputs = {
kwargs[OEMOF_BUSSES][dict_asset[OUTFLOW_DIRECTION]]: solph.Flow(
label=dict_asset[LABEL],
investment=solph.Investment(
ep_costs=dict_asset[SIMULATION_ANNUITY][VALUE],
existing=dict_asset[INSTALLED_CAP][VALUE],
maximum=dict_asset[MAXIMUM_ADD_CAP][VALUE],
),
variable_costs=dict_asset[DISPATCH_PRICE][VALUE],
# add emission_factor for emission contraint
emission_factor=dict_asset[EMISSION_FACTOR][VALUE],
custom_attributes=dict(
emission_factor=dict_asset[EMISSION_FACTOR][VALUE],
),
)
}
source_dispatchable = solph.Source(label=dict_asset[LABEL], outputs=outputs,)
print(dict_asset[LABEL])
source_dispatchable = solph.components.Source(
label=dict_asset[LABEL], outputs=outputs
)
model.add(source_dispatchable)
kwargs[OEMOF_SOURCE].update({dict_asset[LABEL]: source_dispatchable})
logging.debug(
Expand Down Expand Up @@ -1146,15 +1156,18 @@ def source_dispatchable_fix(model, dict_asset, **kwargs):
if TIMESERIES_NORMALIZED in dict_asset:
outputs = {
kwargs[OEMOF_BUSSES][dict_asset[OUTFLOW_DIRECTION]]: solph.Flow(
label=dict_asset[LABEL],
max=dict_asset[TIMESERIES_NORMALIZED],
existing=dict_asset[INSTALLED_CAP][VALUE],
nominal_value=dict_asset[INSTALLED_CAP][VALUE],
variable_costs=dict_asset[DISPATCH_PRICE][VALUE],
# add emission_factor for emission contraint
emission_factor=dict_asset[EMISSION_FACTOR][VALUE],
custom_attributes=dict(
emission_factor=dict_asset[EMISSION_FACTOR][VALUE]
),
)
}
source_dispatchable = solph.Source(label=dict_asset[LABEL], outputs=outputs,)
source_dispatchable = solph.components.Source(
label=dict_asset[LABEL], outputs=outputs,
)
else:
if TIMESERIES in dict_asset:
logging.info(
Expand All @@ -1167,12 +1180,13 @@ def source_dispatchable_fix(model, dict_asset, **kwargs):
)
outputs = {
kwargs[OEMOF_BUSSES][dict_asset[OUTFLOW_DIRECTION]]: solph.Flow(
label=dict_asset[LABEL],
existing=dict_asset[INSTALLED_CAP][VALUE],
nominal_value=dict_asset[INSTALLED_CAP][VALUE],
variable_costs=dict_asset[DISPATCH_PRICE][VALUE],
)
}
source_dispatchable = solph.Source(label=dict_asset[LABEL], outputs=outputs,)
source_dispatchable = solph.components.Source(
label=dict_asset[LABEL], outputs=outputs,
)
model.add(source_dispatchable)
kwargs[OEMOF_SOURCE].update({dict_asset[LABEL]: source_dispatchable})
logging.debug(
Expand Down Expand Up @@ -1206,22 +1220,20 @@ def sink_dispatchable_optimize(model, dict_asset, **kwargs):
index = 0
for bus in dict_asset[INFLOW_DIRECTION]:
inputs[kwargs[OEMOF_BUSSES][bus]] = solph.Flow(
label=dict_asset[LABEL],
variable_costs=dict_asset[DISPATCH_PRICE][VALUE][index],
investment=solph.Investment(),
)
index += 1
else:
inputs = {
kwargs[OEMOF_BUSSES][dict_asset[INFLOW_DIRECTION]]: solph.Flow(
label=dict_asset[LABEL],
variable_costs=dict_asset[DISPATCH_PRICE][VALUE],
investment=solph.Investment(),
)
}

# create and add excess electricity sink to micro_grid_system - variable
sink_dispatchable = solph.Sink(label=dict_asset[LABEL], inputs=inputs,)
sink_dispatchable = solph.components.Sink(label=dict_asset[LABEL], inputs=inputs,)
model.add(sink_dispatchable)
kwargs[OEMOF_SINK].update({dict_asset[LABEL]: sink_dispatchable})
logging.debug(
Expand Down Expand Up @@ -1263,7 +1275,7 @@ def sink_non_dispatchable(model, dict_asset, **kwargs):
}

# create and add demand sink to micro_grid_system - fixed
sink_demand = solph.Sink(label=dict_asset[LABEL], inputs=inputs,)
sink_demand = solph.components.Sink(label=dict_asset[LABEL], inputs=inputs,)
model.add(sink_demand)
kwargs[OEMOF_SINK].update({dict_asset[LABEL]: sink_demand})
logging.debug(
Expand Down
7 changes: 7 additions & 0 deletions src/multi_vector_simulator/D2_model_constraints.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def renewable_share_rule(model):
renewable_assets[asset][OEMOF_SOLPH_OBJECT_ASSET],
renewable_assets[asset][OEMOF_SOLPH_OBJECT_BUS],
:,
:,
]
)
* renewable_assets[asset][WEIGHTING_FACTOR_ENERGY_CARRIER]
Expand All @@ -208,6 +209,7 @@ def renewable_share_rule(model):
non_renewable_assets[asset][OEMOF_SOLPH_OBJECT_ASSET],
non_renewable_assets[asset][OEMOF_SOLPH_OBJECT_BUS],
:,
:,
]
)
* non_renewable_assets[asset][WEIGHTING_FACTOR_ENERGY_CARRIER]
Expand Down Expand Up @@ -439,12 +441,14 @@ def degree_of_autonomy_rule(model):

# Get the flows from demands and add weighing
for asset in demands:

demand_one_asset = (
sum(
model.flow[
demands[asset][OEMOF_SOLPH_OBJECT_BUS],
demands[asset][OEMOF_SOLPH_OBJECT_ASSET],
:,
:,
]
)
* demands[asset][WEIGHTING_FACTOR_ENERGY_CARRIER]
Expand All @@ -463,6 +467,7 @@ def degree_of_autonomy_rule(model):
OEMOF_SOLPH_OBJECT_BUS
],
:,
:,
]
)
* energy_provider_consumption_sources[asset][
Expand Down Expand Up @@ -737,6 +742,7 @@ def net_zero_energy(model):
OEMOF_SOLPH_OBJECT_BUS
],
:,
:,
]
)
* energy_provider_consumption_sources[asset][
Expand All @@ -755,6 +761,7 @@ def net_zero_energy(model):
OEMOF_SOLPH_OBJECT_ASSET
],
:,
:,
]
)
* energy_provider_feedin_sinks[asset][
Expand Down
2 changes: 1 addition & 1 deletion src/multi_vector_simulator/E0_evaluation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import logging

import oemof.solph as solph
from oemof import solph
import pandas as pd

import multi_vector_simulator.E1_process_results as E1
Expand Down
2 changes: 1 addition & 1 deletion src/multi_vector_simulator/E1_process_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ def get_flow(settings, bus, dict_asset, flow_tuple, multi_bus=None):
add_info_flows(
evaluated_period=settings[EVALUATED_PERIOD][VALUE],
dict_asset=dict_asset,
flow=flow,
flow=flow.dropna(),
bus_name=multi_bus,
)
if multi_bus is None:
Expand Down
2 changes: 1 addition & 1 deletion src/multi_vector_simulator/F1_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

import graphviz
import oemof
import oemof.solph as solph
from oemof import solph

from multi_vector_simulator.utils.constants import (
PROJECT_DATA,
Expand Down
8 changes: 4 additions & 4 deletions tests/test_D0_modelling_and_optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import shutil
import argparse

import oemof.solph
from oemof import solph
import pandas as pd
import pytest
import mock
Expand Down Expand Up @@ -115,7 +115,7 @@ def test_energysystem_initialized(dict_values_minimal):
):
assert k in dict_model.keys()
assert isinstance(
model, oemof.solph.network.EnergySystem
model, solph.network.EnergySystem
), f"The oemof model has not been successfully created."


Expand Down Expand Up @@ -231,7 +231,7 @@ def test_if_lp_file_is_stored_to_file_if_output_lp_file_true(dict_values):
model = D0.model_building.adding_assets_to_energysystem_model(
dict_values, dict_model, model
)
local_energy_system = oemof.solph.Model(model)
local_energy_system = solph.Model(model)
dict_values[SIMULATION_SETTINGS][OUTPUT_LP_FILE].update({VALUE: True})
D0.model_building.store_lp_file(dict_values, local_energy_system)
assert (
Expand All @@ -248,7 +248,7 @@ def test_if_lp_file_is_stored_to_file_if_output_lp_file_false(dict_values):
model = D0.model_building.adding_assets_to_energysystem_model(
dict_values, dict_model, model
)
local_energy_system = oemof.solph.Model(model)
local_energy_system = solph.Model(model)
dict_values[SIMULATION_SETTINGS][OUTPUT_LP_FILE].update({VALUE: False})
D0.model_building.store_lp_file(dict_values, local_energy_system)
assert (
Expand Down
Loading

0 comments on commit 9bd5b1e

Please sign in to comment.