pypsa-eur/scripts/build_ammonia_production.py
Tom Brown ecedea02d6 bugfix: include all countries in ammonia production resource
This is so that the full EU28 ammonia demand can be correctly
subtracted in the build_industry_sector_ratios.py script.

No other downstream scripts are affected by this change.
2024-02-14 18:28:22 +01:00

47 lines
1.0 KiB
Python

# -*- coding: utf-8 -*-
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Build historical annual ammonia production per country in ktonNH3/a.
"""
import country_converter as coco
import pandas as pd
import numpy as np
cc = coco.CountryConverter()
if __name__ == "__main__":
if "snakemake" not in globals():
from _helpers import mock_snakemake
snakemake = mock_snakemake("build_ammonia_production")
ammonia = pd.read_excel(
snakemake.input.usgs,
sheet_name="T12",
skiprows=5,
header=0,
index_col=0,
skipfooter=19,
)
ammonia.index = cc.convert(ammonia.index, to="iso2")
years = [str(i) for i in range(2013, 2018)]
ammonia = ammonia[years]
ammonia.replace("--",
np.nan,
inplace=True)
ammonia = ammonia.astype(float)
# convert from ktonN to ktonNH3
ammonia *= 17 / 14
ammonia.index.name = "ktonNH3/a"
ammonia.to_csv(snakemake.output.ammonia_production)