pypsa-eur/scripts/build_industrial_production_per_node.py
Toni Seibold 180d93951d
documentation for industry rules (#1086)
* documentation for industry rules

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-06-05 15:02:44 +02:00

98 lines
3.2 KiB
Python

# -*- coding: utf-8 -*-
# SPDX-FileCopyrightText: : 2020-2024 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Build industrial production per model region.
Inputs
-------
- ``resources/industrial_distribution_key_elec_s{simpl}_{clusters}.csv``
- ``resources/industrial_production_per_country_tomorrow_{planning_horizons}.csv``
Outputs
-------
- ``resources/industrial_production_per_node_elec_s{simpl}_{clusters}_{planning_horizons}.csv``
Description
-------
This rule maps the industrial production per country from a certain time horizon to each bus region.
The mapping file provides a value between 0 and 1 for each bus and industry subcategory, indicating the share of the country's production of that sector in that bus.
The industrial production per country is multiplied by the mapping value to get the industrial production per bus.
The unit of the production is kt/a.
"""
from itertools import product
import pandas as pd
from _helpers import set_scenario_config
# map JRC/our sectors to hotmaps sector, where mapping exist
sector_mapping = {
"Electric arc": "Iron and steel",
"Integrated steelworks": "Iron and steel",
"DRI + Electric arc": "Iron and steel",
"Ammonia": "Chemical industry",
"HVC": "Chemical industry",
"HVC (mechanical recycling)": "Chemical industry",
"HVC (chemical recycling)": "Chemical industry",
"Methanol": "Chemical industry",
"Chlorine": "Chemical industry",
"Other chemicals": "Chemical industry",
"Pharmaceutical products etc.": "Chemical industry",
"Cement": "Cement",
"Ceramics & other NMM": "Non-metallic mineral products",
"Glass production": "Glass",
"Pulp production": "Paper and printing",
"Paper production": "Paper and printing",
"Printing and media reproduction": "Paper and printing",
"Alumina production": "Non-ferrous metals",
"Aluminium - primary production": "Non-ferrous metals",
"Aluminium - secondary production": "Non-ferrous metals",
"Other non-ferrous metals": "Non-ferrous metals",
}
def build_nodal_industrial_production():
fn = snakemake.input.industrial_production_per_country_tomorrow
industrial_production = pd.read_csv(fn, index_col=0)
fn = snakemake.input.industrial_distribution_key
keys = pd.read_csv(fn, index_col=0)
keys["country"] = keys.index.str[:2]
nodal_production = pd.DataFrame(
index=keys.index, columns=industrial_production.columns, dtype=float
)
countries = keys.country.unique()
sectors = industrial_production.columns
for country, sector in product(countries, sectors):
buses = keys.index[keys.country == country]
mapping = sector_mapping.get(sector, "population")
key = keys.loc[buses, mapping]
nodal_production.loc[buses, sector] = (
industrial_production.at[country, sector] * key
)
nodal_production.to_csv(snakemake.output.industrial_production_per_node)
if __name__ == "__main__":
if "snakemake" not in globals():
from _helpers import mock_snakemake
snakemake = mock_snakemake(
"build_industrial_production_per_node",
simpl="",
clusters=48,
)
set_scenario_config(snakemake)
build_nodal_industrial_production()