Skip to content

Commit 9b39da0

Browse files
committed
Simplify and generalise the area potential processing; Cleanup
1 parent 98e959f commit 9b39da0

13 files changed

Lines changed: 255 additions & 355 deletions

config/config.yaml

Lines changed: 67 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,73 @@
44
# A good option is "epsg:8857" (WGS 84 / Equal Earth Greenwich) for global coverage
55
buffer_crs: "epsg:8857"
66

7-
# Technical criteria
8-
techs_onshore:
7+
techs:
8+
pv_rooftop:
9+
initial_area: settlement_area
10+
continuous_layers:
11+
settlement_share:
12+
min: 0.01
13+
max: 1
14+
share: 0.8
15+
binary_layers:
16+
regions_maritime: 0
17+
regions_land: 1
18+
protected: 0
19+
# Include all land cover types; selection is done by settlement_share
20+
landcover_FARM: 1
21+
landcover_FOREST: 1
22+
landcover_URBAN: 1
23+
landcover_OTHER: 1
24+
landcover_NOT_SUITABLE: 0
25+
landcover_WATER: 0
926
pv_open_field:
10-
max_slope: 3
11-
land_cover:
12-
FARM: 0.1
13-
FOREST: 0 # no PV open field in forest
14-
OTHER: 0.2
15-
URBAN: 0 # no PV open field in urban
16-
settlement:
17-
max_settlement: 0.01 # no PV open field in settlement
18-
weight: -1
27+
initial_area: pixel_area
28+
continuous_layers:
29+
slope:
30+
min: 0
31+
max: 3
32+
settlement_share:
33+
min: 0
34+
max: 0.01
35+
binary_layers:
36+
regions_maritime: 0
37+
regions_land: 1
38+
protected: 0
39+
landcover_FARM: 0.1
40+
landcover_FOREST: 0
41+
landcover_URBAN: 0
42+
landcover_OTHER: 0.2
43+
landcover_NOT_SUITABLE: 0
44+
landcover_WATER: 0
1945
wind_onshore:
20-
max_slope: 20
21-
land_cover:
22-
FARM: 0.2
23-
FOREST: 0.05
24-
OTHER: 0.3
25-
URBAN: 0 # no wind onshore in urban
26-
settlement:
27-
max_settlement: 0.01
28-
weight: -1
29-
pv_rooftop:
30-
max_slope: 90
31-
land_cover:
32-
FARM: 0
33-
FOREST: 0
34-
OTHER: 0
35-
URBAN: 1
36-
settlement:
37-
max_settlement: 1
38-
weight: 0.8
39-
40-
techs_offshore:
46+
initial_area: pixel_area
47+
continuous_layers:
48+
slope:
49+
min: 0
50+
max: 20
51+
settlement_share:
52+
min: 0
53+
max: 0.01
54+
binary_layers:
55+
regions_maritime: 0
56+
regions_land: 1
57+
protected: 0
58+
landcover_FARM: 0.2
59+
landcover_FOREST: 0.05
60+
landcover_URBAN: 0
61+
landcover_OTHER: 0.3
62+
landcover_NOT_SUITABLE: 0
63+
landcover_WATER: 0
4164
wind_offshore:
42-
water_depth:
43-
max: 0
44-
min: -50
45-
weight: 0.8
65+
initial_area: pixel_area
66+
continuous_layers:
67+
bathymetry:
68+
min: -50
69+
max: 0
70+
share: 0.8
71+
binary_layers:
72+
regions_land: 0
73+
regions_maritime: 1
74+
protected: 0
75+
shapes_buffer:
76+
land: 10000 # meters

workflow/Snakefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ workflow.source_path("scripts/geo.py")
2222

2323
wildcard_constraints:
2424
shape="[a-zA-Z0-9_-]+",
25-
tech_onshore="|".join(config["techs_onshore"].keys()),
26-
tech_offshore="|".join(config["techs_offshore"].keys()),
25+
tech="|".join(config["techs"].keys()),
2726

