scverse / squidpy

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

how to get a real live img object? #606

Closed stela2502 closed 2 years ago

stela2502 commented 2 years ago

I am trying to follow the tutorial https://squidpy.readthedocs.io/en/stable/external_tutorials/tutorial_tangram.html and am wondering of how to get the img object for a real live dataset. It would be great if there would be substantially more information about this object in the tutorial. I have checked more of the squidpy tutorials and all of them use the same function to get the img object.

I would greatly appreciate your help!

stela2502 commented 2 years ago

A short follow up question - how can a generate_spot_crops fail with the error: "ValueError: Expected height to be in interval [0, 1937], found 21035." if a call to

sc.pl.spatial(
    adata_st, color="louvain", alpha=0.7, frameon=False, show=False, ax=axs[0], title=""
)

already has what it needs to plot the slide with highlighted 'spots'

I would really love to get some help here.

stela2502 commented 2 years ago

Hi Giovanni, Do you need something from me to help me with this question? Can you point me to any web page that could help me with that? I am so totally clueless I do not even know where to start.

giovp commented 2 years ago

hi @stela2502 ,

thanks for the inteerst in SQuidpy, have you checked out the signature of the class? https://squidpy.readthedocs.io/en/latest/classes/squidpy.im.ImageContainer.html

you can also put the storage path as input

img = sq.im.ImageContainer("/path/to/file")

or read the image separately and pass it also to input

import imageio
image = imageio.imread("/path/to/file")
img = sq.im.ImageContainer(image)

you might have to pass a scale_factor if the coordinates stored in anndata (adata.obsm["spatial"]) are not in the same coordinate system as the input image.

hth

giovp commented 2 years ago

A short follow up question - how can a generate_spot_crops fail with the error: "ValueError: Expected height to be in interval [0, 1937], found 21035." if a call to

sc.pl.spatial(
    adata_st, color="louvain", alpha=0.7, frameon=False, show=False, ax=axs[0], title=""
)

already has what it needs to plot the slide with highlighted 'spots'

I would really love to get some help here.

I would also considering using the squidpy functions for plotting, scatter or segment according to the data you have

https://squidpy.readthedocs.io/en/latest/examples.html#plotting

stela2502 commented 2 years ago

Thank you for your input! I am sorry I had to create A issue to get this info. Could you possibly update the tutorials to also include this information? Might spare you some time in the long run. I'll tell you if I succeeded.

stela2502 commented 2 years ago

OK after having used both the scanpy and the squidpy plot functions I need to ask you - why does scanpy know how to crop the images and squidpy does not? Is not squidpy meant to be the 'better' program to deal with spatial data?

giovp commented 2 years ago

hi @stela2502 , squidpy doesn't crop the image cause the heuristics we used in scanpy wasn't very robust. But you can still crop it manually with crop_coords, you can check the argument on how it works!

stela2502 commented 2 years ago

Thank you. If the heuristic you use in scanpy does work for me - how do I get the coordinates from scanpy or how do I apply the same heuristic to get these coordinates?

giovp commented 2 years ago

you can use crop_coords argument in squidpy.pl.spatial_scatter. The heuristics were computed implicitly by the way the plotting was performed with the scanpy scatter functions. It is not possible to retrieve it anymore so I'd suggest to play around with the argument above. We could consider in the future to do something similar, but please open a new issue cause this is not the topic of this issue anymore.

This is also a different issue so I'm gonna go on and close this, but please feel free to open a new issue on the topic.