2023-04-30 08:52:58 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2022-07-29 11:38:21 +00:00
|
|
|
# SPDX-FileCopyrightText: 2022 The PyPSA-Eur Authors
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: MIT
|
2023-04-30 08:52:58 +00:00
|
|
|
"""
|
|
|
|
This rule downloads the load data.
|
|
|
|
"""
|
2022-07-29 11:38:21 +00:00
|
|
|
|
|
|
|
import logging
|
|
|
|
|
2023-04-30 08:52:58 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
2022-07-29 11:38:21 +00:00
|
|
|
import pandas as pd
|
2023-04-30 08:52:58 +00:00
|
|
|
from _helpers import configure_logging
|
2022-07-29 11:38:21 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2023-04-30 08:52:58 +00:00
|
|
|
if "snakemake" not in globals():
|
2022-07-29 11:38:21 +00:00
|
|
|
from _helpers import mock_snakemake
|
2023-04-30 08:52:58 +00:00
|
|
|
|
|
|
|
snakemake = mock_snakemake("build_artificial_load_data", weather_year="")
|
2022-07-29 11:38:21 +00:00
|
|
|
|
|
|
|
configure_logging(snakemake)
|
|
|
|
|
|
|
|
weather_year = snakemake.wildcards.weather_year
|
|
|
|
if weather_year:
|
|
|
|
snapshots = dict(
|
2023-04-30 08:52:58 +00:00
|
|
|
start=weather_year, end=str(int(weather_year) + 1), inclusive="left"
|
2022-07-29 11:38:21 +00:00
|
|
|
)
|
|
|
|
else:
|
2023-04-30 08:52:58 +00:00
|
|
|
snapshots = snakemake.config["snapshots"]
|
|
|
|
snapshots = pd.date_range(freq="h", **snapshots)
|
2022-07-29 11:38:21 +00:00
|
|
|
|
|
|
|
fixed_year = snakemake.config["load"].get("fixed_year", False)
|
2023-04-30 08:52:58 +00:00
|
|
|
years = (
|
|
|
|
slice(str(fixed_year), str(fixed_year))
|
|
|
|
if fixed_year
|
|
|
|
else slice(snapshots[0], snapshots[-1])
|
|
|
|
)
|
|
|
|
countries = snakemake.config["countries"]
|
|
|
|
|
|
|
|
load = pd.read_csv(snakemake.input[0], index_col=0, parse_dates=True).loc[
|
|
|
|
snapshots, countries
|
|
|
|
]
|
|
|
|
|
|
|
|
assert not load.isna().any().any(), "Load data contains nans."
|
2022-07-29 11:38:21 +00:00
|
|
|
|
|
|
|
if fixed_year:
|
|
|
|
load.index = load.index.map(lambda t: t.replace(year=snapshots.year[0]))
|
|
|
|
|
|
|
|
load.to_csv(snakemake.output[0])
|