diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7e2f1149..4279b96a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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"] diff --git a/configs/config.default.yaml b/configs/config.default.yaml index 5218bc22..1305456a 100644 --- a/configs/config.default.yaml +++ b/configs/config.default.yaml @@ -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 diff --git a/doc/preparation.rst b/doc/preparation.rst index a180bb0d..b5a12062 100644 --- a/doc/preparation.rst +++ b/doc/preparation.rst @@ -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: diff --git a/doc/release_notes.rst b/doc/release_notes.rst index e668e92e..3d05f27c 100644 --- a/doc/release_notes.rst +++ b/doc/release_notes.rst @@ -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 `_]. -* Electricity consumption data is now retrieved directly from the `OPSD website `_ using the rule :mod:`build_load_data`. +* Electricity consumption data is now retrieved directly from the `OPSD website `_ 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 `_]. diff --git a/doc/tutorial.rst b/doc/tutorial.rst index b6f5311b..82ccc55a 100644 --- a/doc/tutorial.rst +++ b/doc/tutorial.rst @@ -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 diff --git a/doc/tutorial_sector.rst b/doc/tutorial_sector.rst index 1d8e8ba5..1cbd6779 100644 --- a/doc/tutorial_sector.rst +++ b/doc/tutorial_sector.rst @@ -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"]; diff --git a/envs/environment.fixed.yaml b/envs/environment.fixed.yaml index 516e5ec5..7d8fcc45 100644 --- a/envs/environment.fixed.yaml +++ b/envs/environment.fixed.yaml @@ -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 diff --git a/envs/environment.yaml b/envs/environment.yaml index db533bad..0a9891a5 100644 --- a/envs/environment.yaml +++ b/envs/environment.yaml @@ -29,6 +29,7 @@ dependencies: - pandas>=1.4 - geopandas>=0.11.0 - xarray +- rioxarray - netcdf4 - networkx - scipy diff --git a/rules/build_electricity.smk b/rules/build_electricity.smk index 9be7408d..133ceb6e 100644 --- a/rules/build_electricity.smk +++ b/rules/build_electricity.smk @@ -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 [] ), diff --git a/scripts/add_brownfield.py b/scripts/add_brownfield.py index dc782838..e08b86d7 100644 --- a/scripts/add_brownfield.py +++ b/scripts/add_brownfield.py @@ -2,7 +2,6 @@ # SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors # # SPDX-License-Identifier: MIT - """ Prepares brownfield data from previous planning horizon. """ diff --git a/scripts/add_existing_baseyear.py b/scripts/add_existing_baseyear.py index 992f3f98..5bc0960d 100644 --- a/scripts/add_existing_baseyear.py +++ b/scripts/add_existing_baseyear.py @@ -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. diff --git a/scripts/build_biomass_potentials.py b/scripts/build_biomass_potentials.py index 50f2583c..21d0e623 100644 --- a/scripts/build_biomass_potentials.py +++ b/scripts/build_biomass_potentials.py @@ -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) diff --git a/scripts/build_biomass_transport_costs.py b/scripts/build_biomass_transport_costs.py index 8b6b6927..9271b600 100644 --- a/scripts/build_biomass_transport_costs.py +++ b/scripts/build_biomass_transport_costs.py @@ -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. diff --git a/scripts/build_bus_regions.py b/scripts/build_bus_regions.py index f1a0558a..cfbf90f7 100644 --- a/scripts/build_bus_regions.py +++ b/scripts/build_bus_regions.py @@ -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. diff --git a/scripts/build_clustered_population_layouts.py b/scripts/build_clustered_population_layouts.py index bc81c29a..083f3de4 100644 --- a/scripts/build_clustered_population_layouts.py +++ b/scripts/build_clustered_population_layouts.py @@ -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. diff --git a/scripts/build_cop_profiles.py b/scripts/build_cop_profiles.py index 91d03469..342bd7e0 100644 --- a/scripts/build_cop_profiles.py +++ b/scripts/build_cop_profiles.py @@ -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. diff --git a/scripts/build_cutout.py b/scripts/build_cutout.py index fd148cac..eefa881b 100644 --- a/scripts/build_cutout.py +++ b/scripts/build_cutout.py @@ -2,7 +2,6 @@ # SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors # # SPDX-License-Identifier: MIT - """ Create cutouts with `atlite `_. diff --git a/scripts/build_load_data.py b/scripts/build_electricity_demand.py similarity index 99% rename from scripts/build_load_data.py rename to scripts/build_electricity_demand.py index 01e3fb1e..30f24f5c 100755 --- a/scripts/build_load_data.py +++ b/scripts/build_electricity_demand.py @@ -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) diff --git a/scripts/build_energy_totals.py b/scripts/build_energy_totals.py index f11c134f..45fc960f 100644 --- a/scripts/build_energy_totals.py +++ b/scripts/build_energy_totals.py @@ -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. """ diff --git a/scripts/build_gas_input_locations.py b/scripts/build_gas_input_locations.py index 314cb767..a3b945ab 100644 --- a/scripts/build_gas_input_locations.py +++ b/scripts/build_gas_input_locations.py @@ -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. diff --git a/scripts/build_gas_network.py b/scripts/build_gas_network.py index a9f28e0d..f3021022 100644 --- a/scripts/build_gas_network.py +++ b/scripts/build_gas_network.py @@ -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/). diff --git a/scripts/build_heat_demand.py b/scripts/build_heat_demand.py index 6164d25d..56ceb4b7 100644 --- a/scripts/build_heat_demand.py +++ b/scripts/build_heat_demand.py @@ -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. """ diff --git a/scripts/build_hydro_profile.py b/scripts/build_hydro_profile.py index 279bd7a1..9adf7112 100644 --- a/scripts/build_hydro_profile.py +++ b/scripts/build_hydro_profile.py @@ -4,7 +4,6 @@ # SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors # # SPDX-License-Identifier: MIT - """ Build hydroelectric inflow time-series for each country. diff --git a/scripts/build_industrial_distribution_key.py b/scripts/build_industrial_distribution_key.py index d4518d1c..69daf64d 100644 --- a/scripts/build_industrial_distribution_key.py +++ b/scripts/build_industrial_distribution_key.py @@ -2,7 +2,6 @@ # SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors # # SPDX-License-Identifier: MIT - """ Build spatial distribution of industries from Hotmaps database. """ diff --git a/scripts/build_industrial_energy_demand_per_country_today.py b/scripts/build_industrial_energy_demand_per_country_today.py index 3fa9ef56..703997b1 100644 --- a/scripts/build_industrial_energy_demand_per_country_today.py +++ b/scripts/build_industrial_energy_demand_per_country_today.py @@ -2,7 +2,6 @@ # SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors # # SPDX-License-Identifier: MIT - """ Build industrial energy demand per country. """ diff --git a/scripts/build_industrial_energy_demand_per_node.py b/scripts/build_industrial_energy_demand_per_node.py index b75b2058..55c10c5d 100644 --- a/scripts/build_industrial_energy_demand_per_node.py +++ b/scripts/build_industrial_energy_demand_per_node.py @@ -2,7 +2,6 @@ # SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors # # SPDX-License-Identifier: MIT - """ Build industrial energy demand per model region. """ diff --git a/scripts/build_industrial_energy_demand_per_node_today.py b/scripts/build_industrial_energy_demand_per_node_today.py index da1ec2d7..d845e704 100644 --- a/scripts/build_industrial_energy_demand_per_node_today.py +++ b/scripts/build_industrial_energy_demand_per_node_today.py @@ -2,7 +2,6 @@ # SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors # # SPDX-License-Identifier: MIT - """ Build industrial energy demand per model region. """ diff --git a/scripts/build_industrial_production_per_country.py b/scripts/build_industrial_production_per_country.py index 1c2e4557..437806b3 100644 --- a/scripts/build_industrial_production_per_country.py +++ b/scripts/build_industrial_production_per_country.py @@ -2,7 +2,6 @@ # SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors # # SPDX-License-Identifier: MIT - """ Build industrial production per country. """ diff --git a/scripts/build_industrial_production_per_country_tomorrow.py b/scripts/build_industrial_production_per_country_tomorrow.py index e554e159..6c445608 100644 --- a/scripts/build_industrial_production_per_country_tomorrow.py +++ b/scripts/build_industrial_production_per_country_tomorrow.py @@ -2,7 +2,6 @@ # SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors # # SPDX-License-Identifier: MIT - """ Build future industrial production per country. """ diff --git a/scripts/build_industrial_production_per_node.py b/scripts/build_industrial_production_per_node.py index 7b40cb7c..7b69948a 100644 --- a/scripts/build_industrial_production_per_node.py +++ b/scripts/build_industrial_production_per_node.py @@ -2,7 +2,6 @@ # SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors # # SPDX-License-Identifier: MIT - """ Build industrial production per model region. """ diff --git a/scripts/build_industry_sector_ratios.py b/scripts/build_industry_sector_ratios.py index 5f5f7b90..54f2cfdc 100644 --- a/scripts/build_industry_sector_ratios.py +++ b/scripts/build_industry_sector_ratios.py @@ -2,7 +2,6 @@ # SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors # # SPDX-License-Identifier: MIT - """ Build specific energy consumption by carrier and industries. """ diff --git a/scripts/build_natura_raster.py b/scripts/build_natura_raster.py index 9246508e..12011cd0 100644 --- a/scripts/build_natura_raster.py +++ b/scripts/build_natura_raster.py @@ -2,7 +2,6 @@ # SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors # # SPDX-License-Identifier: MIT - """ Rasters the vector data of the `Natura 2000. diff --git a/scripts/build_population_layouts.py b/scripts/build_population_layouts.py index a9308b7e..e864d925 100644 --- a/scripts/build_population_layouts.py +++ b/scripts/build_population_layouts.py @@ -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). """ diff --git a/scripts/build_population_weighted_energy_totals.py b/scripts/build_population_weighted_energy_totals.py index 85d7a8b3..879e3b9b 100644 --- a/scripts/build_population_weighted_energy_totals.py +++ b/scripts/build_population_weighted_energy_totals.py @@ -2,7 +2,6 @@ # SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors # # SPDX-License-Identifier: MIT - """ Distribute country-level energy demands by population. """ diff --git a/scripts/build_renewable_profiles.py b/scripts/build_renewable_profiles.py index ea4dfa9a..6f03d746 100644 --- a/scripts/build_renewable_profiles.py +++ b/scripts/build_renewable_profiles.py @@ -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 diff --git a/scripts/build_retro_cost.py b/scripts/build_retro_cost.py index 72792c92..cd1dae8d 100644 --- a/scripts/build_retro_cost.py +++ b/scripts/build_retro_cost.py @@ -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 diff --git a/scripts/build_salt_cavern_potentials.py b/scripts/build_salt_cavern_potentials.py index 3fed7f91..956ed431 100644 --- a/scripts/build_salt_cavern_potentials.py +++ b/scripts/build_salt_cavern_potentials.py @@ -2,7 +2,6 @@ # SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors # # SPDX-License-Identifier: MIT - """ Build salt cavern potentials for hydrogen storage. diff --git a/scripts/build_sequestration_potentials.py b/scripts/build_sequestration_potentials.py index e17d4f0e..012effe8 100644 --- a/scripts/build_sequestration_potentials.py +++ b/scripts/build_sequestration_potentials.py @@ -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 diff --git a/scripts/build_ship_raster.py b/scripts/build_ship_raster.py index d290e616..abfcdfa1 100644 --- a/scripts/build_ship_raster.py +++ b/scripts/build_ship_raster.py @@ -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") diff --git a/scripts/build_solar_thermal_profiles.py b/scripts/build_solar_thermal_profiles.py index 1cec57f1..f4eb1557 100644 --- a/scripts/build_solar_thermal_profiles.py +++ b/scripts/build_solar_thermal_profiles.py @@ -2,7 +2,6 @@ # SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors # # SPDX-License-Identifier: MIT - """ Build solar thermal collector time series. """ diff --git a/scripts/build_temperature_profiles.py b/scripts/build_temperature_profiles.py index b1973fd8..8f6d6c6c 100644 --- a/scripts/build_temperature_profiles.py +++ b/scripts/build_temperature_profiles.py @@ -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. """ diff --git a/scripts/build_transport_demand.py b/scripts/build_transport_demand.py index 29973da3..6b8bd04f 100644 --- a/scripts/build_transport_demand.py +++ b/scripts/build_transport_demand.py @@ -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 diff --git a/scripts/cluster_gas_network.py b/scripts/cluster_gas_network.py index 44188638..e7554dff 100755 --- a/scripts/cluster_gas_network.py +++ b/scripts/cluster_gas_network.py @@ -2,7 +2,6 @@ # SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors # # SPDX-License-Identifier: MIT - """ Cluster gas transmission network to clustered model regions. """ diff --git a/scripts/copy_config.py b/scripts/copy_config.py index 06531f03..084601ed 100644 --- a/scripts/copy_config.py +++ b/scripts/copy_config.py @@ -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. """ diff --git a/scripts/make_summary.py b/scripts/make_summary.py index 7b33aed8..3d743942 100644 --- a/scripts/make_summary.py +++ b/scripts/make_summary.py @@ -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. diff --git a/scripts/plot_network.py b/scripts/plot_network.py index 7c194b0c..0a22b2e5 100644 --- a/scripts/plot_network.py +++ b/scripts/plot_network.py @@ -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 diff --git a/scripts/plot_summary.py b/scripts/plot_summary.py index 339a8457..cfa8e361 100644 --- a/scripts/plot_summary.py +++ b/scripts/plot_summary.py @@ -2,7 +2,6 @@ # SPDX-FileCopyrightText: : 2020-2023 The PyPSA-Eur Authors # # SPDX-License-Identifier: MIT - """ Creates plots from summary CSV files. """ diff --git a/scripts/prepare_links_p_nom.py b/scripts/prepare_links_p_nom.py index 7c63f3a4..7941b69a 100644 --- a/scripts/prepare_links_p_nom.py +++ b/scripts/prepare_links_p_nom.py @@ -4,7 +4,6 @@ # SPDX-FileCopyrightText: : 2017-2023 The PyPSA-Eur Authors # # SPDX-License-Identifier: MIT - """ Extracts capacities of HVDC links from `Wikipedia. diff --git a/scripts/prepare_sector_network.py b/scripts/prepare_sector_network.py index 5937eb96..6129d3b5 100644 --- a/scripts/prepare_sector_network.py +++ b/scripts/prepare_sector_network.py @@ -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. diff --git a/scripts/retrieve_databundle.py b/scripts/retrieve_databundle.py index b3a6cb4e..52884328 100644 --- a/scripts/retrieve_databundle.py +++ b/scripts/retrieve_databundle.py @@ -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 diff --git a/scripts/solve_network.py b/scripts/solve_network.py index cfb95bfe..2b8cbb13 100644 --- a/scripts/solve_network.py +++ b/scripts/solve_network.py @@ -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): diff --git a/scripts/solve_operations_network.py b/scripts/solve_operations_network.py index d16b60aa..25fe0753 100644 --- a/scripts/solve_operations_network.py +++ b/scripts/solve_operations_network.py @@ -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`.