Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# snakemake data and build directories
.snakemake/
data/
results/
plots/
*.png
*.csv
notebooks/Dummy*
notebooks/Deliverable/combined_results
notebooks/Deliverable/sensitivities


# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
# lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# Sphinx documentation
docs/_build/

# PyBuilder
.pybuilder/
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
.idea/
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
exclude: 'docs|node_modules|migrations|.git|.tox'
default_stages: [pre-commit]
fail_fast: true

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
files: (^|/)a/.+\.(py|html|sh|css|js)$

- repo: local
hooks:
- id: black
name: black
entry: black
language: python
types: [python]
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Module Integration Workflow

This workflow integrates several data modules to generate a set of Calliope models, run them, and
post-process the results.

## Getting started

First, create a new conda environment with the required dependencies:

```bash
conda env create -f environment.yaml
conda activate module_integration
```

There are several target rules that you can run to create results. `construct_all_eu` will construct all
available Europe-level models at resolution NUTS0 and NUTS2. `run_min_cost_eu` runs all the cost-minimising
models, while `run_max_techs_eu` runs the models that maximise the deployment of a given technology.

Before constructing models, you can also run the target rule for a specific module. Each rule `rules/0_module_*.smk`
contains a target rule that triggers the output of the module.

Rules in `rules/2_prepare.smk` further process the data to meet the data model of the Calliope models. Intermediate
results are stored in `results/prepare/`.

Based on the data in `results/prepare/`, the rules in `rules/3_construct.smk` construct the Calliope models. Different models
can be constructed based on specific templates, defined in `template_components`.

After running the models, the results can be post-processed one-by-one or for several models at once, using
the `Postprocessor` and `Processor` classes, together with extendable routines that process `calliope.Model` results and
return a `pandas.DataFrame`.
67 changes: 67 additions & 0 deletions Snakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
configfile: "config/default.yaml"

PATH_PREPARE = Path("results/prepare/{resolution}")
PATH_MODELS = "results/models/{resolution}/{template}/{scenario}/"

wildcard_constraints:
scenario = "|".join(config["demand_scenario"]),
resolution="NUTS0|NUTS2|NUTS3|NUTS3_PRT",

# module rules
include: "./rules/0_module_area_potentials.smk"
include: "./rules/0_module_demand_electricity.smk"
include: "./rules/0_module_pv_wind.smk"
include: "./rules/0_module_geo_boundaries.smk"
include: "./rules/0_module_electricity_grid.smk"
include: "./rules/0_module_demand_heat.smk"
include: "./rules/0_module_demand_transport.smk"
include: "./rules/0_module_powerplants.smk"

# rules
include: "./rules/2_prepare.smk"
include: "./rules/3_construct.smk"
include: "./rules/4_run.smk"
include: "./rules/5_postprocess.smk"

rule dag:
message: "Plot dependency graph of the workflow."
conda: "envs/dag.yaml"
shell:
"""
mkdir -p build
snakemake --rulegraph > build/dag.dot
dot -Tpdf -o build/dag.pdf build/dag.dot
"""

rule clean: # removes all generated results
message: "Remove all build results but keep downloaded data."
run:
import shutil
shutil.rmtree("results")
print("Data downloaded to data/ has not been cleaned.")

rule construct_all_eu:
input:
expand(
"results/models/{resolution}/{method}/{scenario}/construct",
resolution=["NUTS0", "NUTS2"],
scenario=["base", "res_50", "res_75", "res_90"],
method=["min_cost", "max_techs"]
)

rule run_min_cost_eu:
input:
expand(
"results/models/{resolution}/min_cost/{scenario}/run/{scenario}/model.nc",
resolution=["NUTS0", "NUTS2"],
scenario=["base", "res_50", "res_75", "res_90"]
),

rule run_max_techs_eu:
input:
expand(
"results/models/{resolution}/max_techs/{scenario}/run/{scenario}_{slack}/model.nc",
resolution=["NUTS0", "NUTS2"],
scenario=["base", "res_50", "res_75", "res_90"],
slack=["slack_01", "slack_05", "slack_10"],
)
Loading