Skip to content

Commit

Permalink
better handle unique indexes for shapes
Browse files Browse the repository at this point in the history
  • Loading branch information
ckmah committed Oct 15, 2024
1 parent 639ef56 commit da1ceff
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
3 changes: 2 additions & 1 deletion bento/geometry/_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ def overlay(
shape1 = sdata[s1]
shape2 = sdata[s2]

new_shape = shape1.overlay(shape2, how=how, make_valid=make_valid)
new_shape = shape1.overlay(shape2, how=how, make_valid=make_valid)[["geometry"]]
new_shape.index = new_shape.index.astype(str)
new_shape.attrs = {}

transform = shape1.attrs
Expand Down
1 change: 1 addition & 0 deletions bento/io/_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def _sjoin_shapes(
.dissolve(by="index_right", observed=True, dropna=False)
.reset_index(drop=True)[["geometry"]]
)
child_shape.index = child_shape.index.astype(str)
child_shape = ShapesModel.parse(child_shape)
child_shape.attrs = child_attrs
sdata.shapes[shape_key] = child_shape
Expand Down
24 changes: 13 additions & 11 deletions bento/io/_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,10 @@ def prep(
sdata.points[points_key].attrs["spatialdata_attrs"]["instance_key"] = instance_key

pbar = tqdm(total=3)
if len(point_sjoin) > 0:
pbar.set_description("Mapping points")
sdata = _sjoin_points(
sdata=sdata,
points_key=points_key,
shape_keys=point_sjoin,
)

pbar.update()

if len(shape_sjoin) > 0:
pbar.set_description("Mapping shapes")
pbar.set_description(
"Mapping shapes"
) # Map shapes must happen first; manyto1 mapping resets shape index
sdata = _sjoin_shapes(
sdata=sdata,
instance_key=instance_key,
Expand All @@ -99,6 +91,16 @@ def prep(

pbar.update()

if len(point_sjoin) > 0:
pbar.set_description("Mapping points")
sdata = _sjoin_points(
sdata=sdata,
points_key=points_key,
shape_keys=point_sjoin,
)

pbar.update()

# Only keep points within instance_key shape
_sync_points(sdata, points_key)

Expand Down

0 comments on commit da1ceff

Please sign in to comment.