diff --git a/src/oemof/solph/_helpers.py b/src/oemof/solph/_helpers.py index ceae7e269..b3d0f0e73 100644 --- a/src/oemof/solph/_helpers.py +++ b/src/oemof/solph/_helpers.py @@ -68,8 +68,8 @@ def create_time_index( Parameters ---------- year : int, datetime - The year of the index. If number and start is set the year parameter is - ignored. + The year of the index. + Used to automatically set start and number for the specific year. interval : float The time interval in hours e.g. 0.5 for 30min or 2 for a two hour interval (default: 1). @@ -100,10 +100,10 @@ def create_time_index( """ if number is None: if calendar.isleap(year): - hoy = 8784 + hours_in_year = 8784 else: - hoy = 8760 - number = round(hoy / interval) + hours_in_year = 8760 + number = round(hours_in_year / interval) if start is not None: if year is not None: raise ValueError( diff --git a/src/oemof/solph/_models.py b/src/oemof/solph/_models.py index d29fd621d..5ecbbd474 100644 --- a/src/oemof/solph/_models.py +++ b/src/oemof/solph/_models.py @@ -349,10 +349,9 @@ def _add_child_blocks(self): and adds them to the model. """ for group in self._constraint_groups: - # create instance for block block = group() - # Add block to model self.add_component(str(block), block) + # create constraints etc. related with block for all nodes # in the group block._create(group=self.es.groups.get(group)) diff --git a/src/oemof/solph/constraints/integral_limit.py b/src/oemof/solph/constraints/integral_limit.py index a758a2fd3..0544226db 100644 --- a/src/oemof/solph/constraints/integral_limit.py +++ b/src/oemof/solph/constraints/integral_limit.py @@ -137,7 +137,7 @@ def generic_integral_limit( >>> model = solph.Model(energysystem) >>> flow_with_keyword = {(src1, bel): flow1, } >>> model = solph.constraints.generic_integral_limit( - ... model, "my_factor", flow_with_keyword, limit=777) + ... model, "my_factor", flow_with_keyword, upper_limit=777) """ flows = _check_and_set_flows(om, flows, keyword) if limit_name is None: diff --git a/tests/test_components/test_storage.py b/tests/test_components/test_storage.py index 2d7dda273..763883637 100644 --- a/tests/test_components/test_storage.py +++ b/tests/test_components/test_storage.py @@ -93,8 +93,6 @@ def test_invest_power_uncoupled(): invest_outflow = result[(storage, bus)]["scalars"]["invest"] assert invest_outflow == pytest.approx(0) - print(result) - def test_invest_power_coupled(): es = solph.EnergySystem( @@ -140,8 +138,6 @@ def test_invest_power_coupled(): invest_outflow = result[(storage, bus)]["scalars"]["invest"] assert invest_outflow == pytest.approx(2) - print(result) - def test_storage_charging(): es = solph.EnergySystem( @@ -209,8 +205,8 @@ def test_invest_content_uncoupled(): storage_inflow = result[(bus, storage)]["sequences"]["flow"] assert list(storage_inflow)[:-1] == 10 * [2] - invest_cpacity = result[(storage, None)]["scalars"]["invest"] - assert invest_cpacity == pytest.approx(19) + invest_capacity = result[(storage, None)]["scalars"]["invest"] + assert invest_capacity == pytest.approx(19) storage_content = list( result[(storage, None)]["sequences"]["storage_content"] @@ -250,8 +246,8 @@ def test_invest_content_minimum(): storage_inflow = result[(bus, storage)]["sequences"]["flow"] assert list(storage_inflow)[:-1] == 10 * [2] - invest_cpacity = result[(storage, None)]["scalars"]["invest"] - assert invest_cpacity == pytest.approx(32) + invest_capacity = result[(storage, None)]["scalars"]["invest"] + assert invest_capacity == pytest.approx(32) storage_content = list( result[(storage, None)]["sequences"]["storage_content"] @@ -291,8 +287,8 @@ def test_invest_content_minimum_nonconvex(): storage_inflow = result[(bus, storage)]["sequences"]["flow"] assert list(storage_inflow)[:-1] == 10 * [0] - invest_cpacity = result[(storage, None)]["scalars"]["invest"] - assert invest_cpacity == pytest.approx(0) + invest_capacity = result[(storage, None)]["scalars"]["invest"] + assert invest_capacity == pytest.approx(0) storage_content = list( result[(storage, None)]["sequences"]["storage_content"] @@ -335,8 +331,8 @@ def test_invest_content_maximum(): result = solph.processing.results(model) - invest_cpacity = result[(storage, None)]["scalars"]["invest"] - assert invest_cpacity == pytest.approx(10) + invest_capacity = result[(storage, None)]["scalars"]["invest"] + assert invest_capacity == pytest.approx(10) storage_content = list( result[(storage, None)]["sequences"]["storage_content"] diff --git a/tests/test_constraints/test_constraints_module.py b/tests/test_constraints/test_constraints_module.py index 03a2b3b68..6a36b7049 100644 --- a/tests/test_constraints/test_constraints_module.py +++ b/tests/test_constraints/test_constraints_module.py @@ -60,6 +60,7 @@ def test_integral_limit(): energysystem.add(bel, src1, src2, src3, src4) model = solph.Model(energysystem) + # Note we do not consider flow3 for this constraint. flows_with_keyword = { (src1, bel): flow1, } diff --git a/tests/test_flows/test_non_convex_flow.py b/tests/test_flows/test_non_convex_flow.py index 48d1ff150..d5960a898 100644 --- a/tests/test_flows/test_non_convex_flow.py +++ b/tests/test_flows/test_non_convex_flow.py @@ -67,7 +67,7 @@ def test_activity_costs(): flow = solph.flows.Flow( nominal_value=10, min=0.1, - max=[i * 0.1 for i in range(10)], + max=[0.1] + [i * 0.1 for i in range(1, 10)], nonconvex=solph.NonConvex(activity_costs=9 * [1] + [10]), variable_costs=-0.45, ) diff --git a/tests/test_solph_network_classes.py b/tests/test_solph_network_classes.py index 35d421d87..71726a286 100644 --- a/tests/test_solph_network_classes.py +++ b/tests/test_solph_network_classes.py @@ -25,56 +25,56 @@ def setup_class(cls): @pytest.mark.filterwarnings("ignore::UserWarning") def test_empty_converter(self): - transf = solph.components.Converter() - assert isinstance(transf.conversion_factors, dict) - assert len(transf.conversion_factors.keys()) == 0 + converter = solph.components.Converter() + assert isinstance(converter.conversion_factors, dict) + assert len(converter.conversion_factors.keys()) == 0 def test_default_conversion_factor(self): - transf = solph.components.Converter( + converter = solph.components.Converter( inputs={self.bus: solph.flows.Flow()}, outputs={self.bus: solph.flows.Flow()}, ) - assert transf.conversion_factors[self.bus][2] == 1 + assert converter.conversion_factors[self.bus][2] == 1 def test_sequence_conversion_factor_from_scalar(self): - transf = solph.components.Converter( + converter = 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 + assert converter.conversion_factors[self.bus][6] == 2 def test_sequence_conversion_factor_from_list_correct_length(self): - transf = solph.components.Converter( + converter = 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 + assert len(converter.conversion_factors[self.bus]) == 1 def test_sequence_conversion_factor_from_list_wrong_length(self): - transf = solph.components.Converter( + converter = 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] + self.a = converter.conversion_factors[self.bus][6] def test_converter_missing_output_create_empty_dict(self): with pytest.warns(SuspiciousUsageWarning): - trfr = solph.components.Converter(inputs={}) - assert trfr.outputs == {} + converter = solph.components.Converter(inputs={}) + assert converter.outputs == {} def test_converter_missing_input_create_empty_dict(self): with pytest.warns(SuspiciousUsageWarning): - trfr = solph.components.Converter(outputs={}) - assert trfr.inputs == {} + converter = solph.components.Converter(outputs={}) + assert converter.inputs == {} def test_transformer_wrapper(): + # two warnings: Wrapper and no inputs/outputs with pytest.warns(FutureWarning): - # no inputs/outputs with pytest.warns(SuspiciousUsageWarning): solph.components.Transformer()