simplify if-else expression

This commit is contained in:
Fabian Neumann 2023-08-22 14:42:21 +02:00
parent 33305f9761
commit e12cad2789

View File

@ -435,20 +435,20 @@ def add_heating_capacities_installed_before_baseyear(
# split existing capacities between residential and services # split existing capacities between residential and services
# proportional to energy demand # proportional to energy demand
p_set_sum = n.loads_t.p_set.sum()
ratio_residential = pd.Series( ratio_residential = pd.Series(
[ [
( (
n.loads_t.p_set.sum()[f"{node} residential rural heat"] p_set_sum[f"{node} residential rural heat"]
/ ( / (
n.loads_t.p_set.sum()[f"{node} residential rural heat"] p_set_sum[f"{node} residential rural heat"]
+ n.loads_t.p_set.sum()[f"{node} services rural heat"] + p_set_sum[f"{node} services rural heat"]
) )
) )
# if rural heating demand for one of the nodes doesn't exist, # if rural heating demand for one of the nodes doesn't exist,
# then columns were dropped before and heating demand share should be 0.0 # then columns were dropped before and heating demand share should be 0.0
if (f"{node} residential rural heat" in n.loads_t.p_set.sum().index) if all(f"{node} {service} rural heat" in p_set_sum.index for service in ["residential", "services"])
& (f"{node} services rural heat" in n.loads_t.p_set.sum().index) else 0.
else 0.0
for node in nodal_df.index for node in nodal_df.index
], ],
index=nodal_df.index, index=nodal_df.index,