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-
10051rule 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