scverse / spatialdata

An open and interoperable data framework for spatial omics data
https://spatialdata.scverse.org/
BSD 3-Clause "New" or "Revised" License
174 stars 34 forks source link

Custom spatialdata.models.ShapesModel throws "tuple index out of range" #499

Closed Artur-man closed 1 month ago

Artur-man commented 1 month ago

Dear all,

I have been playing around with spatialdata.models and was trying to build a custom ShapesModel object with Polygon geometry.

I have started with a set of Polygon points, and kept getting IndexError, but then I simplified the example as in here:

import geopandas as gpd
from shapely.geometry import Polygon
from spatialdata.models import ShapesModel
from spatialdata.transformations.transformations import Affine, Identity, Scale

coords = [(151.20138500000007, -43.787852999999984),
          (-151.40006999399998, -43.787852999999984),
          (-151.89015569564776, -43.76377663336097),
          (-152.3755216040806, -43.69177940201614),
          (-152.85149338027227, -43.57255467866103)]

polygon = Polygon(coords)
gdf = gpd.GeoDataFrame(geometry=[polygon], crs='epsg:4326')
gdf

Here is how the GeoDataFrame looks like:

                                            geometry
0  POLYGON ((151.20139 -43.78785, -151.40007 -43....

But still throws the same error. Would love to know if I am doing something wrong here.

shape_spatialdata = ShapesModel.parse(data = gdf, transformations={"global": Identity()})

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/amanuky/opt/anaconda3/envs/scverse/lib/python3.10/functools.py", line 925, in _method
    method = self.dispatcher.dispatch(args[0].__class__)
IndexError: tuple index out of range

This is the version pulled from main branch. Thanks in advance.

LucaMarconato commented 1 month ago

Hi @Artur-man, here the problem is that parse() uses functools.singledispatch, so the first argument should be specified without the prefix data=. We will be making a new release next week that will also add a notebook on the shapes model.

Minor note, we don't interact with the geopandas part that uses the crs, so the line , crs='epsg:4326' should have no effect.

Artur-man commented 1 month ago

Ah that works, thanks!