diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 8719c281..b8eb8bc1 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -3294,7 +3294,6 @@ def lossy_bidirectional_links(n, carrier, losses_per_thousand_km=0.0): carrier_i = n.links.query("carrier == @carrier").index n.links.loc[carrier_i, "p_min_pu"] = 0 - n.links["reversed"] = False n.links.loc[carrier_i, "efficiency"] = ( 1 - n.links.loc[carrier_i, "length"] * losses_per_thousand_km / 1e3 ) @@ -3302,10 +3301,11 @@ def lossy_bidirectional_links(n, carrier, losses_per_thousand_km=0.0): n.links.loc[carrier_i].copy().rename({"bus0": "bus1", "bus1": "bus0"}, axis=1) ) rev_links.capital_cost = 0 - rev_links.reversed = True + rev_links["reversed"] = True rev_links.index = rev_links.index.map(lambda x: x + "-reversed") n.links = pd.concat([n.links, rev_links], sort=False) + n.links["reversed"] = n.links["reversed"].fillna(False) if __name__ == "__main__": diff --git a/scripts/solve_network.py b/scripts/solve_network.py index a68ca074..5e8c0356 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -500,14 +500,10 @@ def add_lossy_bidirectional_link_constraints(n): carriers = n.links.loc[n.links.reversed, "carrier"].unique() - backward_i = n.links.query( - "carrier in @carriers and reversed and p_nom_extendable" - ).index forward_i = n.links.query( "carrier in @carriers and ~reversed and p_nom_extendable" ).index - - assert len(forward_i) == len(backward_i) + backward_i = forward_i + "-reversed" lhs = n.model["Link-p_nom"].loc[backward_i] rhs = n.model["Link-p_nom"].loc[forward_i]