You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importpytestfromsrc.burn_backend.lib.derive_boundaryimport (
derive_boundary,
Pipeline,
FloodFillSegmentation,
OtsuThreshold,
GaussianSmoothing,
FillHoles,
BinaryDilation,
RestrictToSeedPoints,
)
importgeopandasasgpdfromshapely.geometryimportPointimportxarrayasxrimportnumpyasnpfromshapelyimportMultiPolygon, Polygon## TODO(!test): Add test for derive_boundary logic, including restriction polygon# Issue URL: https://github.com/SchmidtDSE/burn-severity-mapping-poc/issues/66deftest_derive_boundary_success_multiple_seeds(
test_intermediate_burn_metrics_tiny_dome,
test_multiple_seed_points_tiny_dome,
):
# Load test_points_gpdseed_locations_gpd=gpd.GeoDataFrame.from_features(
test_multiple_seed_points_tiny_dome["features"]
)
# To match how this runs in the pipeline, select just rbrmetric_layer=test_intermediate_burn_metrics_tiny_dome.sel(burn_metric="rbr")
# Add a dim called 'seed' to denote whether the pixel is a seed pointmetric_layer=metric_layer.expand_dims(dim="seed")
metric_layer["seed"] =xr.full_like(metric_layer, False, dtype=bool)
forpointinseed_locations_gpd.geometry:
# Find the nearest pixel to the seed point, we want the index, not the valuenearest_pixel=metric_layer.sel(x=point.x, y=point.y, method="nearest")
metric_layer["seed"].loc[
dict(x=nearest_pixel.x.values, y=nearest_pixel.y.values)
] =Trueseed_indices=list(zip(*np.where(metric_layer["seed"].values[0, :, :])))
# Define the pipelinepipeline=Pipeline(
thresholding_strategy=OtsuThreshold(),
segmentation_strategy=FloodFillSegmentation(seed_indices=seed_indices),
smoothing_strategies=[GaussianSmoothing(sigma=1)],
postprocessing_strategies=[FillHoles(), BinaryDilation(iterations=2)],
polygon_cleanup_strategies=[
RestrictToSeedPoints(seed_locations_gpd=seed_locations_gpd)
],
)
# Call the derive_boundary functionresult=derive_boundary(metric_layer, pipeline)
# Check that the result is as expectedassertisinstance(result, gpd.GeoSeries)
assertisinstance(result[0], MultiPolygon)
The text was updated successfully, but these errors were encountered:
burn-severity-mapping-poc/tests/unit/lib/test_derive_boundary.py
Lines 18 to 19 in 9f4f901
The text was updated successfully, but these errors were encountered: