From 4087d342b66b71d3ba10134d729b4e425290c9f6 Mon Sep 17 00:00:00 2001 From: birgits Date: Wed, 24 Apr 2024 13:45:02 +0200 Subject: [PATCH 1/7] Fix logger directory creation and add tests --- edisgo/tools/logger.py | 4 +- tests/tools/test_logger.py | 82 ++++++++++++++++++++++++-------------- 2 files changed, 53 insertions(+), 33 deletions(-) diff --git a/edisgo/tools/logger.py b/edisgo/tools/logger.py index 5b1a62a55..20514f947 100644 --- a/edisgo/tools/logger.py +++ b/edisgo/tools/logger.py @@ -119,7 +119,7 @@ def setup_logger( def create_dir(dir_path): if not os.path.isdir(dir_path): - os.mkdir(dir_path) + os.makedirs(dir_path) def get_default_root_dir(): dir_path = str(cfg_edisgo.get("user_dirs", "root_dir")) @@ -140,9 +140,9 @@ def create_home_dir(): log_dir = os.path.join( get_default_root_dir(), cfg_edisgo.get("user_dirs", "log_dir") ) - create_dir(log_dir) if log_dir is not None: + create_dir(log_dir) file_name = os.path.join(log_dir, file_name) if reset_loggers: diff --git a/tests/tools/test_logger.py b/tests/tools/test_logger.py index 80e372eef..eee071df6 100644 --- a/tests/tools/test_logger.py +++ b/tests/tools/test_logger.py @@ -1,65 +1,85 @@ import logging import os +import pytest + from edisgo.tools.logger import setup_logger +def check_file_output(filename, output): + with open(filename) as file: + last_line = file.readlines()[-1].split(" ")[3:] + last_line = " ".join(last_line) + assert last_line == output + + +def reset_loggers(filename): + logger = logging.getLogger("edisgo") + logger.handlers.clear() + logger.propagate = True + # try removing file - when run on github for Windows removing the file leads + # to a PermissionError + try: + os.remove(filename) + except PermissionError: + pass + + class TestClass: def test_setup_logger(self): - def check_file_output(output): - with open("edisgo.log") as file: - last_line = file.readlines()[-1].split(" ")[3:] - last_line = " ".join(last_line) - assert last_line == output - - def reset_loggers(): - logger = logging.getLogger("edisgo") - logger.propagate = True - logger.handlers.clear() - logger = logging.getLogger() - logger.handlers.clear() - - if os.path.exists("edisgo.log"): - os.remove("edisgo.log") + filename = os.path.join( + os.path.expanduser("~"), ".edisgo", "log", "test_log.log" + ) + if os.path.exists(filename): + os.remove(filename) setup_logger( loggers=[ {"name": "root", "file_level": "debug", "stream_level": "debug"}, {"name": "edisgo", "file_level": "debug", "stream_level": "debug"}, ], - file_name="edisgo.log", + file_name="test_log.log", + log_dir="default", ) logger = logging.getLogger("edisgo") # Test that edisgo logger writes to file. logger.debug("root") - check_file_output("edisgo - DEBUG: root\n") + check_file_output(filename, "edisgo - DEBUG: root\n") # Test that root logger writes to file. logging.debug("root") - check_file_output("root - DEBUG: root\n") + check_file_output(filename, "root - DEBUG: root\n") + + reset_loggers(filename) - # reset_loggers() + @pytest.mark.runonlinux + def test_setup_logger_2(self): + """ + This test is only run on linux, as the log file is written to the user + home directory, which is not allowed when tests are run on github. + + """ + + # delete any existing log files + log_files = [_ for _ in os.listdir(os.getcwd()) if ".log" in _] + for log_file in log_files: + os.remove(log_file) setup_logger( loggers=[ {"name": "edisgo", "file_level": "debug", "stream_level": "debug"}, ], - file_name="edisgo.log", reset_loggers=True, debug_message=True, ) logger = logging.getLogger("edisgo") + + filename = [_ for _ in os.listdir(os.getcwd()) if ".log" in _][0] # Test that edisgo logger writes to file. logger.debug("edisgo") - check_file_output("edisgo - DEBUG: edisgo\n") - # Test that root logger doesn't writes to file. - logging.debug("edisgo") - check_file_output("edisgo - DEBUG: edisgo\n") - - @classmethod - def teardown_class(cls): - logger = logging.getLogger("edisgo") - logger.handlers.clear() - logger.propagate = True + check_file_output(filename, "edisgo - DEBUG: edisgo\n") + # Test that root logger doesn't write to file. + logging.debug("root") + check_file_output(filename, "edisgo - DEBUG: edisgo\n") - os.remove("edisgo.log") + reset_loggers(filename) From 5f25525c9a9dc8d96692894b562ae69dd6bb6ed6 Mon Sep 17 00:00:00 2001 From: birgits Date: Wed, 24 Apr 2024 13:46:18 +0200 Subject: [PATCH 2/7] Use number of parallel lines not 1 --- edisgo/network/results.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edisgo/network/results.py b/edisgo/network/results.py index 8f6e8b044..151fbd480 100755 --- a/edisgo/network/results.py +++ b/edisgo/network/results.py @@ -628,7 +628,7 @@ def _add_line_to_equipment_changes(self, line): "iteration_step": [0], "change": ["added"], "equipment": [line.type_info], - "quantity": [1], + "quantity": [line.num_parallel], }, index=[line.name], ), From f77fd611d789ddf27eb1444f28474a1131981069 Mon Sep 17 00:00:00 2001 From: birgits Date: Wed, 24 Apr 2024 13:47:17 +0200 Subject: [PATCH 3/7] Enable getting electricity profiles for status quo --- edisgo/io/timeseries_import.py | 47 +++++++++++++----------------- tests/io/test_timeseries_import.py | 15 ++++++++++ 2 files changed, 35 insertions(+), 27 deletions(-) diff --git a/edisgo/io/timeseries_import.py b/edisgo/io/timeseries_import.py index 99204b1c2..83e4afc65 100644 --- a/edisgo/io/timeseries_import.py +++ b/edisgo/io/timeseries_import.py @@ -1191,7 +1191,7 @@ def get_residential_electricity_profiles_per_building(building_ids, scenario, en List of building IDs to retrieve electricity demand profiles for. scenario : str Scenario for which to retrieve demand data. Possible options - are 'eGon2035' and 'eGon100RE'. + are 'eGon2021', 'eGon2035' and 'eGon100RE'. engine : :sqlalchemy:`sqlalchemy.Engine` Database engine. @@ -1220,30 +1220,21 @@ def _get_scaling_factors_of_zensus_cells(zensus_ids): column factor. """ - with session_scope_egon_data(engine) as session: - if scenario == "eGon2035": - query = session.query( - egon_household_electricity_profile_in_census_cell.cell_id, - egon_household_electricity_profile_in_census_cell.factor_2035.label( - "factor" - ), - ).filter( - egon_household_electricity_profile_in_census_cell.cell_id.in_( - zensus_ids - ) - ) - else: - query = session.query( - egon_household_electricity_profile_in_census_cell.cell_id, - egon_household_electricity_profile_in_census_cell.factor_2050.label( - "factor" - ), - ).filter( - egon_household_electricity_profile_in_census_cell.cell_id.in_( - zensus_ids - ) - ) - return pd.read_sql(query.statement, engine, index_col="cell_id") + if scenario == "eGon2021": + return pd.DataFrame(index=zensus_ids, data={"factor": 1.0}) + else: + with session_scope_egon_data(engine) as session: + if scenario == "eGon2035": + query = session.query( + hh_profile.cell_id, + hh_profile.factor_2035.label("factor"), + ).filter(hh_profile.cell_id.in_(zensus_ids)) + else: + query = session.query( + hh_profile.cell_id, + hh_profile.factor_2050.label("factor"), + ).filter(hh_profile.cell_id.in_(zensus_ids)) + return pd.read_sql(query.statement, engine, index_col="cell_id") def _get_profile_ids_of_buildings(building_ids): """ @@ -1302,7 +1293,9 @@ def _get_profiles(profile_ids): saio.register_schema("demand", engine) from saio.demand import ( - egon_household_electricity_profile_in_census_cell, + egon_household_electricity_profile_in_census_cell as hh_profile, + ) + from saio.demand import ( egon_household_electricity_profile_of_buildings, iee_household_load_profiles, ) @@ -1350,7 +1343,7 @@ def get_industrial_electricity_profiles_per_site(site_ids, scenario, engine): List of industrial site and OSM IDs to retrieve electricity demand profiles for. scenario : str Scenario for which to retrieve demand data. Possible options - are 'eGon2035' and 'eGon100RE'. + are 'eGon2021', 'eGon2035' and 'eGon100RE'. engine : :sqlalchemy:`sqlalchemy.Engine` Database engine. diff --git a/tests/io/test_timeseries_import.py b/tests/io/test_timeseries_import.py index 6c88f54b4..93825e9ac 100644 --- a/tests/io/test_timeseries_import.py +++ b/tests/io/test_timeseries_import.py @@ -268,6 +268,13 @@ def test_get_residential_electricity_profiles_per_building(self): assert df.shape == (8760, 1) assert np.isclose(df.loc[:, 442081].sum(), 3.20688, atol=1e-3) + # test with status quo + df = timeseries_import.get_residential_electricity_profiles_per_building( + [-1, 442081], "eGon2021", pytest.engine + ) + assert df.shape == (8760, 1) + assert np.isclose(df.loc[:, 442081].sum(), 4.288845, atol=1e-3) + @pytest.mark.local def test_get_industrial_electricity_profiles_per_site(self): # test with one site and one OSM area @@ -283,3 +290,11 @@ def test_get_industrial_electricity_profiles_per_site(self): [541658], "eGon2035", pytest.engine ) assert df.shape == (8760, 1) + + # test with status quo + df = timeseries_import.get_industrial_electricity_profiles_per_site( + [1, 541658], "eGon2021", pytest.engine + ) + assert df.shape == (8760, 2) + assert np.isclose(df.loc[:, 1].sum(), 31655.640, atol=1e-3) + assert np.isclose(df.loc[:, 541658].sum(), 2910.816, atol=1e-3) From 767931008d04edd60f1838257fb46cce224c4b7f Mon Sep 17 00:00:00 2001 From: birgits Date: Wed, 24 Apr 2024 13:47:53 +0200 Subject: [PATCH 4/7] Minor fix --- edisgo/io/powermodels_io.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/edisgo/io/powermodels_io.py b/edisgo/io/powermodels_io.py index 16449bd17..b0fb22781 100644 --- a/edisgo/io/powermodels_io.py +++ b/edisgo/io/powermodels_io.py @@ -957,10 +957,16 @@ def _build_load( ) pf, sign = _get_pf(edisgo_obj, pm, idx_bus, "storage") p_d = -min( - [psa_net.storage_units_t.p_set[inflexible_storage_units[stor_i]][0], 0] + [ + psa_net.storage_units_t.p_set[inflexible_storage_units[stor_i]][0], + np.float64(0.0), + ] ) q_d = -max( - [psa_net.storage_units_t.q_set[inflexible_storage_units[stor_i]][0], 0] + [ + psa_net.storage_units_t.q_set[inflexible_storage_units[stor_i]][0], + np.float64(0.0), + ] ) pm["load"][str(stor_i + len(loads_df.index) + 1)] = { "pd": p_d.round(20) / s_base, From 3983c4917844ef6d889574f82675dd473c110d72 Mon Sep 17 00:00:00 2001 From: birgits Date: Wed, 24 Apr 2024 13:50:18 +0200 Subject: [PATCH 5/7] Change workflow --- .github/workflows/tests-coverage.yml | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests-coverage.yml b/.github/workflows/tests-coverage.yml index e0a72b1cd..951972d4d 100644 --- a/.github/workflows/tests-coverage.yml +++ b/.github/workflows/tests-coverage.yml @@ -38,7 +38,7 @@ jobs: python-version: ${{ matrix.python-version }} - name: Set up julia - if: runner.os == 'Linux' && matrix.python-version == 3.8 && matrix.name-suffix == 'coverage' + if: runner.os == 'Linux' uses: julia-actions/setup-julia@v1 with: version: "1.6" @@ -58,8 +58,14 @@ jobs: environment-file: eDisGo_env_dev.yml python-version: ${{ matrix.python-version }} - - name: Run tests - if: ${{ !(runner.os == 'Linux' && matrix.python-version == 3.8 && matrix.name-suffix == 'coverage') }} + - name: Run tests Linux + if: runner.os == 'Linux' && matrix.name-suffix != 'coverage' + run: | + python -m pip install pytest pytest-notebook + python -m pytest --runslow --runonlinux --disable-warnings --color=yes -v + + - name: Run tests Windows + if: runner.os == 'Windows' run: | python -m pip install pytest pytest-notebook python -m pytest --runslow --disable-warnings --color=yes -v From be098336a5451295c4571d554d2f7714a8ca94a7 Mon Sep 17 00:00:00 2001 From: birgits Date: Wed, 24 Apr 2024 13:55:38 +0200 Subject: [PATCH 6/7] Fixes in costs calculation --- edisgo/flex_opt/costs.py | 104 +++++++++++++++++++++++--- tests/flex_opt/test_costs.py | 41 ++++++++-- tests/flex_opt/test_reinforce_grid.py | 2 +- tests/test_edisgo.py | 4 +- 4 files changed, 131 insertions(+), 20 deletions(-) diff --git a/edisgo/flex_opt/costs.py b/edisgo/flex_opt/costs.py index 8bd63d9b7..7cbe359b1 100644 --- a/edisgo/flex_opt/costs.py +++ b/edisgo/flex_opt/costs.py @@ -1,3 +1,4 @@ +import logging import os import pandas as pd @@ -7,6 +8,8 @@ from edisgo.tools.geo import proj2equidistant +logger = logging.getLogger(__name__) + def grid_expansion_costs(edisgo_obj, without_generator_import=False): """ @@ -67,7 +70,8 @@ def _get_transformer_costs(trafos): costs_trafos = pd.DataFrame( { "costs_transformers": len(hvmv_trafos) - * [float(edisgo_obj.config["costs_transformers"]["mv"])] + * [float(edisgo_obj.config["costs_transformers"]["mv"])], + "voltage_level": len(hvmv_trafos) * ["hv/mv"], }, index=hvmv_trafos, ) @@ -77,13 +81,14 @@ def _get_transformer_costs(trafos): pd.DataFrame( { "costs_transformers": len(mvlv_trafos) - * [float(edisgo_obj.config["costs_transformers"]["lv"])] + * [float(edisgo_obj.config["costs_transformers"]["lv"])], + "voltage_level": len(mvlv_trafos) * ["mv/lv"], }, index=mvlv_trafos, ), ] ) - return costs_trafos.loc[trafos.index, "costs_transformers"].values + return costs_trafos.loc[trafos.index, :] def _get_line_costs(lines_added): costs_lines = line_expansion_costs(edisgo_obj, lines_added.index) @@ -107,9 +112,8 @@ def _get_line_costs(lines_added): # costs for transformers if not equipment_changes.empty: transformers = equipment_changes[ - equipment_changes.index.isin( - [f"{_}_station" for _ in edisgo_obj.topology._grids_repr] - ) + equipment_changes.equipment.str.contains("Transformer") + | equipment_changes.equipment.str.contains("transformer") ] added_transformers = transformers[transformers["change"] == "added"] removed_transformers = transformers[transformers["change"] == "removed"] @@ -129,15 +133,16 @@ def _get_line_costs(lines_added): ) trafos = all_trafos.loc[added_transformers["equipment"]] # calculate costs for each transformer + transformer_costs = _get_transformer_costs(trafos) costs = pd.concat( [ costs, pd.DataFrame( { "type": trafos.type_info.values, - "total_costs": _get_transformer_costs(trafos), + "total_costs": transformer_costs.costs_transformers, "quantity": len(trafos) * [1], - "voltage_level": len(trafos) * ["mv/lv"], + "voltage_level": transformer_costs.voltage_level, }, index=trafos.index, ), @@ -161,6 +166,19 @@ def _get_line_costs(lines_added): .sum() .loc[lines_added_unique, ["quantity"]] ) + # use the minimum of quantity and num_parallel, as sometimes lines are added + # and in a next reinforcement step removed again, e.g. when feeder is split + # at 2/3 and a new single standard line is added + lines_added = pd.merge( + lines_added, + edisgo_obj.topology.lines_df.loc[:, ["num_parallel"]], + how="left", + left_index=True, + right_index=True, + ) + lines_added["quantity_added"] = lines_added.loc[ + :, ["quantity", "num_parallel"] + ].min(axis=1) lines_added["length"] = edisgo_obj.topology.lines_df.loc[ lines_added.index, "length" ] @@ -176,9 +194,9 @@ def _get_line_costs(lines_added): ].values, "total_costs": line_costs.costs.values, "length": ( - lines_added.quantity * lines_added.length + lines_added.quantity_added * lines_added.length ).values, - "quantity": lines_added.quantity.values, + "quantity": lines_added.quantity_added.values, "voltage_level": line_costs.voltage_level.values, }, index=lines_added.index, @@ -288,3 +306,69 @@ def line_expansion_costs(edisgo_obj, lines_names=None): ] ) return costs_lines.loc[lines_df.index] + + +def transformer_expansion_costs(edisgo_obj, transformer_names=None): + """ + Returns costs per transformer in kEUR as well as voltage level they are in. + + Parameters + ----------- + edisgo_obj : :class:`~.EDisGo` + eDisGo object + transformer_names: None or list(str) + List of names of transformers to return cost information for. If None, it is + returned for all transformers in + :attr:`~.network.topology.Topology.transformers_df` and + :attr:`~.network.topology.Topology.transformers_hvmv_df`. + + Returns + ------- + costs: :pandas:`pandas.DataFrame` + Dataframe with names of transformers in index and columns 'costs' with + costs per transformer in kEUR and 'voltage_level' with information on voltage + level the transformer is in. + + """ + transformers_df = pd.concat( + [ + edisgo_obj.topology.transformers_df.copy(), + edisgo_obj.topology.transformers_hvmv_df.copy(), + ] + ) + if transformer_names is not None: + transformers_df = transformers_df.loc[transformer_names, ["type_info"]] + + if len(transformers_df) == 0: + return pd.DataFrame(columns=["costs", "voltage_level"]) + + hvmv_transformers = transformers_df[ + transformers_df.index.isin(edisgo_obj.topology.transformers_hvmv_df.index) + ].index + mvlv_transformers = transformers_df[ + transformers_df.index.isin(edisgo_obj.topology.transformers_df.index) + ].index + + costs_hvmv = float(edisgo_obj.config["costs_transformers"]["mv"]) + costs_mvlv = float(edisgo_obj.config["costs_transformers"]["lv"]) + + costs_df = pd.DataFrame( + { + "costs": costs_hvmv, + "voltage_level": "hv/mv", + }, + index=hvmv_transformers, + ) + costs_df = pd.concat( + [ + costs_df, + pd.DataFrame( + { + "costs": costs_mvlv, + "voltage_level": "mv/lv", + }, + index=mvlv_transformers, + ), + ] + ) + return costs_df diff --git a/tests/flex_opt/test_costs.py b/tests/flex_opt/test_costs.py index 813714aa8..308f9e7e6 100644 --- a/tests/flex_opt/test_costs.py +++ b/tests/flex_opt/test_costs.py @@ -3,7 +3,7 @@ import pytest from edisgo import EDisGo -from edisgo.flex_opt.costs import grid_expansion_costs, line_expansion_costs +from edisgo.flex_opt import costs as costs_mod class TestCosts: @@ -76,12 +76,12 @@ def test_costs(self): ], ) - costs = grid_expansion_costs(self.edisgo) + costs = costs_mod.grid_expansion_costs(self.edisgo) assert len(costs) == 4 assert ( costs.loc["MVStation_1_transformer_reinforced_2", "voltage_level"] - == "mv/lv" + == "hv/mv" ) assert costs.loc["MVStation_1_transformer_reinforced_2", "quantity"] == 1 assert costs.loc["MVStation_1_transformer_reinforced_2", "total_costs"] == 1000 @@ -97,13 +97,13 @@ def test_costs(self): assert costs.loc["Line_10019", "type"] == "48-AL1/8-ST1A" assert costs.loc["Line_10019", "voltage_level"] == "mv" assert np.isclose(costs.loc["Line_50000002", "total_costs"], 2.34) - assert np.isclose(costs.loc["Line_50000002", "length"], 0.09) - assert costs.loc["Line_50000002", "quantity"] == 3 + assert np.isclose(costs.loc["Line_50000002", "length"], 0.03) + assert costs.loc["Line_50000002", "quantity"] == 1 assert costs.loc["Line_50000002", "type"] == "NAYY 4x1x35" assert costs.loc["Line_50000002", "voltage_level"] == "lv" def test_line_expansion_costs(self): - costs = line_expansion_costs(self.edisgo) + costs = costs_mod.line_expansion_costs(self.edisgo) assert len(costs) == len(self.edisgo.topology.lines_df) assert (costs.index == self.edisgo.topology.lines_df.index).all() assert len(costs[costs.voltage_level == "mv"]) == len( @@ -116,7 +116,9 @@ def test_line_expansion_costs(self): assert np.isclose(costs.at["Line_10000015", "costs_cable"], 0.27) assert costs.at["Line_10000015", "voltage_level"] == "lv" - costs = line_expansion_costs(self.edisgo, ["Line_10003", "Line_10000015"]) + costs = costs_mod.line_expansion_costs( + self.edisgo, ["Line_10003", "Line_10000015"] + ) assert len(costs) == 2 assert (costs.index.values == ["Line_10003", "Line_10000015"]).all() assert np.isclose(costs.at["Line_10003", "costs_earthworks"], 0.083904 * 60) @@ -125,3 +127,28 @@ def test_line_expansion_costs(self): assert np.isclose(costs.at["Line_10000015", "costs_earthworks"], 1.53) assert np.isclose(costs.at["Line_10000015", "costs_cable"], 0.27) assert costs.at["Line_10000015", "voltage_level"] == "lv" + + def test_transformer_expansion_costs(self): + costs = costs_mod.transformer_expansion_costs(self.edisgo) + transformers_df = pd.concat( + [ + self.edisgo.topology.transformers_df, + self.edisgo.topology.transformers_hvmv_df, + ] + ) + assert len(costs) == len(transformers_df) + assert sorted(costs.index) == sorted(transformers_df.index) + assert len(costs[costs.voltage_level == "hv/mv"]) == len( + self.edisgo.topology.transformers_hvmv_df + ) + assert np.isclose(costs.at["MVStation_1_transformer_1", "costs"], 1000) + assert costs.at["MVStation_1_transformer_1", "voltage_level"] == "hv/mv" + assert np.isclose(costs.at["LVStation_4_transformer_2", "costs"], 10) + assert costs.at["LVStation_4_transformer_2", "voltage_level"] == "mv/lv" + + costs = costs_mod.transformer_expansion_costs( + self.edisgo, ["LVStation_5_transformer_1"] + ) + assert len(costs) == 1 + assert np.isclose(costs.at["LVStation_5_transformer_1", "costs"], 10) + assert costs.at["LVStation_5_transformer_1", "voltage_level"] == "mv/lv" diff --git a/tests/flex_opt/test_reinforce_grid.py b/tests/flex_opt/test_reinforce_grid.py index cb6074310..e073b2326 100644 --- a/tests/flex_opt/test_reinforce_grid.py +++ b/tests/flex_opt/test_reinforce_grid.py @@ -81,7 +81,7 @@ def test_run_separate_lv_grids(self): assert len(g.buses_df) > 1 assert len(lv_grids_new) == 26 - assert np.isclose(edisgo.results.grid_expansion_costs.total_costs.sum(), 280.06) + assert np.isclose(edisgo.results.grid_expansion_costs.total_costs.sum(), 440.06) # check if all generators are still present assert np.isclose( diff --git a/tests/test_edisgo.py b/tests/test_edisgo.py index 1f09e62d9..e0379bd59 100755 --- a/tests/test_edisgo.py +++ b/tests/test_edisgo.py @@ -521,7 +521,7 @@ def test_reinforce_catch_convergence(self): ) results = self.edisgo.reinforce(catch_convergence_problems=True) assert results.unresolved_issues.empty - assert len(results.grid_expansion_costs) == 132 + assert len(results.grid_expansion_costs) == 134 assert len(results.equipment_changes) == 218 assert results.v_res.shape == (4, 142) @@ -543,7 +543,7 @@ def test_enhanced_reinforce_grid(self): results = edisgo_obj.results - assert len(results.grid_expansion_costs) == 445 + assert len(results.grid_expansion_costs) == 454 assert len(results.equipment_changes) == 892 assert results.v_res.shape == (4, 148) From fd75b510ef9491844c6702fcf5c51d516678ae85 Mon Sep 17 00:00:00 2001 From: birgits Date: Wed, 24 Apr 2024 15:03:07 +0200 Subject: [PATCH 7/7] Fix download of simbev and tracbev files --- examples/electromobility_example.ipynb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/electromobility_example.ipynb b/examples/electromobility_example.ipynb index 5bc23ea1d..bfc97335f 100644 --- a/examples/electromobility_example.ipynb +++ b/examples/electromobility_example.ipynb @@ -430,8 +430,7 @@ " url = (f\"https://github.com/openego/eDisGo/tree/dev/\" +\n", " f\"tests/data/simbev_example_scenario/{ags}/\")\n", " page = requests.get(url).text\n", - " items = json.loads(page)[\"payload\"][\"tree\"][\"items\"]\n", - " filenames = [f[\"name\"] for f in items if \"csv\" in f[\"name\"]]\n", + " filenames = [_ for _ in page.split('\"') if \".csv\" in _ and \"/\" not in _]\n", "\n", " for file in filenames:\n", " req = requests.get(f\"{raw_url}/{ags}/{file}\")\n", @@ -470,8 +469,7 @@ " url = (\"https://github.com/openego/eDisGo/tree/dev/\" +\n", " \"tests/data/tracbev_example_scenario/\")\n", " page = requests.get(url).text\n", - " items = json.loads(page)[\"payload\"][\"tree\"][\"items\"]\n", - " filenames = [f[\"name\"] for f in items if \"gpkg\" in f[\"name\"]]\n", + " filenames = [_ for _ in page.split('\"') if \".gpkg\" in _ and \"/\" not in _]\n", "\n", " for file in filenames:\n", " req = requests.get(\n",