From 9530d63e551f1cc19dd6847f10902fec3d59da0f Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Thu, 4 Jan 2024 18:57:09 +0100 Subject: [PATCH] cluster_heat_buses: performance boost and tidy code --- scripts/prepare_sector_network.py | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 62bfa80a..26aa50c9 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -3332,24 +3332,24 @@ def limit_individual_line_extension(n, maxext): aggregate_dict = { - "p_nom": "sum", - "s_nom": "sum", + "p_nom": pd.Series.sum, + "s_nom": pd.Series.sum, "v_nom": "max", "v_mag_pu_max": "min", "v_mag_pu_min": "max", - "p_nom_max": "sum", - "s_nom_max": "sum", - "p_nom_min": "sum", - "s_nom_min": "sum", + "p_nom_max": pd.Series.sum, + "s_nom_max": pd.Series.sum, + "p_nom_min": pd.Series.sum, + "s_nom_min": pd.Series.sum, "v_ang_min": "max", "v_ang_max": "min", "terrain_factor": "mean", "num_parallel": "sum", "p_set": "sum", "e_initial": "sum", - "e_nom": "sum", - "e_nom_max": "sum", - "e_nom_min": "sum", + "e_nom": pd.Series.sum, + "e_nom_max": pd.Series.sum, + "e_nom_min": pd.Series.sum, "state_of_charge_initial": "sum", "state_of_charge_set": "sum", "inflow": "sum", @@ -3411,13 +3411,10 @@ def cluster_heat_buses(n): pnl = c.pnl agg = define_clustering(pd.Index(pnl.keys()), aggregate_dict) for k in pnl.keys(): - pnl[k].rename( - columns=lambda x: x.replace("residential ", "").replace( - "services ", "" - ), - inplace=True, - ) - pnl[k] = pnl[k].groupby(level=0, axis=1).agg(agg[k], **agg_group_kwargs) + def renamer(s): + return s.replace("residential ", "").replace("services ", "") + + pnl[k] = pnl[k].groupby(renamer, axis=1).agg(agg[k], **agg_group_kwargs) # remove unclustered assets of service/residential to_drop = c.df.index.difference(df.index)