Skip to content

Commit

Permalink
build_energy_totals: output district heat share to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
nworbmot committed Jan 15, 2024
1 parent 4560338 commit 15488ed
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
1 change: 1 addition & 0 deletions rules/build_sector.smk
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ rule build_energy_totals:
energy_name=RESOURCES + "energy_totals.csv",
co2_name=RESOURCES + "co2_totals.csv",
transport_name=RESOURCES + "transport_data.csv",
district_heat_share=RESOURCES + "district_heat_share.csv",
threads: 16
resources:
mem_mb=10000,
Expand Down
31 changes: 21 additions & 10 deletions scripts/build_energy_totals.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,13 +394,6 @@ def build_idees(countries, year):
# convert TWh/100km to kWh/km
totals.loc["passenger car efficiency"] *= 10

# district heating share
district_heat = totals.loc[
["derived heat residential", "derived heat services"]
].sum()
total_heat = totals.loc[["thermal uses residential", "thermal uses services"]].sum()
totals.loc["district heat share"] = district_heat.div(total_heat)

return totals.T


Expand Down Expand Up @@ -575,16 +568,31 @@ def build_energy_totals(countries, eurostat, swiss, idees):
ratio = df.at["BA", "total residential"] / df.at["RS", "total residential"]
df.loc["BA", missing] = ratio * df.loc["RS", missing]

return df


def build_district_heat_share(idees):

# district heating share
district_heat = idees[
["derived heat residential", "derived heat services"]
].sum(axis=1)
total_heat = idees[["thermal uses residential", "thermal uses services"]].sum(axis=1)

district_heat_share = district_heat/total_heat

# Missing district heating share
dh_share = pd.read_csv(
snakemake.input.district_heat_share, index_col=0, usecols=[0, 1]
)
# make conservative assumption and take minimum from both data sets
df["district heat share"] = pd.concat(
[df["district heat share"], dh_share.reindex(index=df.index) / 100], axis=1
district_heat_share = pd.concat(
[district_heat_share, dh_share.reindex(index=district_heat_share.index) / 100], axis=1
).min(axis=1)

return df
district_heat_share.name = "district heat share"

return district_heat_share


def build_eea_co2(input_co2, year=1990, emissions_scope="CO2"):
Expand Down Expand Up @@ -753,6 +761,9 @@ def build_transport_data(countries, population, idees):
energy = build_energy_totals(countries, eurostat, swiss, idees)
energy.to_csv(snakemake.output.energy_name)

district_heat_share = build_district_heat_share(idees)
district_heat_share.to_csv(snakemake.output.district_heat_share)

base_year_emissions = params["base_emissions_year"]
emissions_scope = snakemake.params.energy["emissions"]
eea_co2 = build_eea_co2(snakemake.input.co2, base_year_emissions, emissions_scope)
Expand Down

0 comments on commit 15488ed

Please sign in to comment.