Skip to content

Commit

Permalink
Refactor outdated names
Browse files Browse the repository at this point in the history
  • Loading branch information
p-snft committed Aug 19, 2024
1 parent 609cabd commit 2ec9a02
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 37 deletions.
10 changes: 5 additions & 5 deletions src/oemof/solph/_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down Expand Up @@ -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(
Expand Down
3 changes: 1 addition & 2 deletions src/oemof/solph/_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/oemof/solph/constraints/integral_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 8 additions & 12 deletions tests/test_components/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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"]
Expand Down
1 change: 1 addition & 0 deletions tests/test_constraints/test_constraints_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion tests/test_flows/test_non_convex_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
32 changes: 16 additions & 16 deletions tests/test_solph_network_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 2ec9a02

Please sign in to comment.