2023-03-06 08:27:45 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2024-02-19 15:21:48 +00:00
|
|
|
# SPDX-FileCopyrightText: : 2020-2024 The PyPSA-Eur Authors
|
2023-03-06 17:49:23 +00:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: MIT
|
2023-03-06 08:27:45 +00:00
|
|
|
"""
|
2023-03-09 11:45:43 +00:00
|
|
|
Build historical annual ammonia production per country in ktonNH3/a.
|
2024-06-05 13:02:44 +00:00
|
|
|
|
|
|
|
Inputs
|
|
|
|
-------
|
|
|
|
|
|
|
|
- ``data/bundle-sector/myb1-2017-nitro.xls``
|
|
|
|
|
|
|
|
Outputs
|
|
|
|
-------
|
|
|
|
|
|
|
|
- ``resources/ammonia_production.csv``
|
|
|
|
|
|
|
|
Description
|
|
|
|
-------
|
|
|
|
|
2024-07-29 13:44:30 +00:00
|
|
|
This functions takes data from the `Minerals Yearbook <https://www.usgs.gov/centers/national-minerals-information-center/nitrogen-statistics-and-information>`_
|
|
|
|
(July 2024) published by the US Geological Survey (USGS) and the National Minerals Information Center and extracts the annual ammonia production per country in ktonN/a. The data is converted to ktonNH3/a.
|
2023-03-06 08:27:45 +00:00
|
|
|
"""
|
2020-08-28 17:13:18 +00:00
|
|
|
|
2023-03-09 10:04:41 +00:00
|
|
|
import country_converter as coco
|
2023-03-09 10:39:57 +00:00
|
|
|
import pandas as pd
|
2024-02-12 10:53:20 +00:00
|
|
|
from _helpers import set_scenario_config
|
|
|
|
|
2023-03-09 10:04:41 +00:00
|
|
|
cc = coco.CountryConverter()
|
2020-08-28 17:13:18 +00:00
|
|
|
|
|
|
|
|
2023-03-06 08:27:45 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
if "snakemake" not in globals():
|
2023-03-06 18:09:45 +00:00
|
|
|
from _helpers import mock_snakemake
|
2023-03-06 08:27:45 +00:00
|
|
|
|
|
|
|
snakemake = mock_snakemake("build_ammonia_production")
|
|
|
|
|
2024-02-12 10:53:20 +00:00
|
|
|
set_scenario_config(snakemake)
|
|
|
|
|
2023-03-06 08:27:45 +00:00
|
|
|
ammonia = pd.read_excel(
|
|
|
|
snakemake.input.usgs,
|
|
|
|
sheet_name="T12",
|
|
|
|
skiprows=5,
|
|
|
|
header=0,
|
|
|
|
index_col=0,
|
2024-07-29 14:09:38 +00:00
|
|
|
skipfooter=7,
|
2024-02-16 11:13:35 +00:00
|
|
|
na_values=["--"],
|
2023-03-06 08:27:45 +00:00
|
|
|
)
|
2021-07-01 18:09:04 +00:00
|
|
|
|
2023-03-09 10:39:57 +00:00
|
|
|
ammonia.index = cc.convert(ammonia.index, to="iso2")
|
2020-08-28 17:13:18 +00:00
|
|
|
|
2024-07-29 14:09:38 +00:00
|
|
|
years = [str(i) for i in range(2018, 2023)]
|
2024-02-12 17:17:53 +00:00
|
|
|
|
2024-07-29 13:44:30 +00:00
|
|
|
ammonia = ammonia.rename(columns=lambda x: str(x))[years]
|
2020-08-28 17:13:18 +00:00
|
|
|
|
2021-07-01 18:09:04 +00:00
|
|
|
# convert from ktonN to ktonNH3
|
|
|
|
ammonia *= 17 / 14
|
2020-08-28 17:13:18 +00:00
|
|
|
|
2021-07-01 18:09:04 +00:00
|
|
|
ammonia.index.name = "ktonNH3/a"
|
2020-08-28 17:13:18 +00:00
|
|
|
|
2021-07-01 18:09:04 +00:00
|
|
|
ammonia.to_csv(snakemake.output.ammonia_production)
|