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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@ repos:

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

# Snakemake file formatting
- repo: https://github.com/snakemake/snakefmt
rev: v0.11.4
rev: v1.0.0
hooks:
- id: snakefmt

# Spelling
- repo: https://github.com/codespell-project/codespell
rev: v2.4.1
rev: v2.4.2
hooks:
- id: codespell
files: .*\.(py|smk|md)$|^Snakefile$
Expand Down
12 changes: 6 additions & 6 deletions tests/integration/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ with open(workflow.source_path("../../config/config.yaml"), "r") as f:
# `config`: specifies the module configuration.
# `pathvars:` helps you re-wire where the module places files.
module module_co2stop_cdr:
snakefile:
"../../workflow/Snakefile"
config:
module_config["module_co2stop_cdr"]
pathvars:
# Redirect specific user resources (inputs)
user_shapes="resources/inputs/{shapes}/shapes.parquet",
Expand All @@ -25,6 +21,10 @@ module module_co2stop_cdr:
logs="resources/co2stop_cdr/logs",
resources="resources/co2stop_cdr/resources",
results="resources/co2stop_cdr/results",
snakefile:
"../../workflow/Snakefile"
config:
module_config["module_co2stop_cdr"]


# rename all module rules with a prefix, to avoid naming conflicts.
Expand All @@ -36,8 +36,8 @@ FILES = ["aquifer"]

# Request something from the module
rule all:
message:
"A generic test case for your module."
default_target: True
input:
expand("results/outputs/BALK/medium/{cdr}.parquet", cdr=FILES),
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 @@ -43,14 +43,14 @@ workflow.source_path("scripts/_utils.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}'
22 changes: 11 additions & 11 deletions workflow/rules/aggregate.smk
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@


rule aggregate_co2stop:
message:
"Aggregating '{wildcards.shapes}-{wildcards.scenario}-{wildcards.cdr_group}'."
params:
bounds_mtco2=lambda wc: config["imputation"]["aggregated"][wc.cdr_group][
"bounds_mtco2"
],
proj_crs=config["crs"]["projected"],
input:
shapes="<user_shapes>",
storage_units=rules.prepare_co2stop_storage_units.output.mtco2,
Expand All @@ -28,15 +21,18 @@ rule aggregate_co2stop:
cdr_group="|".join(CDR_GROUP),
conda:
"../envs/co2stop.yaml"
params:
bounds_mtco2=lambda wc: config["imputation"]["aggregated"][wc.cdr_group][
"bounds_mtco2"
],
proj_crs=config["crs"]["projected"],
message:
"Aggregating '{wildcards.shapes}-{wildcards.scenario}-{wildcards.cdr_group}'."
script:
"../scripts/aggregate_co2stop.py"


rule aggregate_totals:
message:
"Aggregating totals for '{wildcards.shapes}-{wildcards.scenario}'."
params:
proj_crs=config["crs"]["projected"],
input:
shapes="<user_shapes>",
aggregates=lambda wc: expand(
Expand All @@ -59,5 +55,9 @@ rule aggregate_totals:
scenario="|".join(["low", "medium", "high"]),
conda:
"../envs/co2stop.yaml"
params:
proj_crs=config["crs"]["projected"],
message:
"Aggregating totals for '{wildcards.shapes}-{wildcards.scenario}'."
script:
"../scripts/aggregate_totals.py"
24 changes: 12 additions & 12 deletions workflow/rules/automatic.smk
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,21 @@


rule download_co2stop:
message:
"Downloading the open CO2Stop dataset."
params:
url=internal["resources"]["automatic"]["co2stop"],
output:
zipfile="<resources>/automatic/co2stop.zip",
log:
"<logs>/download_co2stop.log",
conda:
"../envs/shell.yaml"
params:
url=internal["resources"]["automatic"]["co2stop"],
message:
"Downloading the open CO2Stop dataset."
shell:
"curl -sSLo {output.zipfile:q} {params.url:q}"


rule unzip_co2stop:
message:
"Unzipping necessary data from the CO2Stop file."
params:
storage_data="CO2Stop_DataInterrogationSystem/Hydrocarbon_Storage_Units.csv",
storage_map="CO2Stop_Polygons Data/StorageUnits_March13.kml",
traps_data="CO2Stop_DataInterrogationSystem/Hydrocarbon_Traps.csv",
traps_map="CO2Stop_Polygons Data/DaughterUnits_March13.kml",
country_map="CO2Stop_Polygons Data/Basemap.kml",
input:
zipfile=rules.download_co2stop.output.zipfile,
output:
Expand All @@ -37,5 +29,13 @@ rule unzip_co2stop:
"<logs>/automatic/unzip_co2stop.log",
conda:
"../envs/co2stop.yaml"
params:
storage_data="CO2Stop_DataInterrogationSystem/Hydrocarbon_Storage_Units.csv",
storage_map="CO2Stop_Polygons Data/StorageUnits_March13.kml",
traps_data="CO2Stop_DataInterrogationSystem/Hydrocarbon_Traps.csv",
traps_map="CO2Stop_Polygons Data/DaughterUnits_March13.kml",
country_map="CO2Stop_Polygons Data/Basemap.kml",
message:
"Unzipping necessary data from the CO2Stop file."
script:
"../scripts/unzip_co2stop.py"
28 changes: 14 additions & 14 deletions workflow/rules/prepare.smk
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@ CDR_GROUP = ["aquifer", "gas", "oil"]


rule prepare_co2stop_storage_units:
message:
"Harmonising CO2Stop storage units: aquifer."
params:
cdr_group="aquifer",
cdr_group_config=lambda wc: config["imputation"]["co2stop"]["aquifer"],
dataset="storage_units",
geo_crs=config["crs"]["geographic"],
input:
table=rules.unzip_co2stop.output.storage_data,
polygons=rules.unzip_co2stop.output.storage_map,
Expand All @@ -33,18 +26,18 @@ rule prepare_co2stop_storage_units:
"<logs>/storage_units/aquifer/prepare_co2stop.log",
conda:
"../envs/co2stop.yaml"
params:
cdr_group="aquifer",
cdr_group_config=lambda wc: config["imputation"]["co2stop"]["aquifer"],
dataset="storage_units",
geo_crs=config["crs"]["geographic"],
message:
"Harmonising CO2Stop storage units: aquifer."
script:
"../scripts/prepare_co2stop.py"


rule prepare_co2stop_traps:
message:
"Harmonising CO2Stop traps: {wildcards.cdr_group}."
params:
cdr_group=lambda wc: wc.cdr_group,
cdr_group_config=lambda wc: config["imputation"]["co2stop"][wc.cdr_group],
dataset="traps",
geo_crs=config["crs"]["geographic"],
input:
table=rules.unzip_co2stop.output.traps_data,
polygons=rules.unzip_co2stop.output.traps_map,
Expand All @@ -69,5 +62,12 @@ rule prepare_co2stop_traps:
cdr_group="|".join(CDR_GROUP),
conda:
"../envs/co2stop.yaml"
params:
cdr_group=lambda wc: wc.cdr_group,
cdr_group_config=lambda wc: config["imputation"]["co2stop"][wc.cdr_group],
dataset="traps",
geo_crs=config["crs"]["geographic"],
message:
"Harmonising CO2Stop traps: {wildcards.cdr_group}."
script:
"../scripts/prepare_co2stop.py"
Loading