Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update calculations of retrofit costs #759

Merged
merged 16 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rules/build_sector.smk
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ if config["sector"]["retrofitting"]["retro_endogen"]:
countries=config["countries"],
input:
building_stock="data/retro/data_building_stock.csv",
data_tabula="data/retro/tabula-calculator-calcsetbuilding.csv",
data_tabula="data/bundle-sector/retro/tabula-calculator-calcsetbuilding.csv",
air_temperature=RESOURCES + "temp_air_total_elec_s{simpl}_{clusters}.nc",
u_values_PL="data/retro/u_values_poland.csv",
tax_w="data/retro/electricity_taxes_eu.csv",
Expand Down
46 changes: 24 additions & 22 deletions scripts/build_retro_cost.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,13 @@ def prepare_building_stock_data():
}
)

building_data["country_code"] = building_data["country"].map(country_iso_dic)

# heated floor area ----------------------------------------------------------
area = building_data[
(building_data.type == "Heated area [Mm²]")
& (building_data.subsector != "Total")
(building_data.type == "Heated area [Mm²]") & (building_data.detail != "Total")
]
area_tot = area.groupby(["country", "sector"]).sum()
area_tot = area[["country", "sector", "value"]].groupby(["country", "sector"]).sum()
area = pd.concat(
[
area,
Expand All @@ -223,7 +224,7 @@ def prepare_building_stock_data():
usecols=[0, 1, 2, 3],
encoding="ISO-8859-1",
)
area_tot = area_tot.append(area_missing.unstack(level=-1).dropna().stack())
area_tot = pd.concat([area_tot, area_missing.unstack(level=-1).dropna().stack()])
area_tot = area_tot.loc[~area_tot.index.duplicated(keep="last")]

# for still missing countries calculate floor area by population size
Expand All @@ -246,7 +247,7 @@ def prepare_building_stock_data():
averaged_data.index = index
averaged_data["estimated"] = 1
if ct not in area_tot.index.levels[0]:
area_tot = area_tot.append(averaged_data, sort=True)
area_tot = pd.concat([area_tot, averaged_data], sort=True)
else:
area_tot.loc[averaged_data.index] = averaged_data

Expand All @@ -272,7 +273,7 @@ def prepare_building_stock_data():
][x["bage"]].iloc[0],
axis=1,
)
data_PL_final = data_PL_final.append(data_PL)
data_PL_final = pd.concat([data_PL_final, data_PL])

u_values = pd.concat([u_values, data_PL_final]).reset_index(drop=True)

Expand Down Expand Up @@ -943,7 +944,8 @@ def sample_dE_costs_area(
.rename(index=rename_sectors, level=2)
.reset_index()
)
.rename(columns={"country": "country_code"})
# if uncommented, leads to the second `country_code` column
# .rename(columns={"country": "country_code"})
.set_index(["country_code", "subsector", "bage"])
)

Expand All @@ -956,13 +958,14 @@ def sample_dE_costs_area(
)

# map missing countries
for ct in countries.difference(cost_dE.index.levels[0]):
for ct in set(countries).difference(cost_dE.index.levels[0]):
averaged_data = (
cost_dE.reindex(index=map_for_missings[ct], level=0)
.mean(level=1)
.groupby(level=1)
.mean()
.set_index(pd.MultiIndex.from_product([[ct], cost_dE.index.levels[1]]))
)
cost_dE = cost_dE.append(averaged_data)
cost_dE = pd.concat([cost_dE, averaged_data])

# weights costs after construction index
if construction_index:
Expand All @@ -979,24 +982,23 @@ def sample_dE_costs_area(
# drop not considered countries
cost_dE = cost_dE.reindex(countries, level=0)
# get share of residential and service floor area
sec_w = area_tot.value / area_tot.value.groupby(level=0).sum()
sec_w = area_tot.div(area_tot.groupby(level=0).transform("sum"))
# get the total cost-energy-savings weight by sector area
tot = (
cost_dE.mul(sec_w, axis=0)
.groupby(level="country_code")
# sec_w has columns "estimated" and "value"
cost_dE.mul(sec_w.value, axis=0)
# for some reasons names of the levels were lost somewhere
# .groupby(level="country_code")
.groupby(level=0)
.sum()
.set_index(
pd.MultiIndex.from_product(
[cost_dE.index.unique(level="country_code"), ["tot"]]
)
)
.set_index(pd.MultiIndex.from_product([cost_dE.index.unique(level=0), ["tot"]]))
)
cost_dE = cost_dE.append(tot).unstack().stack()
cost_dE = pd.concat([cost_dE, tot]).unstack().stack()

summed_area = pd.DataFrame(area_tot.groupby("country").sum()).set_index(
pd.MultiIndex.from_product([area_tot.index.unique(level="country"), ["tot"]])
summed_area = pd.DataFrame(area_tot.groupby(level=0).sum()).set_index(
pd.MultiIndex.from_product([area_tot.index.unique(level=0), ["tot"]])
)
area_tot = area_tot.append(summed_area).unstack().stack()
area_tot = pd.concat([area_tot, summed_area]).unstack().stack()

cost_per_saving = cost_dE["cost"] / (
1 - cost_dE["dE"]
Expand Down
2 changes: 1 addition & 1 deletion scripts/prepare_sector_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -1954,7 +1954,7 @@ def add_heat(n, costs):
# demand 'dE' [per unit of original heat demand] for each country and
# different retrofitting strengths [additional insulation thickness in m]
retro_data = pd.read_csv(
snakemake.input.retro_cost_energy,
snakemake.input.retro_cost,
index_col=[0, 1],
skipinitialspace=True,
header=[0, 1],
Expand Down
Loading