Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Artur-man opened this issue Mar 21, 2024 · 2 comments · Fixed by scverse/spatialdata-notebooks#90

Comments

@Artur-man
Copy link

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
Copy link
Member

LucaMarconato commented Mar 21, 2024

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.

  • I'll make sure that the notebook also explain this.

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

@LucaMarconato LucaMarconato mentioned this issue Mar 21, 2024
9 tasks
@Artur-man
Copy link
Author

Ah that works, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants