Skip to content

Commit

Permalink
Add mode to topology.assign_feeder and change tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mltja committed Apr 4, 2023
1 parent c55e424 commit f5fd20f
Show file tree
Hide file tree
Showing 3 changed files with 119 additions and 12 deletions.
20 changes: 14 additions & 6 deletions edisgo/network/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -3012,13 +3012,21 @@ def check_integrity(self):
f"optimisation."
)

def assign_feeders(self):
"""Assign the feeder of the grid and the mv feeder to all grids."""
def assign_feeders(self, mode: str = "grid_feeder"):
"""Assign the feeder of the grid or the mv feeder to all grids.
for grid in self.grids:
grid.assign_grid_feeder(mode="grid_feeder")

self.grids[0].assign_grid_feeder(mode="mv_feeder")
Parameters
----------
mode : str
Select 'grid_feeder' or 'mv_feeder' to assign the feeders.
"""
if mode == "grid_feeder":
for grid in self.grids:
grid.assign_grid_feeder(mode="grid_feeder")
elif mode == "mv_feeder":
self.grids[0].assign_grid_feeder(mode="mv_feeder")
else:
raise ValueError(f"Invalid mode '{mode}'!")

def __repr__(self):
return f"Network topology {self.id}"
22 changes: 16 additions & 6 deletions tests/network/test_topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -876,25 +876,35 @@ def test_to_csv(self):
shutil.rmtree(dir)

def test_assign_feeders(self):
self.topology.assign_feeders()
assert self.topology.buses_df.iloc[0:2]["grid_feeder"].to_list() == [
# Test mode 'grid_feeder'
self.topology.assign_feeders(mode="grid_feeder")
assert self.topology.buses_df.loc[
["Bus_MVStation_1", "Bus_Generator_1"], "grid_feeder"
].to_list() == [
"station_node",
"Bus_BranchTee_MVGrid_1_1",
]
assert self.topology.lines_df.iloc[0:2]["grid_feeder"].to_list() == [
assert self.topology.lines_df.loc[
["Line_10003", "Line_10004"], "grid_feeder"
].to_list() == [
"Bus_BranchTee_MVGrid_1_1",
"Bus_BranchTee_MVGrid_1_4",
]

assert self.topology.buses_df.iloc[0:2]["mv_feeder"].to_list() == [
# test mode 'mv_feeder'
self.topology.assign_feeders(mode="mv_feeder")
assert self.topology.buses_df.loc[
["Bus_MVStation_1", "Bus_Generator_1"], "mv_feeder"
].to_list() == [
"station_node",
"Bus_BranchTee_MVGrid_1_1",
]
assert self.topology.lines_df.iloc[0:2]["mv_feeder"].to_list() == [
assert self.topology.lines_df.loc[
["Line_10003", "Line_10004"], "mv_feeder"
].to_list() == [
"Bus_BranchTee_MVGrid_1_1",
"Bus_BranchTee_MVGrid_1_4",
]

lv_grids_mv_bus = self.topology.grids[2].transformers_df["bus0"][0]
feeder_of_lv_grids_mv_bus = self.topology.buses_df.loc[
lv_grids_mv_bus, "mv_feeder"
Expand Down
89 changes: 89 additions & 0 deletions tests/tools/test_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,95 @@ def test_select_cable(self):
assert cable_data.name == "NAYY 4x1x150"
assert num_parallel_cables == 1

def test_assign_feeder(self):

# ######## test MV feeder mode ########
topo = self.edisgo.topology
topo.assign_feeders(mode="mv_feeder")

# check that all lines and all buses (except MV station bus and buses
# in aggregated load areas) have an MV feeder assigned
assert not topo.lines_df.mv_feeder.isna().any()
mv_station = topo.mv_grid.station.index[0]
buses_aggr_la = list(
topo.transformers_df[topo.transformers_df.bus0 == mv_station].bus1.unique()
)
buses_aggr_la.append(mv_station)
assert (
not topo.buses_df[~topo.buses_df.index.isin(buses_aggr_la)]
.mv_feeder.isna()
.any()
)

# check specific buses
# MV and LV bus in feeder 1
assert (
topo.buses_df.at["Bus_GeneratorFluctuating_7", "mv_feeder"]
== "Bus_BranchTee_MVGrid_1_6"
)
assert (
topo.buses_df.at["Bus_BranchTee_LVGrid_4_1", "mv_feeder"]
== "Bus_BranchTee_MVGrid_1_5"
)
# MV bus in feeder 2
assert (
topo.buses_df.at["Bus_GeneratorFluctuating_3", "mv_feeder"]
== "Bus_BranchTee_MVGrid_1_5"
)

# check specific lines
assert topo.lines_df.at["Line_10003", "mv_feeder"] == "Bus_BranchTee_MVGrid_1_1"

# ######## test LV feeder mode ########
topo = self.edisgo.topology
topo.assign_feeders(mode="grid_feeder")

# check that all buses and lines have a grid feeder assigned
assert not topo.lines_df.grid_feeder.isna().any()
assert not topo.buses_df.grid_feeder.isna().any()

# check specific buses
assert (
topo.buses_df.at["Bus_BranchTee_LVGrid_1_8", "grid_feeder"]
== "Bus_BranchTee_LVGrid_1_7"
)
assert (
topo.buses_df.at["Bus_BranchTee_LVGrid_2_4", "grid_feeder"]
== "Bus_BranchTee_LVGrid_2_1"
)

# check specific lines
assert (
topo.lines_df.at["Line_30000005", "grid_feeder"]
== "Bus_BranchTee_LVGrid_3_3"
)
assert (
topo.lines_df.at["Line_40000001", "grid_feeder"]
== "Bus_GeneratorFluctuating_16"
)

# ######## test real ding0 network ########
self.edisgo = EDisGo(
ding0_grid=pytest.ding0_test_network_2_path,
worst_case_analysis="worst-case",
)
topo = self.edisgo.topology
topo.assign_feeders(mode="mv_feeder")

# check that all lines and all buses have an MV feeder assigned
assert not topo.lines_df.mv_feeder.isna().any()
mv_station = topo.mv_grid.station.index[0]
buses_aggr_la = list(
topo.transformers_df[topo.transformers_df.bus0 == mv_station].bus1.unique()
)
buses_aggr_la.append(mv_station)
assert not topo.buses_df.mv_feeder.isna().any()

topo.assign_feeders(mode="grid_feeder")
# check that all buses and lines grid feeder assigned
assert not topo.lines_df.grid_feeder.isna().any()
assert not topo.buses_df.grid_feeder.isna().any()

def test_get_downstream_buses(self):

# ######## test with LV bus ########
Expand Down

0 comments on commit f5fd20f

Please sign in to comment.