2827
# Add all your includes here.
2928
include: "rules/automatic.smk"

workflow/internal/config.schema.yaml

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,41 +16,29 @@ properties:
1616
required: [projection, resolution]
1717
additionalProperties: false
1818

19-
techs_onshore:
19+
techs:
2020
type: object
2121
additionalProperties:
2222
type: object
2323
properties:
24-
max_slope:
25-
type: number
26-
land_cover:
24+
initial_area:
25+
type: string
26+
enum: ["settlement_area", "pixel_area"]
27+
continuous_layers:
2728
type: object
2829
additionalProperties:
29-
type: number
30-
settlement:
31-
type: object
32-
properties:
33-
max_settlement:
34-
type: number
35-
weight:
36-
type: number
37-
required: [max_settlement, weight]
38-
additionalProperties: false
39-
required: [max_slope, land_cover, settlement]
40-
additionalProperties: false
41-
42-
techs_offshore:
43-
type: object
44-
additionalProperties:
45-
type: object
46-
properties:
47-
water_depth:
30+
type: object
31+
properties:
32+
min:
33+
type: number
34+
max:
35+
type: number
36+
required: ["min", "max"]
37+
binary_layers:
4838
type: object
4939
additionalProperties:
5040
type: number
51-
weight:
52-
type: number
53-
required: [water_depth, weight]
54-
additionalProperties: false
55-
56-
required: [techs_onshore, techs_offshore]
41+
shapes_buffer:
42+
type: object
43+
required: ["initial_area", "continuous_layers", "binary_layers"]
44+
additionalProperties: false

workflow/rules/automatic.smk

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ rule download_cutout_slope:
88
input:
99
vector="resources/user/shapes/{shape}.parquet",
1010
output:
11-
path="resources/cutout/{shape}/slope.tif",
11+
path="resources/automatic/cutout/{shape}/slope.tif",
1212
wrapper:
1313
"v7.2.0/geo/rasterio/clip-geotiff"
1414

@@ -20,7 +20,7 @@ rule download_cutout_bathymetry:
2020
input:
2121
vector="resources/user/shapes/{shape}.parquet",
2222
output:
23-
path="resources/cutout/{shape}/bathymetry.tif",
23+
path="resources/automatic/cutout/{shape}/bathymetry.tif",
2424
wrapper:
2525
"v7.2.0/geo/rasterio/clip-geotiff"
2626

@@ -30,7 +30,7 @@ rule download_wdpa:
3030
params:
3131
url=internal["resources"]["automatic"]["wdpa"],
3232
output:
33-
"resources/automatic/wdpa.zip",
33+
"resources/automatic/global/wdpa.zip",
3434
conda:
3535
"../envs/shell.yaml"
3636
shell:
@@ -44,7 +44,7 @@ rule unzip_wdpa:
4444
input:
4545
rules.download_wdpa.output,
4646
output:
47-
directory("resources/automatic/wdpa.gdb"),
47+
directory("resources/automatic/global/wdpa.gdb"),
4848
conda:
4949
"../envs/shell.yaml"
5050
shell:
@@ -61,7 +61,7 @@ rule download_globcover:
6161
params:
6262
url=internal["resources"]["automatic"]["globcover"],
6363
output:
64-
"resources/automatic/globcover.zip",
64+
"resources/automatic/global/globcover.zip",
6565
conda:
6666
"../envs/shell.yaml"
6767
shell:
@@ -75,7 +75,7 @@ rule unzip_globcover:
7575
input:
7676
rules.download_globcover.output,
7777
output:
78-
"resources/automatic/globcover-landcover.tif",
78+
"resources/automatic/global/globcover-landcover.tif",
7979
log:
8080
"logs/unzip_globcover.log",
8181
conda:
@@ -94,7 +94,7 @@ rule download_ghsl:
9494
params:
9595
url=internal["resources"]["automatic"]["ghsl"],
9696
output:
97-
"resources/automatic/ghsl_built_s.zip",
97+
"resources/automatic/global/ghsl_built_s.zip",
9898
conda:
9999
"../envs/shell.yaml"
100100
shell:
@@ -108,7 +108,7 @@ rule unzip_ghsl:
108108
input:
109109
rules.download_ghsl.output,
110110
output:
111-
"resources/automatic/ghsl_built_s.tif",
111+
"resources/automatic/global/ghsl_built_s.tif",
112112
conda:
113113
"../envs/shell.yaml"
114114
shell:

