Skip to content

Commit

Permalink
Merge pull request #352 from openego/feature/csv_import_ding0_no_chan…
Browse files Browse the repository at this point in the history
…ged_test_grids

Feature/csv import ding0 no changed test grids
  • Loading branch information
birgits committed Feb 15, 2023
2 parents f010d70 + 78a010c commit 7e19f84
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
23 changes: 17 additions & 6 deletions edisgo/io/ding0_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
logger = logging.getLogger(__name__)


def import_ding0_grid(path, edisgo_obj):
def import_ding0_grid(path, edisgo_obj, legacy_ding0_grids=True):
"""
Import an eDisGo network topology from
`Ding0 data <https://github.com/openego/ding0>`_.
Expand All @@ -30,7 +30,8 @@ def import_ding0_grid(path, edisgo_obj):
Path to ding0 network csv files.
edisgo_obj: :class:`~.EDisGo`
The eDisGo data container object.
legacy_ding0_grids: `bool`
Allow import of old ding0 grids. Default: True
"""

def sort_transformer_buses(transformers_df):
Expand Down Expand Up @@ -73,9 +74,13 @@ def sort_hvmv_transformer_buses(transformers_df):
# write dataframes to edisgo_obj
edisgo_obj.topology.buses_df = grid.buses[edisgo_obj.topology.buses_df.columns]
edisgo_obj.topology.lines_df = grid.lines[edisgo_obj.topology.lines_df.columns]

grid.loads = grid.loads.drop(columns="p_set").rename(columns={"peak_load": "p_set"})

if legacy_ding0_grids:
logger.debug("Use ding0 legacy grid import.")
grid.loads = grid.loads.drop(columns="p_set").rename(
columns={"peak_load": "p_set"}
)
else:
edisgo_obj.topology.buses_df["in_building"] = False
edisgo_obj.topology.loads_df = grid.loads[edisgo_obj.topology.loads_df.columns]
# set loads without type information to be conventional loads
# this is done, as ding0 currently does not provide information on the type of load
Expand All @@ -85,7 +90,13 @@ def sort_hvmv_transformer_buses(transformers_df):
(edisgo_obj.topology.loads_df.type.isnull())
| (edisgo_obj.topology.loads_df.type == "")
].index
edisgo_obj.topology.loads_df.loc[loads_without_type, "type"] = "conventional_load"
if legacy_ding0_grids:
edisgo_obj.topology.loads_df.loc[
loads_without_type, "type"
] = "conventional_load"
edisgo_obj.topology.loads_df.replace(
to_replace=["retail"], value="cts", inplace=True
)
# drop slack generator from generators
slack = grid.generators.loc[grid.generators.control == "Slack"].index
grid.generators.drop(slack, inplace=True)
Expand Down
2 changes: 1 addition & 1 deletion edisgo/io/timeseries_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def load_time_series_demandlib(config_data, timeindex):

elec_demand.rename(
columns={
"g0": "retail",
"g0": "cts",
"h0": "residential",
"l0": "agricultural",
"i0": "industrial",
Expand Down
4 changes: 2 additions & 2 deletions tests/io/test_timeseries_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def test_import_load_timeseries(self):
timeindex = pd.date_range("1/1/2018", periods=8760, freq="H")
load = timeseries_import.load_time_series_demandlib(self.config, timeindex)
assert (
load.columns == ["retail", "residential", "agricultural", "industrial"]
load.columns == ["cts", "residential", "agricultural", "industrial"]
).all()
assert np.isclose(load.loc[timeindex[453], "retail"], 8.33507e-05)
assert np.isclose(load.loc[timeindex[453], "cts"], 8.33507e-05)
assert np.isclose(load.loc[timeindex[13], "residential"], 1.73151e-04)
assert np.isclose(load.loc[timeindex[6328], "agricultural"], 1.01346e-04)
assert np.isclose(load.loc[timeindex[4325], "industrial"], 9.91768e-05)
12 changes: 6 additions & 6 deletions tests/network/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -1526,7 +1526,7 @@ def test_predefined_conventional_loads_by_sector(self, caplog):
# define expected profiles
profiles = pd.DataFrame(
index=index,
columns=["retail", "residential", "agricultural", "industrial"],
columns=["cts", "residential", "agricultural", "industrial"],
data=[
[0.0000597, 0.0000782, 0.0000654, 0.0000992],
[0.0000526, 0.0000563, 0.0000611, 0.0000992],
Expand Down Expand Up @@ -1589,7 +1589,7 @@ def test_predefined_conventional_loads_by_sector(self, caplog):
self.edisgo.topology.loads_df.loc[
"Load_retail_LVGrid_9_14", "annual_consumption"
]
* profiles["retail"]
* profiles["cts"]
).values,
atol=1e-4,
).all()
Expand Down Expand Up @@ -1645,7 +1645,7 @@ def test_predefined_conventional_loads_by_sector(self, caplog):
# test manual - all
profiles = pd.DataFrame(
index=index,
columns=["retail", "residential", "agricultural", "industrial"],
columns=["cts", "residential", "agricultural", "industrial"],
data=[
[0.003, 0.02, 0.00, 0.1],
[0.004, 0.01, 0.10, 0.2],
Expand Down Expand Up @@ -1683,7 +1683,7 @@ def test_predefined_conventional_loads_by_sector(self, caplog):
self.edisgo.topology.loads_df.loc[
"Load_retail_LVGrid_9_14", "annual_consumption"
]
* profiles["retail"]
* profiles["cts"]
).values,
).all()
assert np.isclose(
Expand All @@ -1701,7 +1701,7 @@ def test_predefined_conventional_loads_by_sector(self, caplog):
profiles_new = (
pd.DataFrame(
index=index,
columns=["retail", "residential", "agricultural", "industrial"],
columns=["cts", "residential", "agricultural", "industrial"],
data=[
[0.003, 0.02, 0.00, 0.1],
[0.004, 0.01, 0.10, 0.2],
Expand Down Expand Up @@ -1742,7 +1742,7 @@ def test_predefined_conventional_loads_by_sector(self, caplog):
self.edisgo.topology.loads_df.loc[
"Load_retail_LVGrid_9_14", "annual_consumption"
]
* profiles["retail"]
* profiles["cts"]
).values,
).all()
assert np.isclose(
Expand Down

0 comments on commit 7e19f84

Please sign in to comment.