diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index a38e6800..d90f5cb9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -51,7 +51,7 @@ repos: # Formatting with "black" coding style - repo: https://github.com/psf/black-pre-commit-mirror - rev: 23.12.1 + rev: 24.1.1 hooks: # Format Python files - id: black diff --git a/scripts/build_retro_cost.py b/scripts/build_retro_cost.py index 67440263..bd285e18 100755 --- a/scripts/build_retro_cost.py +++ b/scripts/build_retro_cost.py @@ -607,21 +607,28 @@ def calculate_costs(u_values, l, cost_retro, window_assumptions): # noqa: E741 """ return u_values.apply( lambda x: ( - cost_retro.loc[x.name[3], "cost_var"] - * 100 - * float(l) - * l_weight.loc[x.name[3]].iloc[0] - + cost_retro.loc[x.name[3], "cost_fix"] - ) - * x.A_element - / x.A_C_Ref - if x.name[3] != "Window" - else ( - (window_cost(x[f"new_U_{l}"], cost_retro, window_assumptions) * x.A_element) + ( + cost_retro.loc[x.name[3], "cost_var"] + * 100 + * float(l) + * l_weight.loc[x.name[3]].iloc[0] + + cost_retro.loc[x.name[3], "cost_fix"] + ) + * x.A_element / x.A_C_Ref - ) - if x.value > window_limit(float(l), window_assumptions) - else 0, + if x.name[3] != "Window" + else ( + ( + ( + 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, ) @@ -648,12 +655,14 @@ def calculate_new_u(u_values, l, l_weight, window_assumptions, k=0.035): # noqa k: thermal conductivity """ return u_values.apply( - lambda x: k / ((k / x.value) + (float(l) * l_weight.loc[x.name[3]])) - if x.name[3] != "Window" - else ( - min(x.value, u_retro_window(float(l), window_assumptions)) - if x.value > window_limit(float(l), window_assumptions) - else x.value + lambda x: ( + k / ((k / x.value) + (float(l) * l_weight.loc[x.name[3]])) + if x.name[3] != "Window" + else ( + min(x.value, u_retro_window(float(l), window_assumptions)) + if x.value > window_limit(float(l), window_assumptions) + else x.value + ) ), axis=1, ) diff --git a/scripts/plot_summary.py b/scripts/plot_summary.py index 92bf726c..cfb32441 100644 --- a/scripts/plot_summary.py +++ b/scripts/plot_summary.py @@ -281,12 +281,14 @@ def plot_balances(): # remove trailing link ports df.index = [ - i[:-1] - if ( - (i not in ["co2", "NH3", "H2"]) - and (i[-1:] in ["0", "1", "2", "3", "4"]) + ( + i[:-1] + if ( + (i not in ["co2", "NH3", "H2"]) + and (i[-1:] in ["0", "1", "2", "3", "4"]) + ) + else i ) - else i for i in df.index ] diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 22fb1bcc..42def055 100755 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -458,9 +458,9 @@ def update_wind_solar_costs(n, costs): ) ) - n.generators.loc[ - n.generators.carrier == tech, "capital_cost" - ] = capital_cost.rename(index=lambda node: node + " " + tech) + n.generators.loc[n.generators.carrier == tech, "capital_cost"] = ( + capital_cost.rename(index=lambda node: node + " " + tech) + ) def add_carrier_buses(n, carrier, nodes=None): @@ -2932,9 +2932,11 @@ def add_industry(n, costs): nodes, suffix=" low-temperature heat for industry", bus=[ - node + " urban central heat" - if node + " urban central heat" in n.buses.index - else node + " services urban decentral heat" + ( + node + " urban central heat" + if node + " urban central heat" in n.buses.index + else node + " services urban decentral heat" + ) for node in nodes ], 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, "efficiency" - ] = efficiency_static * efficiency_per_1000km ** ( - n.links.loc[carrier_i, "length"] / 1e3 + n.links.loc[carrier_i, "efficiency"] = ( + efficiency_static + * efficiency_per_1000km ** (n.links.loc[carrier_i, "length"] / 1e3) ) rev_links = ( n.links.loc[carrier_i].copy().rename({"bus0": "bus1", "bus1": "bus0"}, axis=1) diff --git a/scripts/simplify_network.py b/scripts/simplify_network.py index f8629ea7..31bc8f4e 100644 --- a/scripts/simplify_network.py +++ b/scripts/simplify_network.py @@ -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 ) - dist[ - buses_i - ] = np.inf # bus in buses_i should not be assigned to different bus in buses_i + dist[buses_i] = ( + np.inf + ) # bus in buses_i should not be assigned to different bus in buses_i for c in n.buses.country.unique(): incountry_b = n.buses.country == c diff --git a/scripts/solve_network.py b/scripts/solve_network.py index 23e9b0f8..a1d790a7 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -703,9 +703,11 @@ def add_lossy_bidirectional_link_constraints(n): def get_backward_i(forward_i): return pd.Index( [ - re.sub(r"-(\d{4})$", r"-reversed-\1", s) - if re.search(r"-\d{4}$", s) - else s + "-reversed" + ( + re.sub(r"-(\d{4})$", r"-reversed-\1", s) + if re.search(r"-\d{4}$", s) + else s + "-reversed" + ) for s in forward_i ] )