2024-02-14 17:15:18 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# SPDX-FileCopyrightText: : 2020-2024 The PyPSA-Eur Authors
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
"""
|
|
|
|
Build specific energy consumption by carrier and industries and by country,
|
2024-02-14 17:31:48 +00:00
|
|
|
that interpolates between the current average energy consumption (from
|
|
|
|
2015-2020) and the ideal future best-in-class consumption.
|
2024-02-14 17:15:18 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
import pandas as pd
|
|
|
|
from prepare_sector_network import get
|
|
|
|
|
2024-02-14 17:31:48 +00:00
|
|
|
|
2024-02-14 17:15:18 +00:00
|
|
|
def build_industry_sector_ratios_intermediate():
|
|
|
|
|
|
|
|
# in TWh/a
|
2024-02-14 17:31:48 +00:00
|
|
|
demand = pd.read_csv(
|
|
|
|
snakemake.input.industrial_energy_demand_per_country_today,
|
|
|
|
header=[0, 1],
|
|
|
|
index_col=0,
|
|
|
|
)
|
2024-02-14 17:15:18 +00:00
|
|
|
|
|
|
|
# in Mt/a
|
2024-02-14 17:31:48 +00:00
|
|
|
production = (
|
|
|
|
pd.read_csv(snakemake.input.industrial_production_per_country, index_col=0)
|
|
|
|
/ 1e3
|
2024-02-16 14:14:18 +00:00
|
|
|
).stack()
|
|
|
|
production.index.names = [None, None]
|
2024-02-14 17:15:18 +00:00
|
|
|
|
|
|
|
# in MWh/t
|
2024-02-14 17:31:48 +00:00
|
|
|
future_sector_ratios = pd.read_csv(
|
|
|
|
snakemake.input.industry_sector_ratios, index_col=0
|
|
|
|
)
|
2024-02-14 17:15:18 +00:00
|
|
|
|
|
|
|
today_sector_ratios = demand.div(production, axis=1)
|
|
|
|
|
2024-02-16 14:14:18 +00:00
|
|
|
today_sector_ratios.dropna(how="all", axis=1, inplace=True)
|
2024-02-14 17:15:18 +00:00
|
|
|
|
2024-02-16 14:14:18 +00:00
|
|
|
rename = {
|
|
|
|
"waste": "biomass",
|
|
|
|
"electricity": "elec",
|
|
|
|
"solid": "coke",
|
|
|
|
"gas": "methane",
|
|
|
|
"other": "biomass",
|
|
|
|
"liquid": "naphtha",
|
|
|
|
}
|
|
|
|
today_sector_ratios = today_sector_ratios.rename(rename).groupby(level=0).sum()
|
2024-02-14 17:15:18 +00:00
|
|
|
|
|
|
|
fraction_future = get(params["sector_ratios_fraction_future"], year)
|
|
|
|
|
|
|
|
intermediate_sector_ratios = {}
|
2024-02-16 14:14:18 +00:00
|
|
|
for ct, group in today_sector_ratios.T.groupby(level=0):
|
|
|
|
today_sector_ratios_ct = (
|
|
|
|
group.droplevel(0)
|
|
|
|
.T.reindex_like(future_sector_ratios)
|
|
|
|
.fillna(future_sector_ratios)
|
|
|
|
)
|
|
|
|
intermediate_sector_ratios[ct] = (
|
|
|
|
today_sector_ratios_ct * (1 - fraction_future)
|
|
|
|
+ future_sector_ratios * fraction_future
|
2024-02-14 17:31:48 +00:00
|
|
|
)
|
2024-02-14 17:15:18 +00:00
|
|
|
intermediate_sector_ratios = pd.concat(intermediate_sector_ratios, axis=1)
|
|
|
|
|
2024-02-14 17:31:48 +00:00
|
|
|
|
2024-02-14 17:15:18 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
if "snakemake" not in globals():
|
|
|
|
from _helpers import mock_snakemake
|
|
|
|
|
2024-02-16 14:14:18 +00:00
|
|
|
snakemake = mock_snakemake(
|
|
|
|
"build_industry_sector_ratios_intermediate",
|
|
|
|
planning_horizons="2030",
|
|
|
|
)
|
2024-02-14 17:15:18 +00:00
|
|
|
|
|
|
|
year = int(snakemake.wildcards.planning_horizons[-4:])
|
|
|
|
|
|
|
|
params = snakemake.params.industry
|
|
|
|
|
|
|
|
build_industry_sector_ratios_intermediate()
|