From 8bbd19efcbd1d66e7cbb6271d365c1d42cd1e47e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 Apr 2026 22:08:39 +0000 Subject: [PATCH 1/2] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v5.0.0 → v6.0.0](https://github.com/pre-commit/pre-commit-hooks/compare/v5.0.0...v6.0.0) - [github.com/astral-sh/ruff-pre-commit: v0.9.6 → v0.15.9](https://github.com/astral-sh/ruff-pre-commit/compare/v0.9.6...v0.15.9) - [github.com/snakemake/snakefmt: v0.10.2 → v1.0.0](https://github.com/snakemake/snakefmt/compare/v0.10.2...v1.0.0) - [github.com/codespell-project/codespell: v2.4.1 → v2.4.2](https://github.com/codespell-project/codespell/compare/v2.4.1...v2.4.2) --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c29fc99..643201d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 @@ -24,7 +24,7 @@ repos: # Python file formatting - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.9.6 + rev: v0.15.9 hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] @@ -32,13 +32,13 @@ repos: # Snakemake file formatting - repo: https://github.com/snakemake/snakefmt - rev: v0.10.2 + 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$ From ebb9b69a9d714984ab982b2e9336d03a74b5b98d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 Apr 2026 22:14:06 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- tests/integration/Snakefile | 16 +++---- workflow/Snakefile | 4 +- workflow/rules/automatic.smk | 84 ++++++++++++++++++------------------ workflow/rules/process.smk | 48 ++++++++++----------- 4 files changed, 76 insertions(+), 76 deletions(-) diff --git a/tests/integration/Snakefile b/tests/integration/Snakefile index 61e6a94..90663dc 100644 --- a/tests/integration/Snakefile +++ b/tests/integration/Snakefile @@ -3,14 +3,14 @@ configfile: workflow.source_path("./test_config.yaml") rule download_netherlands_shapes: - message: - "Download and unzip the Netherlands shapes." output: "results/integration_test/resources/user/shapes/NLD.parquet", log: "results/integration_test/logs/download_netherlands_shapes.log", conda: "../../workflow/envs/shell.yaml" + message: + "Download and unzip the Netherlands shapes." shell: """ curl -sSLo {output:q} "https://zenodo.org/records/16684683/files/NLD.parquet" @@ -18,14 +18,14 @@ rule download_netherlands_shapes: rule download_netherlands_protected_areas: - message: - "Download a dummy drop-in dataset for Netherlands protected areas (not based on WDPA)." output: "results/integration_test/resources/user/wdpa.gdb.zip", log: "results/integration_test/logs/download_netherlands_protected_areas.log", conda: "../../workflow/envs/shell.yaml" + message: + "Download a dummy drop-in dataset for Netherlands protected areas (not based on WDPA)." shell: """ curl -sSLo {output:q} "https://zenodo.org/records/16684513/files/wdpa-nl-dropin.gdb.zip" @@ -33,8 +33,6 @@ rule download_netherlands_protected_areas: rule unzip_netherlands_protected_areas: - message: - "Download protected areas data." input: script=workflow.source_path("../../workflow/scripts/unzip_like.py"), zipfile=rules.download_netherlands_protected_areas.output, @@ -44,6 +42,8 @@ rule unzip_netherlands_protected_areas: "results/integration_test/logs/unzip_netherlands_protected_areas.log", conda: "../../workflow/envs/shell.yaml" + message: + "Download protected areas data." shell: """ python {input.script:q} {input.zipfile:q} -t "results/integration_test/resources/user/" 2> {log:q} @@ -68,10 +68,10 @@ use rule * from module_area_potentials as module_area_potentials_* # Request something from the module rule all: - message: - "Run the module for the Netherlands shapes." default_target: True input: "results/integration_test/resources/user/shapes/NLD.parquet", "results/integration_test/resources/user/wdpa.gdb", "results/integration_test/results/NLD/area_potential_report.html", + message: + "Run the module for the Netherlands shapes." diff --git a/workflow/Snakefile b/workflow/Snakefile index e69459b..d99460d 100644 --- a/workflow/Snakefile +++ b/workflow/Snakefile @@ -35,8 +35,6 @@ include: "rules/process.smk" rule all: - message: - "ERROR: Invalid `rule all:` call" default_target: True output: "INVALID", @@ -44,5 +42,7 @@ rule all: 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}' diff --git a/workflow/rules/automatic.smk b/workflow/rules/automatic.smk index 76b2337..1acc2ed 100644 --- a/workflow/rules/automatic.smk +++ b/workflow/rules/automatic.smk @@ -7,30 +7,30 @@ if config.get("tiny_files", False): ## rule clip_slope: - message: - "Download slope data covering the bounds of the input shapefile." - params: - cog_url=internal["resources"]["automatic"]["slope"], input: vector="resources/user/shapes/{shape}.parquet", output: path="resources/automatic/cutout/{shape}/slope.tif", log: "logs/{shape}/clip_slope.log", + params: + cog_url=internal["resources"]["automatic"]["slope"], + message: + "Download slope data covering the bounds of the input shapefile." wrapper: "v7.2.0/geo/rasterio/clip-geotiff" rule clip_bathymetry: - message: - "Download bathymetry data covering the bounds of the input shapefile." - params: - cog_url=internal["resources"]["automatic"]["bathymetry"], input: vector="resources/user/shapes/{shape}.parquet", output: path="resources/automatic/cutout/{shape}/bathymetry.tif", log: "logs/{shape}/clip_bathymetry.log", + params: + cog_url=internal["resources"]["automatic"]["bathymetry"], + message: + "Download bathymetry data covering the bounds of the input shapefile." wrapper: "v7.2.0/geo/rasterio/clip-geotiff" @@ -41,40 +41,38 @@ else: ## rule download_slope: - message: - "Download global slope data." - params: - url=internal["resources"]["automatic"]["slope"], output: path="resources/automatic/global/slope.tif", log: "logs/download_slope.log", conda: "../envs/shell.yaml" + params: + url=internal["resources"]["automatic"]["slope"], + message: + "Download global slope data." shell: """ curl -sSLo {output:q} {params.url:q} """ rule download_bathymetry: - message: - "Download global bathymetry data." - params: - url=internal["resources"]["automatic"]["bathymetry"], output: path="resources/automatic/global/bathymetry.tif", log: "logs/download_bathymetry.log", conda: "../envs/shell.yaml" + params: + url=internal["resources"]["automatic"]["bathymetry"], + message: + "Download global bathymetry data." shell: """ curl -sSLo {output:q} {params.url:q} """ rule clip_slope: - message: - "Cut slope data to the bounds of the input shapefile." input: script=workflow.source_path("../scripts/clip_raster.py"), shapes="resources/user/shapes/{shape}.parquet", @@ -85,14 +83,14 @@ else: "logs/{shape}/clip_slope.log", conda: "../envs/default.yaml" + message: + "Cut slope data to the bounds of the input shapefile." shell: """ python {input.script:q} {input.slope:q} {input.shapes:q} {output:q} 2> {log:q} """ rule clip_bathymetry: - message: - "Cut bathymetry data to the bounds of the input shapefile." input: script=workflow.source_path("../scripts/clip_raster.py"), shapes="resources/user/shapes/{shape}.parquet", @@ -103,6 +101,8 @@ else: "logs/{shape}/clip_bathymetry.log", conda: "../envs/default.yaml" + message: + "Cut bathymetry data to the bounds of the input shapefile." shell: """ python {input.script:q} {input.bathymetry:q} {input.shapes:q} {output:q} 2> {log:q} @@ -115,16 +115,16 @@ else: rule download_globcover: - message: - "Download the GlobCover land cover data (~380 MB)." - params: - url=internal["resources"]["automatic"]["globcover"], output: "resources/automatic/global/globcover.zip", log: "logs/download_globcover.log", conda: "../envs/shell.yaml" + params: + url=internal["resources"]["automatic"]["globcover"], + message: + "Download the GlobCover land cover data (~380 MB)." shell: """ curl -sSLo {output:q} {params.url:q} @@ -132,10 +132,6 @@ rule download_globcover: rule unzip_globcover: - message: - "Unzip the relevant TIF files from the GlobCover zip file." - params: - target_file=internal["resources"]["automatic"]["globcover_landcover_tif"], input: script=workflow.source_path("../scripts/unzip_like.py"), zipfile=rules.download_globcover.output, @@ -145,6 +141,10 @@ rule unzip_globcover: "logs/unzip_globcover.log", conda: "../envs/shell.yaml" + params: + target_file=internal["resources"]["automatic"]["globcover_landcover_tif"], + message: + "Unzip the relevant TIF files from the GlobCover zip file." shell: """ python {input.script:q} {input.zipfile:q} -f {params.target_file:q} -o {output:q} 2> {log:q} @@ -152,8 +152,6 @@ rule unzip_globcover: rule clip_landcover: - message: - "Cut land cover data to the bounds of the input shapefile." input: script=workflow.source_path("../scripts/clip_raster.py"), shapes="resources/user/shapes/{shape}.parquet", @@ -164,6 +162,8 @@ rule clip_landcover: "logs/{shape}/clip_landcover.log", conda: "../envs/default.yaml" + message: + "Cut land cover data to the bounds of the input shapefile." shell: """ python {input.script:q} {input.landcover:q} {input.shapes:q} {output:q} 2> {log:q} @@ -176,16 +176,16 @@ rule clip_landcover: rule download_ghsl: - message: - "Download the GHSL (Global Human Settlement Layer) built-up surface data." - params: - url=internal["resources"]["automatic"]["ghsl"], output: "resources/automatic/global/ghsl_built_s.zip", log: "logs/download_ghsl.log", conda: "../envs/shell.yaml" + params: + url=internal["resources"]["automatic"]["ghsl"], + message: + "Download the GHSL (Global Human Settlement Layer) built-up surface data." shell: """ curl -sSLo {output:q} {params.url:q} @@ -193,10 +193,6 @@ rule download_ghsl: rule unzip_ghsl: - message: - "Unzip the relevant TIF file from the GHSL data." - params: - target_file=internal["resources"]["automatic"]["ghsl_tif"], input: script=workflow.source_path("../scripts/unzip_like.py"), zipfile=rules.download_ghsl.output, @@ -206,6 +202,10 @@ rule unzip_ghsl: "logs/unzip_ghsl.log", conda: "../envs/shell.yaml" + params: + target_file=internal["resources"]["automatic"]["ghsl_tif"], + message: + "Unzip the relevant TIF file from the GHSL data." shell: """ python {input.script:q} {input.zipfile:q} -f {params.target_file:q} -o {output:q} 2> {log:q} @@ -213,8 +213,6 @@ rule unzip_ghsl: rule clip_settlement: - message: - "Cut settlement data to the bounds of the input shapefile." input: script=workflow.source_path("../scripts/clip_raster.py"), shapes="resources/user/shapes/{shape}.parquet", @@ -225,6 +223,8 @@ rule clip_settlement: "logs/{shape}/clip_settlement.log", conda: "../envs/default.yaml" + message: + "Cut settlement data to the bounds of the input shapefile." shell: """ python {input.script:q} {input.settlement:q} {input.shapes:q} {output:q} 2> {log:q} @@ -237,8 +237,6 @@ rule clip_settlement: rule rasterise_clip_wdpa: - message: - "Rasterise and cut WDPA data to the bounds of the input shapefile, using the landcover raster as reference for the rasterisation." input: script=workflow.source_path("../scripts/clip_and_rasterise_polys.py"), shapes="resources/user/shapes/{shape}.parquet", @@ -250,6 +248,8 @@ rule rasterise_clip_wdpa: "logs/{shape}/clip_wdpa.log", conda: "../envs/default.yaml" + message: + "Rasterise and cut WDPA data to the bounds of the input shapefile, using the landcover raster as reference for the rasterisation." shell: """ python {input.script:q} {input.shapes:q} {input.reference_raster:q} {input.protected_areas:q} {output:q} 2> {log:q} diff --git a/workflow/rules/process.smk b/workflow/rules/process.smk index f3b7ce2..8ae0aad 100644 --- a/workflow/rules/process.smk +++ b/workflow/rules/process.smk @@ -1,8 +1,4 @@ checkpoint breakup_shape: - message: - "Break up {wildcards.shape} into the configured subunits." - params: - split_by=config["split_by"], input: script=workflow.source_path("../scripts/breakup_shape.py"), shapes="resources/user/shapes/{shape}.parquet", @@ -12,6 +8,10 @@ checkpoint breakup_shape: "logs/{shape}/breakup_shape.log", conda: "../envs/default.yaml" + params: + split_by=config["split_by"], + message: + "Break up {wildcards.shape} into the configured subunits." shell: """ python {input.script:q} {input.shapes:q} {params.split_by:q} {output:q} 2> {log:q} @@ -19,12 +19,6 @@ checkpoint breakup_shape: rule prepare_resampled_inputs: - message: - "Resample inputs for {wildcards.subunit} in {wildcards.shape} to the projection and resolution of the land cover data, while aggregating land cover types." - params: - # Use internal defaults if not overridden - land_cover_types_yaml_string=internal["land_cover_types"] - | config.get("land_cover_types", {}), input: script=workflow.source_path("../scripts/resample.py"), shapes=rules.breakup_shape.output, @@ -43,6 +37,12 @@ rule prepare_resampled_inputs: "logs/{shape}/{subunit}/prepare_resampled_inputs.log", conda: "../envs/default.yaml" + params: + # Use internal defaults if not overridden + land_cover_types_yaml_string=internal["land_cover_types"] + | config.get("land_cover_types", {}), + message: + "Resample inputs for {wildcards.subunit} in {wildcards.shape} to the projection and resolution of the land cover data, while aggregating land cover types." shell: """ python {input.script:q} \ @@ -54,14 +54,6 @@ rule prepare_resampled_inputs: rule area_potential: - message: - "Compute area potential for the tech {wildcards.tech} and {wildcards.subunit} in {wildcards.shape}." - params: - config=lambda wildcards: config["techs"][f"{wildcards.tech}"], - subunit_override_config=lambda wildcards: config.get("overrides", {}) - .get(wildcards.subunit, {}) - .get(wildcards.tech, {}), - buffer_crs=lambda wildcards: config["buffer_crs"], input: script=workflow.source_path("../scripts/area_potential.py"), shapes=rules.breakup_shape.output, @@ -76,6 +68,14 @@ rule area_potential: "logs/{shape}/{subunit}/area_potential_{tech}.log", conda: "../envs/default.yaml" + params: + config=lambda wildcards: config["techs"][f"{wildcards.tech}"], + subunit_override_config=lambda wildcards: config.get("overrides", {}) + .get(wildcards.subunit, {}) + .get(wildcards.tech, {}), + buffer_crs=lambda wildcards: config["buffer_crs"], + message: + "Compute area potential for the tech {wildcards.tech} and {wildcards.subunit} in {wildcards.shape}." shell: """ python {input.script:q} "{input.shapes}/{wildcards.subunit}.parquet" {input.resampled_path:q} {params.config:q} {params.buffer_crs:q} {output.area_potential:q} {output.plot:q} --override_config={params.subunit_override_config:q} 2> {log:q} @@ -83,8 +83,6 @@ rule area_potential: rule aggregate_area_potential: - message: - "Aggregate area potential for the tech {wildcards.tech} in {wildcards.shape}." input: get_subunits, output: @@ -93,6 +91,8 @@ rule aggregate_area_potential: "logs/{shape}/aggregate_area_potential_{tech}.log", conda: "../envs/default.yaml" + message: + "Aggregate area potential for the tech {wildcards.tech} in {wildcards.shape}." shell: """ gdalwarp --config GDAL_CACHEMAX 3000 -wm 3000 -of GTiff -co COMPRESS=LZW {input} {output.aggregated_area_potential:q} @@ -100,8 +100,6 @@ rule aggregate_area_potential: rule plot_aggregated_area_potential: - message: - "Plot aggregated area potential for the tech {wildcards.tech} in {wildcards.shape}." input: rules.aggregate_area_potential.output.aggregated_area_potential, output: @@ -112,13 +110,13 @@ rule plot_aggregated_area_potential: "logs/{shape}/plot_aggregated_area_potential_{tech}.log", conda: "../envs/default.yaml" + message: + "Plot aggregated area potential for the tech {wildcards.tech} in {wildcards.shape}." script: "../scripts/tif_to_png.py" rule area_potential_report: - message: - "Generate an overview report of the area potential for all techs in shapes {wildcards.shape}." input: shapes="resources/user/shapes/{shape}.parquet", area_potentials=expand( @@ -139,5 +137,7 @@ rule area_potential_report: "logs/{shape}/area_potential_report.log", conda: "../envs/default.yaml" + message: + "Generate an overview report of the area potential for all techs in shapes {wildcards.shape}." script: "../scripts/report.py"