Merge branch 'master' into configs-in-one-folder

This commit is contained in:
Fabian 2023-04-21 10:26:45 +02:00
commit e40011cb3c
53 changed files with 54 additions and 79 deletions

View File

@ -39,7 +39,7 @@ repos:
# Make docstrings PEP 257 compliant
- repo: https://github.com/PyCQA/docformatter
rev: v1.6.0
rev: v1.6.1-rc1
hooks:
- id: docformatter
args: ["--in-place", "--make-summary-multi-line", "--pre-summary-newline"]

View File

@ -464,7 +464,7 @@ sector:
solar_cf_correction: 0.788457 # = >>> 1/1.2683
marginal_cost_storage: 0. #1e-4
methanation: true
helmeth: true
helmeth: false
coal_cc: false
dac: true
co2_vent: false

View File

@ -86,13 +86,13 @@ Rule ``build_powerplants``
.. automodule:: build_powerplants
.. _load_data:
.. _electricity_demand:
Rule ``build_load_data``
Rule ``build_electricity_demand``
=============================
.. automodule:: build_load_data
.. automodule:: build_electricity_demand
.. _ship:

View File

@ -12,6 +12,8 @@ Upcoming Release
* Bugfix: Correct typo in the CPLEX solver configuration in ``config.default.yaml``.
* Renamed script file from PyPSA-EUR ``build_load_data`` to ``build_electricity_demand``.
PyPSA-Eur 0.8.0 (18th March 2023)
=================================
@ -558,7 +560,7 @@ More OPSD integration:
This will overwrite the capacities calculated from the heuristic approach in :func:`estimate_renewable_capacities()`
[`#212 <https://github.com/PyPSA/pypsa-eur/pull/212>`_].
* Electricity consumption data is now retrieved directly from the `OPSD website <https://data.open-power-system-data.org/time_series/2019-06-05>`_ using the rule :mod:`build_load_data`.
* Electricity consumption data is now retrieved directly from the `OPSD website <https://data.open-power-system-data.org/time_series/2019-06-05>`_ using the rule :mod:`build_electricity_demand`.
The user can decide whether to take the ENTSO-E power statistics data (default) or the ENTSO-E transparency data
[`#211 <https://github.com/PyPSA/pypsa-eur/pull/211>`_].

View File

@ -155,7 +155,7 @@ This triggers a workflow of multiple preceding jobs that depend on each rule's i
19[label = "build_hydro_profile", color = "0.44 0.6 0.85", style="rounded"];
20[label = "retrieve_cost_data", color = "0.30 0.6 0.85", style="rounded"];
21[label = "build_powerplants", color = "0.16 0.6 0.85", style="rounded"];
22[label = "build_load_data", color = "0.00 0.6 0.85", style="rounded"];
22[label = "build_electricity_demand", color = "0.00 0.6 0.85", style="rounded"];
23[label = "retrieve_load_data", color = "0.34 0.6 0.85", style="rounded,dashed"];
1 -> 0
2 -> 1
@ -232,7 +232,7 @@ In the terminal, this will show up as a list of jobs to be run:
base_network 1 1 1
build_bus_regions 1 1 1
build_hydro_profile 1 1 1
build_load_data 1 1 1
build_electricity_demand 1 1 1
build_powerplants 1 1 1
build_renewable_profiles 4 1 1
build_shapes 1 1 1

View File

@ -140,7 +140,7 @@ successfully.
18[label = "retrieve_ship_raster", color = "0.15 0.6 0.85", style="rounded"];
19[label = "retrieve_cost_data", color = "0.50 0.6 0.85", style="rounded"];
20[label = "build_powerplants", color = "0.49 0.6 0.85", style="rounded"];
21[label = "build_load_data", color = "0.39 0.6 0.85", style="rounded"];
21[label = "build_electricity_demand", color = "0.39 0.6 0.85", style="rounded"];
22[label = "retrieve_load_data", color = "0.05 0.6 0.85", style="rounded"];
23[label = "build_gas_input_locations", color = "0.45 0.6 0.85", style="rounded"];
24[label = "prepare_network", color = "0.31 0.6 0.85", style="rounded"];
@ -367,7 +367,7 @@ implemented in the workflow:
18[label = "retrieve_ship_raster", color = "0.09 0.6 0.85", style="rounded"];
19[label = "retrieve_cost_data", color = "0.04 0.6 0.85", style="rounded"];
20[label = "build_powerplants", color = "0.28 0.6 0.85", style="rounded"];
21[label = "build_load_data", color = "0.46 0.6 0.85", style="rounded"];
21[label = "build_electricity_demand", color = "0.46 0.6 0.85", style="rounded"];
22[label = "retrieve_load_data", color = "0.44 0.6 0.85", style="rounded"];
23[label = "build_energy_totals", color = "0.53 0.6 0.85", style="rounded"];
24[label = "build_population_weighted_energy_totals", color = "0.03 0.6 0.85", style="rounded"];

View File

