Skip to content

Commit

Permalink
filter large polygons before grouping by wofs_ls regions
Browse files Browse the repository at this point in the history
  • Loading branch information
vikineema committed Nov 21, 2023
1 parent 1315ade commit aafcf9b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
29 changes: 14 additions & 15 deletions deafrica_waterbodies/cli/generate_polygons.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,6 @@
show_default=True,
help="Maximum area in m2 of the waterbody polygons to be included.",
)
@click.option(
"--length-threshold-km",
default=150,
show_default=True,
help="Length threshold in kilometers by which to filter out large polygons.",
)
@click.option(
"--output-directory",
type=str,
Expand All @@ -125,10 +119,16 @@
help="File name for the final output",
)
@click.option(
"--split-by-wofs-ls-regions/--no-split-by-wofs-ls-regions",
"--group-by-wofs-ls-regions/--not-group-by-wofs-ls-regions",
default=True,
help="Group waterbody polygons by wofs_ls regions.",
)
@click.option(
"--length-threshold-km",
default=150,
show_default=True,
help="Length threshold in kilometers by which to filter out large polygons before grouping polygons by wofs_ls region.",
)
def generate_polygons(
verbose,
aoi_vector_file,
Expand All @@ -142,11 +142,11 @@ def generate_polygons(
overwrite,
min_polygon_size,
max_polygon_size,
length_threshold_km,
output_directory,
timeseries_directory,
file_name_prefix,
split_by_wofs_ls_regions,
group_by_wofs_ls_regions,
length_threshold_km,
):
"""
Generate water body polygons from WOfS All Time Summary data
Expand Down Expand Up @@ -196,7 +196,7 @@ def generate_polygons(
fs.mkdirs(final_outputs_dir, exist_ok=True)
_log.info(f"Created directory {final_outputs_dir}")

if split_by_wofs_ls_regions:
if group_by_wofs_ls_regions:
if not check_dir_exists(polygons_split_by_region_dir):
fs.mkdirs(polygons_split_by_region_dir, exist_ok=True)
_log.info(f"Created directory {polygons_split_by_region_dir}")
Expand Down Expand Up @@ -333,10 +333,6 @@ def generate_polygons(

waterbodies_gdf = add_polygon_properties(polygons=waterbodies_gdf)

waterbodies_gdf = filter_by_length(
polygons_gdf=waterbodies_gdf, length_threshold_km=length_threshold_km
)

waterbodies_gdf = add_timeseries_attribute(
polygons=waterbodies_gdf,
timeseries_directory=timeseries_directory,
Expand All @@ -355,7 +351,10 @@ def generate_polygons(

waterbodies_gdf_4326.to_parquet(os.path.join(final_outputs_dir, f"{file_name_prefix}.parquet"))

if split_by_wofs_ls_regions:
if group_by_wofs_ls_regions:
waterbodies_gdf_4326 = filter_by_length(polygons_gdf=waterbodies_gdf_4326,
length_threshold_km=length_threshold_km)

split_by_region_fps = split_polygons_by_region( # noqa F841
polygons_gdf=waterbodies_gdf_4326,
output_directory=polygons_split_by_region_dir,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_generate_polygons_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_generate_polygons(runner, capsys: pytest.CaptureFixture):
f"--max-polygon-size={max_polygon_size}",
f"--length-threshold-km={length_threshold_km}",
"--overwrite",
"--no-split-by-wofs-ls-regions",
"--not-group-by-wofs-ls-regions",
f"--timeseries-directory={timeseries_directory}",
f"--file-name-prefix={file_name_prefix}",
f"--output-directory={output_directory}",
Expand Down

0 comments on commit aafcf9b

Please sign in to comment.