diff --git a/docs/usage.rst b/docs/usage.rst index 1f7b6f82b..bc02bbf07 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, @@ -1143,7 +1143,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, @@ -1177,7 +1177,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, @@ -1472,12 +1472,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..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 ------------------------- @@ -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..8ecaa15af 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,14 @@ 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..38d2874c3 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,14 @@ 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 cf6bce6f6..2d889787e 100644 --- a/src/oemof/solph/_energy_system.py +++ b/src/oemof/solph/_energy_system.py @@ -138,10 +138,9 @@ 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.SuspiciousUsageWarning) + warnings.warn(msg, debugging.ExperimentalFeatureWarning) elif timeindex is not None and timeincrement is None: df = pd.DataFrame(timeindex) @@ -156,7 +155,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) @@ -176,7 +175,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._extract_periods_years() self._extract_periods_matrix() self._extract_end_year_of_optimization() 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 4145d8428..fe99af99d 100644 --- a/src/oemof/solph/components/_generic_storage.py +++ b/src/oemof/solph/components/_generic_storage.py @@ -24,7 +24,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 @@ -41,7 +41,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. @@ -150,7 +150,7 @@ class GenericStorage(network.Component): >>> 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/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 562a65e50..f150dff5a 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/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/src/oemof/solph/flows/_flow.py b/src/oemof/solph/flows/_flow.py index 9ff497782..ae9b4e6e6 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 diff --git a/src/oemof/solph/views.py b/src/oemof/solph/views.py index 5719eb583..93a08921e 100644 --- a/src/oemof/solph/views.py +++ b/src/oemof/solph/views.py @@ -406,18 +406,21 @@ def net_storage_flow(results, node_type): dataframes = [] for lb in labels: - subset = df.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), - axis=1, - ).sum() + 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"] diff --git a/tests/constraint_tests.py b/tests/constraint_tests.py index 53a35936e..b3a186a36 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,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)}, - investment=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") @@ -376,12 +386,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 +410,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 +436,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 ), ) @@ -456,12 +468,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_storage_capacity=solph.Investment(ep_costs=145), ) self.energysystem.add(bel, storage) self.compare_lp_files("storage_invest_unbalanced.lp") @@ -499,7 +510,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 +519,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 +561,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 +585,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 +629,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 +694,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 +706,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 +716,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 +911,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 +925,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 +1067,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 +1090,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 +1123,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 +1157,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 +1193,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 +1385,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 +1669,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 +1694,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 +1701,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 +1718,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 +1725,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 +1744,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 +1755,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 +1764,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 +1782,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 +1802,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 +1826,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 ), ) @@ -1860,8 +1871,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, diff --git a/tests/multi_period_constraint_tests.py b/tests/multi_period_constraint_tests.py index 79db5642b..e2992856f 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, @@ -193,7 +193,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, @@ -285,7 +285,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 ), ) @@ -303,7 +303,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 ), ) @@ -329,7 +329,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), ) }, ) @@ -376,7 +376,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, @@ -386,7 +385,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, @@ -442,15 +441,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 ), ) @@ -468,7 +467,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, @@ -478,7 +477,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, @@ -494,7 +493,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 ), ) @@ -513,14 +512,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, @@ -539,18 +538,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 ), ) @@ -567,7 +566,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, @@ -584,7 +583,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, @@ -649,7 +648,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, @@ -661,7 +659,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, @@ -686,7 +684,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, @@ -697,7 +694,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, @@ -724,7 +721,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, @@ -734,7 +730,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, @@ -783,7 +779,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, @@ -809,7 +805,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, @@ -854,7 +850,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 ), ) @@ -1100,13 +1096,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) ) }, ) @@ -1114,7 +1112,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) ) }, ) @@ -1183,13 +1181,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) ) }, ) @@ -1208,7 +1208,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) ) }, ) @@ -1252,7 +1252,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) ) }, ) @@ -1297,7 +1297,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) ) }, ) @@ -1346,13 +1346,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) ) }, ) @@ -1896,7 +1898,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, @@ -1906,7 +1907,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, @@ -1962,7 +1963,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, @@ -1972,7 +1972,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, @@ -2028,7 +2028,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, @@ -2040,7 +2040,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, @@ -2050,7 +2050,7 @@ def test_nonconvex_invest_storage_all_nonconvex(self): ) ) }, - investment=solph.Investment( + nominal_storage_capacity=solph.Investment( nonconvex=True, ep_costs=20, offset=30, @@ -2073,7 +2073,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, @@ -2125,7 +2125,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, @@ -2179,7 +2179,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, @@ -2322,7 +2322,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, @@ -2334,7 +2334,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, @@ -2349,7 +2349,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/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") 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 2e53813ed..3ac3938eb 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -72,7 +72,12 @@ 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=[timeindex]) + es = solph.EnergySystem( + timeindex=timeindex, + timeincrement=[1] * len(timeindex), + periods=[timeindex], + infer_last_interval=False, + ) 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 488e826ef..d4f3592f3 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 @@ -39,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}, @@ -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_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 6cc68ccc2..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 @@ -301,7 +304,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 +316,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 +336,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_connect_invest/test_connect_invest.py b/tests/test_scripts/test_solph/test_connect_invest/test_connect_invest.py index 91637d424..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 @@ -14,6 +14,7 @@ import os import pandas as pd +import pytest from oemof.solph import EnergySystem from oemof.solph import Investment @@ -29,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( @@ -78,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) @@ -118,24 +119,26 @@ 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")] - ] - 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 +149,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_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 9c1a0ecc0..335e30964 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 @@ -37,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") @@ -139,4 +140,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..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 @@ -15,6 +15,7 @@ import os import pandas as pd +import pytest from oemof import solph as solph from oemof.solph import processing @@ -31,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") @@ -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_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 f3ea9f649..740ed47d9 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 @@ -33,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 @@ -54,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, ) @@ -124,24 +125,32 @@ 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 ( - 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_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 ee694a772..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 @@ -16,6 +16,7 @@ import os import pandas as pd +import pytest from oemof.solph import EnergySystem from oemof.solph import Model @@ -125,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, @@ -190,4 +193,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..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 @@ -16,6 +16,7 @@ import os import pandas as pd +import pytest from oemof.tools import economics from oemof.solph import EnergySystem @@ -60,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), ) }, ) @@ -71,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), ) }, ) @@ -141,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, @@ -208,4 +211,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_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 a22ec81bb..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 @@ -38,6 +38,7 @@ import os import pandas as pd +import pytest from oemof.tools import economics from oemof import solph @@ -55,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=",") @@ -135,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, + ), ) ) @@ -179,7 +186,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" @@ -196,7 +203,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 845820fcf..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 @@ -39,6 +39,7 @@ from collections import namedtuple import pandas as pd +import pytest from oemof import solph as solph from oemof.solph import processing @@ -64,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=",") @@ -171,9 +175,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 +207,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" @@ -218,4 +224,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 59b940a82..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 @@ -16,6 +16,7 @@ import os import pandas as pd +import pytest from oemof import solph from oemof.solph import views @@ -26,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) @@ -172,14 +175,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 ( @@ -196,4 +199,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 489dd8c91..287c6740c 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 @@ -22,12 +21,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 +30,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 +46,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 +54,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 == {} @@ -86,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" 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 cf465ac53..446739277 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'" ): @@ -50,18 +49,9 @@ 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() + look_out = solph.Bus() with pytest.raises( TypeError, match="got an unexpected keyword argument 'inputs'" ): @@ -84,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 ." @@ -109,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 ." @@ -124,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 ." @@ -145,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(),