[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci
This commit is contained in:
pre-commit-ci[bot] 2023-10-08 09:20:57 +00:00
parent 3c36c60bdd
commit f054180a62
14 changed files with 22 additions and 49 deletions

View File

@ -41,10 +41,7 @@ def add_brownfield(n, n_p, year):
# remove assets if their optimized nominal capacity is lower than a threshold # 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 # since CHP heat Link is proportional to CHP electric Link, make sure threshold is compatible
chp_heat = c.df.index[ 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("CHP")
& c.df.index.str.contains("heat") & c.df.index.str.contains("heat")
] ]
@ -60,9 +57,7 @@ def add_brownfield(n, n_p, year):
) )
n_p.mremove( n_p.mremove(
c.name, c.name,
chp_heat[ chp_heat[c.df.loc[chp_heat, f"{attr}_nom_opt"] < threshold_chp_heat],
c.df.loc[chp_heat, f"{attr}_nom_opt"] < threshold_chp_heat
],
) )
n_p.mremove( n_p.mremove(

View File

@ -545,9 +545,7 @@ def add_heating_capacities_installed_before_baseyear(
bus0=nodes[name], bus0=nodes[name],
bus1=nodes[name] + " " + name + " heat", bus1=nodes[name] + " " + name + " heat",
carrier=name + " resistive heater", carrier=name + " resistive heater",
efficiency=costs.at[ efficiency=costs.at[f"{name_type} resistive heater", "efficiency"],
f"{name_type} resistive heater", "efficiency"
],
capital_cost=( capital_cost=(
costs.at[f"{name_type} resistive heater", "efficiency"] costs.at[f"{name_type} resistive heater", "efficiency"]
* costs.at[f"{name_type} resistive heater", "fixed"] * costs.at[f"{name_type} resistive heater", "fixed"]

View File

@ -609,10 +609,7 @@ def calculate_costs(u_values, l, cost_retro, window_assumptions):
/ x.A_C_Ref / x.A_C_Ref
if x.name[3] != "Window" if x.name[3] != "Window"
else ( 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 / x.A_C_Ref
) )
if x.value > window_limit(float(l), window_assumptions) if x.value > window_limit(float(l), window_assumptions)

View File

@ -66,11 +66,7 @@ def salt_cavern_potential_by_region(caverns, regions):
"capacity_per_area * share * area_caverns / 1000" "capacity_per_area * share * area_caverns / 1000"
) # TWh ) # TWh
return ( return overlay.groupby(["name", "storage_type"]).e_nom.sum().unstack("storage_type")
overlay.groupby(["name", "storage_type"])
.e_nom.sum()
.unstack("storage_type")
)
if __name__ == "__main__": if __name__ == "__main__":

View File

@ -119,9 +119,7 @@ def countries(naturalearth, country_list):
fieldnames = ( fieldnames = (
df[x].where(lambda s: s != "-99") for x in ("ISO_A2", "WB_A2", "ADM0_A3") df[x].where(lambda s: s != "-99") for x in ("ISO_A2", "WB_A2", "ADM0_A3")
) )
df["name"] = reduce( df["name"] = reduce(lambda x, y: x.fillna(y), fieldnames, next(fieldnames)).str[:2]
lambda x, y: x.fillna(y), fieldnames, next(fieldnames)
).str[:2]
df = df.loc[ df = df.loc[
df.name.isin(country_list) & ((df["scalerank"] == 0) | (df["scalerank"] == 5)) df.name.isin(country_list) & ((df["scalerank"] == 0) | (df["scalerank"] == 5))

View File

@ -322,7 +322,9 @@ def busmap_for_n_clusters(
neighbor_bus = n.lines.query( neighbor_bus = n.lines.query(
"bus0 == @disconnected_bus or bus1 == @disconnected_bus" "bus0 == @disconnected_bus or bus1 == @disconnected_bus"
).iloc[0][["bus0", "bus1"]] ).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( logger.info(
f"overwriting country `{country}` of bus `{disconnected_bus}` " f"overwriting country `{country}` of bus `{disconnected_bus}` "

View File

@ -517,7 +517,9 @@ def calculate_weighted_prices(n, label, weighted_prices):
if not names.empty: if not names.empty:
load += ( 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 # Add H2 Store when charging

View File

@ -260,9 +260,7 @@ def group_pipes(df, drop_direction=False):
lambda x: f"H2 pipeline {x.bus0.replace(' H2', '')} -> {x.bus1.replace(' H2', '')}", lambda x: f"H2 pipeline {x.bus0.replace(' H2', '')} -> {x.bus1.replace(' H2', '')}",
axis=1, axis=1,
) )
return df.groupby(level=0).agg( return df.groupby(level=0).agg({"p_nom_opt": sum, "bus0": "first", "bus1": "first"})
{"p_nom_opt": sum, "bus0": "first", "bus1": "first"}
)
def plot_h2_map(network, regions): def plot_h2_map(network, regions):

View File

@ -583,8 +583,5 @@ if __name__ == "__main__":
for sector_opts in snakemake.params.sector_opts: for sector_opts in snakemake.params.sector_opts:
opts = sector_opts.split("-") opts = sector_opts.split("-")
if ( if any("cb" in o for o in opts) or snakemake.config["foresight"] == "perfect":
any("cb" in o for o in opts)
or snakemake.config["foresight"] == "perfect"
):
plot_carbon_budget_distribution(snakemake.input.eurostat) plot_carbon_budget_distribution(snakemake.input.eurostat)

View File

@ -86,8 +86,7 @@ def cross_border_time_series(countries, data):
) )
title = "Historic" if (axis % 2) == 0 else "Optimized" title = "Historic" if (axis % 2) == 0 else "Optimized"
ax[axis].set_title( ax[axis].set_title(
f"{title} Import / Export for " f"{title} Import / Export for " + cc.convert(country, to="name_short")
+ cc.convert(country, to="name_short")
) )
# Custom legend elements # Custom legend elements

View File

@ -56,9 +56,7 @@ def get_investment_weighting(time_weighting, r=0.01):
end = time_weighting.cumsum() end = time_weighting.cumsum()
start = time_weighting.cumsum().shift().fillna(0) start = time_weighting.cumsum().shift().fillna(0)
return pd.concat([start, end], axis=1).apply( return pd.concat([start, end], axis=1).apply(
lambda x: sum( lambda x: sum(get_social_discount(t, r) for t in range(int(x[0]), int(x[1]))),
get_social_discount(t, r) for t in range(int(x[0]), int(x[1]))
),
axis=1, axis=1,
) )

View File

@ -410,7 +410,9 @@ def update_wind_solar_costs(n, costs):
# e.g. clusters == 37m means that VRE generators are left # e.g. clusters == 37m means that VRE generators are left
# at clustering of simplified network, but that they are # at clustering of simplified network, but that they are
# connected to 37-node network # 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( connection_cost = (connection_cost * weight).groupby(
genmap genmap
).sum() / weight.groupby(genmap).sum() ).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. Remove buses from pypsa-eur with carriers which are not AC buses.
""" """
if to_drop := list( if to_drop := list(n.buses.query("carrier not in ['AC', 'DC']").carrier.unique()):
n.buses.query("carrier not in ['AC', 'DC']").carrier.unique()
):
logger.info(f"Drop buses from PyPSA-Eur with carrier: {to_drop}") logger.info(f"Drop buses from PyPSA-Eur with carrier: {to_drop}")
n.buses = n.buses[n.buses.carrier.isin(["AC", "DC"])] n.buses = n.buses[n.buses.carrier.isin(["AC", "DC"])]

View File

@ -153,10 +153,7 @@ def _add_land_use_constraint_m(n, planning_horizons, config):
for carrier in ["solar", "onwind", "offwind-ac", "offwind-dc"]: for carrier in ["solar", "onwind", "offwind-ac", "offwind-dc"]:
existing = n.generators.loc[n.generators.carrier == carrier, "p_nom"] existing = n.generators.loc[n.generators.carrier == carrier, "p_nom"]
ind = list( 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 = [ previous_years = [

View File

@ -36,11 +36,7 @@ if __name__ == "__main__":
configure_logging(snakemake) configure_logging(snakemake)
update_config_with_sector_opts(snakemake.config, snakemake.wildcards.sector_opts) update_config_with_sector_opts(snakemake.config, snakemake.wildcards.sector_opts)
opts = ( opts = f"{snakemake.wildcards.opts}-{snakemake.wildcards.sector_opts}".split("-")
f"{snakemake.wildcards.opts}-{snakemake.wildcards.sector_opts}".split(
"-"
)
)
opts = [o for o in opts if o != ""] opts = [o for o in opts if o != ""]
solve_opts = snakemake.params.options solve_opts = snakemake.params.options