2023-03-06 08:27:45 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2023-03-06 17:49:23 +00:00
|
|
|
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: MIT
|
2023-03-06 08:27:45 +00:00
|
|
|
"""
|
2023-03-09 11:45:43 +00:00
|
|
|
Distribute country-level energy demands by population.
|
2023-03-06 08:27:45 +00:00
|
|
|
"""
|
2022-04-03 16:49:35 +00:00
|
|
|
|
|
|
|
import pandas as pd
|
|
|
|
|
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
|
|
|
|
2022-04-03 16:49:35 +00:00
|
|
|
snakemake = mock_snakemake(
|
2023-03-06 08:27:45 +00:00
|
|
|
"build_population_weighted_energy_totals",
|
2023-04-29 16:49:49 +00:00
|
|
|
weather_year="",
|
2023-03-06 08:27:45 +00:00
|
|
|
simpl="",
|
2022-04-03 16:49:35 +00:00
|
|
|
clusters=48,
|
|
|
|
)
|
|
|
|
|
2022-07-25 12:35:54 +00:00
|
|
|
config = snakemake.config["energy"]
|
|
|
|
data_year = int(config["energy_totals_year"])
|
2023-04-30 08:52:58 +00:00
|
|
|
if snakemake.wildcards.weather_year and snakemake.wildcards.kind == "heat":
|
2022-07-25 12:35:54 +00:00
|
|
|
data_year = int(snakemake.wildcards.weather_year)
|
|
|
|
|
2022-04-03 16:49:35 +00:00
|
|
|
pop_layout = pd.read_csv(snakemake.input.clustered_pop_layout, index_col=0)
|
|
|
|
|
2023-04-30 08:52:58 +00:00
|
|
|
totals = pd.read_csv(snakemake.input.totals, index_col=[0, 1])
|
|
|
|
totals = totals.xs(data_year, level="year")
|
2022-04-03 16:49:35 +00:00
|
|
|
|
2023-04-30 08:52:58 +00:00
|
|
|
nodal_totals = totals.loc[pop_layout.ct].fillna(0.0)
|
2022-07-25 12:35:54 +00:00
|
|
|
nodal_totals.index = pop_layout.index
|
|
|
|
nodal_totals = nodal_totals.multiply(pop_layout.fraction, axis=0)
|
2022-04-03 16:49:35 +00:00
|
|
|
|
2022-07-25 12:35:54 +00:00
|
|
|
nodal_totals.to_csv(snakemake.output[0])
|