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
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ default_language_version:
repos:
# Generic 'file quality' testing
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
# Machine-friendliness
- id: trailing-whitespace
Expand All @@ -24,21 +24,21 @@ repos:

# Python file formatting
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.6
rev: v0.16.6
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format

# Snakemake file formatting
- repo: https://github.com/snakemake/snakefmt
rev: v0.10.2
rev: v2.0.3
hooks:
- id: snakefmt

# Spelling
- repo: https://github.com/codespell-project/codespell
rev: v2.4.1
rev: v2.4.3
hooks:
- id: codespell
files: .*\.(py|smk|md)$|^Snakefile$
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ configfile: workflow.source_path("./test_config.yaml")

# Emulate how another workflow might create inputs for this module.
rule create_external_input:
message:
"Example of a rule external to your module."
output:
text_file="results/integration_test/resources/user/user_message.md",
message:
"Example of a rule external to your module."
run:
from pathlib import Path
from textwrap import dedent
Expand Down Expand Up @@ -40,8 +40,8 @@ use rule * from module_euro_industry as module_euro_industry_*

# Request something from the module
rule all:
message:
"A generic test case for your module."
default_target: True
input:
"results/integration_test/results/combined_text.md",
message:
"A generic test case for your module."
4 changes: 2 additions & 2 deletions workflow/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ workflow.source_path("scripts/_schemas.py")


rule all:
message:
"ERROR: Invalid `rule all:` call"
default_target: True
output:
"INVALID",
log:
stderr="logs/all.stderr",
conda:
"envs/shell.yaml"
message:
"ERROR: Invalid `rule all:` call"
shell:
'echo "This workflow must be called as a snakemake module." > {log.stderr}'
100 changes: 50 additions & 50 deletions workflow/rules/automatic.smk
Original file line number Diff line number Diff line change
Expand Up @@ -2,180 +2,176 @@


rule download_eurostat:
message:
"Download stable Eurostat energy balances."
params:
url=internal["resources"]["automatic"]["eurostat"],
output:
file=temp("resources/automatic/eurostat.zip"),
log:
"logs/automatic/download_eurostat.log",
conda:
"../envs/shell.yaml"
params:
url=internal["resources"]["automatic"]["eurostat"],
message:
"Download stable Eurostat energy balances."
shell:
'curl -sSLo {output.file} "{params.url}"'


rule download_jrc_idees:
message:
"Download the JRC IDEES dataset."
params:
url=internal["resources"]["automatic"]["jrc_idees"],
output:
file=temp("resources/automatic/jrc_idees.zip"),
log:
"logs/automatic/download_jrc_idees.log",
conda:
"../envs/shell.yaml"
params:
url=internal["resources"]["automatic"]["jrc_idees"],
message:
"Download the JRC IDEES dataset."
shell:
'curl -sSLo {output.file} "{params.url}"'


rule download_hotmaps:
message:
"Download the Hotmaps energy intensive industry dataset."
params:
url=internal["resources"]["automatic"]["hotmaps"],
output:
file="resources/automatic/hotmaps.csv",
log:
"logs/automatic/download_hotmaps.log",
conda:
"../envs/shell.yaml"
params:
url=internal["resources"]["automatic"]["hotmaps"],
message:
"Download the Hotmaps energy intensive industry dataset."
shell:
'curl -sSLo {output.file} "{params.url}"'


rule download_ammonia_usgs:
message:
"Download the U.S. geological survey on ammonia supply."
params:
url=internal["resources"]["automatic"]["ammonia"]["usgs"],
output:
file=temp("resources/automatic/ammonia/usgs.xlsx"),
log:
"logs/automatic/download_ammonia_usgs.log",
conda:
"../envs/shell.yaml"
params:
url=internal["resources"]["automatic"]["ammonia"]["usgs"],
message:
"Download the U.S. geological survey on ammonia supply."
shell:
'curl -sSLo {output.file} "{params.url}"'


rule download_ammonia_plants:
message:
"Download ammonia plants as collected by PyPSA-Eur."
params:
url=internal["resources"]["automatic"]["ammonia"]["plants"],
output:
file="resources/automatic/ammonia/plants.csv",
log:
"logs/automatic/download_ammonia_plants.log",
conda:
"../envs/shell.yaml"
params:
url=internal["resources"]["automatic"]["ammonia"]["plants"],
message:
"Download ammonia plants as collected by PyPSA-Eur."
shell:
'curl -sSLo {output.file} "{params.url}"'


rule download_GEM_SPT:
message:
"Download the Global Energy Monitor - Steel Plant Tracker."
params:
url=internal["resources"]["automatic"]["GEM_SPT"],
output:
file="resources/automatic/GEM_SPT.xlsx",
log:
"logs/automatic/download_GEM_SPT.log",
conda:
"../envs/shell.yaml"
params:
url=internal["resources"]["automatic"]["GEM_SPT"],
message:
"Download the Global Energy Monitor - Steel Plant Tracker."
shell:
'curl -sSLo {output.file} "{params.url}"'


rule download_cement_non_eu:
message:
"Download cement plants as collected by PyPSA-Eur."
params:
url=internal["resources"]["automatic"]["non_eu"]["cement"],
output:
file="resources/automatic/cement_non_eu.csv",
log:
"logs/automatic/download_cement_non_eu.log",
conda:
"../envs/shell.yaml"
params:
url=internal["resources"]["automatic"]["non_eu"]["cement"],
message:
"Download cement plants as collected by PyPSA-Eur."
shell:
'curl -sSLo {output.file} "{params.url}"'


