diff --git a/etrago/cluster/disaggregation.py b/etrago/cluster/disaggregation.py index 08b2a5e3..b878c18b 100644 --- a/etrago/cluster/disaggregation.py +++ b/etrago/cluster/disaggregation.py @@ -14,9 +14,7 @@ class Disaggregation: - def __init__( - self, original_network, clustered_network, busmap, skip=() - ): + def __init__(self, original_network, clustered_network, busmap, skip=()): """ :param original_network: Initial (unclustered) network structure :param clustered_network: Clustered network used for the optimization @@ -280,6 +278,7 @@ def solve(self, scenario, solver): } profile = cProfile.Profile() profile = noops + for i, cluster in enumerate(sorted(clusters)): log.info(f"Decompose {cluster=} ({i + 1}/{n})") profile.enable() @@ -287,6 +286,7 @@ def solve(self, scenario, solver): partial_network, externals = self.construct_partial_network( cluster, scenario ) + profile.disable() self.stats["clusters"].loc[cluster, "decompose"] = time.time() - t log.info( @@ -324,9 +324,9 @@ def solve(self, scenario, solver): ): log.info(f"Attribute sums, {bt}, clustered - disaggregated:") cnb = getattr(self.clustered_network, bt) - cnb = cnb[cnb.carrier!="DC"] + cnb = cnb[cnb.carrier != "DC"] onb = getattr(self.original_network, bt) - onb = onb[onb.carrier!="DC"] + onb = onb[onb.carrier != "DC"] log.info( "{:>{}}: {}".format( "p_nom_opt", @@ -624,6 +624,7 @@ def solve_partial_network( f" & (bus1 in {index})" ) pnb = pnb.query(query) + assert not pnb.empty or ( # In some cases, a district heating grid is connected to a # substation only via a resistive_heater but not e.g. by a @@ -684,6 +685,7 @@ def solve_partial_network( " it has on the buses of it's partial network." ) + print(clb.iloc[0].carrier) if clb.iloc[0].at[extendable_flag]: # That means, `p_nom` got computed via optimization and we # have to distribute it into the subnetwork first. @@ -753,6 +755,10 @@ def solve_partial_network( ) delta = abs((new_columns.sum(axis=1) - clt).sum()) epsilon = 1e-5 + if delta > epsilon: + import pdb + + pdb.set_trace() assert delta < epsilon, ( "Sum of disaggregated time series does not match" f" aggregated timeseries: {delta=} > {epsilon=}." diff --git a/etrago/cluster/electrical.py b/etrago/cluster/electrical.py index 1778e78b..6ddc8dec 100755 --- a/etrago/cluster/electrical.py +++ b/etrago/cluster/electrical.py @@ -1053,7 +1053,6 @@ def run_spatial_clustering(self): None """ if self.args["network_clustering"]["active"]: - if self.args["disaggregation"] is not None: self.disaggregated_network = self.network.copy() else: @@ -1091,12 +1090,12 @@ def run_spatial_clustering(self): busmap = pd.Series(dtype=str) medoid_idx = pd.Series(dtype=str) - self.clustering, busmap = postprocessing( + clustering, busmap = postprocessing( self, busmap, busmap_foreign, medoid_idx ) self.update_busmap(busmap) - self.network = self.clustering.network + self.network = clustering.network self.buses_by_country()