Skip to content

Commit

Permalink
style: simplify update_heat_pump_efficiency functions
Browse files Browse the repository at this point in the history
  • Loading branch information
amos-schledorn committed Sep 30, 2024
1 parent 85a878b commit b27227f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
11 changes: 7 additions & 4 deletions scripts/add_brownfield.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,13 @@ def update_heat_pump_efficiency(n: pypsa.Network, n_p: pypsa.Network, year: int)
This function updates the efficiency in place and does not return a value.
"""

for link_name_p in n_p.links.index:
if "heat pump" in link_name_p:
link_name = link_name_p.replace(link_name_p[-4:], str(year))
n_p.links_t["efficiency"][link_name_p] = n.links_t["efficiency"][link_name]
# get names of heat pumps in previous iteration
heat_pump_idx_previous_iteration = n_p.links.index[n_p.links.index.str.contains("heat pump")]
# construct names of same-technology heat pumps in the current iteration
corresponding_idx_this_iteration = heat_pump_idx_previous_iteration.str[:-4] + str(year)
# update efficiency of heat pumps in previous iteration in-place to efficiency in this iteration
n_p.links_t["efficiency"].loc[:, heat_pump_idx_previous_iteration] = n.links_t["efficiency"].loc[:, corresponding_idx_this_iteration].values



if __name__ == "__main__":
Expand Down
24 changes: 14 additions & 10 deletions scripts/prepare_perfect_foresight.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,16 +508,20 @@ def update_heat_pump_efficiency(n: pypsa.Network, years: List[int]):
This function updates the efficiency in place and does not return a value.
"""

for link_name in n.links.index:
if "heat pump" in link_name:
heat_pump_name = link_name[:-4]
for year in years:
correct_efficiency = n.links_t["efficiency"].loc[
(year, slice(None)), heat_pump_name + str(year)
]
n.links_t["efficiency"].loc[
(year, slice(None)), link_name
] = correct_efficiency
# get names of all heat pumps
heat_pump_idx = n.links.index[n.links.index.str.contains("heat pump")]
for year in years:
# for each heat pump type, correct efficiency is the efficiency of that technology built in <year>
correct_efficiency = n.links_t["efficiency"].loc[
(year, slice(None)), heat_pump_idx.str[:-4] + str(year)
]
# in <year>, set the efficiency of all heat pumps to the correct efficiency
n.links_t["efficiency"].loc[
(year, slice(None)), heat_pump_idx
] = correct_efficiency.values





if __name__ == "__main__":
Expand Down

0 comments on commit b27227f

Please sign in to comment.