2017-12-18 19:34:15 +00:00
|
|
|
|
#!/usr/bin/env python
|
2022-09-16 13:04:04 +00:00
|
|
|
|
# -*- coding: utf-8 -*-
|
2020-05-29 07:50:55 +00:00
|
|
|
|
|
2024-02-19 15:21:48 +00:00
|
|
|
|
# SPDX-FileCopyrightText: : 2017-2024 The PyPSA-Eur Authors
|
2020-05-29 07:50:55 +00:00
|
|
|
|
#
|
2021-09-14 14:37:41 +00:00
|
|
|
|
# SPDX-License-Identifier: MIT
|
2019-08-08 13:02:28 +00:00
|
|
|
|
"""
|
2022-09-16 13:20:10 +00:00
|
|
|
|
Extracts capacities of HVDC links from `Wikipedia.
|
|
|
|
|
|
2022-09-16 13:04:04 +00:00
|
|
|
|
<https://en.wikipedia.org/wiki/List_of_HVDC_projects>`_.
|
2019-08-11 09:40:47 +00:00
|
|
|
|
|
|
|
|
|
Relevant Settings
|
|
|
|
|
-----------------
|
|
|
|
|
|
2019-08-11 20:34:18 +00:00
|
|
|
|
.. code:: yaml
|
|
|
|
|
|
|
|
|
|
enable:
|
|
|
|
|
prepare_links_p_nom:
|
2019-08-11 11:17:36 +00:00
|
|
|
|
|
2019-11-14 16:50:24 +00:00
|
|
|
|
.. seealso::
|
2023-04-21 08:41:44 +00:00
|
|
|
|
Documentation of the configuration file ``config/config.yaml`` at
|
2019-08-13 08:03:46 +00:00
|
|
|
|
:ref:`toplevel_cf`
|
|
|
|
|
|
2019-08-11 09:40:47 +00:00
|
|
|
|
Inputs
|
|
|
|
|
------
|
|
|
|
|
|
2019-08-11 20:34:18 +00:00
|
|
|
|
*None*
|
|
|
|
|
|
2019-08-11 09:40:47 +00:00
|
|
|
|
Outputs
|
|
|
|
|
-------
|
|
|
|
|
|
2019-08-11 20:34:18 +00:00
|
|
|
|
- ``data/links_p_nom.csv``: A plain download of https://en.wikipedia.org/wiki/List_of_HVDC_projects#Europe plus extracted coordinates.
|
|
|
|
|
|
2019-08-11 09:40:47 +00:00
|
|
|
|
Description
|
|
|
|
|
-----------
|
|
|
|
|
|
2019-08-11 20:34:18 +00:00
|
|
|
|
*None*
|
2019-08-08 13:02:28 +00:00
|
|
|
|
"""
|
2017-12-18 19:34:15 +00:00
|
|
|
|
|
2019-11-28 07:22:52 +00:00
|
|
|
|
import logging
|
|
|
|
|
|
2017-12-18 19:34:15 +00:00
|
|
|
|
import pandas as pd
|
2023-08-15 13:02:41 +00:00
|
|
|
|
from _helpers import configure_logging, set_scenario_config
|
2017-12-18 19:34:15 +00:00
|
|
|
|
|
2020-12-03 18:50:53 +00:00
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def multiply(s):
|
|
|
|
|
return s.str[0].astype(float) * s.str[1].astype(float)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def extract_coordinates(s):
|
2022-09-16 13:04:04 +00:00
|
|
|
|
regex = (
|
|
|
|
|
r"(\d{1,2})°(\d{1,2})′(\d{1,2})″(N|S) " r"(\d{1,2})°(\d{1,2})′(\d{1,2})″(E|W)"
|
|
|
|
|
)
|
2020-12-03 18:50:53 +00:00
|
|
|
|
e = s.str.extract(regex, expand=True)
|
2022-09-16 13:04:04 +00:00
|
|
|
|
lat = (
|
|
|
|
|
e[0].astype(float) + (e[1].astype(float) + e[2].astype(float) / 60.0) / 60.0
|
|
|
|
|
) * e[3].map({"N": +1.0, "S": -1.0})
|
|
|
|
|
lon = (
|
|
|
|
|
e[4].astype(float) + (e[5].astype(float) + e[6].astype(float) / 60.0) / 60.0
|
|
|
|
|
) * e[7].map({"E": +1.0, "W": -1.0})
|
2020-12-03 18:50:53 +00:00
|
|
|
|
return lon, lat
|
|
|
|
|
|
|
|
|
|
|
2019-08-08 13:02:28 +00:00
|
|
|
|
if __name__ == "__main__":
|
2022-09-16 13:04:04 +00:00
|
|
|
|
if "snakemake" not in globals():
|
|
|
|
|
from _helpers import mock_snakemake # rule must be enabled in config
|
|
|
|
|
|
2024-03-04 16:48:56 +00:00
|
|
|
|
snakemake = mock_snakemake("prepare_links_p_nom", simpl="")
|
2019-11-28 07:22:52 +00:00
|
|
|
|
configure_logging(snakemake)
|
2023-08-15 13:02:41 +00:00
|
|
|
|
set_scenario_config(snakemake)
|
2019-11-28 07:22:52 +00:00
|
|
|
|
|
2022-09-16 13:04:04 +00:00
|
|
|
|
links_p_nom = pd.read_html(
|
|
|
|
|
"https://en.wikipedia.org/wiki/List_of_HVDC_projects", header=0, match="SwePol"
|
|
|
|
|
)[0]
|
2017-12-18 19:34:15 +00:00
|
|
|
|
|
2020-12-03 18:50:53 +00:00
|
|
|
|
mw = "Power (MW)"
|
2022-09-16 13:04:04 +00:00
|
|
|
|
m_b = links_p_nom[mw].str.contains("x").fillna(False)
|
|
|
|
|
|
|
|
|
|
links_p_nom.loc[m_b, mw] = links_p_nom.loc[m_b, mw].str.split("x").pipe(multiply)
|
|
|
|
|
links_p_nom[mw] = (
|
|
|
|
|
links_p_nom[mw].str.extract("[-/]?([\d.]+)", expand=False).astype(float)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
links_p_nom["x1"], links_p_nom["y1"] = extract_coordinates(
|
|
|
|
|
links_p_nom["Converterstation 1"]
|
|
|
|
|
)
|
|
|
|
|
links_p_nom["x2"], links_p_nom["y2"] = extract_coordinates(
|
|
|
|
|
links_p_nom["Converterstation 2"]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
links_p_nom.dropna(subset=["x1", "y1", "x2", "y2"]).to_csv(
|
|
|
|
|
snakemake.output[0], index=False
|
|
|
|
|
)
|