From 93a507285e497b38af112ca3c8babb37fc544aac Mon Sep 17 00:00:00 2001 From: paulhoefer Date: Wed, 6 May 2026 14:21:15 +0200 Subject: [PATCH] Fix EV efficiency handling --- examples/loma-14a.py | 95 +++++++++++--------------------------------- 1 file changed, 24 insertions(+), 71 deletions(-) diff --git a/examples/loma-14a.py b/examples/loma-14a.py index e373f6d6..7d9221ed 100644 --- a/examples/loma-14a.py +++ b/examples/loma-14a.py @@ -61,21 +61,6 @@ def run_optimization_14a(edisgo): def integrate_ev_and_hp_for_14a(edisgo, *, shapefile_path, output_dir): """Import EV charging points, apply charging strategy, and adjust CP/HP counts.""" - # Temporary Check: Amount of CPs before importing eDisGo CPs - names = edisgo.topology.loads_df.query("type == 'charging_point'").index.astype(str) - print( - { - "existing": names.str.contains("Existing", case=False).sum(), - "additional": names.str.contains("Additional", case=False).sum(), - "rest": ( - ~( - names.str.contains("Existing", case=False) - | names.str.contains("Additional", case=False) - ) - ).sum(), - "total": len(names), - } - ) """ After this function there are no time series yet. Only charging points and @@ -91,21 +76,6 @@ def integrate_ev_and_hp_for_14a(edisgo, *, shapefile_path, output_dir): import_electromobility_data_kwds={"shapefile_path": shapefile_path}, ) - # Temporary Check: Amount of CPs after importing eDisGo CPs - names = edisgo.topology.loads_df.query("type == 'charging_point'").index.astype(str) - print( - { - "existing": names.str.contains("Existing", case=False).sum(), - "additional": names.str.contains("Additional", case=False).sum(), - "rest": ( - ~( - names.str.contains("Existing", case=False) - | names.str.contains("Additional", case=False) - ) - ).sum(), - "total": len(names), - } - ) """ This step created the time series for the new eDisGo charging points. @@ -125,6 +95,21 @@ def integrate_ev_and_hp_for_14a(edisgo, *, shapefile_path, output_dir): edisgo.apply_charging_strategy(strategy="dumb") + # Apply EV charging efficiency correction + ev_charging_efficiency = 0.9 + + lap = edisgo.timeseries.loads_active_power.copy() + + cp_names_before_transfer = edisgo.topology.loads_df.query( + "type == 'charging_point'" + ).index.intersection(lap.columns) + + lap.loc[:, cp_names_before_transfer] = ( + lap.loc[:, cp_names_before_transfer] * ev_charging_efficiency + ) + edisgo.timeseries.loads_active_power = lap + + """ This step then finally transfers the time series from suitable eDisGo charging_points to Existing_ und Additional_ charging points which are @@ -143,22 +128,6 @@ def integrate_ev_and_hp_for_14a(edisgo, *, shapefile_path, output_dir): tol_2=0.9, ) - # Temporary Check: Amount of CPs after transferring time series - names = edisgo.topology.loads_df.query("type == 'charging_point'").index.astype(str) - print( - { - "existing": names.str.contains("Existing", case=False).sum(), - "additional": names.str.contains("Additional", case=False).sum(), - "rest": ( - ~( - names.str.contains("Existing", case=False) - | names.str.contains("Additional", case=False) - ) - ).sum(), - "total": len(names), - } - ) - # ============================================================ # Optional Utilities for sensitivity analysis/changing the amount of cp/hp # - target by absolute value or relative percentage @@ -179,7 +148,7 @@ def integrate_ev_and_hp_for_14a(edisgo, *, shapefile_path, output_dir): set_charging_points_to_target( edisgo, - target_total=100, # sets total amount of CP to 1000 + target_total=1500, # sets total amount of CP to 1000 # percentage=0.10, # increases total amount of CP by 10% # percentage=-0.10, # decreases total amount of CP by 10% eligible_buses=cp_eligible_buses, @@ -191,7 +160,7 @@ def integrate_ev_and_hp_for_14a(edisgo, *, shapefile_path, output_dir): set_heat_pumps_to_target( edisgo, - target_total=100, # sets total amount of HP to 50 + target_total=1500, # sets total amount of HP to 50 # percentage=0.10, # increases total amount of HP by 10% # percentage=-0.10, # decreases total amount of HP by 10% eligible_buses=hp_eligible_buses, @@ -200,22 +169,6 @@ def integrate_ev_and_hp_for_14a(edisgo, *, shapefile_path, output_dir): export_dir=output_dir, # only applies when there are deleted HP ) - # Temporary Check: Amount of CPs after total amount changed - names = edisgo.topology.loads_df.query("type == 'charging_point'").index.astype(str) - print( - { - "existing": names.str.contains("Existing", case=False).sum(), - "additional": names.str.contains("Additional", case=False).sum(), - "rest": ( - ~( - names.str.contains("Existing", case=False) - | names.str.contains("Additional", case=False) - ) - ).sum(), - "total": len(names), - } - ) - def prepare_edisgo_for_14a(edisgo, *, shapefile_path, output_dir): """Apply topology fixes, EV integration, and pre-optimization setup.""" @@ -256,14 +209,14 @@ def main(): # grid_path = "/home/carlos/LoMa/exec_folder/results/MGB_quo_model_pypsa" # Whole husum paths - # grid_path = "/home/carlos/LoMa/exec_folder/results/Husum_SLP_CP_pypsa" - # path_husum_district_shp = ( - # "/home/carlos/LoMa/exec_folder/data/Input_files/MV_grid_district/husum_district.shp" - # ) + grid_path = "/home/paul/LoMa/loma-repo/results/Whole_Husum_model_pypsa" + path_husum_district_shp = ( + "/home/paul/LoMa/loma-repo/data/Input_files/MV_grid_district/husum_district.shp" + ) # MGB paths - grid_path = "/home/carlos/LoMa/exec_folder/results/MGB_SLP_CP_pypsa" - path_husum_district_shp = "/home/carlos/LoMa/exec_folder/MGB_district" + # grid_path = "/home/paul/LoMa/MGB_2035_model_pypsa" + # path_husum_district_shp = "/home/paul/LoMa/loma-repo/data/Input_files/MGB_district" edisgo = EDisGo(pypsa_csv_dir=grid_path, snapshot_range=(0, 23)) @@ -275,7 +228,7 @@ def main(): pypsa_n = edisgo.to_pypsa() edisgo.analyze() - output_dir = "/home/carlos/LoMa/output_edisgo" + output_dir = "/home/paul/LoMa/test/edisgo_output" prepare_edisgo_for_14a( edisgo,