gustaveroussy / sopa

Technology-invariant pipeline for spatial omics analysis (Xenium / Visium HD / MERSCOPE / CosMx / PhenoCycler / MACSima / ...) that scales to millions of cells
https://gustaveroussy.github.io/sopa/
BSD 3-Clause "New" or "Revised" License
129 stars 15 forks source link

[Bug] Self-intersection in resolve conflict (TopologyException) #11

Closed quentinblampey closed 9 months ago

quentinblampey commented 9 months ago

Sometimes, after cellpose, some cells may be self-intersecting, leading to a TopologyException

sopa/segmentation/shapes.py:52 in solve_conflicts cell1.union(cell2).buffer(0) GEOSException: TopologyException: Input geom 1 is invalid: Self-intersection

quentinblampey commented 9 months ago

After intersections, some cells may become a GeometryCollection: we now consider this case scenario Also, _ensure_polygon is now safer: it should really return a Polygon, else the cell is filtered (it should not happen though)