From c4f93658ae76f1bd50aa3c9633e4778606dc7b15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sch=C3=B6nfeldt?= Date: Wed, 11 Oct 2023 13:16:51 +0200 Subject: [PATCH 01/25] Delete useless test The test seems to be designed to test if warnings can be turned off. However, the operation never created one. --- tests/test_warnings.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/tests/test_warnings.py b/tests/test_warnings.py index cf465ac53..616277a0c 100644 --- a/tests/test_warnings.py +++ b/tests/test_warnings.py @@ -50,15 +50,6 @@ def test_that_the_sink_errors_actually_get_raised(warning_fixture): assert msg in str(w[-1].message) -def test_filtered_warning(warning_fixture): - """Sink doesn't warn about potentially erroneous usage.""" - warnings.filterwarnings("ignore", category=SuspiciousUsageWarning) - look_out = network.Bus() - with warnings.catch_warnings(record=True) as w: - network.Sink(outputs={look_out: "A typo!"}) - assert len(w) == 0 - - def test_that_the_source_warnings_actually_get_raised(warning_fixture): """Source doesn't warn about potentially erroneous usage.""" look_out = network.Bus() From 860b74237bc955d39ed8389bd8361a41bdeb6493 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sch=C3=B6nfeldt?= Date: Wed, 11 Oct 2023 13:18:17 +0200 Subject: [PATCH 02/25] Disuse network.Bus in warnings test --- tests/test_warnings.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/test_warnings.py b/tests/test_warnings.py index 616277a0c..c3fac5e37 100644 --- a/tests/test_warnings.py +++ b/tests/test_warnings.py @@ -13,7 +13,6 @@ import pandas as pd import pytest -from oemof.network import network from oemof.tools.debugging import SuspiciousUsageWarning from oemof import solph @@ -31,7 +30,7 @@ def warning_fixture(): def test_that_the_sink_errors_actually_get_raised(warning_fixture): """Sink doesn't warn about potentially erroneous usage.""" - look_out = network.Bus() + look_out = solph.Bus() with pytest.raises( TypeError, match="got an unexpected keyword argument 'outputs'" ): @@ -52,7 +51,7 @@ def test_that_the_sink_errors_actually_get_raised(warning_fixture): def test_that_the_source_warnings_actually_get_raised(warning_fixture): """Source doesn't warn about potentially erroneous usage.""" - look_out = network.Bus() + look_out = solph.Bus() with pytest.raises( TypeError, match="got an unexpected keyword argument 'inputs'" ): @@ -75,7 +74,7 @@ def test_that_the_source_warnings_actually_get_raised(warning_fixture): def test_that_the_converter_warnings_actually_get_raised(warning_fixture): """Converter doesn't warn about potentially erroneous usage.""" - look_out = network.Bus() + look_out = solph.Bus() msg = ( "Attribute is missing in Node of ." @@ -100,7 +99,7 @@ def test_that_the_converter_warnings_actually_get_raised(warning_fixture): def test_storage_without_outputs(warning_fixture): """GenericStorage doesn't warn correctly about missing outputs.""" - look_out = network.Bus() + look_out = solph.Bus() msg = ( "Attribute is missing in Node " " of ." @@ -115,7 +114,7 @@ def test_storage_without_outputs(warning_fixture): def test_storage_without_inputs(warning_fixture): """GenericStorage doesn't warn correctly about missing inputs.""" - look_out = network.Bus() + look_out = solph.Bus() msg = ( "Attribute is missing in Node " " of ." From 55f3fdc91a7a8704e0d2d8c3c9ba392c6f9a420d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sch=C3=B6nfeldt?= Date: Wed, 11 Oct 2023 17:01:25 +0200 Subject: [PATCH 03/25] Disuse subclasses of oemof.network.Node --- src/oemof/solph/buses/_bus.py | 4 ++-- src/oemof/solph/components/_converter.py | 4 ++-- src/oemof/solph/components/_generic_chp.py | 4 ++-- src/oemof/solph/components/_generic_storage.py | 4 ++-- src/oemof/solph/components/_link.py | 4 ++-- src/oemof/solph/components/_offset_converter.py | 4 ++-- src/oemof/solph/components/_sink.py | 4 ++-- src/oemof/solph/components/_source.py | 4 ++-- src/oemof/solph/components/experimental/_generic_caes.py | 4 ++-- .../components/experimental/_piecewise_linear_converter.py | 4 ++-- src/oemof/solph/flows/_flow.py | 4 ++-- 11 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/oemof/solph/buses/_bus.py b/src/oemof/solph/buses/_bus.py index 704ddd7a9..20f97ecaa 100644 --- a/src/oemof/solph/buses/_bus.py +++ b/src/oemof/solph/buses/_bus.py @@ -15,13 +15,13 @@ """ -from oemof.network import network as on +from oemof.network import Node from pyomo.core import BuildAction from pyomo.core import Constraint from pyomo.core.base.block import ScalarBlock -class Bus(on.Bus): +class Bus(Node): """A balance object. Every component has to be connected to buses. The sum of all inputs of a Bus object must equal the sum of all outputs diff --git a/src/oemof/solph/components/_converter.py b/src/oemof/solph/components/_converter.py index 90782646b..a2e9a559b 100644 --- a/src/oemof/solph/components/_converter.py +++ b/src/oemof/solph/components/_converter.py @@ -23,7 +23,7 @@ from warnings import warn -from oemof.network import network as on +from oemof.network import Node from pyomo.core import BuildAction from pyomo.core import Constraint from pyomo.core.base.block import ScalarBlock @@ -32,7 +32,7 @@ from oemof.solph._plumbing import sequence -class Converter(on.Transformer): +class Converter(Node): """A linear ConverterBlock object with n inputs and n outputs. Node object that relates any number of inflow and outflows with diff --git a/src/oemof/solph/components/_generic_chp.py b/src/oemof/solph/components/_generic_chp.py index d817f00f5..d7853e2fe 100644 --- a/src/oemof/solph/components/_generic_chp.py +++ b/src/oemof/solph/components/_generic_chp.py @@ -19,7 +19,7 @@ """ import numpy as np -from oemof.network import network +from oemof.network import Node from pyomo.core.base.block import ScalarBlock from pyomo.environ import Binary from pyomo.environ import Constraint @@ -30,7 +30,7 @@ from oemof.solph._plumbing import sequence -class GenericCHP(network.Transformer): +class GenericCHP(Node): r""" Component `GenericCHP` to model combined heat and power plants. diff --git a/src/oemof/solph/components/_generic_storage.py b/src/oemof/solph/components/_generic_storage.py index a10e02ca3..5175985ad 100644 --- a/src/oemof/solph/components/_generic_storage.py +++ b/src/oemof/solph/components/_generic_storage.py @@ -23,7 +23,7 @@ from warnings import warn import numpy as np -from oemof.network import network +from oemof.network import Node from oemof.tools import debugging from oemof.tools import economics from pyomo.core.base.block import ScalarBlock @@ -40,7 +40,7 @@ from oemof.solph._plumbing import sequence as solph_sequence -class GenericStorage(network.Component): +class GenericStorage(Node): r""" Component `GenericStorage` to model with basic characteristics of storages. diff --git a/src/oemof/solph/components/_link.py b/src/oemof/solph/components/_link.py index e4b2c47f2..f48a04209 100644 --- a/src/oemof/solph/components/_link.py +++ b/src/oemof/solph/components/_link.py @@ -18,7 +18,7 @@ """ from warnings import warn -from oemof.network import network as on +from oemof.network import Node from oemof.tools import debugging from pyomo.core import Set from pyomo.core.base.block import ScalarBlock @@ -29,7 +29,7 @@ from oemof.solph._plumbing import sequence -class Link(on.Transformer): +class Link(Node): """A Link object with 2 inputs and 2 outputs. Parameters diff --git a/src/oemof/solph/components/_offset_converter.py b/src/oemof/solph/components/_offset_converter.py index d73165d6a..606b0f3ad 100644 --- a/src/oemof/solph/components/_offset_converter.py +++ b/src/oemof/solph/components/_offset_converter.py @@ -21,7 +21,7 @@ from warnings import warn -from oemof.network import network +from oemof.network import Node from pyomo.core import BuildAction from pyomo.core.base.block import ScalarBlock from pyomo.environ import Constraint @@ -30,7 +30,7 @@ from oemof.solph._plumbing import sequence -class OffsetConverter(network.Transformer): +class OffsetConverter(Node): """An object with one input and one output and two coefficients to model part load behaviour. diff --git a/src/oemof/solph/components/_sink.py b/src/oemof/solph/components/_sink.py index 883dda31a..1890ec7d0 100644 --- a/src/oemof/solph/components/_sink.py +++ b/src/oemof/solph/components/_sink.py @@ -15,11 +15,11 @@ """ from warnings import warn -from oemof.network import network as on +from oemof.network import Node from oemof.tools import debugging -class Sink(on.Sink): +class Sink(Node): """A component which is designed for one input flow. Parameters diff --git a/src/oemof/solph/components/_source.py b/src/oemof/solph/components/_source.py index 287c8d2b5..fae32697f 100644 --- a/src/oemof/solph/components/_source.py +++ b/src/oemof/solph/components/_source.py @@ -16,11 +16,11 @@ from warnings import warn -from oemof.network import network as on +from oemof.network import Node from oemof.tools import debugging -class Source(on.Source): +class Source(Node): """A component which is designed for one output flow. Parameters diff --git a/src/oemof/solph/components/experimental/_generic_caes.py b/src/oemof/solph/components/experimental/_generic_caes.py index 25948b5bc..69e4d5643 100644 --- a/src/oemof/solph/components/experimental/_generic_caes.py +++ b/src/oemof/solph/components/experimental/_generic_caes.py @@ -17,7 +17,7 @@ """ -from oemof.network import network as on +from oemof.network import Node from pyomo.core.base.block import ScalarBlock from pyomo.environ import Binary from pyomo.environ import Constraint @@ -26,7 +26,7 @@ from pyomo.environ import Var -class GenericCAES(on.Transformer): +class GenericCAES(Node): """ Component `GenericCAES` to model arbitrary compressed air energy storages. diff --git a/src/oemof/solph/components/experimental/_piecewise_linear_converter.py b/src/oemof/solph/components/experimental/_piecewise_linear_converter.py index ebdf47349..6d6b68c9b 100644 --- a/src/oemof/solph/components/experimental/_piecewise_linear_converter.py +++ b/src/oemof/solph/components/experimental/_piecewise_linear_converter.py @@ -17,7 +17,7 @@ """ -from oemof.network import network as on +from oemof.network import Node from pyomo.core.base.block import ScalarBlock from pyomo.environ import BuildAction from pyomo.environ import Constraint @@ -26,7 +26,7 @@ from pyomo.environ import Var -class PiecewiseLinearConverter(on.Transformer): +class PiecewiseLinearConverter(Node): """Component to model an energy converter with one input and one output and an arbitrary piecewise linear conversion function. diff --git a/src/oemof/solph/flows/_flow.py b/src/oemof/solph/flows/_flow.py index 03b929575..964f570d1 100644 --- a/src/oemof/solph/flows/_flow.py +++ b/src/oemof/solph/flows/_flow.py @@ -23,14 +23,14 @@ from warnings import warn import numpy as np -from oemof.network import network as on +from oemof.network import Edge from oemof.tools import debugging from oemof.solph._options import Investment from oemof.solph._plumbing import sequence -class Flow(on.Edge): +class Flow(Edge): r"""Defines a flow between two nodes. Keyword arguments are used to set the attributes of this flow. Parameters From ecb8c25c76101751c14002f1be320810888ad667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sch=C3=B6nfeldt?= Date: Wed, 11 Oct 2023 18:21:46 +0200 Subject: [PATCH 04/25] Use pytest.approx(x) instead of int(round(x)) --- .../test_connect_invest/test_connect_invest.py | 11 ++++++----- .../test_solph/test_generic_caes/test_generic_caes.py | 3 ++- .../test_solph/test_generic_chp/test_generic_chp.py | 3 ++- tests/test_scripts/test_solph/test_lopf/test_lopf.py | 5 +++-- .../test_simple_model/test_simple_dispatch.py | 3 ++- .../test_simple_model/test_simple_dispatch_one.py | 4 +++- .../test_simple_dispatch_one_explicit_timemode.py | 4 +++- .../test_simple_model/test_simple_invest.py | 3 ++- .../test_storage_investment.py | 3 ++- .../test_storage_with_tuple_label.py | 11 +++++++---- .../test_solph/test_variable_chp/test_variable_chp.py | 9 +++++---- 11 files changed, 37 insertions(+), 22 deletions(-) diff --git a/tests/test_scripts/test_solph/test_connect_invest/test_connect_invest.py b/tests/test_scripts/test_solph/test_connect_invest/test_connect_invest.py index 91637d424..f2bdfbc98 100644 --- a/tests/test_scripts/test_solph/test_connect_invest/test_connect_invest.py +++ b/tests/test_scripts/test_solph/test_connect_invest/test_connect_invest.py @@ -12,6 +12,7 @@ import logging import os +import pytest import pandas as pd @@ -131,11 +132,11 @@ def test_connect_invest(): stor_res = views.node(results, "storage")["scalars"] my_results["storage_in"] = stor_res[ [(("electricity1", "storage"), "invest")] - ] - my_results["storage"] = stor_res[[(("storage", "None"), "invest")]] + ].iloc[0] + my_results["storage"] = stor_res[[(("storage", "None"), "invest")]].iloc[0] my_results["storage_out"] = stor_res[ [(("storage", "electricity1"), "invest")] - ] + ].iloc[0] connect_invest_dict = { "line12": 814705, @@ -146,6 +147,6 @@ def test_connect_invest(): } for key in connect_invest_dict.keys(): - assert int(round(my_results[key])) == int( - round(connect_invest_dict[key]) + assert my_results[key] == pytest.approx( + connect_invest_dict[key], abs=0.5 ) diff --git a/tests/test_scripts/test_solph/test_generic_caes/test_generic_caes.py b/tests/test_scripts/test_solph/test_generic_caes/test_generic_caes.py index 281637777..a4a907ba4 100644 --- a/tests/test_scripts/test_solph/test_generic_caes/test_generic_caes.py +++ b/tests/test_scripts/test_solph/test_generic_caes/test_generic_caes.py @@ -15,6 +15,7 @@ import os import pandas as pd +import pytest from oemof.solph import EnergySystem from oemof.solph import Model @@ -140,4 +141,4 @@ def test_gen_caes(): } for key in test_dict.keys(): - assert int(round(data[key])) == int(round(test_dict[key])) + assert data[key] == pytest.approx(test_dict[key]) diff --git a/tests/test_scripts/test_solph/test_generic_chp/test_generic_chp.py b/tests/test_scripts/test_solph/test_generic_chp/test_generic_chp.py index 175157200..54c2744af 100644 --- a/tests/test_scripts/test_solph/test_generic_chp/test_generic_chp.py +++ b/tests/test_scripts/test_solph/test_generic_chp/test_generic_chp.py @@ -15,6 +15,7 @@ import os import pandas as pd +import pytest from oemof import solph as solph from oemof.solph import processing @@ -124,4 +125,4 @@ def test_gen_chp(): } for key in test_dict.keys(): - assert int(round(data[key])) == int(round(test_dict[key])) + assert data[key] == pytest.approx(test_dict[key]) diff --git a/tests/test_scripts/test_solph/test_lopf/test_lopf.py b/tests/test_scripts/test_solph/test_lopf/test_lopf.py index f3ea9f649..3b36fdf28 100644 --- a/tests/test_scripts/test_solph/test_lopf/test_lopf.py +++ b/tests/test_scripts/test_solph/test_lopf/test_lopf.py @@ -15,6 +15,7 @@ import logging import pandas as pd +import pytest from oemof.solph import EnergySystem from oemof.solph import Investment @@ -124,8 +125,8 @@ def test_lopf(solver="cbc"): for key in generators_test_results.keys(): logging.debug("Test genertor production of {0}".format(key)) - assert int(round(generators[key])) == int( - round(generators_test_results[key]) + assert generators[key].iloc[0] == pytest.approx( + generators_test_results[key] ) assert ( diff --git a/tests/test_scripts/test_solph/test_simple_model/test_simple_dispatch.py b/tests/test_scripts/test_solph/test_simple_model/test_simple_dispatch.py index ee694a772..44da686c7 100644 --- a/tests/test_scripts/test_solph/test_simple_model/test_simple_dispatch.py +++ b/tests/test_scripts/test_solph/test_simple_model/test_simple_dispatch.py @@ -16,6 +16,7 @@ import os import pandas as pd +import pytest from oemof.solph import EnergySystem from oemof.solph import Model @@ -190,4 +191,4 @@ def test_dispatch_example(solver="cbc", periods=24 * 5): } for key in test_results.keys(): - assert int(round(results[key])) == int(round(test_results[key])) + assert results[key] == pytest.approx(test_results[key], abs=0.5) diff --git a/tests/test_scripts/test_solph/test_simple_model/test_simple_dispatch_one.py b/tests/test_scripts/test_solph/test_simple_model/test_simple_dispatch_one.py index d7e4c3a6c..bb4d30d20 100644 --- a/tests/test_scripts/test_solph/test_simple_model/test_simple_dispatch_one.py +++ b/tests/test_scripts/test_solph/test_simple_model/test_simple_dispatch_one.py @@ -11,6 +11,8 @@ SPDX-License-Identifier: MIT """ +import pytest + from oemof.solph import EnergySystem from oemof.solph import Model from oemof.solph import processing @@ -116,4 +118,4 @@ def test_dispatch_one_time_step(solver="cbc"): } for key in test_results.keys(): - assert int(round(results[key])) == int(round(test_results[key])) + assert results[key] == pytest.approx(test_results[key], abs=0.5) diff --git a/tests/test_scripts/test_solph/test_simple_model/test_simple_dispatch_one_explicit_timemode.py b/tests/test_scripts/test_solph/test_simple_model/test_simple_dispatch_one_explicit_timemode.py index d7e4c3a6c..bb4d30d20 100644 --- a/tests/test_scripts/test_solph/test_simple_model/test_simple_dispatch_one_explicit_timemode.py +++ b/tests/test_scripts/test_solph/test_simple_model/test_simple_dispatch_one_explicit_timemode.py @@ -11,6 +11,8 @@ SPDX-License-Identifier: MIT """ +import pytest + from oemof.solph import EnergySystem from oemof.solph import Model from oemof.solph import processing @@ -116,4 +118,4 @@ def test_dispatch_one_time_step(solver="cbc"): } for key in test_results.keys(): - assert int(round(results[key])) == int(round(test_results[key])) + assert results[key] == pytest.approx(test_results[key], abs=0.5) diff --git a/tests/test_scripts/test_solph/test_simple_model/test_simple_invest.py b/tests/test_scripts/test_solph/test_simple_model/test_simple_invest.py index 5a60a3e61..a1d53601a 100644 --- a/tests/test_scripts/test_solph/test_simple_model/test_simple_invest.py +++ b/tests/test_scripts/test_solph/test_simple_model/test_simple_invest.py @@ -16,6 +16,7 @@ import os import pandas as pd +import pytest from oemof.tools import economics from oemof.solph import EnergySystem @@ -208,4 +209,4 @@ def test_dispatch_example(solver="cbc", periods=24 * 5): } for key in test_results.keys(): - assert int(round(comp_results[key])) == int(round(test_results[key])) + assert comp_results[key] == pytest.approx(test_results[key], abs=0.5) diff --git a/tests/test_scripts/test_solph/test_storage_investment/test_storage_investment.py b/tests/test_scripts/test_solph/test_storage_investment/test_storage_investment.py index a22ec81bb..3772edddc 100644 --- a/tests/test_scripts/test_solph/test_storage_investment/test_storage_investment.py +++ b/tests/test_scripts/test_solph/test_storage_investment/test_storage_investment.py @@ -38,6 +38,7 @@ import os import pandas as pd +import pytest from oemof.tools import economics from oemof import solph @@ -179,7 +180,7 @@ def test_results_with_actual_dump(): } for key in stor_invest_dict.keys(): - assert int(round(my_results[key])) == int(round(stor_invest_dict[key])) + assert my_results[key] == pytest.approx(stor_invest_dict[key]) # Solver results assert str(meta["solver"]["Termination condition"]) == "optimal" diff --git a/tests/test_scripts/test_solph/test_storage_investment/test_storage_with_tuple_label.py b/tests/test_scripts/test_solph/test_storage_investment/test_storage_with_tuple_label.py index 845820fcf..2c38fcdb6 100644 --- a/tests/test_scripts/test_solph/test_storage_investment/test_storage_with_tuple_label.py +++ b/tests/test_scripts/test_solph/test_storage_investment/test_storage_with_tuple_label.py @@ -36,6 +36,7 @@ import logging import os +import pytest from collections import namedtuple import pandas as pd @@ -171,9 +172,11 @@ def test_tuples_as_labels_example( my_results = electricity_bus["sequences"].sum(axis=0).to_dict() storage = es.groups["storage_electricity_battery"] storage_node = views.node(results, storage) - my_results["max_load"] = storage_node["sequences"].max()[ - [((storage, None), "storage_content")] - ] + my_results["max_load"] = ( + storage_node["sequences"] + .max()[[((storage, None), "storage_content")]] + .iloc[0] + ) commodity_bus = views.node(results, "bus_natural_gas_None") gas_usage = commodity_bus["sequences"][ @@ -201,7 +204,7 @@ def test_tuples_as_labels_example( } for key in stor_invest_dict.keys(): - assert int(round(my_results[key])) == int(round(stor_invest_dict[key])) + assert my_results[key] == pytest.approx(stor_invest_dict[key]) # Solver results assert str(meta["solver"]["Termination condition"]) == "optimal" diff --git a/tests/test_scripts/test_solph/test_variable_chp/test_variable_chp.py b/tests/test_scripts/test_solph/test_variable_chp/test_variable_chp.py index 59b940a82..918249e7e 100644 --- a/tests/test_scripts/test_solph/test_variable_chp/test_variable_chp.py +++ b/tests/test_scripts/test_solph/test_variable_chp/test_variable_chp.py @@ -16,6 +16,7 @@ import os import pandas as pd +import pytest from oemof import solph from oemof.solph import views @@ -172,14 +173,14 @@ def test_variable_chp(filename="variable_chp.csv", solver="cbc"): for key in variable_chp_dict_max.keys(): logging.debug("Test the maximum value of {0}".format(key)) - assert int(round(maxresults[[key]])) == int( - round(variable_chp_dict_max[key]) + assert maxresults[[key]].iloc[0] == pytest.approx( + variable_chp_dict_max[key] ) for key in variable_chp_dict_sum.keys(): logging.debug("Test the summed up value of {0}".format(key)) - assert int(round(sumresults[[key]])) == int( - round(variable_chp_dict_sum[key]) + assert sumresults[[key]].iloc[0] == pytest.approx( + variable_chp_dict_sum[key] ) assert ( From 3e02fc59e987553b6baae77fa1850c237ac72748 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sch=C3=B6nfeldt?= Date: Wed, 11 Oct 2023 22:10:05 +0200 Subject: [PATCH 05/25] Embrace conformity * pytest.approx instead of roundin * series.iloc[int] instead of series[int] --- tests/test_non_equidistant_time_index.py | 37 ++++++++++--------- tests/test_processing.py | 24 +++++++----- .../test_solph/test_lopf/test_lopf.py | 16 ++++++-- .../test_storage_investment.py | 2 +- .../test_storage_with_tuple_label.py | 2 +- .../test_variable_chp/test_variable_chp.py | 4 +- tests/test_solph_network_classes.py | 14 ++++--- 7 files changed, 60 insertions(+), 39 deletions(-) diff --git a/tests/test_non_equidistant_time_index.py b/tests/test_non_equidistant_time_index.py index 488e826ef..60da70a97 100644 --- a/tests/test_non_equidistant_time_index.py +++ b/tests/test_non_equidistant_time_index.py @@ -10,6 +10,7 @@ import random import pandas as pd +import pytest from oemof.solph import EnergySystem from oemof.solph import Investment @@ -84,7 +85,7 @@ def test_timesteps_timeincrements_with_storage_charging(self): for k, v in self.comp.items() if k[0].label == "storage" ][0] - assert storage_content[0] == storage_content[-1] + assert storage_content.iloc[0] == storage_content.iloc[-1] charge = [ v["sequences"]["flow"] @@ -96,9 +97,9 @@ def test_timesteps_timeincrements_with_storage_charging(self): # Charging - timestep (ts) with its timeincrement (ti) time = [(23, 1), (24, 0.5)] for ts, ti in time: - assert round(storage_content[ts] + charge[ts] * ti, 5) == round( - storage_content[ts + 1], 5 - ) + assert storage_content.iloc[ts] + charge.iloc[ + ts + ] * ti == pytest.approx(storage_content.iloc[ts + 1]) assert self.es.timeincrement[ts] == ti assert charge.isnull().any() @@ -110,7 +111,7 @@ def test_timesteps_timeincrements_with_storage_discharging(self): ][0] # Storage content at the last time point is equal to the content of # the first time point because the storage is balanced. - assert storage_content[0] == storage_content[-1] + assert storage_content.iloc[0] == storage_content.iloc[-1] discharge = [ v["sequences"]["flow"] @@ -123,11 +124,10 @@ def test_timesteps_timeincrements_with_storage_discharging(self): # Discharging - timestep (ts) with its timeincrement (ti) time = [(7, 1), (40, 0.5)] for ts, ti in time: - assert round( - storage_content[ts] - - (discharge[ts] + (discharge[ts] * 1 / 9)) * ti, - 5, - ) == round(storage_content[ts + 1], 5) + assert ( + storage_content.iloc[ts] + - (discharge.iloc[ts] + (discharge.iloc[ts] * 1 / 9)) * ti + ) == pytest.approx(storage_content.iloc[ts + 1]) assert self.es.timeincrement[ts] == ti def test_timeincrements(self): @@ -150,8 +150,11 @@ def test_without_last_time_point(self): # The first and the last value are not the same because the last value # of the storage is missing. Adding the charging of the last time step # will result the final storage content, which is equal to the first - assert storage_content[0] != storage_content[-1] - assert storage_content[0] == storage_content[-1] + charge[-1] / 2 + assert storage_content.iloc[0] != storage_content.iloc[-1] + assert ( + storage_content.iloc[0] + == storage_content.iloc[-1] + charge.iloc[-1] / 2 + ) assert not charge.isnull().any() assert storage_content.index[0] == datetime.datetime( 2012, 1, 1, 0, 0, 0 @@ -168,7 +171,7 @@ def test_time_index_with_last_time_point(self): for k, v in self.comp.items() if k[0].label == "storage" ][0] - assert storage_content[0] == storage_content[-1] + assert storage_content.iloc[0] == storage_content.iloc[-1] charge = [ v["sequences"]["flow"] @@ -205,7 +208,7 @@ def test_numeric_index(self): for k, v in self.comp.items() if k[0].label == "storage" ][0] - assert storage_content[0] == storage_content[-1] + assert storage_content.iloc[0] == storage_content.iloc[-1] charge = [ v["sequences"]["flow"] @@ -217,8 +220,8 @@ def test_numeric_index(self): # Charging - timestep (ts) with its timeincrement (ti) time = [(23, 1), (24, 0.5)] for ts, ti in time: - assert round(storage_content[ts] + charge[ts] * ti, 5) == round( - storage_content[ts + 1], 5 - ) + assert ( + storage_content.iloc[ts] + charge.iloc[ts] * ti + ) == pytest.approx(storage_content.iloc[ts + 1]) assert self.es.timeincrement[ts] == ti assert charge.isnull().any() diff --git a/tests/test_processing.py b/tests/test_processing.py index 6cc68ccc2..ae0695ae4 100644 --- a/tests/test_processing.py +++ b/tests/test_processing.py @@ -301,7 +301,9 @@ def test_node_weight_by_type(self): storage_content = views.node_weight_by_type( results, node_type=GenericStorage ) - assert round(float(storage_content.sum()), 1) == 1437.5 + assert ( + storage_content.sum().iloc[0] == pytest.approx(1437.5, abs=0.1) + ).all() def test_output_by_type_view(self): results = processing.results(self.om) @@ -311,13 +313,13 @@ def test_output_by_type_view(self): compare = views.node(results, "diesel", multiindex=True)["sequences"][ ("diesel", "b_el1", "flow") ] - assert int(converter_output.sum()) == int(compare.sum()) + assert converter_output.sum().iloc[0] == pytest.approx(compare.sum()) def test_input_by_type_view(self): results = processing.results(self.om) sink_input = views.node_input_by_type(results, node_type=Sink) compare = views.node(results, "demand_el", multiindex=True) - assert int(sink_input.sum()) == int( + assert sink_input.sum().iloc[0] == pytest.approx( compare["sequences"][("b_el2", "demand_el", "flow")].sum() ) @@ -331,13 +333,17 @@ def test_net_storage_flow(self): assert ( ( - compare[("storage", "b_el2", "flow")] - - compare[("b_el1", "storage", "flow")] + ( + compare[("storage", "b_el2", "flow")] + - compare[("b_el1", "storage", "flow")] + ) + .to_frame() + .fillna(0) + == storage_flow.values ) - .to_frame() - .fillna(0) - == storage_flow.values - ).all()[0] + .all() + .iloc[0] + ) def test_output_by_type_view_empty(self): results = processing.results(self.om) diff --git a/tests/test_scripts/test_solph/test_lopf/test_lopf.py b/tests/test_scripts/test_solph/test_lopf/test_lopf.py index 3b36fdf28..beccd909a 100644 --- a/tests/test_scripts/test_solph/test_lopf/test_lopf.py +++ b/tests/test_scripts/test_solph/test_lopf/test_lopf.py @@ -130,19 +130,27 @@ def test_lopf(solver="cbc"): ) assert ( - results[es.groups["b_2"], es.groups["b_0"]]["sequences"]["flow"][0] + results[es.groups["b_2"], es.groups["b_0"]]["sequences"]["flow"].iloc[ + 0 + ] == -40 ) assert ( - results[es.groups["b_1"], es.groups["b_2"]]["sequences"]["flow"][0] + results[es.groups["b_1"], es.groups["b_2"]]["sequences"]["flow"].iloc[ + 0 + ] == 60 ) assert ( - results[es.groups["b_0"], es.groups["b_1"]]["sequences"]["flow"][0] + results[es.groups["b_0"], es.groups["b_1"]]["sequences"]["flow"].iloc[ + 0 + ] == -20 ) # objective function - assert round(processing.meta_results(om)["objective"]) == 3200 + assert processing.meta_results(om)["objective"] == pytest.approx( + 3200, abs=0.5 + ) diff --git a/tests/test_scripts/test_solph/test_storage_investment/test_storage_investment.py b/tests/test_scripts/test_solph/test_storage_investment/test_storage_investment.py index 3772edddc..0975a8d15 100644 --- a/tests/test_scripts/test_solph/test_storage_investment/test_storage_investment.py +++ b/tests/test_scripts/test_solph/test_storage_investment/test_storage_investment.py @@ -197,7 +197,7 @@ def test_results_with_actual_dump(): assert str(meta["problem"]["Sense"]) == "minimize" # Objective function - assert round(meta["objective"]) == 423167578261115584 + assert meta["objective"] == pytest.approx(423167578261115584, abs=0.5) def test_solph_converter_attributes_before_dump_and_after_restore(): diff --git a/tests/test_scripts/test_solph/test_storage_investment/test_storage_with_tuple_label.py b/tests/test_scripts/test_solph/test_storage_investment/test_storage_with_tuple_label.py index 2c38fcdb6..6ddbf5c18 100644 --- a/tests/test_scripts/test_solph/test_storage_investment/test_storage_with_tuple_label.py +++ b/tests/test_scripts/test_solph/test_storage_investment/test_storage_with_tuple_label.py @@ -221,4 +221,4 @@ def test_tuples_as_labels_example( assert str(meta["problem"]["Sense"]) == "minimize" # Objective function - assert round(meta["objective"]) == 37819254 + assert meta["objective"] == pytest.approx(37819254, abs=0.5) diff --git a/tests/test_scripts/test_solph/test_variable_chp/test_variable_chp.py b/tests/test_scripts/test_solph/test_variable_chp/test_variable_chp.py index 918249e7e..4af4e53fa 100644 --- a/tests/test_scripts/test_solph/test_variable_chp/test_variable_chp.py +++ b/tests/test_scripts/test_solph/test_variable_chp/test_variable_chp.py @@ -197,4 +197,6 @@ def test_variable_chp(filename="variable_chp.csv", solver="cbc"): ) # objective function - assert round(solph.processing.meta_results(om)["objective"]) == 326661590 + assert solph.processing.meta_results(om)["objective"] == pytest.approx( + 326661590, abs=0.5 + ) diff --git a/tests/test_solph_network_classes.py b/tests/test_solph_network_classes.py index 24c540a62..efd868279 100644 --- a/tests/test_solph_network_classes.py +++ b/tests/test_solph_network_classes.py @@ -22,12 +22,8 @@ class TestConverterClass: def setup_class(cls): """Setup default values""" cls.bus = solph.buses.Bus() - warnings.filterwarnings("ignore", category=SuspiciousUsageWarning) - - @classmethod - def teardown_class(cls): - warnings.filterwarnings("always", category=SuspiciousUsageWarning) + @pytest.mark.filterwarnings("ignore::UserWarning") def test_empty_converter(self): transf = solph.components.Converter() assert isinstance(transf.conversion_factors, dict) @@ -35,13 +31,15 @@ def test_empty_converter(self): def test_default_conversion_factor(self): transf = solph.components.Converter( - inputs={self.bus: solph.flows.Flow()} + inputs={self.bus: solph.flows.Flow()}, + outputs={self.bus: solph.flows.Flow()}, ) assert transf.conversion_factors[self.bus][2] == 1 def test_sequence_conversion_factor_from_scalar(self): transf = solph.components.Converter( inputs={self.bus: solph.flows.Flow()}, + outputs={self.bus: solph.flows.Flow()}, conversion_factors={self.bus: 2}, ) assert transf.conversion_factors[self.bus][6] == 2 @@ -49,6 +47,7 @@ def test_sequence_conversion_factor_from_scalar(self): def test_sequence_conversion_factor_from_list_correct_length(self): transf = solph.components.Converter( inputs={self.bus: solph.flows.Flow()}, + outputs={self.bus: solph.flows.Flow()}, conversion_factors={self.bus: [2]}, ) assert len(transf.conversion_factors[self.bus]) == 1 @@ -56,15 +55,18 @@ def test_sequence_conversion_factor_from_list_correct_length(self): def test_sequence_conversion_factor_from_list_wrong_length(self): transf = solph.components.Converter( inputs={self.bus: solph.flows.Flow()}, + outputs={self.bus: solph.flows.Flow()}, conversion_factors={self.bus: [2]}, ) with pytest.raises(IndexError): self.a = transf.conversion_factors[self.bus][6] + @pytest.mark.filterwarnings("ignore:Attribute :UserWarning") def test_converter_missing_output_create_empty_dict(self): trfr = solph.components.Converter(inputs={}) assert trfr.outputs == {} + @pytest.mark.filterwarnings("ignore:Attribute :UserWarning") def test_converter_missing_input_create_empty_dict(self): trfr = solph.components.Converter(outputs={}) assert trfr.inputs == {} From 962abb60fd90f21ae36bd278b715d4570c11ea92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sch=C3=B6nfeldt?= Date: Wed, 11 Oct 2023 22:26:27 +0200 Subject: [PATCH 06/25] Use full_load_time_min instead of summed_min --- tests/constraint_tests.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/constraint_tests.py b/tests/constraint_tests.py index 53a35936e..55a7e3027 100644 --- a/tests/constraint_tests.py +++ b/tests/constraint_tests.py @@ -1860,8 +1860,8 @@ def test_summed_min_max_source(self): label="excess", inputs={ bel: solph.flows.Flow( - summed_min=3, - summed_max=100, + full_load_time_min=3, + full_load_time_max=100, variable_costs=25, max=0.8, nominal_value=10, From aa43b30ad3a235fd692453e35101a51058c42d6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sch=C3=B6nfeldt?= Date: Wed, 11 Oct 2023 22:28:08 +0200 Subject: [PATCH 07/25] Sort imports --- .../test_solph/test_connect_invest/test_connect_invest.py | 2 +- .../test_storage_investment/test_storage_with_tuple_label.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_scripts/test_solph/test_connect_invest/test_connect_invest.py b/tests/test_scripts/test_solph/test_connect_invest/test_connect_invest.py index f2bdfbc98..9bff4ad64 100644 --- a/tests/test_scripts/test_solph/test_connect_invest/test_connect_invest.py +++ b/tests/test_scripts/test_solph/test_connect_invest/test_connect_invest.py @@ -12,9 +12,9 @@ import logging import os -import pytest import pandas as pd +import pytest from oemof.solph import EnergySystem from oemof.solph import Investment diff --git a/tests/test_scripts/test_solph/test_storage_investment/test_storage_with_tuple_label.py b/tests/test_scripts/test_solph/test_storage_investment/test_storage_with_tuple_label.py index 6ddbf5c18..9efa8ed88 100644 --- a/tests/test_scripts/test_solph/test_storage_investment/test_storage_with_tuple_label.py +++ b/tests/test_scripts/test_solph/test_storage_investment/test_storage_with_tuple_label.py @@ -36,10 +36,10 @@ import logging import os -import pytest from collections import namedtuple import pandas as pd +import pytest from oemof import solph as solph from oemof.solph import processing From 01564779e0d33135ebabb9fedebc171a001de325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sch=C3=B6nfeldt?= Date: Wed, 11 Oct 2023 22:31:59 +0200 Subject: [PATCH 08/25] Delete unused import --- tests/test_solph_network_classes.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_solph_network_classes.py b/tests/test_solph_network_classes.py index efd868279..fa403541a 100644 --- a/tests/test_solph_network_classes.py +++ b/tests/test_solph_network_classes.py @@ -12,7 +12,6 @@ import warnings import pytest -from oemof.tools.debugging import SuspiciousUsageWarning from oemof import solph From 63e699ee3a9d244579b2ce1d6e31926ccf32edfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sch=C3=B6nfeldt?= Date: Thu, 12 Oct 2023 14:02:25 +0200 Subject: [PATCH 09/25] Change deprecated API calls --- docs/usage.rst | 17 ++- examples/electrical/lopf.py | 2 +- examples/electrical/transshipment.py | 4 +- .../example_generic_invest.py | 6 +- .../diesel_genset_nonconvex_investment.py | 17 +-- .../house_with_nonconvex_investment.py | 2 +- .../house_without_nonconvex_investment.py | 2 +- .../minimal_invest.py | 3 +- ...fset_diesel_genset_nonconvex_investment.py | 17 +-- .../v1_invest_optimize_all_technologies.py | 6 +- ...v2_invest_optimize_only_gas_and_storage.py | 2 +- ...optimize_only_storage_with_fossil_share.py | 2 +- ...mize_all_technologies_with_fossil_share.py | 4 +- src/oemof/solph/_energy_system.py | 6 +- .../solph/components/_generic_storage.py | 2 +- .../solph/constraints/equate_variables.py | 4 +- .../solph/constraints/investment_limit.py | 4 +- tests/constraint_tests.py | 113 ++++++++++-------- tests/multi_period_constraint_tests.py | 104 ++++++++-------- tests/test_components.py | 27 +++-- tests/test_constraints_module.py | 13 +- tests/test_energy_system.py | 4 +- tests/test_grouping.py | 2 +- tests/test_models.py | 4 +- tests/test_non_equidistant_time_index.py | 2 +- tests/test_options.py | 4 +- tests/test_outputlib/__init__.py | 2 +- tests/test_processing.py | 11 +- .../test_connect_invest.py | 26 ++-- .../test_add_constraints.py | 5 +- .../test_generic_caes/test_generic_caes.py | 2 +- .../test_generic_chp/test_generic_chp.py | 2 +- .../test_simple_invest_fixed.py | 6 +- .../test_solph/test_lopf/test_lopf.py | 4 +- .../test_multi_period_investment_model.py | 14 +-- .../test_piecewiselineartransformer.py | 4 +- .../test_simple_model/test_simple_dispatch.py | 4 +- .../test_simple_model/test_simple_invest.py | 8 +- .../test_invest_storage_regression.py | 13 +- .../test_storage_investment.py | 10 +- .../test_storage_with_tuple_label.py | 5 +- .../test_variable_chp/test_variable_chp.py | 4 +- tests/test_time_index.py | 10 +- tests/test_warnings.py | 3 +- 44 files changed, 277 insertions(+), 229 deletions(-) diff --git a/docs/usage.rst b/docs/usage.rst index 32b8e3741..fe60ea434 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -643,8 +643,8 @@ The following example pictures a Pumped Hydroelectric Energy Storage (PHES). Bot solph.components.GenericStorage( label='PHES', - inputs={b_el: solph.flows.Flow(investment= solph.Investment(ep_costs=500))}, - outputs={b_el: solph.flows.Flow(investment= solph.Investment(ep_costs=500)}, + inputs={b_el: solph.flows.Flow(nominal_value= solph.Investment(ep_costs=500))}, + outputs={b_el: solph.flows.Flow(nominal_value= solph.Investment(ep_costs=500)}, loss_rate=0.001, inflow_conversion_factor=0.98, outflow_conversion_factor=0.8), investment = solph.Investment(ep_costs=40)) @@ -912,7 +912,7 @@ turbines. solph.components.Source(label='new_wind_pp', outputs={electricity: solph.flows.Flow( fix=wind_power_time_series, - investment=solph.Investment(ep_costs=epc, maximum=50000))}) + nominal_value=solph.Investment(ep_costs=epc, maximum=50000))}) Let's slightly alter the case and consider for already existing wind power capacity of 20,000 kW. We're still expecting the total wind power capacity, thus we @@ -922,7 +922,7 @@ allow for 30,000 kW of new installations and formulate as follows. solph.components.Source(label='new_wind_pp', outputs={electricity: solph.flows.Flow( fix=wind_power_time_series, - investment=solph.Investment(ep_costs=epc, + nominal_value=solph.Investment(ep_costs=epc, maximum=30000, existing=20000))}) @@ -957,7 +957,7 @@ example of a converter: label='converter_nonconvex', inputs={bus_0: solph.flows.Flow()}, outputs={bus_1: solph.flows.Flow( - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=4, maximum=100, minimum=20, @@ -1144,7 +1144,7 @@ Here is an example inputs={hydrogen_bus: solph.flows.Flow()}, outputs={ electricity_bus: solph.flows.Flow( - investment=solph.Investment( + nominal_value=solph.Investment( maximum=1000, ep_costs=1e6, lifetime=30, @@ -1178,7 +1178,7 @@ This would mean that for investments in the particular period, these values woul inputs={hydrogen_bus: solph.flows.Flow()}, outputs={ electricity_bus: solph.flows.Flow( - investment=solph.Investment( + nominal_value=solph.Investment( maximum=1000, ep_costs=[1e6, 1.1e6], lifetime=30, @@ -1466,12 +1466,11 @@ This nonlinearity is linearised in the inputs={b_diesel: solph.flows.Flow()}, outputs={ b_el: solph.flows.Flow( - nominal_value=None, variable_costs=0.04, min=0.2, max=1, nonconvex=solph.NonConvex(), - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=90, maximum=150, # required for the linearization ), diff --git a/examples/electrical/lopf.py b/examples/electrical/lopf.py index 33be875c0..b8ab5d210 100644 --- a/examples/electrical/lopf.py +++ b/examples/electrical/lopf.py @@ -151,7 +151,7 @@ def main(): input=b_el0, output=b_el1, reactance=0.0001, - investment=Investment(ep_costs=10), + nominal_value=Investment(ep_costs=10), min=-1, max=1, ) diff --git a/examples/electrical/transshipment.py b/examples/electrical/transshipment.py index 2379da98b..8f6349c72 100644 --- a/examples/electrical/transshipment.py +++ b/examples/electrical/transshipment.py @@ -144,8 +144,8 @@ def main(): label="line_0", inputs={b_0: Flow(), b_1: Flow()}, outputs={ - b_1: Flow(investment=Investment()), - b_0: Flow(investment=Investment()), + b_1: Flow(nominal_value=Investment()), + b_0: Flow(nominal_value=Investment()), }, conversion_factors={(b_0, b_1): 0.95, (b_1, b_0): 0.9}, ) diff --git a/examples/generic_invest_limit/example_generic_invest.py b/examples/generic_invest_limit/example_generic_invest.py index f7b6387bf..841d49e5a 100644 --- a/examples/generic_invest_limit/example_generic_invest.py +++ b/examples/generic_invest_limit/example_generic_invest.py @@ -141,8 +141,7 @@ def main(): inputs={bus_a_0: solph.Flow()}, outputs={ bus_a_1: solph.Flow( - nominal_value=None, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=epc_invest, custom_attributes={"space": 2}, ), @@ -159,8 +158,7 @@ def main(): inputs={bus_b_0: solph.Flow()}, outputs={ bus_b_1: solph.Flow( - nominal_value=None, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=epc_invest, custom_attributes={"space": 1}, ), diff --git a/examples/invest_nonconvex_flow_examples/diesel_genset_nonconvex_investment.py b/examples/invest_nonconvex_flow_examples/diesel_genset_nonconvex_investment.py index e90d0f10c..d273d3380 100644 --- a/examples/invest_nonconvex_flow_examples/diesel_genset_nonconvex_investment.py +++ b/examples/invest_nonconvex_flow_examples/diesel_genset_nonconvex_investment.py @@ -132,8 +132,7 @@ def main(): outputs={ b_el_dc: solph.flows.Flow( fix=solar_potential / peak_solar_potential, - nominal_value=None, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=epc_pv * n_days / n_days_in_year ), variable_costs=0, @@ -157,11 +156,10 @@ def main(): inputs={b_diesel: solph.flows.Flow()}, outputs={ b_el_ac: solph.flows.Flow( - nominal_value=None, variable_costs=variable_cost_diesel_genset, min=min_load, max=max_load, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=epc_diesel_genset * n_days / n_days_in_year, maximum=2 * peak_demand, ), @@ -177,8 +175,7 @@ def main(): label="rectifier", inputs={ b_el_ac: solph.flows.Flow( - nominal_value=None, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=epc_rectifier * n_days / n_days_in_year ), variable_costs=0, @@ -196,8 +193,7 @@ def main(): label="inverter", inputs={ b_el_dc: solph.flows.Flow( - nominal_value=None, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=epc_inverter * n_days / n_days_in_year ), variable_costs=0, @@ -213,13 +209,12 @@ def main(): epc_battery = 101.00 # currency/kWh/year battery = solph.components.GenericStorage( label="battery", - nominal_storage_capacity=None, - investment=solph.Investment( + nominal_storage_capacity=solph.Investment( ep_costs=epc_battery * n_days / n_days_in_year ), inputs={b_el_dc: solph.flows.Flow(variable_costs=0)}, outputs={ - b_el_dc: solph.flows.Flow(investment=solph.Investment(ep_costs=0)) + b_el_dc: solph.flows.Flow(nominal_value=solph.Investment(ep_costs=0)) }, initial_storage_level=0.0, min_storage_level=0.0, diff --git a/examples/invest_nonconvex_flow_examples/house_with_nonconvex_investment.py b/examples/invest_nonconvex_flow_examples/house_with_nonconvex_investment.py index e8fbb1458..ba50494ab 100644 --- a/examples/invest_nonconvex_flow_examples/house_with_nonconvex_investment.py +++ b/examples/invest_nonconvex_flow_examples/house_with_nonconvex_investment.py @@ -91,7 +91,7 @@ def heat_demand(d): minimum_uptime=5, initial_status=1, ), - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=epc, minimum=1.0, maximum=10.0, diff --git a/examples/invest_nonconvex_flow_examples/house_without_nonconvex_investment.py b/examples/invest_nonconvex_flow_examples/house_without_nonconvex_investment.py index cca936cce..15baeacf3 100644 --- a/examples/invest_nonconvex_flow_examples/house_without_nonconvex_investment.py +++ b/examples/invest_nonconvex_flow_examples/house_without_nonconvex_investment.py @@ -117,7 +117,7 @@ def solar_thermal(d): outputs={ b_heat: solph.flows.Flow( fix=[solar_thermal(day) for day in range(0, periods)], - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=epc, minimum=1.0, maximum=5.0 ), ) diff --git a/examples/investment_with_minimal_invest/minimal_invest.py b/examples/investment_with_minimal_invest/minimal_invest.py index 8e9944ede..6302fa816 100644 --- a/examples/investment_with_minimal_invest/minimal_invest.py +++ b/examples/investment_with_minimal_invest/minimal_invest.py @@ -86,8 +86,7 @@ def main(): inputs={bus_0: solph.Flow()}, outputs={ bus_1: solph.Flow( - nominal_value=None, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=c_var, maximum=p_install_max, minimum=p_install_min, diff --git a/examples/offset_converter_example/offset_diesel_genset_nonconvex_investment.py b/examples/offset_converter_example/offset_diesel_genset_nonconvex_investment.py index 38e8cccf9..15e5164ae 100644 --- a/examples/offset_converter_example/offset_diesel_genset_nonconvex_investment.py +++ b/examples/offset_converter_example/offset_diesel_genset_nonconvex_investment.py @@ -127,8 +127,7 @@ def offset_converter_example(): outputs={ b_el_dc: solph.flows.Flow( fix=solar_potential / peak_solar_potential, - nominal_value=None, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=epc_pv * n_days / n_days_in_year ), variable_costs=0, @@ -168,11 +167,10 @@ def offset_converter_example(): inputs={b_diesel: solph.flows.Flow()}, outputs={ b_el_ac: solph.flows.Flow( - nominal_value=None, variable_costs=variable_cost_diesel_genset, min=min_load, max=max_load, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=epc_diesel_genset * n_days / n_days_in_year, maximum=2 * peak_demand, ), @@ -188,8 +186,7 @@ def offset_converter_example(): label="rectifier", inputs={ b_el_ac: solph.flows.Flow( - nominal_value=None, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=epc_rectifier * n_days / n_days_in_year ), variable_costs=0, @@ -207,8 +204,7 @@ def offset_converter_example(): label="inverter", inputs={ b_el_dc: solph.flows.Flow( - nominal_value=None, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=epc_inverter * n_days / n_days_in_year ), variable_costs=0, @@ -224,13 +220,12 @@ def offset_converter_example(): epc_battery = 101.00 # currency/kWh/year battery = solph.components.GenericStorage( label="battery", - nominal_storage_capacity=None, - investment=solph.Investment( + nominal_storage_capacity=solph.Investment( ep_costs=epc_battery * n_days / n_days_in_year ), inputs={b_el_dc: solph.flows.Flow(variable_costs=0)}, outputs={ - b_el_dc: solph.flows.Flow(investment=solph.Investment(ep_costs=0)) + b_el_dc: solph.flows.Flow(nominal_value=solph.Investment(ep_costs=0)) }, initial_storage_level=0.0, min_storage_level=0.0, diff --git a/examples/storage_investment/v1_invest_optimize_all_technologies.py b/examples/storage_investment/v1_invest_optimize_all_technologies.py index 7bb185509..07a139778 100644 --- a/examples/storage_investment/v1_invest_optimize_all_technologies.py +++ b/examples/storage_investment/v1_invest_optimize_all_technologies.py @@ -151,7 +151,7 @@ def main(): outputs={ bel: solph.Flow( fix=data["wind"], - investment=solph.Investment(ep_costs=epc_wind), + nominal_value=solph.Investment(ep_costs=epc_wind), ) }, ) @@ -161,7 +161,7 @@ def main(): label="pv", outputs={ bel: solph.Flow( - fix=data["pv"], investment=solph.Investment(ep_costs=epc_pv) + fix=data["pv"], nominal_value=solph.Investment(ep_costs=epc_pv) ) }, ) @@ -191,7 +191,7 @@ def main(): invest_relation_output_capacity=1 / 6, inflow_conversion_factor=1, outflow_conversion_factor=0.8, - investment=solph.Investment(ep_costs=epc_storage), + nominal_value=solph.Investment(ep_costs=epc_storage), ) energysystem.add(excess, gas_resource, wind, pv, demand, pp_gas, storage) diff --git a/examples/storage_investment/v2_invest_optimize_only_gas_and_storage.py b/examples/storage_investment/v2_invest_optimize_only_gas_and_storage.py index 3e91950c5..b82cef608 100644 --- a/examples/storage_investment/v2_invest_optimize_only_gas_and_storage.py +++ b/examples/storage_investment/v2_invest_optimize_only_gas_and_storage.py @@ -184,7 +184,7 @@ def main(): invest_relation_output_capacity=1 / 6, inflow_conversion_factor=1, outflow_conversion_factor=0.8, - investment=solph.Investment(ep_costs=epc_storage), + nominal_value=solph.Investment(ep_costs=epc_storage), ) energysystem.add(excess, gas_resource, wind, pv, demand, pp_gas, storage) diff --git a/examples/storage_investment/v3_invest_optimize_only_storage_with_fossil_share.py b/examples/storage_investment/v3_invest_optimize_only_storage_with_fossil_share.py index 1046a8d29..7e8c9cc0c 100644 --- a/examples/storage_investment/v3_invest_optimize_only_storage_with_fossil_share.py +++ b/examples/storage_investment/v3_invest_optimize_only_storage_with_fossil_share.py @@ -194,7 +194,7 @@ def main(): invest_relation_output_capacity=1 / 6, inflow_conversion_factor=1, outflow_conversion_factor=0.8, - investment=solph.Investment(ep_costs=epc_storage), + nominal_value=solph.Investment(ep_costs=epc_storage), ) energysystem.add(excess, gas_resource, wind, pv, demand, pp_gas, storage) diff --git a/examples/storage_investment/v4_invest_optimize_all_technologies_with_fossil_share.py b/examples/storage_investment/v4_invest_optimize_all_technologies_with_fossil_share.py index 7c1c89a7b..d25af3f40 100644 --- a/examples/storage_investment/v4_invest_optimize_all_technologies_with_fossil_share.py +++ b/examples/storage_investment/v4_invest_optimize_all_technologies_with_fossil_share.py @@ -162,7 +162,7 @@ def main(): outputs={ bel: solph.Flow( fix=data["wind"], - investment=solph.Investment(ep_costs=epc_wind), + nominal_value=solph.Investment(ep_costs=epc_wind), ) }, ) @@ -172,7 +172,7 @@ def main(): label="pv", outputs={ bel: solph.Flow( - fix=data["pv"], investment=solph.Investment(ep_costs=epc_pv) + fix=data["pv"], nominal_value=solph.Investment(ep_costs=epc_pv) ) }, ) diff --git a/src/oemof/solph/_energy_system.py b/src/oemof/solph/_energy_system.py index a2a166fb5..90125d9ac 100644 --- a/src/oemof/solph/_energy_system.py +++ b/src/oemof/solph/_energy_system.py @@ -136,7 +136,7 @@ def __init__( "consistent.\nIf you are not considering non-equidistant " "timeindices, consider only specifying a timeindex." ) - warnings.warn(msg, debugging.SuspiciousUsageWarning) + warnings.warn(msg, debugging.ExperimentalFeatureWarning) elif timeindex is not None and timeincrement is None: df = pd.DataFrame(timeindex) @@ -151,7 +151,7 @@ def __init__( if timeincrement is not None and (pd.Series(timeincrement) <= 0).any(): msg = ( "The time increment is inconsistent. Negative values and zero " - "is not allowed.\nThis is caused by a inconsistent " + "are not allowed.\nThis is caused by a inconsistent " "timeincrement parameter or an incorrect timeindex." ) raise TypeError(msg) @@ -170,7 +170,7 @@ def __init__( "now. If you find anything suspicious or any bugs, " "please report them." ) - warnings.warn(msg, debugging.SuspiciousUsageWarning) + warnings.warn(msg, debugging.ExperimentalFeatureWarning) self.periods = periods self._extract_periods_years() self._extract_periods_matrix() diff --git a/src/oemof/solph/components/_generic_storage.py b/src/oemof/solph/components/_generic_storage.py index a6156f06a..ef7b37cd6 100644 --- a/src/oemof/solph/components/_generic_storage.py +++ b/src/oemof/solph/components/_generic_storage.py @@ -149,7 +149,7 @@ class GenericStorage(Node): >>> my_investment_storage = solph.components.GenericStorage( ... label='storage', - ... investment=solph.Investment(ep_costs=50), + ... nominal_storage_capacity=solph.Investment(ep_costs=50), ... inputs={my_bus: solph.flows.Flow()}, ... outputs={my_bus: solph.flows.Flow()}, ... loss_rate=0.02, diff --git a/src/oemof/solph/constraints/equate_variables.py b/src/oemof/solph/constraints/equate_variables.py index 770062df1..5ce350da4 100644 --- a/src/oemof/solph/constraints/equate_variables.py +++ b/src/oemof/solph/constraints/equate_variables.py @@ -71,12 +71,12 @@ def equate_variables(model, var1, var2, factor1=1, name=None): ... label='powerline_1_2', ... inputs={bel1: solph.flows.Flow()}, ... outputs={bel2: solph.flows.Flow( - ... investment=solph.Investment(ep_costs=20))})) + ... nominal_value=solph.Investment(ep_costs=20))})) >>> energysystem.add(solph.components.Converter( ... label='powerline_2_1', ... inputs={bel2: solph.flows.Flow()}, ... outputs={bel1: solph.flows.Flow( - ... investment=solph.Investment(ep_costs=20))})) + ... nominal_value=solph.Investment(ep_costs=20))})) >>> om = solph.Model(energysystem) >>> line12 = energysystem.groups['powerline_1_2'] >>> line21 = energysystem.groups['powerline_2_1'] diff --git a/src/oemof/solph/constraints/investment_limit.py b/src/oemof/solph/constraints/investment_limit.py index cf6ea8d78..078b553b1 100644 --- a/src/oemof/solph/constraints/investment_limit.py +++ b/src/oemof/solph/constraints/investment_limit.py @@ -178,13 +178,13 @@ def additional_investment_flow_limit(model, keyword, limit=None): ... solph.flows.Flow(nominal_value=10, fix=[10, 20, 30, 40, 50])}) >>> src1 = solph.components.Source( ... label='source_0', outputs={bus: solph.flows.Flow( - ... investment=solph.Investment( + ... nominal_value=solph.Investment( ... ep_costs=50, custom_attributes={"space": 4}, ... )) ... }) >>> src2 = solph.components.Source( ... label='source_1', outputs={bus: solph.flows.Flow( - ... investment=solph.Investment( + ... nominal_value=solph.Investment( ... ep_costs=100, custom_attributes={"space": 1}, ... )) ... }) diff --git a/tests/constraint_tests.py b/tests/constraint_tests.py index 55a7e3027..71cfbd534 100644 --- a/tests/constraint_tests.py +++ b/tests/constraint_tests.py @@ -124,7 +124,7 @@ def test_linear_converter_invest(self): outputs={ bel: solph.flows.Flow( variable_costs=50, - investment=solph.Investment(maximum=1000, ep_costs=20), + nominal_value=solph.Investment(maximum=1000, ep_costs=20), ) }, conversion_factors={bel: 0.58}, @@ -143,11 +143,10 @@ def test_nonconvex_invest_converter(self): inputs={bfuel: solph.flows.Flow()}, outputs={ bel: solph.flows.Flow( - nominal_value=None, variable_costs=25, min=0.25, max=0.5, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=500, maximum=1234, ), @@ -234,7 +233,7 @@ def test_fixed_source_invest_sink(self): full_load_time_max=2.3, variable_costs=25, max=0.8, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=500, maximum=1e6, existing=50 ), ) @@ -254,7 +253,7 @@ def test_invest_source_fixed_sink(self): bel: solph.flows.Flow( max=[45, 83, 65], variable_costs=13, - investment=solph.Investment(ep_costs=123), + nominal_value=solph.Investment(ep_costs=123), ) }, ) @@ -300,7 +299,9 @@ def test_storage_invest_1(self): label="storage1", inputs={bel: solph.flows.Flow(variable_costs=56)}, outputs={bel: solph.flows.Flow(variable_costs=24)}, - nominal_storage_capacity=None, + nominal_storage_capacity=solph.Investment( + ep_costs=145, maximum=234 + ), loss_rate=0.13, max_storage_level=0.9, min_storage_level=0.1, @@ -308,7 +309,6 @@ def test_storage_invest_1(self): invest_relation_output_capacity=1 / 6, inflow_conversion_factor=0.97, outflow_conversion_factor=0.86, - investment=solph.Investment(ep_costs=145, maximum=234), ) self.energysystem.add(bel, storage) self.compare_lp_files("storage_invest_1.lp") @@ -320,12 +320,16 @@ def test_storage_invest_2(self): storage = solph.components.GenericStorage( label="storage2", inputs={ - bel: solph.flows.Flow(investment=solph.Investment(ep_costs=99)) + bel: solph.flows.Flow( + nominal_value=solph.Investment(ep_costs=99) + ) }, outputs={ - bel: solph.flows.Flow(investment=solph.Investment(ep_costs=9)) + bel: solph.flows.Flow( + nominal_value=solph.Investment(ep_costs=9) + ) }, - investment=solph.Investment(ep_costs=145), + nominal_storage_capacity=solph.Investment(ep_costs=145), initial_storage_level=0.5, ) self.energysystem.add(bel, storage) @@ -341,10 +345,14 @@ def test_storage_invest_3(self): storage = solph.components.GenericStorage( label="storage3", inputs={ - bel: solph.flows.Flow(investment=solph.Investment(ep_costs=99)) + bel: solph.flows.Flow( + nominal_value=solph.Investment(ep_costs=99) + ) }, outputs={ - bel: solph.flows.Flow(investment=solph.Investment(ep_costs=9)) + bel: solph.flows.Flow( + nominal_value=solph.Investment(ep_costs=9) + ) }, nominal_storage_capacity=5000, ) @@ -359,7 +367,7 @@ def test_storage_invest_4(self): label="storage4", inputs={bel: solph.flows.Flow(nominal_value=80)}, outputs={bel: solph.flows.Flow(nominal_value=100)}, - investment=solph.Investment(ep_costs=145, maximum=500), + nominal_value=solph.Investment(ep_costs=145, maximum=500), ) self.energysystem.add(bel, storage) self.compare_lp_files("storage_invest_4.lp") @@ -376,12 +384,12 @@ def test_storage_invest_5(self): label="storage5", inputs={ bel: solph.flows.Flow( - investment=solph.Investment(ep_costs=99, existing=110) + nominal_value=solph.Investment(ep_costs=99, existing=110) ) }, outputs={ bel: solph.flows.Flow( - investment=solph.Investment(existing=100) + nominal_value=solph.Investment(existing=100) ) }, invest_relation_input_output=1.1, @@ -400,16 +408,18 @@ def test_storage_invest_6(self): label="storage6", inputs={ bel: solph.flows.Flow( - investment=solph.Investment(ep_costs=99, existing=110) + nominal_value=solph.Investment(ep_costs=99, existing=110) ) }, outputs={ bel: solph.flows.Flow( - investment=solph.Investment(existing=100) + nominal_value=solph.Investment(existing=100) ) }, invest_relation_input_output=1.1, - investment=solph.Investment(ep_costs=145, existing=10000), + nominal_storage_capacity=solph.Investment( + ep_costs=145, existing=10000 + ), ) self.energysystem.add(bel, storage) self.compare_lp_files("storage_invest_6.lp") @@ -424,7 +434,7 @@ def test_storage_minimum_invest(self): label="storage1", inputs={bel: solph.flows.Flow()}, outputs={bel: solph.flows.Flow()}, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=145, minimum=100, maximum=200 ), ) @@ -456,12 +466,11 @@ def test_storage_invest_unbalanced(self): label="storage1", inputs={bel: solph.flows.Flow()}, outputs={bel: solph.flows.Flow()}, - nominal_storage_capacity=None, initial_storage_level=0.5, balanced=False, invest_relation_input_capacity=1, invest_relation_output_capacity=1, - investment=solph.Investment(ep_costs=145), + nominal_value=solph.Investment(ep_costs=145), ) self.energysystem.add(bel, storage) self.compare_lp_files("storage_invest_unbalanced.lp") @@ -499,7 +508,6 @@ def test_storage_invest_1_fixed_losses(self): label="storage1", inputs={bel: solph.flows.Flow(variable_costs=56)}, outputs={bel: solph.flows.Flow(variable_costs=24)}, - nominal_storage_capacity=None, loss_rate=0.13, fixed_losses_relative=0.01, fixed_losses_absolute=3, @@ -509,7 +517,9 @@ def test_storage_invest_1_fixed_losses(self): invest_relation_output_capacity=1 / 6, inflow_conversion_factor=0.97, outflow_conversion_factor=0.86, - investment=solph.Investment(ep_costs=145, maximum=234), + nominal_storage_capacity=solph.Investment( + ep_costs=145, maximum=234 + ), ) self.energysystem.add(bel, storage) self.compare_lp_files("storage_invest_1_fixed_losses.lp") @@ -549,7 +559,7 @@ def test_converter_invest(self): outputs={ bel: solph.flows.Flow( variable_costs=50, - investment=solph.Investment(maximum=1000, ep_costs=20), + nominal_value=solph.Investment(maximum=1000, ep_costs=20), ), bth: solph.flows.Flow(variable_costs=20), }, @@ -573,7 +583,7 @@ def test_converter_invest_with_existing(self): outputs={ bel: solph.flows.Flow( variable_costs=50, - investment=solph.Investment( + nominal_value=solph.Investment( maximum=1000, ep_costs=20, existing=200 ), ), @@ -617,7 +627,7 @@ def test_linear_converter_chp_invest(self): inputs={ bgas: solph.flows.Flow( variable_costs=50, - investment=solph.Investment(maximum=1000, ep_costs=20), + nominal_value=solph.Investment(maximum=1000, ep_costs=20), ) }, outputs={bel: solph.flows.Flow(), bheat: solph.flows.Flow()}, @@ -682,7 +692,7 @@ def test_generic_invest_limit(self): label="source_0", outputs={ bus: solph.flows.Flow( - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=50, custom_attributes={"space": 4}, ) @@ -694,7 +704,7 @@ def test_generic_invest_limit(self): label="source_1", outputs={ bus: solph.flows.Flow( - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=100, custom_attributes={"space": 1} ), ) @@ -704,7 +714,9 @@ def test_generic_invest_limit(self): source_2 = solph.components.Source( label="source_2", outputs={ - bus: solph.flows.Flow(investment=solph.Investment(ep_costs=75)) + bus: solph.flows.Flow( + nominal_value=solph.Investment(ep_costs=75) + ) }, ) @@ -897,13 +909,13 @@ def test_equate_variables_constraint(self): invest_relation_output_capacity=0.2, inputs={bus1: solph.flows.Flow()}, outputs={bus1: solph.flows.Flow()}, - investment=solph.Investment(ep_costs=145), + nominal_storage_capacity=solph.Investment(ep_costs=145), ) sink = solph.components.Sink( label="Sink", inputs={ bus1: solph.flows.Flow( - investment=solph.Investment(ep_costs=500) + nominal_value=solph.Investment(ep_costs=500) ) }, ) @@ -911,7 +923,7 @@ def test_equate_variables_constraint(self): label="Source", outputs={ bus1: solph.flows.Flow( - investment=solph.Investment(ep_costs=123) + nominal_value=solph.Investment(ep_costs=123) ) }, ) @@ -1053,13 +1065,13 @@ def test_investment_limit(self): invest_relation_output_capacity=0.2, inputs={bus1: solph.flows.Flow()}, outputs={bus1: solph.flows.Flow()}, - investment=solph.Investment(ep_costs=145), + nominal_storage_capacity=solph.Investment(ep_costs=145), ) source = solph.components.Source( label="Source", outputs={ bus1: solph.flows.Flow( - investment=solph.Investment(ep_costs=123) + nominal_value=solph.Investment(ep_costs=123) ) }, ) @@ -1076,7 +1088,7 @@ def test_investment_limit_with_dsm1(self): label="Source", outputs={ bus1: solph.flows.Flow( - investment=solph.Investment(ep_costs=123) + nominal_value=solph.Investment(ep_costs=123) ) }, ) @@ -1109,7 +1121,7 @@ def test_investment_limit_with_dsm2(self): label="Source", outputs={ bus1: solph.flows.Flow( - investment=solph.Investment(ep_costs=123) + nominal_value=solph.Investment(ep_costs=123) ) }, ) @@ -1143,7 +1155,7 @@ def test_investment_limit_with_dsm3(self): label="Source", outputs={ bus1: solph.flows.Flow( - investment=solph.Investment(ep_costs=123) + nominal_value=solph.Investment(ep_costs=123) ) }, ) @@ -1179,13 +1191,13 @@ def test_investment_limit_per_period_error_no_multi_period(self): invest_relation_output_capacity=0.2, inputs={bus1: solph.flows.Flow()}, outputs={bus1: solph.flows.Flow()}, - investment=solph.Investment(ep_costs=145), + nominal_storage_capacity=solph.Investment(ep_costs=145), ) solph.components.Source( label="Source", outputs={ bus1: solph.flows.Flow( - investment=solph.Investment(ep_costs=123) + nominal_value=solph.Investment(ep_costs=123) ) }, ) @@ -1371,7 +1383,7 @@ def test_offsetconverter_nonconvex_investment(self): b_el: solph.flows.Flow( min=0.2, nonconvex=solph.NonConvex(), - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=100, maximum=1234, ), @@ -1655,11 +1667,10 @@ def test_invest_non_convex_flow(self): label="b2", inputs={ b1: solph.Flow( - nominal_value=None, variable_costs=8, min=0.25, max=0.5, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=0.75, maximum=10, ), @@ -1681,7 +1692,6 @@ def test_nonconvex_investment_storage_without_offset(self): label="storage_non_convex", inputs={bel: solph.flows.Flow(variable_costs=56)}, outputs={bel: solph.flows.Flow(variable_costs=24)}, - nominal_storage_capacity=None, loss_rate=0.13, max_storage_level=0.9, min_storage_level=0.1, @@ -1689,7 +1699,7 @@ def test_nonconvex_investment_storage_without_offset(self): invest_relation_output_capacity=1 / 6, inflow_conversion_factor=0.97, outflow_conversion_factor=0.86, - investment=solph.Investment( + nominal_storage_capacity=solph.Investment( ep_costs=141, maximum=244, minimum=12, nonconvex=True ), ) @@ -1706,7 +1716,6 @@ def test_nonconvex_investment_storage_with_offset(self): label="storage_non_convex", inputs={bel: solph.flows.Flow(variable_costs=56)}, outputs={bel: solph.flows.Flow(variable_costs=24)}, - nominal_storage_capacity=None, loss_rate=0.13, max_storage_level=0.9, min_storage_level=0.1, @@ -1714,7 +1723,7 @@ def test_nonconvex_investment_storage_with_offset(self): invest_relation_output_capacity=1 / 6, inflow_conversion_factor=0.97, outflow_conversion_factor=0.86, - investment=solph.Investment( + nominal_storage_capacity=solph.Investment( ep_costs=145, minimum=19, offset=5, @@ -1733,7 +1742,7 @@ def test_nonconvex_invest_storage_all_nonconvex(self): label="storage_all_nonconvex", inputs={ b1: solph.flows.Flow( - investment=solph.Investment( + nominal_value=solph.Investment( nonconvex=True, minimum=5, offset=10, @@ -1744,7 +1753,7 @@ def test_nonconvex_invest_storage_all_nonconvex(self): }, outputs={ b1: solph.flows.Flow( - investment=solph.Investment( + nominal_value=solph.Investment( nonconvex=True, minimum=8, offset=15, @@ -1753,7 +1762,7 @@ def test_nonconvex_invest_storage_all_nonconvex(self): ) ) }, - investment=solph.Investment( + nominal_storage_capacity=solph.Investment( nonconvex=True, ep_costs=20, offset=30, minimum=20, maximum=100 ), ) @@ -1771,7 +1780,7 @@ def test_nonconvex_invest_sink_without_offset(self): full_load_time_max=2.3, variable_costs=25, max=0.8, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=500, minimum=15, nonconvex=True, maximum=172 ), ) @@ -1791,7 +1800,7 @@ def test_nonconvex_invest_source_with_offset(self): full_load_time_max=2.3, variable_costs=25, max=0.8, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=500, minimum=15, maximum=20, @@ -1815,7 +1824,7 @@ def test_nonconvex_invest_source_with_offset_no_minimum(self): full_load_time_max=2.3, variable_costs=25, max=0.8, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=500, maximum=1234, offset=34, nonconvex=True ), ) diff --git a/tests/multi_period_constraint_tests.py b/tests/multi_period_constraint_tests.py index 2696f5ace..0679a7681 100644 --- a/tests/multi_period_constraint_tests.py +++ b/tests/multi_period_constraint_tests.py @@ -131,7 +131,7 @@ def test_linear_converter_invest(self): outputs={ bel: solph.flows.Flow( variable_costs=50, - investment=solph.Investment( + nominal_value=solph.Investment( existing=50, maximum=1000, overall_maximum=10000, @@ -160,7 +160,7 @@ def test_linear_converter_invest_old_capacity(self): outputs={ bel: solph.flows.Flow( variable_costs=50, - investment=solph.Investment( + nominal_value=solph.Investment( existing=50, maximum=1000, overall_maximum=10000, @@ -252,7 +252,7 @@ def test_fixed_source_invest_sink(self): summed_max=2.3, variable_costs=25, max=0.8, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=500, maximum=1e6, existing=50, lifetime=20 ), ) @@ -270,7 +270,7 @@ def test_investment_lifetime_missing(self): inputs={ bel: solph.flows.Flow( max=0.8, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=500, maximum=1e6, existing=50 ), ) @@ -296,7 +296,7 @@ def test_invest_source_fixed_sink(self): bel: solph.flows.Flow( max=[45, 83, 65, 67, 33, 96], variable_costs=13, - investment=solph.Investment(ep_costs=123, lifetime=25), + nominal_value=solph.Investment(ep_costs=123, lifetime=25), ) }, ) @@ -343,7 +343,6 @@ def test_storage_invest_1(self): label="storage1", inputs={bel: solph.flows.Flow(variable_costs=56)}, outputs={bel: solph.flows.Flow(variable_costs=24)}, - nominal_storage_capacity=None, loss_rate=0.13, max_storage_level=0.9, min_storage_level=0.1, @@ -353,7 +352,7 @@ def test_storage_invest_1(self): lifetime_outflow=20, inflow_conversion_factor=0.97, outflow_conversion_factor=0.86, - investment=solph.Investment( + nominal_storage_capacity=solph.Investment( ep_costs=145, maximum=234, lifetime=20, @@ -373,15 +372,15 @@ def test_storage_invest_2(self): label="storage2", inputs={ bel: solph.flows.Flow( - investment=solph.Investment(ep_costs=99, lifetime=20) + nominal_value=solph.Investment(ep_costs=99, lifetime=20) ) }, outputs={ bel: solph.flows.Flow( - investment=solph.Investment(ep_costs=9, lifetime=20) + nominal_value=solph.Investment(ep_costs=9, lifetime=20) ) }, - investment=solph.Investment( + nominal_storage_capacity=solph.Investment( ep_costs=145, lifetime=20, existing=20, age=19 ), ) @@ -399,7 +398,7 @@ def test_storage_invest_3(self): label="storage3", inputs={ bel: solph.flows.Flow( - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=99, lifetime=2, age=1, @@ -409,7 +408,7 @@ def test_storage_invest_3(self): }, outputs={ bel: solph.flows.Flow( - investment=solph.Investment(ep_costs=9, lifetime=20) + nominal_value=solph.Investment(ep_costs=9, lifetime=20) ) }, nominal_storage_capacity=5000, @@ -425,7 +424,7 @@ def test_storage_invest_4(self): label="storage4", inputs={bel: solph.flows.Flow(nominal_value=80)}, outputs={bel: solph.flows.Flow(nominal_value=100)}, - investment=solph.Investment( + nominal_storage_capacity=solph.Investment( ep_costs=145, maximum=500, lifetime=2, age=1, existing=100 ), ) @@ -444,14 +443,14 @@ def test_storage_invest_5(self): label="storage5", inputs={ bel: solph.flows.Flow( - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=99, existing=110, lifetime=20 ) ) }, outputs={ bel: solph.flows.Flow( - investment=solph.Investment(existing=100, lifetime=20) + nominal_value=solph.Investment(existing=100, lifetime=20) ) }, invest_relation_input_output=1.1, @@ -470,18 +469,18 @@ def test_storage_invest_6(self): label="storage6", inputs={ bel: solph.flows.Flow( - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=99, existing=110, lifetime=20 ) ) }, outputs={ bel: solph.flows.Flow( - investment=solph.Investment(existing=100, lifetime=20) + nominal_value=solph.Investment(existing=100, lifetime=20) ) }, invest_relation_input_output=1.1, - investment=solph.Investment( + nominal_storage_capacity=solph.Investment( ep_costs=145, existing=1000, lifetime=20, age=17 ), ) @@ -498,7 +497,7 @@ def test_storage_minimum_invest(self): label="storage1", inputs={bel: solph.flows.Flow()}, outputs={bel: solph.flows.Flow()}, - investment=solph.Investment( + nominal_storage_capacity=solph.Investment( ep_costs=145, minimum=100, maximum=200, lifetime=40 ), lifetime_inflow=40, @@ -515,7 +514,7 @@ def test_storage_invest_multi_period(self): label="storage1", inputs={bel: solph.flows.Flow()}, outputs={bel: solph.flows.Flow()}, - investment=solph.Investment( + nominal_storage_capacity=solph.Investment( ep_costs=145, minimum=100, maximum=200, @@ -580,7 +579,6 @@ def test_storage_invest_1_fixed_losses(self): label="storage1", inputs={bel: solph.flows.Flow(variable_costs=56)}, outputs={bel: solph.flows.Flow(variable_costs=24)}, - nominal_storage_capacity=None, loss_rate=0.13, fixed_losses_relative=0.01, fixed_losses_absolute=3, @@ -592,7 +590,7 @@ def test_storage_invest_1_fixed_losses(self): outflow_conversion_factor=0.86, lifetime_inflow=40, lifetime_outflow=40, - investment=solph.Investment( + nominal_storage_capacity=solph.Investment( ep_costs=145, maximum=234, lifetime=20, @@ -617,7 +615,6 @@ def test_storage_invest_1_initial_storage_level(self): label="storage1", inputs={bel: solph.flows.Flow(variable_costs=56)}, outputs={bel: solph.flows.Flow(variable_costs=24)}, - nominal_storage_capacity=None, loss_rate=0.13, max_storage_level=0.9, min_storage_level=0.1, @@ -628,7 +625,7 @@ def test_storage_invest_1_initial_storage_level(self): lifetime_inflow=40, lifetime_outflow=40, initial_storage_level=0.5, - investment=solph.Investment( + nominal_storage_capacity=solph.Investment( ep_costs=145, maximum=234, lifetime=20, @@ -655,7 +652,6 @@ def test_storage_invest_1_missing_lifetime(self): label="storage1", inputs={bel: solph.flows.Flow(variable_costs=56)}, outputs={bel: solph.flows.Flow(variable_costs=24)}, - nominal_storage_capacity=None, loss_rate=0.13, max_storage_level=0.9, min_storage_level=0.1, @@ -665,7 +661,7 @@ def test_storage_invest_1_missing_lifetime(self): outflow_conversion_factor=0.86, lifetime_inflow=40, lifetime_outflow=40, - investment=solph.Investment( + nominal_storage_capacity=solph.Investment( ep_costs=145, maximum=234, interest_rate=0.05, @@ -714,7 +710,7 @@ def test_converter_invest(self): outputs={ bel: solph.flows.Flow( variable_costs=50, - investment=solph.Investment( + nominal_value=solph.Investment( maximum=1000, ep_costs=20, lifetime=20, @@ -740,7 +736,7 @@ def test_converter_invest_with_existing(self): outputs={ bel: solph.flows.Flow( variable_costs=50, - investment=solph.Investment( + nominal_value=solph.Investment( maximum=1000, ep_costs=20, existing=200, @@ -785,7 +781,7 @@ def test_linear_converter_chp_invest(self): inputs={ bgas: solph.flows.Flow( variable_costs=50, - investment=solph.Investment( + nominal_value=solph.Investment( maximum=1000, ep_costs=20, lifetime=50 ), ) @@ -1031,13 +1027,15 @@ def test_equate_variables_constraint(self): outputs={bus1: solph.flows.Flow()}, lifetime_inflow=3, lifetime_outflow=3, - investment=solph.Investment(ep_costs=145, lifetime=3), + nominal_storage_capacity=solph.Investment( + ep_costs=145, lifetime=3 + ), ) sink = solph.components.Sink( label="Sink", inputs={ bus1: solph.flows.Flow( - investment=solph.Investment(ep_costs=500, lifetime=3) + nominal_value=solph.Investment(ep_costs=500, lifetime=3) ) }, ) @@ -1045,7 +1043,7 @@ def test_equate_variables_constraint(self): label="Source", outputs={ bus1: solph.flows.Flow( - investment=solph.Investment(ep_costs=123, lifetime=3) + nominal_value=solph.Investment(ep_costs=123, lifetime=3) ) }, ) @@ -1114,13 +1112,15 @@ def test_periodical_investment_limit(self): outputs={bus1: solph.flows.Flow()}, lifetime_inflow=20, lifetime_outflow=20, - investment=solph.Investment(ep_costs=145, lifetime=30), + nominal_storage_capacity=solph.Investment( + ep_costs=145, lifetime=30 + ), ) source = solph.components.Source( label="Source", outputs={ bus1: solph.flows.Flow( - investment=solph.Investment(ep_costs=123, lifetime=100) + nominal_value=solph.Investment(ep_costs=123, lifetime=100) ) }, ) @@ -1139,7 +1139,7 @@ def test_periodical_investment_limit_with_dsm1(self): label="Source", outputs={ bus1: solph.flows.Flow( - investment=solph.Investment(ep_costs=123, lifetime=100) + nominal_value=solph.Investment(ep_costs=123, lifetime=100) ) }, ) @@ -1183,7 +1183,7 @@ def test_periodical_investment_limit_with_dsm2(self): label="Source", outputs={ bus1: solph.flows.Flow( - investment=solph.Investment(ep_costs=123, lifetime=100) + nominal_value=solph.Investment(ep_costs=123, lifetime=100) ) }, ) @@ -1228,7 +1228,7 @@ def test_periodical_investment_limit_with_dsm3(self): label="Source", outputs={ bus1: solph.flows.Flow( - investment=solph.Investment(ep_costs=123, lifetime=100) + nominal_value=solph.Investment(ep_costs=123, lifetime=100) ) }, ) @@ -1277,13 +1277,15 @@ def test_periodical_investment_limit_missing(self): outputs={bus1: solph.flows.Flow()}, lifetime_inflow=20, lifetime_outflow=20, - investment=solph.Investment(ep_costs=145, lifetime=30), + nominal_storage_capacity=solph.Investment( + ep_costs=145, lifetime=30 + ), ) source = solph.components.Source( label="Source", outputs={ bus1: solph.flows.Flow( - investment=solph.Investment(ep_costs=123, lifetime=100) + nominal_value=solph.Investment(ep_costs=123, lifetime=100) ) }, ) @@ -1711,7 +1713,6 @@ def test_nonconvex_investment_storage_without_offset(self): label="storage_non_convex", inputs={bel: solph.flows.Flow(variable_costs=56)}, outputs={bel: solph.flows.Flow(variable_costs=24)}, - nominal_storage_capacity=None, loss_rate=0.13, max_storage_level=0.9, min_storage_level=0.1, @@ -1721,7 +1722,7 @@ def test_nonconvex_investment_storage_without_offset(self): outflow_conversion_factor=0.86, lifetime_inflow=20, lifetime_outflow=20, - investment=solph.Investment( + nominal_storage_capacity=solph.Investment( ep_costs=141, maximum=244, minimum=12, @@ -1742,7 +1743,6 @@ def test_nonconvex_investment_storage_with_offset(self): label="storage_non_convex", inputs={bel: solph.flows.Flow(variable_costs=56)}, outputs={bel: solph.flows.Flow(variable_costs=24)}, - nominal_storage_capacity=None, loss_rate=0.13, max_storage_level=0.9, min_storage_level=0.1, @@ -1752,7 +1752,7 @@ def test_nonconvex_investment_storage_with_offset(self): outflow_conversion_factor=0.86, lifetime_inflow=20, lifetime_outflow=20, - investment=solph.Investment( + nominal_storage_capacity=solph.Investment( ep_costs=145, minimum=19, offset=5, @@ -1772,7 +1772,7 @@ def test_nonconvex_invest_storage_all_nonconvex(self): label="storage_all_nonconvex", inputs={ b1: solph.flows.Flow( - investment=solph.Investment( + nominal_value=solph.Investment( nonconvex=True, minimum=5, offset=10, @@ -1784,7 +1784,7 @@ def test_nonconvex_invest_storage_all_nonconvex(self): }, outputs={ b1: solph.flows.Flow( - investment=solph.Investment( + nominal_value=solph.Investment( nonconvex=True, minimum=8, offset=15, @@ -1794,7 +1794,7 @@ def test_nonconvex_invest_storage_all_nonconvex(self): ) ) }, - investment=solph.Investment( + nominal_storage_capacity=solph.Investment( nonconvex=True, ep_costs=20, offset=30, @@ -1817,7 +1817,7 @@ def test_nonconvex_invest_sink_without_offset(self): summed_max=2.3, variable_costs=25, max=0.8, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=500, minimum=15, nonconvex=True, @@ -1841,7 +1841,7 @@ def test_nonconvex_invest_source_with_offset(self): summed_max=2.3, variable_costs=25, max=0.8, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=500, minimum=15, maximum=20, @@ -1866,7 +1866,7 @@ def test_nonconvex_invest_source_with_offset_no_minimum(self): summed_max=2.3, variable_costs=25, max=0.8, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=500, maximum=1234, offset=34, @@ -2009,7 +2009,7 @@ def test_multi_period_varying_period_length(self): inputs={ bel: solph.Flow( variable_costs=0, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=10, existing=0, lifetime=20, @@ -2021,7 +2021,7 @@ def test_multi_period_varying_period_length(self): outputs={ bel: solph.Flow( variable_costs=0, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=10, existing=0, lifetime=20, @@ -2036,7 +2036,7 @@ def test_multi_period_varying_period_length(self): # inflow_conversion_factor=1, # outflow_conversion_factor=0.8, # nominal_storage_capacity=100, - investment=solph.Investment( + nominal_storage_capacity=solph.Investment( ep_costs=10, maximum=float("+inf"), existing=0, diff --git a/tests/test_components.py b/tests/test_components.py index cde311415..9e71d4b13 100644 --- a/tests/test_components.py +++ b/tests/test_components.py @@ -36,7 +36,7 @@ def test_generic_storage_1(): invest_relation_input_output=1, invest_relation_output_capacity=1, invest_relation_input_capacity=1, - investment=Investment(), + nominal_storage_capacity=Investment(), inflow_conversion_factor=1, outflow_conversion_factor=0.8, ) @@ -112,7 +112,7 @@ def test_generic_storage_with_non_convex_investment(): outputs={bel: Flow()}, invest_relation_input_capacity=1 / 6, invest_relation_output_capacity=1 / 6, - investment=Investment(nonconvex=True, existing=5, maximum=25), + nominal_value=Investment(nonconvex=True, existing=5, maximum=25), ) @@ -128,7 +128,7 @@ def test_generic_storage_with_non_convex_invest_maximum(): outputs={bel: Flow()}, invest_relation_input_capacity=1 / 6, invest_relation_output_capacity=1 / 6, - investment=Investment(nonconvex=True), + nominal_storage_capacity=Investment(nonconvex=True), ) @@ -144,7 +144,7 @@ def test_generic_storage_with_convex_invest_offset(): outputs={bel: Flow()}, invest_relation_input_capacity=1 / 6, invest_relation_output_capacity=1 / 6, - investment=Investment(offset=10), + nominal_storage_capacity=Investment(offset=10), ) @@ -164,13 +164,16 @@ def test_generic_storage_with_invest_and_fixed_losses_absolute(): label="storage4", inputs={bel: Flow()}, outputs={bel: Flow()}, - investment=Investment(ep_costs=23, minimum=0, existing=0), + nominal_storage_capacity=Investment( + ep_costs=23, minimum=0, existing=0 + ), fixed_losses_absolute=[0, 0, 4], ) def test_generic_storage_without_inputs(): - components.GenericStorage(label="storage5") + with pytest.warns(SuspiciousUsageWarning): + components.GenericStorage(label="storage5") def test_generic_storage_too_many_inputs(): @@ -179,7 +182,9 @@ def test_generic_storage_too_many_inputs(): bel2 = Bus() with pytest.raises(AttributeError, match=msg): components.GenericStorage( - label="storage6", inputs={bel1: Flow(), bel2: Flow()} + label="storage6", + inputs={bel1: Flow(), bel2: Flow()}, + outputs={bel2: Flow()}, ) @@ -189,7 +194,9 @@ def test_generic_storage_too_many_outputs(): bel2 = Bus() with pytest.raises(AttributeError, match=msg): components.GenericStorage( - label="storage7", outputs={bel1: Flow(), bel2: Flow()} + label="storage7", + inputs={bel1: Flow()}, + outputs={bel1: Flow(), bel2: Flow()}, ) @@ -234,10 +241,10 @@ def test_offsetconverter_investment_on_inputs(): ): b_diesel = Bus(label="bus_diesel") components.OffsetConverter( - inputs={b_diesel: Flow(investment=Investment())}, + inputs={b_diesel: Flow(nominal_value=Investment())}, outputs={ b_diesel: Flow( - nonconvex=NonConvex(), investment=Investment(maximum=1) + nonconvex=NonConvex(), nominal_value=Investment(maximum=1) ) }, coefficients=(2.5, 0.5), diff --git a/tests/test_constraints_module.py b/tests/test_constraints_module.py index 09f461525..e28889a55 100644 --- a/tests/test_constraints_module.py +++ b/tests/test_constraints_module.py @@ -5,7 +5,10 @@ def test_special(): date_time_index = pd.date_range("1/1/2012", periods=5, freq="H") - energysystem = solph.EnergySystem(timeindex=date_time_index) + energysystem = solph.EnergySystem( + timeindex=date_time_index, + infer_last_interval=True, + ) bel = solph.buses.Bus(label="electricityBus") flow1 = solph.flows.Flow( nominal_value=100, @@ -26,7 +29,9 @@ def test_special(): def test_something_else(): date_time_index = pd.date_range("1/1/2012", periods=5, freq="H") - energysystem = solph.EnergySystem(timeindex=date_time_index) + energysystem = solph.EnergySystem( + timeindex=date_time_index, infer_last_interval=True + ) bel1 = solph.buses.Bus(label="electricity1") bel2 = solph.buses.Bus(label="electricity2") energysystem.add(bel1, bel2) @@ -36,7 +41,7 @@ def test_something_else(): inputs={bel1: solph.flows.Flow()}, outputs={ bel2: solph.flows.Flow( - investment=solph.Investment(ep_costs=20) + nominal_value=solph.Investment(ep_costs=20) ) }, ) @@ -47,7 +52,7 @@ def test_something_else(): inputs={bel2: solph.flows.Flow()}, outputs={ bel1: solph.flows.Flow( - investment=solph.Investment(ep_costs=20) + nominal_value=solph.Investment(ep_costs=20) ) }, ) diff --git a/tests/test_energy_system.py b/tests/test_energy_system.py index 574d5cf9f..7828f31dd 100644 --- a/tests/test_energy_system.py +++ b/tests/test_energy_system.py @@ -19,7 +19,9 @@ def test_add_periods(): pd.date_range(start="2012-01-01", periods=8784, freq="H"), pd.date_range(start="2013-01-01", periods=1217, freq="H"), ] - es = EnergySystem(timeindex=timeindex, periods=periods) + es = EnergySystem( + timeindex=timeindex, periods=periods, infer_last_interval=True + ) assert len(es.periods) == 2 assert es.periods[0].equals( pd.date_range(start="2012-01-01", periods=8784, freq="H") diff --git a/tests/test_grouping.py b/tests/test_grouping.py index 1d4801d3b..c9f0c450d 100644 --- a/tests/test_grouping.py +++ b/tests/test_grouping.py @@ -55,7 +55,7 @@ def test_investment_flow_grouping(self): full_load_time_max=2.3, variable_costs=25, max=0.8, - investment=Investment(ep_costs=500, maximum=10e5), + nominal_value=Investment(ep_costs=500, maximum=10e5), ) }, ) diff --git a/tests/test_models.py b/tests/test_models.py index d42f4252f..4eabbd783 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -72,7 +72,9 @@ def test_multi_period_default_discount_rate(): """Test error being thrown for default multi-period discount rate""" warnings.filterwarnings("ignore", category=FutureWarning) timeindex = pd.date_range(start="2017-01-01", periods=100, freq="D") - es = solph.EnergySystem(timeindex=timeindex, periods={0: timeindex}) + es = solph.EnergySystem( + timeindex=timeindex, periods={0: timeindex}, infer_last_interval=True + ) bel = solph.buses.Bus(label="bus") es.add(bel) es.add( diff --git a/tests/test_non_equidistant_time_index.py b/tests/test_non_equidistant_time_index.py index 60da70a97..d4f3592f3 100644 --- a/tests/test_non_equidistant_time_index.py +++ b/tests/test_non_equidistant_time_index.py @@ -40,7 +40,7 @@ def setup_class(cls): inputs={b_diesel: flows.Flow(variable_costs=2)}, outputs={ b_el1: flows.Flow( - variable_costs=1, investment=Investment(ep_costs=500) + variable_costs=1, nominal_value=Investment(ep_costs=500) ) }, conversion_factors={b_el1: 0.5}, diff --git a/tests/test_options.py b/tests/test_options.py index c209c5e79..a0700c329 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -15,4 +15,6 @@ def test_check_age_and_lifetime(): """Check error being thrown if age > lifetime""" msg = "A unit's age must be smaller than its expected lifetime." with pytest.raises(AttributeError, match=msg): - solph.components.Sink(investment=solph.Investment(age=41, lifetime=40)) + solph.components.Sink( + nominal_value=solph.Investment(age=41, lifetime=40) + ) diff --git a/tests/test_outputlib/__init__.py b/tests/test_outputlib/__init__.py index 78f002380..752119194 100644 --- a/tests/test_outputlib/__init__.py +++ b/tests/test_outputlib/__init__.py @@ -123,7 +123,7 @@ ) datetimeindex = pd.date_range("1/1/2012", periods=24, freq="H") -energysystem = EnergySystem(timeindex=datetimeindex) +energysystem = EnergySystem(timeindex=datetimeindex, infer_last_interval=True) energysystem.add( bcoal, bgas, diff --git a/tests/test_processing.py b/tests/test_processing.py index ae0695ae4..c7d9d5842 100644 --- a/tests/test_processing.py +++ b/tests/test_processing.py @@ -32,8 +32,11 @@ def setup_class(cls): cls.period = 24 cls.es = EnergySystem( timeindex=pandas.date_range( - "2016-01-01", periods=cls.period, freq="H" - ) + "2016-01-01", + periods=cls.period, + freq="H", + ), + infer_last_interval=True, ) # BUSSES @@ -48,7 +51,7 @@ def setup_class(cls): inputs={b_diesel: Flow(variable_costs=2)}, outputs={ b_el1: Flow( - variable_costs=1, investment=Investment(ep_costs=0.5) + variable_costs=1, nominal_value=Investment(ep_costs=0.5) ) }, conversion_factors={b_el1: 2}, @@ -64,7 +67,7 @@ def setup_class(cls): invest_relation_output_capacity=1 / 6, inflow_conversion_factor=1, outflow_conversion_factor=0.8, - investment=Investment(ep_costs=0.4), + nominal_storage_capacity=Investment(ep_costs=0.4), ) cls.demand_values = [0.0] + [100] * 23 diff --git a/tests/test_scripts/test_solph/test_connect_invest/test_connect_invest.py b/tests/test_scripts/test_solph/test_connect_invest/test_connect_invest.py index 9bff4ad64..498261204 100644 --- a/tests/test_scripts/test_solph/test_connect_invest/test_connect_invest.py +++ b/tests/test_scripts/test_solph/test_connect_invest/test_connect_invest.py @@ -30,7 +30,7 @@ def test_connect_invest(): date_time_index = pd.date_range("1/1/2012", periods=24 * 7, freq="H") - es = EnergySystem(timeindex=date_time_index) + es = EnergySystem(timeindex=date_time_index, infer_last_interval=True) # Read data file full_filename = os.path.join( @@ -79,21 +79,21 @@ def test_connect_invest(): invest_relation_output_capacity=1 / 6, inflow_conversion_factor=1, outflow_conversion_factor=0.8, - investment=Investment(ep_costs=0.2), + nominal_storage_capacity=Investment(ep_costs=0.2), ) es.add(storage) line12 = components.Converter( label="line12", inputs={bel1: Flow()}, - outputs={bel2: Flow(investment=Investment(ep_costs=20))}, + outputs={bel2: Flow(nominal_value=Investment(ep_costs=20))}, ) es.add(line12) line21 = components.Converter( label="line21", inputs={bel2: Flow()}, - outputs={bel1: Flow(investment=Investment(ep_costs=20))}, + outputs={bel1: Flow(nominal_value=Investment(ep_costs=20))}, ) es.add(line21) @@ -119,16 +119,18 @@ def test_connect_invest(): results = processing.results(om) my_results = dict() - my_results["line12"] = float( - views.node(results, "line12")["scalars"].loc[ - [(("line12", "electricity2"), "invest")] - ] + my_results["line12"] = ( + views.node(results, "line12")["scalars"] + .loc[[(("line12", "electricity2"), "invest")]] + .iloc[0] ) - my_results["line21"] = float( - views.node(results, "line21")["scalars"].loc[ - [(("line21", "electricity1"), "invest")] - ] + + my_results["line21"] = ( + views.node(results, "line21")["scalars"] + .loc[[(("line21", "electricity1"), "invest")]] + .iloc[0] ) + stor_res = views.node(results, "storage")["scalars"] my_results["storage_in"] = stor_res[ [(("electricity1", "storage"), "invest")] diff --git a/tests/test_scripts/test_solph/test_flexible_modelling/test_add_constraints.py b/tests/test_scripts/test_solph/test_flexible_modelling/test_add_constraints.py index 7dfd74a12..7851f9d52 100644 --- a/tests/test_scripts/test_solph/test_flexible_modelling/test_add_constraints.py +++ b/tests/test_scripts/test_solph/test_flexible_modelling/test_add_constraints.py @@ -31,7 +31,10 @@ def test_add_constraints_example(solver="cbc", nologg=False): logging.basicConfig(level=logging.INFO) # ##### creating an oemof solph optimization model, nothing special here ## # create an energy system object for the oemof solph nodes - es = EnergySystem(timeindex=pd.date_range("1/1/2012", periods=4, freq="H")) + es = EnergySystem( + timeindex=pd.date_range("1/1/2012", periods=4, freq="H"), + infer_last_interval=True, + ) # add some nodes boil = Bus(label="oil", balanced=False) diff --git a/tests/test_scripts/test_solph/test_generic_caes/test_generic_caes.py b/tests/test_scripts/test_solph/test_generic_caes/test_generic_caes.py index a4a907ba4..1b2b78590 100644 --- a/tests/test_scripts/test_solph/test_generic_caes/test_generic_caes.py +++ b/tests/test_scripts/test_solph/test_generic_caes/test_generic_caes.py @@ -38,7 +38,7 @@ def test_gen_caes(): # create an energy system idx = pd.date_range("1/1/2017", periods=periods, freq="H") - es = EnergySystem(timeindex=idx) + es = EnergySystem(timeindex=idx, infer_last_interval=True) # resources bgas = Bus(label="bgas") diff --git a/tests/test_scripts/test_solph/test_generic_chp/test_generic_chp.py b/tests/test_scripts/test_solph/test_generic_chp/test_generic_chp.py index 54c2744af..910c83532 100644 --- a/tests/test_scripts/test_solph/test_generic_chp/test_generic_chp.py +++ b/tests/test_scripts/test_solph/test_generic_chp/test_generic_chp.py @@ -32,7 +32,7 @@ def test_gen_chp(): # create an energy system idx = pd.date_range("1/1/2017", periods=periods, freq="H") - es = solph.EnergySystem(timeindex=idx) + es = solph.EnergySystem(timeindex=idx, infer_last_interval=True) # resources bgas = solph.buses.Bus(label="bgas") diff --git a/tests/test_scripts/test_solph/test_invest_fix_flow/test_simple_invest_fixed.py b/tests/test_scripts/test_solph/test_invest_fix_flow/test_simple_invest_fixed.py index 3778ed6c3..8f2eb1d71 100644 --- a/tests/test_scripts/test_solph/test_invest_fix_flow/test_simple_invest_fixed.py +++ b/tests/test_scripts/test_solph/test_invest_fix_flow/test_simple_invest_fixed.py @@ -50,7 +50,7 @@ def test_dispatch_fix_example(solver="cbc", periods=10): pv = Source( label="pv", outputs={ - bel: Flow(fix=data["pv"], investment=Investment(ep_costs=ep_pv)) + bel: Flow(fix=data["pv"], nominal_value=Investment(ep_costs=ep_pv)) }, ) @@ -62,7 +62,9 @@ def test_dispatch_fix_example(solver="cbc", periods=10): datetimeindex = pd.date_range("1/1/2012", periods=periods, freq="H") - energysystem = EnergySystem(timeindex=datetimeindex) + energysystem = EnergySystem( + timeindex=datetimeindex, infer_last_interval=True + ) energysystem.add(bel, excess_el, pv, demand_el) diff --git a/tests/test_scripts/test_solph/test_lopf/test_lopf.py b/tests/test_scripts/test_solph/test_lopf/test_lopf.py index beccd909a..740ed47d9 100644 --- a/tests/test_scripts/test_solph/test_lopf/test_lopf.py +++ b/tests/test_scripts/test_solph/test_lopf/test_lopf.py @@ -34,7 +34,7 @@ def test_lopf(solver="cbc"): # create time index for 192 hours in May. date_time_index = pd.date_range("5/5/2012", periods=1, freq="H") - es = EnergySystem(timeindex=date_time_index) + es = EnergySystem(timeindex=date_time_index, infer_last_interval=True) ########################################################################## # Create oemof.solph objects @@ -55,7 +55,7 @@ def test_lopf(solver="cbc"): input=b_el0, output=b_el1, reactance=0.0001, - investment=Investment(ep_costs=10), + nominal_value=Investment(ep_costs=10), min=-1, max=1, ) diff --git a/tests/test_scripts/test_solph/test_multi_period_model/test_multi_period_investment_model.py b/tests/test_scripts/test_solph/test_multi_period_model/test_multi_period_investment_model.py index 1c6d4ca63..ccf3e3b91 100644 --- a/tests/test_scripts/test_solph/test_multi_period_model/test_multi_period_investment_model.py +++ b/tests/test_scripts/test_solph/test_multi_period_model/test_multi_period_investment_model.py @@ -139,7 +139,7 @@ def test_multi_period_investment_model(solver="cbc"): inputs={bus_lignite: flows.Flow()}, outputs={ bus_el: flows.Flow( - investment=_options.Investment( + nominal_value=_options.Investment( maximum=1000, ep_costs=2e6, existing=0, @@ -158,7 +158,7 @@ def test_multi_period_investment_model(solver="cbc"): inputs={bus_hardcoal: flows.Flow()}, # )}, outputs={ bus_el: flows.Flow( - investment=_options.Investment( + nominal_value=_options.Investment( maximum=1000, ep_costs=1.6e6, existing=0, @@ -177,7 +177,7 @@ def test_multi_period_investment_model(solver="cbc"): inputs={bus_natgas: flows.Flow()}, # )}, outputs={ bus_el: flows.Flow( - investment=_options.Investment( + nominal_value=_options.Investment( maximum=1000, ep_costs=1e6, existing=0, @@ -196,7 +196,7 @@ def test_multi_period_investment_model(solver="cbc"): inputs={bus_natgas: flows.Flow()}, # )}, outputs={ bus_el: flows.Flow( - investment=_options.Investment( + nominal_value=_options.Investment( maximum=1000, ep_costs=[0.6e6, 0.5e6, 0.8e6, 0.4e6], existing=0, @@ -217,7 +217,7 @@ def test_multi_period_investment_model(solver="cbc"): bus_el: flows.Flow( variable_costs=0, max=1, - investment=_options.Investment( + nominal_value=_options.Investment( maximum=20, ep_costs=1000, existing=10, @@ -231,7 +231,7 @@ def test_multi_period_investment_model(solver="cbc"): bus_el: flows.Flow( variable_costs=0, max=1, - investment=_options.Investment( + nominal_value=_options.Investment( maximum=20, ep_costs=1000, existing=10, @@ -251,7 +251,7 @@ def test_multi_period_investment_model(solver="cbc"): invest_relation_input_capacity=None, invest_relation_output_capacity=None, fixed_costs=10, - investment=_options.Investment( + nominal_storage_capacity=_options.Investment( maximum=20, ep_costs=1000, existing=10, diff --git a/tests/test_scripts/test_solph/test_piecewiselineartransformer/test_piecewiselineartransformer.py b/tests/test_scripts/test_solph/test_piecewiselineartransformer/test_piecewiselineartransformer.py index 89942bb6c..19a89ad27 100644 --- a/tests/test_scripts/test_solph/test_piecewiselineartransformer/test_piecewiselineartransformer.py +++ b/tests/test_scripts/test_solph/test_piecewiselineartransformer/test_piecewiselineartransformer.py @@ -31,7 +31,9 @@ def test_pwltf(): demand = np.arange(0, step * periods, step) # Set up EnergySystem, buses and sink - energysystem = EnergySystem(timeindex=datetimeindex) + energysystem = EnergySystem( + timeindex=datetimeindex, infer_last_interval=True + ) b_gas = Bus(label="biogas", balanced=False) b_el = Bus(label="electricity") demand_el = Sink( diff --git a/tests/test_scripts/test_solph/test_simple_model/test_simple_dispatch.py b/tests/test_scripts/test_solph/test_simple_model/test_simple_dispatch.py index 44da686c7..d7fc978ec 100644 --- a/tests/test_scripts/test_solph/test_simple_model/test_simple_dispatch.py +++ b/tests/test_scripts/test_solph/test_simple_model/test_simple_dispatch.py @@ -126,7 +126,9 @@ def test_dispatch_example(solver="cbc", periods=24 * 5): ) datetimeindex = pd.date_range("1/1/2012", periods=periods, freq="H") - energysystem = EnergySystem(timeindex=datetimeindex) + energysystem = EnergySystem( + timeindex=datetimeindex, infer_last_interval=True + ) energysystem.add( bcoal, bgas, diff --git a/tests/test_scripts/test_solph/test_simple_model/test_simple_invest.py b/tests/test_scripts/test_solph/test_simple_model/test_simple_invest.py index a1d53601a..dcefb11e8 100644 --- a/tests/test_scripts/test_solph/test_simple_model/test_simple_invest.py +++ b/tests/test_scripts/test_solph/test_simple_model/test_simple_invest.py @@ -61,7 +61,7 @@ def test_dispatch_example(solver="cbc", periods=24 * 5): outputs={ bel: Flow( fix=data["wind"], - investment=Investment(ep_costs=ep_wind, existing=100), + nominal_value=Investment(ep_costs=ep_wind, existing=100), ) }, ) @@ -72,7 +72,7 @@ def test_dispatch_example(solver="cbc", periods=24 * 5): outputs={ bel: Flow( fix=data["pv"], - investment=Investment(ep_costs=ep_pv, existing=80), + nominal_value=Investment(ep_costs=ep_pv, existing=80), ) }, ) @@ -142,7 +142,9 @@ def test_dispatch_example(solver="cbc", periods=24 * 5): ) datetimeindex = pd.date_range("1/1/2012", periods=periods, freq="H") - energysystem = EnergySystem(timeindex=datetimeindex) + energysystem = EnergySystem( + timeindex=datetimeindex, infer_last_interval=True + ) energysystem.add( bcoal, bgas, diff --git a/tests/test_scripts/test_solph/test_storage_investment/test_invest_storage_regression.py b/tests/test_scripts/test_solph/test_storage_investment/test_invest_storage_regression.py index 34089738d..1faa13677 100644 --- a/tests/test_scripts/test_solph/test_storage_investment/test_invest_storage_regression.py +++ b/tests/test_scripts/test_solph/test_storage_investment/test_invest_storage_regression.py @@ -68,12 +68,16 @@ def test_regression_investment_storage(solver="cbc"): label="storage", inputs={ bel: solph.flows.Flow( - investment=solph.Investment(existing=625046 / 6, maximum=0) + nominal_value=solph.Investment( + existing=625046 / 6, maximum=0 + ) ) }, outputs={ bel: solph.flows.Flow( - investment=solph.Investment(existing=104174.33, maximum=1) + nominal_value=solph.Investment( + existing=104174.33, maximum=1 + ) ) }, loss_rate=0.00, @@ -82,7 +86,10 @@ def test_regression_investment_storage(solver="cbc"): invest_relation_output_capacity=1 / 6, inflow_conversion_factor=1, outflow_conversion_factor=0.8, - investment=solph.Investment(ep_costs=50, existing=625046), + nominal_storage_capacity=solph.Investment( + ep_costs=50, + existing=625046, + ), ) ) diff --git a/tests/test_scripts/test_solph/test_storage_investment/test_storage_investment.py b/tests/test_scripts/test_solph/test_storage_investment/test_storage_investment.py index 0975a8d15..3d89bde91 100644 --- a/tests/test_scripts/test_solph/test_storage_investment/test_storage_investment.py +++ b/tests/test_scripts/test_solph/test_storage_investment/test_storage_investment.py @@ -56,7 +56,10 @@ def test_optimise_storage_size( logging.info("Initialize the energy system") date_time_index = pd.date_range("1/1/2012", periods=400, freq="H") - es = solph.EnergySystem(timeindex=date_time_index) + es = solph.EnergySystem( + timeindex=date_time_index, + infer_last_interval=True, + ) full_filename = os.path.join(os.path.dirname(__file__), filename) data = pd.read_csv(full_filename, sep=",") @@ -136,7 +139,10 @@ def test_optimise_storage_size( invest_relation_output_capacity=1 / 6, inflow_conversion_factor=1, outflow_conversion_factor=0.8, - investment=solph.Investment(ep_costs=epc, existing=6851), + nominal_storage_capacity=solph.Investment( + ep_costs=epc, + existing=6851, + ), ) ) diff --git a/tests/test_scripts/test_solph/test_storage_investment/test_storage_with_tuple_label.py b/tests/test_scripts/test_solph/test_storage_investment/test_storage_with_tuple_label.py index 9efa8ed88..998373fac 100644 --- a/tests/test_scripts/test_solph/test_storage_investment/test_storage_with_tuple_label.py +++ b/tests/test_scripts/test_solph/test_storage_investment/test_storage_with_tuple_label.py @@ -65,7 +65,10 @@ def test_tuples_as_labels_example( logging.info("Initialize the energy system") date_time_index = pd.date_range("1/1/2012", periods=40, freq="H") - energysystem = solph.EnergySystem(timeindex=date_time_index) + energysystem = solph.EnergySystem( + timeindex=date_time_index, + infer_last_interval=True, + ) full_filename = os.path.join(os.path.dirname(__file__), filename) data = pd.read_csv(full_filename, sep=",") diff --git a/tests/test_scripts/test_solph/test_variable_chp/test_variable_chp.py b/tests/test_scripts/test_solph/test_variable_chp/test_variable_chp.py index 4af4e53fa..9753e3684 100644 --- a/tests/test_scripts/test_solph/test_variable_chp/test_variable_chp.py +++ b/tests/test_scripts/test_solph/test_variable_chp/test_variable_chp.py @@ -27,7 +27,9 @@ def test_variable_chp(filename="variable_chp.csv", solver="cbc"): # create time index for 192 hours in May. date_time_index = pd.date_range("5/5/2012", periods=5, freq="H") - energysystem = solph.EnergySystem(timeindex=date_time_index) + energysystem = solph.EnergySystem( + timeindex=date_time_index, infer_last_interval=True + ) # Read data file with heat and electrical demand (192 hours) full_filename = os.path.join(os.path.dirname(__file__), filename) diff --git a/tests/test_time_index.py b/tests/test_time_index.py index 91d5870bf..db4049a1b 100644 --- a/tests/test_time_index.py +++ b/tests/test_time_index.py @@ -17,7 +17,7 @@ def test_energysystem_with_datetimeindex_infer_last_interval(): """Test EnergySystem with DatetimeIndex (equidistant)""" datetimeindex = pd.date_range("1/1/2012", periods=24, freq="H") - es = solph.EnergySystem(timeindex=datetimeindex) + es = solph.EnergySystem(timeindex=datetimeindex, infer_last_interval=True) assert es.timeincrement[1] == 1.0 assert es.timeincrement.sum() == 24 @@ -39,7 +39,7 @@ def test_energysystem_with_datetimeindex_non_equidistant_infer_last_interval(): "DatetimeIndex is None." ) with pytest.raises(AttributeError, match=msg): - solph.EnergySystem(timeindex=dtindex) + solph.EnergySystem(timeindex=dtindex, infer_last_interval=True) def test_energysystem_with_datetimeindex_non_equidistant(): @@ -102,7 +102,7 @@ def test_energysystem_with_numeric_index_non_equidistant(): def test_model_timeincrement_with_valid_timeindex(): datetimeindex = pd.date_range("1/1/2012", periods=5, freq="H") - es = solph.EnergySystem(timeindex=datetimeindex) + es = solph.EnergySystem(timeindex=datetimeindex, infer_last_interval=True) m = solph._models.BaseModel(es) assert es.timeincrement.sum() == 5 assert m.timeincrement.sum() == 5 @@ -125,6 +125,7 @@ def test_conflicting_time_index(): solph.EnergySystem( timeindex=pd.date_range("1/1/2012", periods=2, freq="H"), timeincrement=[1, 2, 3, 4], + infer_last_interval=False, ) @@ -140,7 +141,8 @@ def test_missing_timeincrement(): def test_overwrite_timeincrement(): es = solph.EnergySystem( - timeindex=pd.date_range("1/1/2012", periods=2, freq="H") + timeindex=pd.date_range("1/1/2012", periods=2, freq="H"), + infer_last_interval=True, ) assert es.timeincrement[0] == 1 m = solph._models.BaseModel(es, timeincrement=[3]) diff --git a/tests/test_warnings.py b/tests/test_warnings.py index c3fac5e37..446739277 100644 --- a/tests/test_warnings.py +++ b/tests/test_warnings.py @@ -135,11 +135,10 @@ def test_nonconvex_investment_without_maximum_raises_warning(warning_fixture): with pytest.raises(AttributeError): solph.flows.Flow( - nominal_value=None, variable_costs=25, min=0.2, max=0.8, - investment=solph.Investment( + nominal_value=solph.Investment( ep_costs=500, # no maximum is provided here ), nonconvex=solph.NonConvex(), From fc403d358deb6f3ac766c52be869f71a75b4171f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sch=C3=B6nfeldt?= Date: Thu, 12 Oct 2023 19:54:57 +0200 Subject: [PATCH 10/25] Fix wrong replacement in TestsConstraint --- tests/constraint_tests.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/constraint_tests.py b/tests/constraint_tests.py index 71cfbd534..68a714aee 100644 --- a/tests/constraint_tests.py +++ b/tests/constraint_tests.py @@ -367,7 +367,7 @@ def test_storage_invest_4(self): label="storage4", inputs={bel: solph.flows.Flow(nominal_value=80)}, outputs={bel: solph.flows.Flow(nominal_value=100)}, - nominal_value=solph.Investment(ep_costs=145, maximum=500), + nominal_storage_capacity=solph.Investment(ep_costs=145, maximum=500), ) self.energysystem.add(bel, storage) self.compare_lp_files("storage_invest_4.lp") @@ -434,7 +434,7 @@ def test_storage_minimum_invest(self): label="storage1", inputs={bel: solph.flows.Flow()}, outputs={bel: solph.flows.Flow()}, - nominal_value=solph.Investment( + nominal_storage_capacity=solph.Investment( ep_costs=145, minimum=100, maximum=200 ), ) @@ -470,7 +470,7 @@ def test_storage_invest_unbalanced(self): balanced=False, invest_relation_input_capacity=1, invest_relation_output_capacity=1, - nominal_value=solph.Investment(ep_costs=145), + nominal_storage_capacity=solph.Investment(ep_costs=145), ) self.energysystem.add(bel, storage) self.compare_lp_files("storage_invest_unbalanced.lp") From 01ebeaafcd19bfc200ec300f2e55166db6def743 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sch=C3=B6nfeldt?= Date: Thu, 12 Oct 2023 20:03:25 +0200 Subject: [PATCH 11/25] Fix implicit time step inference --- tests/regression_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/regression_tests.py b/tests/regression_tests.py index c2409c914..8ec62c759 100644 --- a/tests/regression_tests.py +++ b/tests/regression_tests.py @@ -25,7 +25,7 @@ def test_version_metadata(): def test_wrong_logging_level(): datetimeindex = pd.date_range("1/1/2012", periods=12, freq="H") - es = solph.EnergySystem(timeindex=datetimeindex) + es = solph.EnergySystem(timeindex=datetimeindex, infer_last_interval=True) tools.logger.define_logging() my_logger = logging.getLogger() my_logger.setLevel("DEBUG") From f677ad93a1dbca06904f430b23fabde08db13f2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sch=C3=B6nfeldt?= Date: Thu, 12 Oct 2023 20:05:30 +0200 Subject: [PATCH 12/25] Adhere to Black --- tests/constraint_tests.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/constraint_tests.py b/tests/constraint_tests.py index 68a714aee..b3a186a36 100644 --- a/tests/constraint_tests.py +++ b/tests/constraint_tests.py @@ -367,7 +367,9 @@ def test_storage_invest_4(self): label="storage4", inputs={bel: solph.flows.Flow(nominal_value=80)}, outputs={bel: solph.flows.Flow(nominal_value=100)}, - nominal_storage_capacity=solph.Investment(ep_costs=145, maximum=500), + nominal_storage_capacity=solph.Investment( + ep_costs=145, maximum=500 + ), ) self.energysystem.add(bel, storage) self.compare_lp_files("storage_invest_4.lp") From f9c79ab2a4fc5da70d2816bcac62f8b0f2099cd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sch=C3=B6nfeldt?= Date: Thu, 12 Oct 2023 20:07:17 +0200 Subject: [PATCH 13/25] Adhere to Black --- .../diesel_genset_nonconvex_investment.py | 4 +++- .../offset_diesel_genset_nonconvex_investment.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/invest_nonconvex_flow_examples/diesel_genset_nonconvex_investment.py b/examples/invest_nonconvex_flow_examples/diesel_genset_nonconvex_investment.py index d273d3380..8ecaa15af 100644 --- a/examples/invest_nonconvex_flow_examples/diesel_genset_nonconvex_investment.py +++ b/examples/invest_nonconvex_flow_examples/diesel_genset_nonconvex_investment.py @@ -214,7 +214,9 @@ def main(): ), inputs={b_el_dc: solph.flows.Flow(variable_costs=0)}, outputs={ - b_el_dc: solph.flows.Flow(nominal_value=solph.Investment(ep_costs=0)) + b_el_dc: solph.flows.Flow( + nominal_value=solph.Investment(ep_costs=0) + ) }, initial_storage_level=0.0, min_storage_level=0.0, diff --git a/examples/offset_converter_example/offset_diesel_genset_nonconvex_investment.py b/examples/offset_converter_example/offset_diesel_genset_nonconvex_investment.py index 15e5164ae..38d2874c3 100644 --- a/examples/offset_converter_example/offset_diesel_genset_nonconvex_investment.py +++ b/examples/offset_converter_example/offset_diesel_genset_nonconvex_investment.py @@ -225,7 +225,9 @@ def offset_converter_example(): ), inputs={b_el_dc: solph.flows.Flow(variable_costs=0)}, outputs={ - b_el_dc: solph.flows.Flow(nominal_value=solph.Investment(ep_costs=0)) + b_el_dc: solph.flows.Flow( + nominal_value=solph.Investment(ep_costs=0) + ) }, initial_storage_level=0.0, min_storage_level=0.0, From 2129b0a800a7109f052023a7f60e0e516ef05348 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sch=C3=B6nfeldt?= Date: Thu, 12 Oct 2023 20:28:40 +0200 Subject: [PATCH 14/25] Delete warning about timeincrement in EnergySystem The ExperimentalFeatureWarning is only issued in multi-period-mode, which is experimental anyway. I don't think we need two warnings. --- src/oemof/solph/_energy_system.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/oemof/solph/_energy_system.py b/src/oemof/solph/_energy_system.py index 90125d9ac..871d3bf02 100644 --- a/src/oemof/solph/_energy_system.py +++ b/src/oemof/solph/_energy_system.py @@ -130,13 +130,6 @@ def __init__( "conflicting to each other." ) raise AttributeError(msg) - else: - msg = ( - "Ensure that your timeindex and timeincrement are " - "consistent.\nIf you are not considering non-equidistant " - "timeindices, consider only specifying a timeindex." - ) - warnings.warn(msg, debugging.ExperimentalFeatureWarning) elif timeindex is not None and timeincrement is None: df = pd.DataFrame(timeindex) From 240746c5c43f5130c416b4d7aae281d16a06235b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sch=C3=B6nfeldt?= Date: Thu, 12 Oct 2023 20:32:38 +0200 Subject: [PATCH 15/25] Fix include of example_genergic_invest --- examples/generic_invest_limit/example_generic_invest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/generic_invest_limit/example_generic_invest.py b/examples/generic_invest_limit/example_generic_invest.py index 841d49e5a..a428f9c8f 100644 --- a/examples/generic_invest_limit/example_generic_invest.py +++ b/examples/generic_invest_limit/example_generic_invest.py @@ -42,7 +42,7 @@ .. literalinclude:: /../examples/generic_invest_limit/example_generic_invest.py :language: python - :lines: 62-219 + :lines: 62- Installation requirements ------------------------- From 442c3a68423f81c77d6a6ef9a2ae071976ddb9fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sch=C3=B6nfeldt?= Date: Thu, 12 Oct 2023 20:39:22 +0200 Subject: [PATCH 16/25] Avoid DataFrame.groupby(*args, axis=1, **kwargs) DataFrame.groupby with axis=1 is deprecated. The message says to do `frame.T.groupby(...)` without axis instead. So did I. --- src/oemof/solph/views.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/oemof/solph/views.py b/src/oemof/solph/views.py index 5719eb583..a97fcdf7d 100644 --- a/src/oemof/solph/views.py +++ b/src/oemof/solph/views.py @@ -406,7 +406,7 @@ def net_storage_flow(results, node_type): dataframes = [] for lb in labels: - subset = df.groupby( + subset = df.T.groupby( lambda x1: ( lambda fr, to, ty: "output" if (fr == lb and ty == "flow") @@ -415,9 +415,8 @@ def net_storage_flow(results, node_type): else "level" if (fr == lb and ty != "flow") else None - )(*x1), - axis=1, - ).sum() + )(*x1) + ).sum().T subset["net_flow"] = subset["output"] - subset["input"] From 1a681f08c9d0c3415b1f8b79f78078637b3850f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sch=C3=B6nfeldt?= Date: Thu, 12 Oct 2023 20:44:17 +0200 Subject: [PATCH 17/25] Ignore ExperimentalFeatureWarning in pytest --- pytest.ini | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 000000000..33447956b --- /dev/null +++ b/pytest.ini @@ -0,0 +1,4 @@ +[pytest] +filterwarnings = + ignore::oemof.tools.debugging.ExperimentalFeatureWarning + From b3ba6f2633da1fb388a6df6300627555d7690e8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sch=C3=B6nfeldt?= Date: Thu, 12 Oct 2023 20:44:47 +0200 Subject: [PATCH 18/25] Adhere to Black --- src/oemof/solph/views.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/oemof/solph/views.py b/src/oemof/solph/views.py index a97fcdf7d..93a08921e 100644 --- a/src/oemof/solph/views.py +++ b/src/oemof/solph/views.py @@ -406,17 +406,21 @@ def net_storage_flow(results, node_type): dataframes = [] for lb in labels: - subset = df.T.groupby( - lambda x1: ( - lambda fr, to, ty: "output" - if (fr == lb and ty == "flow") - else "input" - if (to == lb and ty == "flow") - else "level" - if (fr == lb and ty != "flow") - else None - )(*x1) - ).sum().T + subset = ( + df.T.groupby( + lambda x1: ( + lambda fr, to, ty: "output" + if (fr == lb and ty == "flow") + else "input" + if (to == lb and ty == "flow") + else "level" + if (fr == lb and ty != "flow") + else None + )(*x1) + ) + .sum() + .T + ) subset["net_flow"] = subset["output"] - subset["input"] From 8ef4c4c527a7439563619eb75777f2ac9c0bb4c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sch=C3=B6nfeldt?= Date: Fri, 13 Oct 2023 14:00:00 +0200 Subject: [PATCH 19/25] Include pytest.ini in MANIFEST --- MANIFEST.in | 1 + 1 file changed, 1 insertion(+) diff --git a/MANIFEST.in b/MANIFEST.in index c80f59439..a6ae4d0f5 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -17,6 +17,7 @@ include *.md include VERSION include tox.ini +include pytest.ini include *.yml include *.yaml From cfc69664a0637429c1b9c3aad3fc0f1c00be6f0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sch=C3=B6nfeldt?= Date: Fri, 13 Oct 2023 14:37:21 +0200 Subject: [PATCH 20/25] Revert "Ignore ExperimentalFeatureWarning in pytest" This reverts commit 1a681f08c9d0c3415b1f8b79f78078637b3850f3. --- pytest.ini | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index 33447956b..000000000 --- a/pytest.ini +++ /dev/null @@ -1,4 +0,0 @@ -[pytest] -filterwarnings = - ignore::oemof.tools.debugging.ExperimentalFeatureWarning - From 99385e6ae20396d262746d75d0615246fed0ee5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sch=C3=B6nfeldt?= Date: Fri, 13 Oct 2023 14:37:28 +0200 Subject: [PATCH 21/25] Revert "Include pytest.ini in MANIFEST" This reverts commit 8ef4c4c527a7439563619eb75777f2ac9c0bb4c1. --- MANIFEST.in | 1 - 1 file changed, 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index a6ae4d0f5..c80f59439 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -17,7 +17,6 @@ include *.md include VERSION include tox.ini -include pytest.ini include *.yml include *.yaml From ceba43dce89d638cda65175b9764c167f62ba824 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sch=C3=B6nfeldt?= Date: Fri, 13 Oct 2023 17:06:30 +0200 Subject: [PATCH 22/25] Delete tangling white space in docs --- docs/usage.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/usage.rst b/docs/usage.rst index fe60ea434..6f8373798 100644 --- a/docs/usage.rst +++ b/docs/usage.rst @@ -643,8 +643,8 @@ The following example pictures a Pumped Hydroelectric Energy Storage (PHES). Bot solph.components.GenericStorage( label='PHES', - inputs={b_el: solph.flows.Flow(nominal_value= solph.Investment(ep_costs=500))}, - outputs={b_el: solph.flows.Flow(nominal_value= solph.Investment(ep_costs=500)}, + inputs={b_el: solph.flows.Flow(nominal_value=solph.Investment(ep_costs=500))}, + outputs={b_el: solph.flows.Flow(nominal_value=solph.Investment(ep_costs=500)}, loss_rate=0.001, inflow_conversion_factor=0.98, outflow_conversion_factor=0.8), investment = solph.Investment(ep_costs=40)) From 6cb4bbfc96e3bbd3a939aeb6a231e3ba227db458 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sch=C3=B6nfeldt?= Date: Fri, 13 Oct 2023 17:21:31 +0200 Subject: [PATCH 23/25] Test Future warning in Flow invenstment --- tests/test_solph_network_classes.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_solph_network_classes.py b/tests/test_solph_network_classes.py index fa403541a..bce095289 100644 --- a/tests/test_solph_network_classes.py +++ b/tests/test_solph_network_classes.py @@ -87,6 +87,12 @@ def test_wrong_combination_invest_and_nominal_value(): solph.flows.Flow(investment=solph.Investment(), nominal_value=4) +def test_invest_attribute_warning(): + msg = "For backward compatibility, the option investment overwrites" + with pytest.warns(FutureWarning, match=msg): + solph.flows.Flow(investment=solph.Investment()) + + def test_fixed_costs_warning(): msg = ( "Be aware that the fixed costs attribute is only\n" From 321a35af47bd7454356a1cb2dae8963ca161b3f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sch=C3=B6nfeldt?= Date: Mon, 16 Oct 2023 19:34:57 +0200 Subject: [PATCH 24/25] Revert "Delete warning about timeincrement in EnergySystem" This reverts commit 2129b0a800a7109f052023a7f60e0e516ef05348. --- src/oemof/solph/_energy_system.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/oemof/solph/_energy_system.py b/src/oemof/solph/_energy_system.py index f566c51c7..89c3d22d3 100644 --- a/src/oemof/solph/_energy_system.py +++ b/src/oemof/solph/_energy_system.py @@ -130,6 +130,13 @@ def __init__( "conflicting to each other." ) raise AttributeError(msg) + else: + msg = ( + "Ensure that your timeindex and timeincrement are " + "consistent.\nIf you are not considering non-equidistant " + "timeindices, consider only specifying a timeindex." + ) + warnings.warn(msg, debugging.ExperimentalFeatureWarning) elif timeindex is not None and timeincrement is None: df = pd.DataFrame(timeindex) From 561688d27465d467c5f28bad43b9bf964148434d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sch=C3=B6nfeldt?= Date: Mon, 16 Oct 2023 19:40:47 +0200 Subject: [PATCH 25/25] Tell about need for timeincrement in MP models As described in #979, timeincrement currently needs to be set for multi period optimisation models. --- src/oemof/solph/_energy_system.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/oemof/solph/_energy_system.py b/src/oemof/solph/_energy_system.py index 89c3d22d3..de2d2ad79 100644 --- a/src/oemof/solph/_energy_system.py +++ b/src/oemof/solph/_energy_system.py @@ -133,8 +133,7 @@ def __init__( else: msg = ( "Ensure that your timeindex and timeincrement are " - "consistent.\nIf you are not considering non-equidistant " - "timeindices, consider only specifying a timeindex." + "consistent." ) warnings.warn(msg, debugging.ExperimentalFeatureWarning)