Skip to content

Commit f061c68

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent c061cc5 commit f061c68

11 files changed

Lines changed: 40 additions & 26 deletions

File tree

AUTHORS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ code or documentation. For a full contributor list, see:
55
<https://github.com/calliope-project/module_area_potentials/graphs/contributors>
66

77
Linh Ho-Tran, <L.Ho@tudelft.nl>
8-
Stefan Pfenninger-Lee, <s.pfenninger@tudelft.nl>
8+
Stefan Pfenninger-Lee, <s.pfenninger@tudelft.nl>

tests/integration/Snakefile

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
# Emulate a user configuring the module.
22
configfile: workflow.source_path("./test_config.yaml")
33

4+
45
rule download_netherlands_shapes:
5-
message: "Download and unzip the Netherlands shapes."
6+
message:
7+
"Download and unzip the Netherlands shapes."
68
output:
79
"results/module_area_potentials/resources/user/shapes/NLD.parquet",
810
shell:
911
"""
1012
curl -sSLo {output} https://surfdrive.surf.nl/files/index.php/s/ey3RmiCbajp69oQ/download
1113
"""
1214

15+
1316
rule download_netherlands_protected_areas:
14-
message: "Download and unzip a dummy drop-in dataset for Netherlands protected areas (not based on WDPA)."
17+
message:
18+
"Download and unzip a dummy drop-in dataset for Netherlands protected areas (not based on WDPA)."
1519
output:
1620
zipfile="results/module_area_potentials/resources/user/wdpa.gdb.zip",
1721
wdpa=directory("results/module_area_potentials/resources/user/wdpa.gdb"),
@@ -21,20 +25,27 @@ rule download_netherlands_protected_areas:
2125
unzip {output.zipfile} -d results/module_area_potentials/resources/user/
2226
"""
2327

28+
2429
# Import the module and configure it.
2530
# `snakefile:` specifies the module. It can use file paths and special github(...) / gitlab(...) markers
2631
# `prefix:` re-routes all input/output paths of the module, helping to avoid file conflicts.
2732
module module_area_potentials:
28-
snakefile: "../../workflow/Snakefile"
29-
config: config["module_area_potentials"]
30-
prefix: "results/module_area_potentials/"
33+
snakefile:
34+
"../../workflow/Snakefile"
35+
config:
36+
config["module_area_potentials"]
37+
prefix:
38+
"results/module_area_potentials/"
39+
3140

3241
# rename all module rules with a prefix, to avoid naming conflicts.
3342
use rule * from module_area_potentials as module_area_potentials_*
3443

44+
3545
# Request something from the module
3646
rule all:
37-
message: "Run the module for the Netherlands shapes."
47+
message:
48+
"Run the module for the Netherlands shapes."
3849
default_target: True
3950
input:
4051
"results/module_area_potentials/resources/user/shapes/NLD.parquet",

workflow/Snakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ with open(workflow.source_path("internal/settings.yaml"), "r") as f:
2020
workflow.source_path("scripts/script_utils.py")
2121
workflow.source_path("scripts/geo.py")
2222

23+
2324
wildcard_constraints:
2425
shape="[a-zA-Z0-9_-]+",
2526
tech="|".join(config["techs"].keys()),
2627

28+
2729
# Add all your includes here.
2830
include: "rules/automatic.smk"
2931
include: "rules/prepare.smk"

workflow/internal/config.schema.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ properties:
4141
shapes_buffer:
4242
type: object
4343
required: ["initial_area", "continuous_layers", "binary_layers"]
44-
additionalProperties: false
44+
additionalProperties: false

workflow/rules/automatic.smk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Rules to used to download automatic resource files."""
22

3+
34
rule download_cutout_slope:
45
message:
56
"Download slope data covering the bounds of the input shapefile."
@@ -12,6 +13,7 @@ rule download_cutout_slope:
1213
wrapper:
1314
"v7.2.0/geo/rasterio/clip-geotiff"
1415

16+
1517
rule download_cutout_bathymetry:
1618
message:
1719
"Download bathymetry data covering the bounds of the input shapefile."
@@ -24,6 +26,7 @@ rule download_cutout_bathymetry:
2426
wrapper:
2527
"v7.2.0/geo/rasterio/clip-geotiff"
2628

29+
2730
rule download_globcover:
2831
message:
2932
"Download the GlobCover land cover data (~380 MB)."
@@ -36,6 +39,7 @@ rule download_globcover:
3639
shell:
3740
'curl -sSLo {output} "{params.url}"'
3841

