pypsa-eur/scripts/build_population_weighted_energy_totals.py
Fabian Neumann 013b705ee4
Clustering: build renewable profiles and add all assets after clustering (#1201)
* Cluster first: build renewable profiles and add all assets after clustering

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* correction: pass landfall_lengths through functions

* assign landfall_lenghts correctly

* remove parameter add_land_use_constraint

* fix network_dict

* calculate distance to shoreline, remove underwater_fraction

* adjust simplification parameter to exclude Crete from offshore wind connections

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* remove unused geth2015 hydro capacities

* removing remaining traces of {simpl} wildcard

* add release notes and update workflow graphics

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: lisazeyen <lisa.zeyen@web.de>
2024-09-13 15:37:01 +02:00

42 lines
1.3 KiB
Python

# -*- coding: utf-8 -*-
# SPDX-FileCopyrightText: : 2020-2024 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Distribute country-level energy demands by population.
"""
import pandas as pd
from _helpers import set_scenario_config
if __name__ == "__main__":
if "snakemake" not in globals():
from _helpers import mock_snakemake
snakemake = mock_snakemake(
"build_population_weighted_energy_totals",
kind="heat",
clusters=60,
)
set_scenario_config(snakemake)
config = snakemake.config["energy"]
if snakemake.wildcards.kind == "heat":
years = pd.date_range(freq="h", **snakemake.params.snapshots).year.unique()
assert len(years) == 1, "Currently only works for single year."
data_year = years[0]
else:
data_year = int(config["energy_totals_year"])
pop_layout = pd.read_csv(snakemake.input.clustered_pop_layout, index_col=0)
totals = pd.read_csv(snakemake.input.energy_totals, index_col=[0, 1])
totals = totals.xs(data_year, level="year")
nodal_totals = totals.loc[pop_layout.ct].fillna(0.0)
nodal_totals.index = pop_layout.index
nodal_totals = nodal_totals.multiply(pop_layout.fraction, axis=0)
nodal_totals.to_csv(snakemake.output[0])