[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
e14bae345b
commit
b45df1724b
@ -443,7 +443,8 @@ rule build_industry_sector_ratios_intermediate:
|
||||
industrial_production_per_country=RESOURCES
|
||||
+ "industrial_production_per_country.csv",
|
||||
output:
|
||||
industry_sector_ratios=RESOURCES + "industry_sector_ratios_{planning_horizons}.csv",
|
||||
industry_sector_ratios=RESOURCES
|
||||
+ "industry_sector_ratios_{planning_horizons}.csv",
|
||||
threads: 1
|
||||
resources:
|
||||
mem_mb=1000,
|
||||
@ -559,7 +560,8 @@ rule build_industrial_production_per_node:
|
||||
|
||||
rule build_industrial_energy_demand_per_node:
|
||||
input:
|
||||
industry_sector_ratios=RESOURCES + "industry_sector_ratios_{planning_horizons}.csv",
|
||||
industry_sector_ratios=RESOURCES
|
||||
+ "industry_sector_ratios_{planning_horizons}.csv",
|
||||
industrial_production_per_node=RESOURCES
|
||||
+ "industrial_production_elec_s{simpl}_{clusters}_{planning_horizons}.csv",
|
||||
industrial_energy_demand_per_node_today=RESOURCES
|
||||
|
@ -96,19 +96,35 @@ def industrial_energy_demand_per_country(country, year, jrc_dir):
|
||||
|
||||
def separate_basic_chemicals(demand, production):
|
||||
|
||||
ammonia = pd.DataFrame({"hydrogen": production["Ammonia"] * params["MWh_H2_per_tNH3_electrolysis"],
|
||||
"electricity" : production["Ammonia"] * params["MWh_elec_per_tNH3_electrolysis"]}).T
|
||||
chlorine = pd.DataFrame({"hydrogen": production["Chlorine"] * params["MWh_H2_per_tCl"],
|
||||
"electricity" : production["Chlorine"] * params["MWh_elec_per_tCl"]}).T
|
||||
methanol = pd.DataFrame({"gas": production["Methanol"] * params["MWh_CH4_per_tMeOH"],
|
||||
"electricity" : production["Methanol"] * params["MWh_elec_per_tMeOH"]}).T
|
||||
ammonia = pd.DataFrame(
|
||||
{
|
||||
"hydrogen": production["Ammonia"] * params["MWh_H2_per_tNH3_electrolysis"],
|
||||
"electricity": production["Ammonia"]
|
||||
* params["MWh_elec_per_tNH3_electrolysis"],
|
||||
}
|
||||
).T
|
||||
chlorine = pd.DataFrame(
|
||||
{
|
||||
"hydrogen": production["Chlorine"] * params["MWh_H2_per_tCl"],
|
||||
"electricity": production["Chlorine"] * params["MWh_elec_per_tCl"],
|
||||
}
|
||||
).T
|
||||
methanol = pd.DataFrame(
|
||||
{
|
||||
"gas": production["Methanol"] * params["MWh_CH4_per_tMeOH"],
|
||||
"electricity": production["Methanol"] * params["MWh_elec_per_tMeOH"],
|
||||
}
|
||||
).T
|
||||
|
||||
demand["Ammonia"] = ammonia.unstack().reindex(index=demand.index, fill_value=0.0)
|
||||
demand["Chlorine"] = chlorine.unstack().reindex(index=demand.index, fill_value=0.0)
|
||||
demand["Methanol"] = methanol.unstack().reindex(index=demand.index, fill_value=0.0)
|
||||
|
||||
demand["HVC"] = (
|
||||
demand["Basic chemicals"] - demand["Ammonia"] - demand["Methanol"] - demand["Chlorine"]
|
||||
demand["Basic chemicals"]
|
||||
- demand["Ammonia"]
|
||||
- demand["Methanol"]
|
||||
- demand["Chlorine"]
|
||||
)
|
||||
|
||||
demand.drop(columns="Basic chemicals", inplace=True)
|
||||
@ -166,8 +182,10 @@ if __name__ == "__main__":
|
||||
demand = industrial_energy_demand(countries.intersection(eu28), year)
|
||||
|
||||
# output in MtMaterial/a
|
||||
production = pd.read_csv(snakemake.input.industrial_production_per_country,
|
||||
index_col=0) / 1e3
|
||||
production = (
|
||||
pd.read_csv(snakemake.input.industrial_production_per_country, index_col=0)
|
||||
/ 1e3
|
||||
)
|
||||
|
||||
demand = separate_basic_chemicals(demand, production)
|
||||
|
||||
|
@ -21,9 +21,7 @@ if __name__ == "__main__":
|
||||
|
||||
# import ratios
|
||||
fn = snakemake.input.industry_sector_ratios
|
||||
sector_ratios = pd.read_csv(fn,
|
||||
header=[0,1],
|
||||
index_col=0)
|
||||
sector_ratios = pd.read_csv(fn, header=[0, 1], index_col=0)
|
||||
|
||||
# material demand per node and industry (Mton/a)
|
||||
fn = snakemake.input.industrial_production_per_node
|
||||
@ -33,14 +31,19 @@ if __name__ == "__main__":
|
||||
fn = snakemake.input.industrial_energy_demand_per_node_today
|
||||
nodal_today = pd.read_csv(fn, index_col=0)
|
||||
|
||||
nodal_sector_ratios = pd.concat({node: sector_ratios[node[:2]] for node in nodal_production.index},
|
||||
axis=1)
|
||||
nodal_sector_ratios = pd.concat(
|
||||
{node: sector_ratios[node[:2]] for node in nodal_production.index}, axis=1
|
||||
)
|
||||
|
||||
nodal_production_stacked = nodal_production.stack()
|
||||
nodal_production_stacked.index.names = [None, None]
|
||||
|
||||
# final energy consumption per node and industry (TWh/a)
|
||||
nodal_df = (nodal_sector_ratios.multiply(nodal_production_stacked)).T.groupby(level=0).sum()
|
||||
nodal_df = (
|
||||
(nodal_sector_ratios.multiply(nodal_production_stacked))
|
||||
.T.groupby(level=0)
|
||||
.sum()
|
||||
)
|
||||
|
||||
rename_sectors = {
|
||||
"elec": "electricity",
|
||||
|
@ -261,7 +261,11 @@ def separate_basic_chemicals(demand, year):
|
||||
demand["Basic chemicals"].clip(lower=0.0, inplace=True)
|
||||
|
||||
# assume HVC, methanol, chlorine production proportional to non-ammonia basic chemicals
|
||||
distribution_key = demand["Basic chemicals"] / params["basic_chemicals_without_NH3_production_today"] / 1e3
|
||||
distribution_key = (
|
||||
demand["Basic chemicals"]
|
||||
/ params["basic_chemicals_without_NH3_production_today"]
|
||||
/ 1e3
|
||||
)
|
||||
demand["HVC"] = params["HVC_production_today"] * 1e3 * distribution_key
|
||||
demand["Chlorine"] = params["chlorine_production_today"] * 1e3 * distribution_key
|
||||
demand["Methanol"] = params["methanol_production_today"] * 1e3 * distribution_key
|
||||
|
@ -4,39 +4,45 @@
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""
|
||||
Build specific energy consumption by carrier and industries and by country,
|
||||
that interpolates between the current average energy consumption (from 2015-2020)
|
||||
and the ideal future best-in-class consumption.
|
||||
that interpolates between the current average energy consumption (from
|
||||
2015-2020) and the ideal future best-in-class consumption.
|
||||
"""
|
||||
|
||||
import pandas as pd
|
||||
|
||||
from prepare_sector_network import get
|
||||
|
||||
|
||||
def build_industry_sector_ratios_intermediate():
|
||||
|
||||
# in TWh/a
|
||||
demand = pd.read_csv(snakemake.input.industrial_energy_demand_per_country_today,
|
||||
demand = pd.read_csv(
|
||||
snakemake.input.industrial_energy_demand_per_country_today,
|
||||
header=[0, 1],
|
||||
index_col=0)
|
||||
index_col=0,
|
||||
)
|
||||
|
||||
# in Mt/a
|
||||
production = pd.read_csv(snakemake.input.industrial_production_per_country,
|
||||
index_col=0) / 1e3
|
||||
production = (
|
||||
pd.read_csv(snakemake.input.industrial_production_per_country, index_col=0)
|
||||
/ 1e3
|
||||
)
|
||||
production = production.unstack().swaplevel()
|
||||
|
||||
# in MWh/t
|
||||
future_sector_ratios = pd.read_csv(snakemake.input.industry_sector_ratios,
|
||||
index_col=0)
|
||||
future_sector_ratios = pd.read_csv(
|
||||
snakemake.input.industry_sector_ratios, index_col=0
|
||||
)
|
||||
|
||||
production.index.names = [None, None]
|
||||
|
||||
today_sector_ratios = demand.div(production, axis=1)
|
||||
|
||||
today_sector_ratios.drop(columns=today_sector_ratios.columns[today_sector_ratios.isna().all()],
|
||||
inplace=True)
|
||||
today_sector_ratios.drop(
|
||||
columns=today_sector_ratios.columns[today_sector_ratios.isna().all()],
|
||||
inplace=True,
|
||||
)
|
||||
|
||||
rename = pd.Series(today_sector_ratios.index,
|
||||
today_sector_ratios.index)
|
||||
rename = pd.Series(today_sector_ratios.index, today_sector_ratios.index)
|
||||
rename["waste"] = "biomass"
|
||||
rename["electricity"] = "elec"
|
||||
rename["solid"] = "coke"
|
||||
@ -44,9 +50,7 @@ def build_industry_sector_ratios_intermediate():
|
||||
rename["other"] = "biomass"
|
||||
rename["liquid"] = "naphtha"
|
||||
|
||||
today_sector_ratios.rename(rename,
|
||||
inplace=True)
|
||||
|
||||
today_sector_ratios.rename(rename, inplace=True)
|
||||
|
||||
fraction_future = get(params["sector_ratios_fraction_future"], year)
|
||||
|
||||
@ -56,14 +60,22 @@ def build_industry_sector_ratios_intermediate():
|
||||
|
||||
intermediate_sector_ratio = future_sector_ratios.copy()
|
||||
|
||||
intermediate_sector_ratio.loc[today_sector_ratios[ct].index,today_sector_ratios[ct].columns] = (fraction_future*intermediate_sector_ratio.loc[today_sector_ratios[ct].index,today_sector_ratios[ct].columns]
|
||||
+ (1 - fraction_future)*today_sector_ratios[ct])
|
||||
intermediate_sector_ratio.loc[
|
||||
today_sector_ratios[ct].index, today_sector_ratios[ct].columns
|
||||
] = (
|
||||
fraction_future
|
||||
* intermediate_sector_ratio.loc[
|
||||
today_sector_ratios[ct].index, today_sector_ratios[ct].columns
|
||||
]
|
||||
+ (1 - fraction_future) * today_sector_ratios[ct]
|
||||
)
|
||||
intermediate_sector_ratios[ct] = intermediate_sector_ratio
|
||||
|
||||
intermediate_sector_ratios = pd.concat(intermediate_sector_ratios, axis=1)
|
||||
|
||||
intermediate_sector_ratios.to_csv(snakemake.output.industry_sector_ratios)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if "snakemake" not in globals():
|
||||
from _helpers import mock_snakemake
|
||||
|
Loading…
Reference in New Issue
Block a user