scverse / squidpy

Spatial Single Cell Analysis in Python
https://squidpy.readthedocs.io/en/stable/
BSD 3-Clause "New" or "Revised" License
440 stars 79 forks source link

Working on 3D segmentation matrix #861

Open rsemeraro opened 3 months ago

rsemeraro commented 3 months ago

Hello everyone, First of all, I'd like to extend my sincere thanks to all the developers and contributors to Squidpy and the entire Scanpy ecosystem. Your work is immensely valuable and greatly appreciated. I've been working with single-cell data for quite a while, but this is my first time exploring spatial data. Following the tutorial on the website, I was analyzing Nanostring data and encountered an issue at the visualization step using sq.pl.spatial_segment. The error message I received was: ValueError: all the input arrays must have same number of dimensions, but the array at index 0 has 4 dimension(s) and the array at index 1 has 3 dimension(s). After inspecting my data object and comparing it with the one from the tutorial, I noticed that the "segment" field in my object contains 3-dimensional arrays, whereas the tutorial's object uses 2-dimensional arrays. Could anyone provide guidance on how I might resolve this issue and successfully visualize my images? Thank you in advance for your assistance and for fostering such a supportive community. Best regards!

giovp commented 2 months ago

Could anyone provide guidance on how I might resolve this issue and successfully visualize my images?

could you try to squeeze() the numpy array? I'm not sure how the segmentation mask is imported but it should indeed only be 2 dimensions

rsemeraro commented 2 months ago

Dear @giovp, Thank you for the answer, but unfortunately, I cannot use the squeeze() function because none of the axes in my matrix have a dimension of 1, as required by that function. The dimensions of my matrix are (4256, 4256, 3). In the meantime, I made other observations.

The first one is related to the composition of the 'spatial' field in my AnnData. In particular, I have some IDs (20-37) containing the 'hires' field and others (1-19) where this field is missing.

Screenshot 2024-09-04 at 12 20 39

Moreover, I also tried to open the data with the spatialdata_io.cosmx command, but it fails during opening.

Screenshot 2024-09-04 at 12 16 11

Could this error also be related to the presence/absence of the hires field for some IDs?