Can I aggregate images and data by shapes?

The MERSCOPE data I have is anndata (table/metadata) and an original image. Then I get the polygon shape using Napari. Can I use the shape to aggregate the image and get the data and image correlated to the shape I want to learn about?

Hi, yes please use the polygon_query() API for obtaining this information.
For cropping the image this is still not supported by the polygon_query() API, but you can do it by manually finding the bounding box of the shape (using .bounds() from geopandas and creating a new polygon from its min and max values) and then calling bounding_box_query().

Two more notes:

  • we will prioritize supporting this with the polygon_query() function, thanks for reporting;
  • a user reported a bug with polygon_query() in some cases in which the shape to query by or the elements being queried are not in the same coordinate system and need alignment. If you experience this with your data please tell us here and we will fix it promptly.

Thanks a lot! Does the polygon_query() only return filtered shape and points? Could I also get the filtered table?

By default it filters also the table (and this can be toggled off using the parameter filter_table=False. I just noticed that we forgot to document the filter_table parameter, but as you can see it appears in the signature of the function: spatialdata.polygon_query — spatialdata

I recommend to update spatialdata because we are currently in a phase in which we are improving it weekly and you may be running an old version that doesn’t have the filter_table parameter.

Please let me know in case you need further advice.