42+
3943
rule unzip_globcover:
4044
message:
4145
"Unzip the relevant TIF files from the GlobCover zip file."
@@ -57,6 +61,7 @@ rule unzip_globcover:
5761
rm -R $temp_dir
5862
"""
5963

64+
6065
rule download_ghsl:
6166
message:
6267
"Download the GHSL (Global Human Settlement Layer) built-up surface data."
@@ -69,6 +74,7 @@ rule download_ghsl:
6974
shell:
7075
'curl -sSLo {output} "{params.url}"'
7176

77+
7278
rule unzip_ghsl:
7379
message:
7480
"Unzip the relevant TIF file from the GHSL data."

workflow/rules/prepare.smk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Cut out the datasets to bounds determined by the input shapefile."""
22

3+
34
rule cutout_landcover:
45
message:
56
"Cut land cover data to the bounds of the input shapefile."
@@ -15,6 +16,7 @@ rule cutout_landcover:
1516
rio clip --overwrite "{input.landcover}" "{output}" --bounds "$(fio info '{input.shapes}' --bounds)"
1617
"""
1718

19+
1820
rule cutout_settlement:
1921
message:
2022
"Cut settlement data to the bounds of the input shapefile."

workflow/rules/process.smk

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
rule prepare_resampled_inputs:
22
message:
3-
"Resample inputs for {wildcards.shape} to the projection and resolution of the land cover data, while aggregating land cover types.",
3+
"Resample inputs for {wildcards.shape} to the projection and resolution of the land cover data, while aggregating land cover types."
44
input:
55
script=workflow.source_path("../scripts/resample.py"),
66
shapes="resources/user/shapes/{shape}.parquet",
@@ -24,6 +24,7 @@ rule prepare_resampled_inputs:
2424
"{output.resampled_input}" "{output.plot}"
2525
"""
2626

27+
2728
rule area_potential:
2829
message:
2930
"Compute area potential for the tech {wildcards.tech} and shapes {wildcards.shape}."
@@ -48,16 +49,17 @@ rule area_potential:
4849
python "{input.script}" "{input.shapes}" "{input.resampled_path}" "{params.config}" "{params.buffer_crs}" "{output.area_potential}" "{output.plot}"
4950
"""
5051

52+
5153
rule area_potential_report:
5254
message:
53-
"Generate an overview report of the area potential for all techs in shapes {wildcards.shape}.",
55+
"Generate an overview report of the area potential for all techs in shapes {wildcards.shape}."
5456
input:
5557
shapes="resources/user/shapes/{shape}.parquet",
5658
resampled_path=rules.prepare_resampled_inputs.output.resampled_input,
5759
area_potentials=expand(
5860
"results/{{shape}}/area_potential_{tech}.tif",
5961
tech=config["techs"].keys(),
60-
)
62+
),
6163
output:
6264
csv="results/{shape}/area_potential_report.csv",
6365
html=report(

workflow/scripts/area_potential.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,7 @@
1414
@click.argument("output_path", type=str)
1515
@click.argument("plot_path", type=str)
1616
def get_area_potential(
17-
shapes_path,
18-
resampled_path,
19-
config,
20-
buffer_crs,
21-
output_path,
22-
plot_path,
17+
shapes_path, resampled_path, config, buffer_crs, output_path, plot_path
2318
):
2419
shapes = gpd.read_parquet(shapes_path)
2520
ds = xr.open_dataset(resampled_path, decode_coords="all")

workflow/scripts/report.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def report(shapes, resampled_path, area_potentials, csv_path, html_path):
3939
sums.name = "Total"
4040
df = pd.concat([df, sums.to_frame().T])
4141

42-
df.to_html(html_path, float_format=lambda x: f"{x/1e6:.2f}")
42+
df.to_html(html_path, float_format=lambda x: f"{x / 1e6:.2f}")
4343

4444

4545
if __name__ == "__main__":

workflow/scripts/resample.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ def determine_pixel_areas(raster_input):
127127
"""
128128
# the following is based on https://gis.stackexchange.com/a/288034/77760
129129
# and assumes the data to be in EPSG:4326
130-
assert (
131-
raster_input.rio.crs.to_epsg() == 4326
132-
), "raster_input does not have the projection EPSG:4326"
130+
assert raster_input.rio.crs.to_epsg() == 4326, (
131+
"raster_input does not have the projection EPSG:4326"
132+
)
133133
resolution = raster_input.rio.resolution()[0] # resolution in degrees
134134
varea_of_pixel = np.vectorize(lambda lat: _area_of_pixel(resolution, lat))
135135
pixel_area = varea_of_pixel(raster_input.y) * 1000**2 # convert to m^2
@@ -206,10 +206,7 @@ def get_same_shape_and_resolution(
206206
print(f"Number of land regions: {len(shapes_land)}")
207207
print(f"Number of maritime regions: {len(shapes_maritime)}")
208208

209-
resampled["regions"] = (
210-
("y", "x"),
211-
_rasterize_regions(shapes, reference_raster),
212-
)
209+
resampled["regions"] = (("y", "x"), _rasterize_regions(shapes, reference_raster))
213210

214211
mask_land = xr.DataArray(
215212
np.isin(resampled["regions"], shapes_land),

0 commit comments

Comments
 (0)