2023-08-16 09:41:48 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2024-02-12 09:49:45 +00:00
|
|
|
# SPDX-FileCopyrightText: 2023-2024 The PyPSA-Eur Authors
|
2023-08-16 09:41:48 +00:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: MIT
|
|
|
|
"""
|
2024-02-12 09:49:45 +00:00
|
|
|
Retrieve electricity prices from OPSD.
|
2023-08-16 09:41:48 +00:00
|
|
|
"""
|
|
|
|
|
|
|
|
import logging
|
|
|
|
|
|
|
|
import pandas as pd
|
2024-02-12 10:53:20 +00:00
|
|
|
from _helpers import configure_logging, set_scenario_config
|
2023-08-16 09:41:48 +00:00
|
|
|
|
2024-05-21 13:28:24 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
2023-08-16 09:41:48 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
if "snakemake" not in globals():
|
|
|
|
from _helpers import mock_snakemake
|
|
|
|
|
2023-08-17 08:17:12 +00:00
|
|
|
snakemake = mock_snakemake("retrieve_electricity_demand")
|
2023-08-16 09:41:48 +00:00
|
|
|
rootpath = ".."
|
|
|
|
else:
|
|
|
|
rootpath = "."
|
|
|
|
configure_logging(snakemake)
|
2024-02-12 10:53:20 +00:00
|
|
|
set_scenario_config(snakemake)
|
2023-08-16 09:41:48 +00:00
|
|
|
|
|
|
|
url = "https://data.open-power-system-data.org/time_series/{version}/time_series_60min_singleindex.csv"
|
|
|
|
|
|
|
|
df1, df2 = [
|
2023-08-16 09:47:27 +00:00
|
|
|
pd.read_csv(url.format(version=version), index_col=0)
|
|
|
|
for version in snakemake.params.versions
|
2023-08-16 09:41:48 +00:00
|
|
|
]
|
2023-08-17 08:17:12 +00:00
|
|
|
combined = pd.concat([df1, df2[df2.index > df1.index[-1]]])
|
|
|
|
|
|
|
|
pattern = "_load_actual_entsoe_transparency"
|
|
|
|
transparency = combined.filter(like=pattern).rename(
|
|
|
|
columns=lambda x: x.replace(pattern, "")
|
|
|
|
)
|
|
|
|
pattern = "_load_actual_entsoe_power_statistics"
|
|
|
|
powerstatistics = combined.filter(like=pattern).rename(
|
|
|
|
columns=lambda x: x.replace(pattern, "")
|
|
|
|
)
|
|
|
|
|
|
|
|
res = transparency.fillna(powerstatistics)
|
|
|
|
|
2023-08-16 09:41:48 +00:00
|
|
|
res.to_csv(snakemake.output[0])
|