Skip to content

Commit

Permalink
Merge pull request #207 from ckmah/main
Browse files Browse the repository at this point in the history
merscope reader remove invalid polygons
  • Loading branch information
LucaMarconato authored Jan 5, 2025
2 parents d4b9c8c + 15f8f68 commit a5dfb92
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/spatialdata_io/readers/merscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import xarray
from dask import array as da
from dask_image.imread import imread
from shapely.geometry import MultiPolygon
from spatialdata import SpatialData
from spatialdata._logging import logger
from spatialdata.models import Image2DModel, PointsModel, ShapesModel, TableModel
Expand Down Expand Up @@ -313,7 +314,8 @@ def _get_polygons(boundaries_path: Path, transformations: dict[str, BaseTransfor
geo_df = geopandas.read_parquet(boundaries_path)
geo_df = geo_df.rename_geometry("geometry")
geo_df = geo_df[geo_df[MerscopeKeys.Z_INDEX] == 0] # Avoid duplicate boundaries on all z-levels
geo_df.geometry = geo_df.geometry.map(lambda x: x.geoms[0]) # The MultiPolygons contain only one polygon
geo_df = geo_df[geo_df.geometry.is_valid] # Remove invalid geometries
geo_df.geometry = geo_df.geometry.map(lambda x: MultiPolygon(x.geoms))
geo_df.index = geo_df[MerscopeKeys.METADATA_CELL_KEY].astype(str)

return ShapesModel.parse(geo_df, transformations=transformations)
Expand Down

0 comments on commit a5dfb92

Please sign in to comment.