diff --git a/scripts/add_brownfield.py b/scripts/add_brownfield.py index 2e0dad17..679060b3 100644 --- a/scripts/add_brownfield.py +++ b/scripts/add_brownfield.py @@ -41,10 +41,7 @@ def add_brownfield(n, n_p, year): # remove assets if their optimized nominal capacity is lower than a threshold # since CHP heat Link is proportional to CHP electric Link, make sure threshold is compatible chp_heat = c.df.index[ - ( - c.df[f"{attr}_nom_extendable"] - & c.df.index.str.contains("urban central") - ) + (c.df[f"{attr}_nom_extendable"] & c.df.index.str.contains("urban central")) & c.df.index.str.contains("CHP") & c.df.index.str.contains("heat") ] @@ -60,9 +57,7 @@ def add_brownfield(n, n_p, year): ) n_p.mremove( c.name, - chp_heat[ - c.df.loc[chp_heat, f"{attr}_nom_opt"] < threshold_chp_heat - ], + chp_heat[c.df.loc[chp_heat, f"{attr}_nom_opt"] < threshold_chp_heat], ) n_p.mremove( diff --git a/scripts/add_existing_baseyear.py b/scripts/add_existing_baseyear.py index 60a3b203..7cdca5af 100644 --- a/scripts/add_existing_baseyear.py +++ b/scripts/add_existing_baseyear.py @@ -545,9 +545,7 @@ def add_heating_capacities_installed_before_baseyear( bus0=nodes[name], bus1=nodes[name] + " " + name + " heat", carrier=name + " resistive heater", - efficiency=costs.at[ - f"{name_type} resistive heater", "efficiency" - ], + efficiency=costs.at[f"{name_type} resistive heater", "efficiency"], capital_cost=( costs.at[f"{name_type} resistive heater", "efficiency"] * costs.at[f"{name_type} resistive heater", "fixed"] diff --git a/scripts/build_retro_cost.py b/scripts/build_retro_cost.py index 7a3e3e6e..5373f873 100644 --- a/scripts/build_retro_cost.py +++ b/scripts/build_retro_cost.py @@ -609,10 +609,7 @@ def calculate_costs(u_values, l, cost_retro, window_assumptions): / x.A_C_Ref if x.name[3] != "Window" else ( - ( - window_cost(x[f"new_U_{l}"], cost_retro, window_assumptions) - * x.A_element - ) + (window_cost(x[f"new_U_{l}"], cost_retro, window_assumptions) * x.A_element) / x.A_C_Ref ) if x.value > window_limit(float(l), window_assumptions) diff --git a/scripts/build_salt_cavern_potentials.py b/scripts/build_salt_cavern_potentials.py index d425dbac..ed039772 100644 --- a/scripts/build_salt_cavern_potentials.py +++ b/scripts/build_salt_cavern_potentials.py @@ -66,11 +66,7 @@ def salt_cavern_potential_by_region(caverns, regions): "capacity_per_area * share * area_caverns / 1000" ) # TWh - return ( - overlay.groupby(["name", "storage_type"]) - .e_nom.sum() - .unstack("storage_type") - ) + return overlay.groupby(["name", "storage_type"]).e_nom.sum().unstack("storage_type") if __name__ == "__main__": diff --git a/scripts/build_shapes.py b/scripts/build_shapes.py index 236c086a..fa707ad5 100644 --- a/scripts/build_shapes.py +++ b/scripts/build_shapes.py @@ -119,9 +119,7 @@ def countries(naturalearth, country_list): fieldnames = ( df[x].where(lambda s: s != "-99") for x in ("ISO_A2", "WB_A2", "ADM0_A3") ) - df["name"] = reduce( - lambda x, y: x.fillna(y), fieldnames, next(fieldnames) - ).str[:2] + df["name"] = reduce(lambda x, y: x.fillna(y), fieldnames, next(fieldnames)).str[:2] df = df.loc[ df.name.isin(country_list) & ((df["scalerank"] == 0) | (df["scalerank"] == 5)) diff --git a/scripts/cluster_network.py b/scripts/cluster_network.py index 1d637510..9dbe887a 100644 --- a/scripts/cluster_network.py +++ b/scripts/cluster_network.py @@ -322,7 +322,9 @@ def busmap_for_n_clusters( neighbor_bus = n.lines.query( "bus0 == @disconnected_bus or bus1 == @disconnected_bus" ).iloc[0][["bus0", "bus1"]] - new_country = list(set(n.buses.loc[neighbor_bus].country) - {country})[0] + new_country = list(set(n.buses.loc[neighbor_bus].country) - {country})[ + 0 + ] logger.info( f"overwriting country `{country}` of bus `{disconnected_bus}` " diff --git a/scripts/make_summary.py b/scripts/make_summary.py index 367eccf5..3ec01b66 100644 --- a/scripts/make_summary.py +++ b/scripts/make_summary.py @@ -517,7 +517,9 @@ def calculate_weighted_prices(n, label, weighted_prices): if not names.empty: load += ( - n.links_t.p0[names].groupby(n.links.loc[names, "bus0"], axis=1).sum() + n.links_t.p0[names] + .groupby(n.links.loc[names, "bus0"], axis=1) + .sum() ) # Add H2 Store when charging diff --git a/scripts/plot_network.py b/scripts/plot_network.py index 4ed8d1ef..c2ba72c7 100644 --- a/scripts/plot_network.py +++ b/scripts/plot_network.py @@ -260,9 +260,7 @@ def group_pipes(df, drop_direction=False): lambda x: f"H2 pipeline {x.bus0.replace(' H2', '')} -> {x.bus1.replace(' H2', '')}", axis=1, ) - return df.groupby(level=0).agg( - {"p_nom_opt": sum, "bus0": "first", "bus1": "first"} - ) + return df.groupby(level=0).agg({"p_nom_opt": sum, "bus0": "first", "bus1": "first"}) def plot_h2_map(network, regions): diff --git a/scripts/plot_summary.py b/scripts/plot_summary.py index 10874fce..a40563f6 100644 --- a/scripts/plot_summary.py +++ b/scripts/plot_summary.py @@ -583,8 +583,5 @@ if __name__ == "__main__": for sector_opts in snakemake.params.sector_opts: opts = sector_opts.split("-") - if ( - any("cb" in o for o in opts) - or snakemake.config["foresight"] == "perfect" - ): + if any("cb" in o for o in opts) or snakemake.config["foresight"] == "perfect": plot_carbon_budget_distribution(snakemake.input.eurostat) diff --git a/scripts/plot_validation_cross_border_flows.py b/scripts/plot_validation_cross_border_flows.py index fd52a1b1..65f4f8c7 100644 --- a/scripts/plot_validation_cross_border_flows.py +++ b/scripts/plot_validation_cross_border_flows.py @@ -86,8 +86,7 @@ def cross_border_time_series(countries, data): ) title = "Historic" if (axis % 2) == 0 else "Optimized" ax[axis].set_title( - f"{title} Import / Export for " - + cc.convert(country, to="name_short") + f"{title} Import / Export for " + cc.convert(country, to="name_short") ) # Custom legend elements diff --git a/scripts/prepare_perfect_foresight.py b/scripts/prepare_perfect_foresight.py index 906920c8..73b4d0e1 100644 --- a/scripts/prepare_perfect_foresight.py +++ b/scripts/prepare_perfect_foresight.py @@ -56,9 +56,7 @@ def get_investment_weighting(time_weighting, r=0.01): end = time_weighting.cumsum() start = time_weighting.cumsum().shift().fillna(0) return pd.concat([start, end], axis=1).apply( - lambda x: sum( - get_social_discount(t, r) for t in range(int(x[0]), int(x[1])) - ), + lambda x: sum(get_social_discount(t, r) for t in range(int(x[0]), int(x[1]))), axis=1, ) diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index d23936b7..aa54898c 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -410,7 +410,9 @@ def update_wind_solar_costs(n, costs): # e.g. clusters == 37m means that VRE generators are left # at clustering of simplified network, but that they are # connected to 37-node network - genmap = busmap_s if snakemake.wildcards.clusters[-1:] == "m" else clustermaps + genmap = ( + busmap_s if snakemake.wildcards.clusters[-1:] == "m" else clustermaps + ) connection_cost = (connection_cost * weight).groupby( genmap ).sum() / weight.groupby(genmap).sum() @@ -498,9 +500,7 @@ def remove_non_electric_buses(n): """ Remove buses from pypsa-eur with carriers which are not AC buses. """ - if to_drop := list( - n.buses.query("carrier not in ['AC', 'DC']").carrier.unique() - ): + if to_drop := list(n.buses.query("carrier not in ['AC', 'DC']").carrier.unique()): logger.info(f"Drop buses from PyPSA-Eur with carrier: {to_drop}") n.buses = n.buses[n.buses.carrier.isin(["AC", "DC"])] diff --git a/scripts/solve_network.py b/scripts/solve_network.py index 48691688..ed566eaf 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -153,10 +153,7 @@ def _add_land_use_constraint_m(n, planning_horizons, config): for carrier in ["solar", "onwind", "offwind-ac", "offwind-dc"]: existing = n.generators.loc[n.generators.carrier == carrier, "p_nom"] ind = list( - { - i.split(sep=" ")[0] + " " + i.split(sep=" ")[1] - for i in existing.index - } + {i.split(sep=" ")[0] + " " + i.split(sep=" ")[1] for i in existing.index} ) previous_years = [ diff --git a/scripts/solve_operations_network.py b/scripts/solve_operations_network.py index 53d5cc1d..dca49d02 100644 --- a/scripts/solve_operations_network.py +++ b/scripts/solve_operations_network.py @@ -36,11 +36,7 @@ if __name__ == "__main__": configure_logging(snakemake) update_config_with_sector_opts(snakemake.config, snakemake.wildcards.sector_opts) - opts = ( - f"{snakemake.wildcards.opts}-{snakemake.wildcards.sector_opts}".split( - "-" - ) - ) + opts = f"{snakemake.wildcards.opts}-{snakemake.wildcards.sector_opts}".split("-") opts = [o for o in opts if o != ""] solve_opts = snakemake.params.options