Merge pull request #902 from PyPSA/pre-commit-ci-update-config

[pre-commit.ci] pre-commit autoupdate
This commit is contained in:
Fabian Neumann 2024-01-29 20:35:59 +01:00 committed by GitHub
commit cb00f42476
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 56 additions and 42 deletions

View File

@ -51,7 +51,7 @@ repos:
# Formatting with "black" coding style # Formatting with "black" coding style
- repo: https://github.com/psf/black-pre-commit-mirror - repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.12.1 rev: 24.1.1
hooks: hooks:
# Format Python files # Format Python files
- id: black - id: black

View File

@ -607,21 +607,28 @@ def calculate_costs(u_values, l, cost_retro, window_assumptions): # noqa: E741
""" """
return u_values.apply( return u_values.apply(
lambda x: ( lambda x: (
cost_retro.loc[x.name[3], "cost_var"] (
* 100 cost_retro.loc[x.name[3], "cost_var"]
* float(l) * 100
* l_weight.loc[x.name[3]].iloc[0] * float(l)
+ cost_retro.loc[x.name[3], "cost_fix"] * l_weight.loc[x.name[3]].iloc[0]
) + cost_retro.loc[x.name[3], "cost_fix"]
* x.A_element )
/ x.A_C_Ref * x.A_element
if x.name[3] != "Window"
else (
(window_cost(x[f"new_U_{l}"], cost_retro, window_assumptions) * x.A_element)
/ x.A_C_Ref / x.A_C_Ref
) if x.name[3] != "Window"
if x.value > window_limit(float(l), window_assumptions) else (
else 0, (
(
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)
else 0
)
),
axis=1, axis=1,
) )
@ -648,12 +655,14 @@ def calculate_new_u(u_values, l, l_weight, window_assumptions, k=0.035): # noqa
k: thermal conductivity k: thermal conductivity
""" """
return u_values.apply( return u_values.apply(
lambda x: k / ((k / x.value) + (float(l) * l_weight.loc[x.name[3]])) lambda x: (
if x.name[3] != "Window" k / ((k / x.value) + (float(l) * l_weight.loc[x.name[3]]))
else ( if x.name[3] != "Window"
min(x.value, u_retro_window(float(l), window_assumptions)) else (
if x.value > window_limit(float(l), window_assumptions) min(x.value, u_retro_window(float(l), window_assumptions))
else x.value if x.value > window_limit(float(l), window_assumptions)
else x.value
)
), ),
axis=1, axis=1,
) )

View File

@ -281,12 +281,14 @@ def plot_balances():
# remove trailing link ports # remove trailing link ports
df.index = [ df.index = [
i[:-1] (
if ( i[:-1]
(i not in ["co2", "NH3", "H2"]) if (
and (i[-1:] in ["0", "1", "2", "3", "4"]) (i not in ["co2", "NH3", "H2"])
and (i[-1:] in ["0", "1", "2", "3", "4"])
)
else i
) )
else i
for i in df.index for i in df.index
] ]

View File

@ -458,9 +458,9 @@ def update_wind_solar_costs(n, costs):
) )
) )
n.generators.loc[ n.generators.loc[n.generators.carrier == tech, "capital_cost"] = (
n.generators.carrier == tech, "capital_cost" capital_cost.rename(index=lambda node: node + " " + tech)
] = capital_cost.rename(index=lambda node: node + " " + tech) )
def add_carrier_buses(n, carrier, nodes=None): def add_carrier_buses(n, carrier, nodes=None):
@ -2932,9 +2932,11 @@ def add_industry(n, costs):
nodes, nodes,
suffix=" low-temperature heat for industry", suffix=" low-temperature heat for industry",
bus=[ bus=[
node + " urban central heat" (
if node + " urban central heat" in n.buses.index node + " urban central heat"
else node + " services urban decentral heat" if node + " urban central heat" in n.buses.index
else node + " services urban decentral heat"
)
for node in nodes for node in nodes
], ],
carrier="low-temperature heat for industry", carrier="low-temperature heat for industry",
@ -3529,10 +3531,9 @@ def lossy_bidirectional_links(n, carrier, efficiencies={}):
) )
n.links.loc[carrier_i, "p_min_pu"] = 0 n.links.loc[carrier_i, "p_min_pu"] = 0
n.links.loc[ n.links.loc[carrier_i, "efficiency"] = (
carrier_i, "efficiency" efficiency_static
] = efficiency_static * efficiency_per_1000km ** ( * efficiency_per_1000km ** (n.links.loc[carrier_i, "length"] / 1e3)
n.links.loc[carrier_i, "length"] / 1e3
) )
rev_links = ( rev_links = (
n.links.loc[carrier_i].copy().rename({"bus0": "bus1", "bus1": "bus0"}, axis=1) n.links.loc[carrier_i].copy().rename({"bus0": "bus1", "bus1": "bus0"}, axis=1)

View File

@ -468,9 +468,9 @@ def aggregate_to_substations(n, aggregation_strategies=dict(), buses_i=None):
dijkstra(adj, directed=False, indices=bus_indexer), buses_i, n.buses.index dijkstra(adj, directed=False, indices=bus_indexer), buses_i, n.buses.index
) )
dist[ dist[buses_i] = (
buses_i np.inf
] = np.inf # bus in buses_i should not be assigned to different bus in buses_i ) # bus in buses_i should not be assigned to different bus in buses_i
for c in n.buses.country.unique(): for c in n.buses.country.unique():
incountry_b = n.buses.country == c incountry_b = n.buses.country == c

View File

@ -703,9 +703,11 @@ def add_lossy_bidirectional_link_constraints(n):
def get_backward_i(forward_i): def get_backward_i(forward_i):
return pd.Index( return pd.Index(
[ [
re.sub(r"-(\d{4})$", r"-reversed-\1", s) (
if re.search(r"-\d{4}$", s) re.sub(r"-(\d{4})$", r"-reversed-\1", s)
else s + "-reversed" if re.search(r"-\d{4}$", s)
else s + "-reversed"
)
for s in forward_i for s in forward_i
] ]
) )