@ -287,11 +287,14 @@ dependencies:
- qt-main=5.15.8
- rasterio=1.3.4
- readline=8.1.2
- requests=2.28.2
- reretry=0.11.8
- rtree=1.0.1
- scikit-learn=1.2.1
- scipy=1.10.0
- requests=2.28.1
- retry=0.9.2
- rich=12.5.1
- rioxarray=0.13.3
- rtree=1.0.0
- s2n=1.0.10
- scikit-learn=1.1.1
- scipy=1.8.1
- scotch=6.0.9
- seaborn=0.12.2
- seaborn-base=0.12.2

View File

@ -29,6 +29,7 @@ dependencies:
- pandas>=1.4
- geopandas>=0.11.0
- xarray
- rioxarray
- netcdf4
- networkx
- scipy

View File

@ -18,19 +18,19 @@ if config["enable"].get("prepare_links_p_nom", False):
"../scripts/prepare_links_p_nom.py"
rule build_load_data:
rule build_electricity_demand:
input:
ancient("data/load_raw.csv"),
output:
RESOURCES + "load.csv",
log:
LOGS + "build_load_data.log",
LOGS + "build_electricity_demand.log",
resources:
mem_mb=5000,
conda:
"../envs/environment.yaml"
script:
"../scripts/build_load_data.py"
"../scripts/build_electricity_demand.py"
rule build_powerplants:
@ -172,7 +172,7 @@ rule build_ship_raster:
],
),
output:
RESOURCES + "shipdensity_raster.nc",
RESOURCES + "shipdensity_raster.tif",
log:
LOGS + "build_ship_raster.log",
resources:
@ -202,7 +202,7 @@ rule build_renewable_profiles:
)
),
ship_density=lambda w: (
RESOURCES + "shipdensity_raster.nc"
RESOURCES + "shipdensity_raster.tif"
if "ship_threshold" in config["renewable"][w.technology].keys()
else []
),

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Prepares brownfield data from previous planning horizon.
"""

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Adds existing power and heat generation capacities for initial planning
horizon.

View File

@ -197,7 +197,7 @@ def convert_nuts2_to_regions(bio_nuts2, regions):
)
overlay[adjust_cols] = overlay[adjust_cols].multiply(overlay["share"], axis=0)
bio_regions = overlay.groupby("name").sum()
bio_regions = overlay.dissolve("name", aggfunc="sum")
bio_regions.drop(["area_nuts2", "share"], axis=1, inplace=True)

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Reads biomass transport costs for different countries of the JRC report.

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Creates Voronoi shapes for each bus representing both onshore and offshore
regions.

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Build population layouts for all clustered model regions as total as well as
split by urban and rural population.

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Build coefficient of performance (COP) time series for air- or ground-sourced
heat pumps.

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Create cutouts with `atlite <https://atlite.readthedocs.io/en/latest/>`_.

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020 @JanFrederickUnnewehr, The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
This rule downloads the load data from `Open Power System Data Time series.
@ -276,7 +275,7 @@ if __name__ == "__main__":
if "snakemake" not in globals():
from _helpers import mock_snakemake
snakemake = mock_snakemake("build_load_data")
snakemake = mock_snakemake("build_electricity_demand")
configure_logging(snakemake)

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Build total energy demands per country using JRC IDEES, eurostat, and EEA data.
"""

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2021-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Build import locations for fossil gas from entry-points, LNG terminals and
production sites with data from SciGRID_gas and Global Energy Monitor.

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Preprocess gas network based on data from bthe SciGRID_gas project
(https://www.gas.scigrid.de/).

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Build heat demand time series using heating degree day (HDD) approximation.
"""

View File

@ -4,7 +4,6 @@
# SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Build hydroelectric inflow time-series for each country.

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Build spatial distribution of industries from Hotmaps database.
"""

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Build industrial energy demand per country.
"""

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Build industrial energy demand per model region.
"""

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Build industrial energy demand per model region.
"""

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Build industrial production per country.
"""

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Build future industrial production per country.
"""

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Build industrial production per model region.
"""

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Build specific energy consumption by carrier and industries.
"""

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Rasters the vector data of the `Natura 2000.

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Build mapping between cutout grid cells and population (total, urban, rural).
"""

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Distribute country-level energy demands by population.
"""

View File

@ -4,7 +4,6 @@
# SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Calculates for each network node the (i) installable capacity (based on land-
use), (ii) the available generation time series (based on weather data), and

View File

@ -3,7 +3,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
This script calculates the space heating savings through better insulation of
the thermal envelope of a building and corresponding costs for different

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Build salt cavern potentials for hydrogen storage.

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Build regionalised geological sequestration potential for carbon dioxide using
data from `CO2Stop <https://setis.ec.europa.eu/european-co2-storage-

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Creates GIS shape files of the countries, exclusive economic zones and `NUTS3 <
https://en.wikipedia.org/wiki/Nomenclature_of_Territorial_Units_for_Statistics>

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2022 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Transforms the global ship density data from the `World Bank Data Catalogue.
@ -46,7 +45,7 @@ import logging
import os
import zipfile
import xarray as xr
import rioxarray
from _helpers import configure_logging
from build_natura_raster import determine_cutout_xXyY
@ -64,10 +63,10 @@ if __name__ == "__main__":
with zipfile.ZipFile(snakemake.input.ship_density) as zip_f:
zip_f.extract("shipdensity_global.tif")
with xr.open_rasterio("shipdensity_global.tif") as ship_density:
with rioxarray.open_rasterio("shipdensity_global.tif") as ship_density:
ship_density = ship_density.drop(["band"]).sel(
x=slice(min(xs), max(Xs)), y=slice(max(Ys), min(ys))
)
ship_density.to_netcdf(snakemake.output[0])
ship_density.rio.to_raster(snakemake.output[0])
os.remove("shipdensity_global.tif")

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Build solar thermal collector time series.
"""

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Build time series for air and soil temperatures per clustered model region.
"""

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Build land transport demand per clustered model region including efficiency
improvements due to drivetrain changes, time series for electric vehicle

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Cluster gas transmission network to clustered model regions.
"""

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Copy used configuration files and important scripts for archiving.
"""

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Create summary CSV files for all scenario runs including costs, capacities,
capacity factors, curtailment, energy balances, prices and other metrics.

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Creates plots for optimised network topologies, including electricity, gas and
hydrogen networks, and regional generation, storage and conversion capacities

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Creates plots from summary CSV files.
"""

View File

@ -4,7 +4,6 @@
# SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Extracts capacities of HVDC links from `Wikipedia.

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Adds all sector-coupling components to the network, including demand and supply
technologies for the buildings, transport and industry sectors.

View File

@ -3,7 +3,6 @@
# SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
.. image:: https://zenodo.org/badge/DOI/10.5281/zenodo.3517935.svg
:target: https://doi.org/10.5281/zenodo.3517935

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Solves optimal operation and capacity for a network with the option to
iteratively optimize while updating line reactances.
@ -43,6 +42,7 @@ from vresutils.benchmark import memory_logger
logger = logging.getLogger(__name__)
pypsa.pf.logger.setLevel(logging.WARNING)
from pypsa.descriptors import get_switchable_as_dense as get_as_dense
def add_land_use_constraint(n, config):
@ -414,7 +414,7 @@ def add_operational_reserve_margin(n, sns, config):
0, np.inf, coords=[sns, n.generators.index], name="Generator-r"
)
reserve = n.model["Generator-r"]
lhs = reserve.sum("Generator")
summed_reserve = reserve.sum("Generator")
# Share of extendable renewable capacities
ext_i = n.generators.query("p_nom_extendable").index
@ -426,10 +426,12 @@ def add_operational_reserve_margin(n, sns, config):
.loc[vres_i.intersection(ext_i)]
.rename({"Generator-ext": "Generator"})
)
lhs = lhs + (p_nom_vres * (-EPSILON_VRES * capacity_factor)).sum()
lhs = summed_reserve + (p_nom_vres * (-EPSILON_VRES * capacity_factor)).sum(
"Generator"
)
# Total demand per t
demand = n.loads_t.p_set.sum(axis=1)
demand = get_as_dense(n, "Load", "p_set").sum(axis=1)
# VRES potential of non extendable generators
capacity_factor = n.generators_t.p_max_pu[vres_i.difference(ext_i)]
@ -441,17 +443,26 @@ def add_operational_reserve_margin(n, sns, config):
n.model.add_constraints(lhs >= rhs, name="reserve_margin")
# additional constraint that capacity is not exceeded
gen_i = n.generators.index
ext_i = n.generators.query("p_nom_extendable").index
fix_i = n.generators.query("not p_nom_extendable").index
dispatch = n.model["Generator-p"]
reserve = n.model["Generator-r"]
lhs = n.model.constraints["Generator-fix-p-upper"].lhs
lhs = lhs + reserve.loc[:, lhs.coords["Generator-fix"]].drop("Generator")
rhs = n.model.constraints["Generator-fix-p-upper"].rhs
n.model.add_constraints(lhs <= rhs, name="Generator-fix-p-upper-reserve")
capacity_variable = n.model["Generator-p_nom"].rename(
{"Generator-ext": "Generator"}
)
capacity_fixed = n.generators.p_nom[fix_i]
lhs = n.model.constraints["Generator-ext-p-upper"].lhs
lhs = lhs + reserve.loc[:, lhs.coords["Generator-ext"]].drop("Generator")
rhs = n.model.constraints["Generator-ext-p-upper"].rhs
n.model.add_constraints(lhs >= rhs, name="Generator-ext-p-upper-reserve")
p_max_pu = get_as_dense(n, "Generator", "p_max_pu")
lhs = dispatch + reserve - capacity_variable * p_max_pu[ext_i]
rhs = (p_max_pu[fix_i] * capacity_fixed).reindex(columns=gen_i, fill_value=0)
n.model.add_constraints(lhs <= rhs, name="Generator-p-reserve-upper")
def add_battery_constraints(n):

View File

@ -2,7 +2,6 @@
# SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors
#
# SPDX-License-Identifier: MIT
"""
Solves linear optimal dispatch in hourly resolution using the capacities of
previous capacity expansion in rule :mod:`solve_network`.