Merge branch 'master' into multi-horizon
This commit is contained in:
commit
21d1109853
@ -51,7 +51,7 @@ repos:
|
||||
|
||||
# Formatting with "black" coding style
|
||||
- repo: https://github.com/psf/black
|
||||
rev: 23.7.0
|
||||
rev: 23.9.1
|
||||
hooks:
|
||||
# Format Python files
|
||||
- id: black
|
||||
|
24
Snakefile
24
Snakefile
@ -66,18 +66,32 @@ if config["foresight"] == "myopic":
|
||||
include: "rules/solve_myopic.smk"
|
||||
|
||||
|
||||
|
||||
if config["foresight"] == "perfect":
|
||||
|
||||
include: "rules/solve_perfect.smk"
|
||||
|
||||
rule all:
|
||||
input:
|
||||
RESULTS + "graphs/costs.pdf",
|
||||
default_target: True
|
||||
|
||||
|
||||
|
||||
rule purge:
|
||||
message:
|
||||
"Purging generated resources, results and docs. Downloads are kept."
|
||||
run:
|
||||
rmtree("resources/", ignore_errors=True)
|
||||
rmtree("results/", ignore_errors=True)
|
||||
rmtree("doc/_build", ignore_errors=True)
|
||||
import builtins
|
||||
|
||||
do_purge = builtins.input(
|
||||
"Do you really want to delete all generated resources, \nresults and docs (downloads are kept)? [y/N] "
|
||||
)
|
||||
if do_purge == "y":
|
||||
rmtree("resources/", ignore_errors=True)
|
||||
rmtree("results/", ignore_errors=True)
|
||||
rmtree("doc/_build", ignore_errors=True)
|
||||
print("Purging generated resources, results and docs. Downloads are kept.")
|
||||
else:
|
||||
raise Exception(f"Input {do_purge}. Aborting purge.")
|
||||
|
||||
|
||||
rule dag:
|
||||
|
@ -22,6 +22,19 @@ Upcoming Release
|
||||
|
||||
* New feature multi-decade optimisation with perfect foresight.
|
||||
|
||||
* It is now possible to specify years for biomass potentials which do not exist
|
||||
in the JRC-ENSPRESO database, e.g. 2037. These are linearly interpolated.
|
||||
|
||||
* In pathway mode, the biomass potential is linked to the investment year.
|
||||
|
||||
* Rule ``purge`` now initiates a dialog to confirm if purge is desired.
|
||||
|
||||
|
||||
**Bugs and Compatibility**
|
||||
|
||||
* A bug preventing custom powerplants specified in ``data/custom_powerplants.csv`` was fixed. (https://github.com/PyPSA/pypsa-eur/pull/732)
|
||||
|
||||
|
||||
PyPSA-Eur 0.8.1 (27th July 2023)
|
||||
================================
|
||||
|
||||
|
@ -59,7 +59,7 @@ To run an overnight / greenfiled scenario with the specifications above, run
|
||||
|
||||
.. code:: bash
|
||||
|
||||
snakemake -call --configfile config/test/config.overnight.yaml all
|
||||
snakemake -call all --configfile config/test/config.overnight.yaml
|
||||
|
||||
which will result in the following *additional* jobs ``snakemake`` wants to run
|
||||
on top of those already included in the electricity-only tutorial:
|
||||
@ -318,7 +318,7 @@ To run a myopic foresight scenario with the specifications above, run
|
||||
|
||||
.. code:: bash
|
||||
|
||||
snakemake -call --configfile config/test/config.myopic.yaml all
|
||||
snakemake -call all --configfile config/test/config.myopic.yaml
|
||||
|
||||
which will result in the following *additional* jobs ``snakemake`` wants to run:
|
||||
|
||||
|
@ -280,15 +280,16 @@ rule build_biomass_potentials:
|
||||
country_shapes=RESOURCES + "country_shapes.geojson",
|
||||
output:
|
||||
biomass_potentials_all=RESOURCES
|
||||
+ "biomass_potentials_all_s{simpl}_{clusters}.csv",
|
||||
biomass_potentials=RESOURCES + "biomass_potentials_s{simpl}_{clusters}.csv",
|
||||
+ "biomass_potentials_all_s{simpl}_{clusters}_{planning_horizons}.csv",
|
||||
biomass_potentials=RESOURCES
|
||||
+ "biomass_potentials_s{simpl}_{clusters}_{planning_horizons}.csv",
|
||||
threads: 1
|
||||
resources:
|
||||
mem_mb=1000,
|
||||
log:
|
||||
LOGS + "build_biomass_potentials_s{simpl}_{clusters}.log",
|
||||
LOGS + "build_biomass_potentials_s{simpl}_{clusters}_{planning_horizons}.log",
|
||||
benchmark:
|
||||
BENCHMARKS + "build_biomass_potentials_s{simpl}_{clusters}"
|
||||
BENCHMARKS + "build_biomass_potentials_s{simpl}_{clusters}_{planning_horizons}"
|
||||
conda:
|
||||
"../envs/environment.yaml"
|
||||
script:
|
||||
@ -735,7 +736,12 @@ rule prepare_sector_network:
|
||||
dsm_profile=RESOURCES + "dsm_profile_s{simpl}_{clusters}.csv",
|
||||
co2_totals_name=RESOURCES + "co2_totals.csv",
|
||||
co2="data/bundle-sector/eea/UNFCCC_v23.csv",
|
||||
biomass_potentials=RESOURCES + "biomass_potentials_s{simpl}_{clusters}.csv",
|
||||
biomass_potentials=RESOURCES
|
||||
+ "biomass_potentials_s{simpl}_{clusters}_"
|
||||
+ "{}.csv".format(config["biomass"]["year"])
|
||||
if config["foresight"] == "overnight"
|
||||
else RESOURCES
|
||||
+ "biomass_potentials_s{simpl}_{clusters}_{planning_horizons}.csv",
|
||||
heat_profile="data/heat_load_profile_BDEW.csv",
|
||||
costs="data/costs_{}.csv".format(config["costs"]["year"])
|
||||
if config["foresight"] == "overnight"
|
||||
|
@ -14,12 +14,6 @@ localrules:
|
||||
plot_networks,
|
||||
|
||||
|
||||
rule all:
|
||||
input:
|
||||
RESULTS + "graphs/costs.pdf",
|
||||
default_target: True
|
||||
|
||||
|
||||
rule cluster_networks:
|
||||
input:
|
||||
expand(RESOURCES + "networks/elec_s{simpl}_{clusters}.nc", **config["scenario"]),
|
||||
|
@ -7,9 +7,15 @@ Compute biogas and solid biomass potentials for each clustered model region
|
||||
using data from JRC ENSPRESO.
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
import geopandas as gpd
|
||||
import numpy as np
|
||||
import pandas as pd
|
||||
|
||||
AVAILABLE_BIOMASS_YEARS = [2010, 2020, 2030, 2040, 2050]
|
||||
|
||||
|
||||
def build_nuts_population_data(year=2013):
|
||||
pop = pd.read_csv(
|
||||
@ -208,13 +214,41 @@ if __name__ == "__main__":
|
||||
if "snakemake" not in globals():
|
||||
from _helpers import mock_snakemake
|
||||
|
||||
snakemake = mock_snakemake("build_biomass_potentials", simpl="", clusters="5")
|
||||
snakemake = mock_snakemake(
|
||||
"build_biomass_potentials",
|
||||
simpl="",
|
||||
clusters="5",
|
||||
planning_horizons=2050,
|
||||
)
|
||||
|
||||
overnight = snakemake.config["foresight"] == "overnight"
|
||||
params = snakemake.params.biomass
|
||||
year = params["year"]
|
||||
investment_year = int(snakemake.wildcards.planning_horizons)
|
||||
year = params["year"] if overnight else investment_year
|
||||
scenario = params["scenario"]
|
||||
|
||||
enspreso = enspreso_biomass_potentials(year, scenario)
|
||||
if year > 2050:
|
||||
logger.info("No biomass potentials for years after 2050, using 2050.")
|
||||
max_year = max(AVAILABLE_BIOMASS_YEARS)
|
||||
enspreso = enspreso_biomass_potentials(max_year, scenario)
|
||||
|
||||
elif year not in AVAILABLE_BIOMASS_YEARS:
|
||||
before = int(np.floor(year / 10) * 10)
|
||||
after = int(np.ceil(year / 10) * 10)
|
||||
logger.info(
|
||||
f"No biomass potentials for {year}, interpolating linearly between {before} and {after}."
|
||||
)
|
||||
|
||||
enspreso_before = enspreso_biomass_potentials(before, scenario)
|
||||
enspreso_after = enspreso_biomass_potentials(after, scenario)
|
||||
|
||||
fraction = (year - before) / (after - before)
|
||||
|
||||
enspreso = enspreso_before + fraction * (enspreso_after - enspreso_before)
|
||||
|
||||
else:
|
||||
logger.info(f"Using biomass potentials for {year}.")
|
||||
enspreso = enspreso_biomass_potentials(year, scenario)
|
||||
|
||||
enspreso = disaggregate_nuts0(enspreso)
|
||||
|
||||
|
@ -89,7 +89,7 @@ logger = logging.getLogger(__name__)
|
||||
def add_custom_powerplants(ppl, custom_powerplants, custom_ppl_query=False):
|
||||
if not custom_ppl_query:
|
||||
return ppl
|
||||
add_ppls = pd.read_csv(custom_powerplants, index_col=0, dtype={"bus": "str"})
|
||||
add_ppls = pd.read_csv(custom_powerplants, dtype={"bus": "str"})
|
||||
if isinstance(custom_ppl_query, str):
|
||||
add_ppls.query(custom_ppl_query, inplace=True)
|
||||
return pd.concat(
|
||||
|
Loading…
Reference in New Issue
Block a user