workflow/rules/prepare.smk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ rule cutout_landcover:
77
shapes="resources/user/shapes/{shape}.parquet",
88
landcover=rules.unzip_globcover.output,
99
output:
10-
"resources/cutout/{shape}/landcover.tif",
10+
"resources/automatic/cutout/{shape}/landcover.tif",
1111
conda:
1212
"../envs/default.yaml"
1313
shell:
@@ -23,7 +23,7 @@ rule cutout_settlement:
2323
shapes="resources/user/shapes/{shape}.parquet",
2424
settlement=rules.unzip_ghsl.output,
2525
output:
26-
"resources/cutout/{shape}/settlement.tif",
26+
"resources/automatic/cutout/{shape}/settlement.tif",
2727
conda:
2828
"../envs/default.yaml"
2929
shell:

workflow/rules/process.smk

Lines changed: 16 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
rule resample_same_resolution:
1+
rule prepare_resampled_inputs:
22
message:
33
"Resample inputs for {wildcards.shape} to the projection and resolution of the land cover data, while aggregating land cover types.",
44
input:
@@ -10,9 +10,9 @@ rule resample_same_resolution:
1010
bathymetry_path=rules.download_cutout_bathymetry.output,
1111
protected_area_path=rules.unzip_wdpa.output,
1212
output:
13-
resampled_input="resources/{shape}/resampled_inputs.nc",
13+
resampled_input="resources/automatic/{shape}.resampled_inputs.nc",
1414
plot=report(
15-
"resources/{shape}/resampled_inputs.png",
15+
"resources/automatic/{shape}.resampled_inputs.png",
1616
category="resampled_input",
1717
),
1818
conda:
@@ -24,92 +24,40 @@ rule resample_same_resolution:
2424
"{output.resampled_input}" "{output.plot}"
2525
"""
2626

27-
rule technical_mask_onshore:
27+
rule area_potential:
2828
message:
29-
"Get fraction satisfied all technical criteria: not too steep slope, suitable land cover, and not exceeding max_settlement for the tech {wildcards.tech_onshore} and shape {wildcards.shape}.",
29+
"Compute area potential for the tech {wildcards.tech} and shapes {wildcards.shape}."
3030
params:
31-
suitable_land_cover_types=lambda wildcards: config["techs_onshore"][f"{wildcards.tech_onshore}"]["land_cover"],
32-
max_slope=lambda wildcards: config["techs_onshore"][f"{wildcards.tech_onshore}"]["max_slope"],
33-
max_settlement=lambda wildcards: config["techs_onshore"][f"{wildcards.tech_onshore}"]["settlement"]["max_settlement"],
34-
input:
35-
script=workflow.source_path("../scripts/apply_technical_mask.py"),
36-
resampled_path=rules.resample_same_resolution.output.resampled_input,
37-
output:
38-
technical_mask="resources/{shape}/technical_mask_{tech_onshore}.nc",
39-
# plot=report(
40-
# "resources/{shape}/technical_mask_{tech_onshore}.pdf",
41-
# category="technical_mask",
42-
# ),
43-
conda:
44-
"../envs/default.yaml"
45-
shell:
46-
"""
47-
python "{input.script}" "{input.resampled_path}" "{params.suitable_land_cover_types}" "{params.max_slope}" "{params.max_settlement}" "{output}"
48-
"""
49-
50-
rule area_potential_onshore:
51-
message:
52-
"Compute onshore area potential for the tech {wildcards.tech_onshore} and shape {wildcards.shape}."
53-
params:
54-
technical_mask=lambda wildcards: config["techs_onshore"][f"{wildcards.tech_onshore}"]
55-
input:
56-
script=workflow.source_path("../scripts/potential_onshore.py"),
57-
shapes="resources/user/shapes/{shape}.parquet",
58-
masked_path=rules.technical_mask_onshore.output.technical_mask,
59-
output:
60-
area_potential="results/{shape}/area_potential_{tech_onshore}.tif",
61-
plot=report(
62-
"results/{shape}/area_potential_{tech_onshore}.png",
63-
category="area_potential",
64-
),
65-
conda:
66-
"../envs/default.yaml"
67-
shell:
68-
"""
69-
python "{input.script}" "{input.masked_path}" "{params.technical_mask}" "{input.shapes}" "{output.area_potential}" "{output.plot}"
70-
"""
71-
72-
rule area_potential_offshore:
73-
message:
74-
"Compute offshore area potential for the tech {wildcards.tech_offshore} and shape {wildcards.shape}."
75-
params:
76-
water_depth=lambda wildcards: config["techs_offshore"][f"{wildcards.tech_offshore}"]["water_depth"],
77-
weight=lambda wildcards: config["techs_offshore"][f"{wildcards.tech_offshore}"]["weight"],
31+
config=lambda wildcards: config["techs"][f"{wildcards.tech}"],
7832
buffer_crs=lambda wildcards: config["buffer_crs"],
7933
input:
80-
script=workflow.source_path("../scripts/potential_offshore.py"),
34+
script=workflow.source_path("../scripts/area_potential.py"),
8135
shapes="resources/user/shapes/{shape}.parquet",
82-
resampled_input_path=rules.resample_same_resolution.output.resampled_input,
36+
resampled_path=rules.prepare_resampled_inputs.output.resampled_input,
8337
output:
84-
area_potential="results/{shape}/area_potential_{tech_offshore}.tif",
38+
area_potential="results/{shape}/area_potential_{tech}.tif",
8539
plot=report(
86-
"results/{shape}/area_potential_{tech_offshore}.png",
40+
"results/{shape}/area_potential_{tech}.png",
8741
category="area_potential",
8842
),
89-
log:
90-
"logs/area_potential_{shape}_{tech_offshore}.log",
9143
conda:
9244
"../envs/default.yaml"
9345
shell:
9446
"""
95-
python "{input.script}" "{input.shapes}" \
96-
"{params.water_depth}" "{input.resampled_input_path}" "{params.weight}" "{params.buffer_crs}" "{output.area_potential}" "{output.plot}" 2> "{log}"
47+
set -x
48+
python "{input.script}" "{input.shapes}" "{input.resampled_path}" "{params.config}" "{params.buffer_crs}" "{output.area_potential}" "{output.plot}"
9749
"""
9850

99-
10051
rule area_potential_report:
10152
message:
102-
"Generate an overview report of the area potential for all techs in shape {wildcards.shape}.",
53+
"Generate an overview report of the area potential for all techs in shapes {wildcards.shape}.",
10354
input:
10455
shapes="resources/user/shapes/{shape}.parquet",
105-
resampled_path=rules.resample_same_resolution.output.resampled_input,
56+
resampled_path=rules.prepare_resampled_inputs.output.resampled_input,
10657
area_potentials=expand(
10758
"results/{{shape}}/area_potential_{tech}.tif",
108-
tech=config["techs_offshore"].keys(),
109-
) + expand(
110-
"results/{{shape}}/area_potential_{tech}.tif",
111-
tech=config["techs_onshore"].keys(),
112-
),
59+
tech=config["techs"].keys(),
60+
)
11361
output:
11462
csv="results/{shape}/area_potential_report.csv",
11563
html=report(

0 commit comments

Comments
 (0)