rule download_refineries_non_eu:
message:
"Download refineries as collected by PyPSA-Eur."
params:
url=internal["resources"]["automatic"]["non_eu"]["refineries"],
output:
file="resources/automatic/non_eu/refineries.csv",
log:
"logs/automatic/download_refineries_non_eu.log",
conda:
"../envs/shell.yaml"
params:
url=internal["resources"]["automatic"]["non_eu"]["refineries"],
message:
"Download refineries as collected by PyPSA-Eur."
shell:
'curl -sSLo {output.file} "{params.url}"'


rule download_CHE_industry:
message:
"Download CHE industrial production per subsector."
params:
url=internal["resources"]["automatic"]["CHE_industry"],
output:
file="resources/automatic/CHE_industry.csv",
log:
"logs/automatic/download_CHE_industry.log",
conda:
"../envs/shell.yaml"
params:
url=internal["resources"]["automatic"]["CHE_industry"],
message:
"Download CHE industrial production per subsector."
shell:
'curl -sSLo {output.file} "{params.url}"'


rule download_GHSL_population:
message:
"Download the Global Human Settlement Layer population raster."
params:
url=get_ghsl_url(
internal["population"]["epoch"], internal["population"]["resolution"]
),
output:
file=temp("resources/automatic/GHSL.zip"),
log:
"logs/automatic/download_CHE_industry.log",
conda:
"../envs/shell.yaml"
params:
url=get_ghsl_url(
internal["population"]["epoch"], internal["population"]["resolution"]
),
message:
"Download the Global Human Settlement Layer population raster."
shell:
'curl -sSLo {output.file} "{params.url}"'


rule unzip_directory:
message:
"Unzipping {wildcards.directory}."
input:
zip_file="resources/automatic/{directory}.zip",
output:
directory("resources/automatic/{directory}/"),
wildcard_constraints:
directory="|".join({"eurostat", "jrc_idees"}),
log:
"logs/automatic/unzip_directory_{directory}.log",
wildcard_constraints:
directory="|".join({"eurostat", "jrc_idees"}),
conda:
"../envs/industry.yaml"
message:
"Unzipping {wildcards.directory}."
script:
"../scripts/unzip.py"


# TODO: standardised epoch and resolution, or user configured?
rule unzip_GHSL:
message:
"Unzipping {params.file}."
params:
file=f"GHS_POP_E{internal['population']['epoch']}_GLOBE_R2023A_54009_{internal['population']['resolution']}_V1_0.tif",
input:
zip_file="resources/automatic/GHSL.zip",
output:
Expand All @@ -184,5 +180,9 @@ rule unzip_GHSL:
"logs/automatic/unzip_GHSL.log",
conda:
"../envs/industry.yaml"
params:
file=f"GHS_POP_E{internal['population']['epoch']}_GLOBE_R2023A_54009_{internal['population']['resolution']}_V1_0.tif",
message:
"Unzipping {params.file}."
script:
"../scripts/unzip.py"
22 changes: 11 additions & 11 deletions workflow/rules/disaggregate.smk
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@


rule disaggregate_production_rates:
message:
"{wildcards.shape}: estimating production rates per shape using proxies."
params:
hotmaps_locate_missing=config["industry"]["hotmaps_locate_missing"],
geographic_crs=internal["crs"]["geographic"],
input:
shapes=rules.prepare_shapes.output.shapes,
hotmaps=rules.download_hotmaps.output.file,
Expand All @@ -20,13 +15,16 @@ rule disaggregate_production_rates:
"logs/{shape}/disaggregate_production_rates.log",
conda:
"../envs/industry.yaml"
params:
hotmaps_locate_missing=config["industry"]["hotmaps_locate_missing"],
geographic_crs=internal["crs"]["geographic"],
message:
"{wildcards.shape}: estimating production rates per shape using proxies."
script:
"../scripts/disaggregate_production_rates.py"


rule disaggregate_current_energy_demand:
message:
"{wildcards.shape}: disaggregating current energy demand."
input:
shapes=rules.prepare_shapes.output.shapes,
production_rates=rules.disaggregate_production_rates.output.production_rates,
Expand All @@ -37,13 +35,13 @@ rule disaggregate_current_energy_demand:
"logs/{shape}/disaggregate_current_energy_demand.log",
conda:
"../envs/industry.yaml"
message:
"{wildcards.shape}: disaggregating current energy demand."
script:
"../scripts/disaggregate_current_energy_demand.py"


rule disaggregate_future_production:
message:
"{wildcards.shape}/{wildcards.year}: disaggregating future production."
input:
shapes=rules.prepare_shapes.output.shapes,
production_rates=rules.disaggregate_production_rates.output.production_rates,
Expand All @@ -54,13 +52,13 @@ rule disaggregate_future_production:
"logs/{shape}/{year}/disaggregate_future_production.log",
conda:
"../envs/industry.yaml"
message:
"{wildcards.shape}/{wildcards.year}: disaggregating future production."
script:
"../scripts/disaggregate_future_production.py"


rule disaggregate_future_energy_demand:
message:
"{wildcards.shape}/{wildcards.year}: disaggregating energy demand."
input:
shapes=rules.prepare_shapes.output.shapes,
sector_rates=rules.prepare_future_europe_sector_rates.output.sector_rates,
Expand All @@ -72,5 +70,7 @@ rule disaggregate_future_energy_demand:
"logs/{shape}/{year}/disaggregate_future_energy_demand.log",
conda:
"../envs/industry.yaml"
message:
"{wildcards.shape}/{wildcards.year}: disaggregating energy demand."
script:
"../scripts/disaggregate_future_energy_demand.py"
Loading