Open LucaCalderoni opened 1 month ago
Hi, can you please try this code here: https://github.com/scverse/napari-spatialdata/issues/242#issuecomment-2317186193?
There was a typo in the code I linked, please try this one on the latest napari-spatialdata main
:
from spatialdata.datasets import blobs_annotating_element
from napari_spatialdata import Interactive
import spatialdata as sd
sdata = blobs_annotating_element("blobs_labels")
##
labels = sdata["blobs_labels"]
print(sd.get_element_instances(labels))
obs = sdata["table"].obs
obs["strings"] = ["A", "A", "B", "B", "C"]
##
sdata["table"].uns["strings_colors"] = {
"A": "#FF5733", # red
"B": "#3498DB", # blue
"C": "#2ECC71", # green
}
Interactive(sdata)
It should give you this:
If you can't reproduce the bug with the code above please modify the code so that I can reproduce your bug with a small script. Thanks a lot!
Hi! I lauched the code above, but it gave me different colors: I did not incur in the bug though. I launched the code above on my windows laptop after I downloaded the latest main branch, so as soon as I get back to my ubuntu machine in my workplace I'll try to do the same and see if the bug occurs again. On the ubuntu machine I downloaded the development branch 0.5.4.dev2+gf84b79b because I needed a specific fix, but now I see that it has been merged into the main branch so I should have no problems.
Thank you for sending the details. It's a bit strange because yesterday another user tried the code and it seems that things worked: https://scverse.zulipchat.com/#narrow/stream/315824-spatial/topic/napari-spatialdata/near/476109235. I will look into this; meanwhile please send any other details that could help reproduce the bug.
It seems these bugs somewhat depend on the operating system. For example, I just tried on my windows laptop to visualize some custom annotations that were not included in the metadata csv file. I manually inserted them in the adata inside the spatialdata object as additional entries of the obs slot. This operation worked perfectly on linux, but on my windows it does not work, for some reason all cells are uniformly colored with a dull gray color, regardless of the annotation I select on the right. Even the annotations taken from the metadata csv are not colored. The same happened some time ago to my student on his windows machine, that's why I suspect these bugs might be different for each OS.
Please check the napari versions. We have introduced bugfixes in rendering colormaps. So using the old napari version may impact different visible colors
I confirm I am using the latest napari (0.5.4) on both windows and ubuntu.
Hi! I have another update: I just downloaded the latest napari-spatialdata main branch on the linux machine in my workplace, and then I tried again to set customized colors through a dictionary in the uns slot of the anndata object. This time no error messages popped up, however napari ignored my instructions and colored the annotation with its default palette. Furthermore, I cannot visualize anymore the annotation label of each cell by hovering on it with the mouse cursor.
Hey @LucaCalderoni, @LucaMarconato
I just wanted to add weight to this. a legend of what colors mean in Napari interactive is really critical for smooth quality control. Hover information in a little corner in my opinion is not enough.
I am not sure of the capabilities of napari in this sense, but from my naive point of view a little legend matching color to categorical in a small pop up or box would be good enough, setting our own { categoricals : color } dictionaries to set colors would be even better.
Hi! I am testing napari-spatialdata on a public Nanostring Cosmx dataset (https://kero.hgc.jp/Breast_Cancer_Spatial.html), and I would like to set a custom color for each label of a specific categorical variable, i.e., the cell types obtained with an external tool. I tried to manually insert a dictionary in the uns slot of the anndata object used as 'table' in the spatialdata object, in the format {:, :, ..... }. However, after I load the spatialdata object on napari and I select the desired annotation in the 'observations' panel on the right, an error message pops up, and the annotation is not visualized at all. Here is the full error:
I have no clue about this, especially considering that a student of mine previously succeeded in setting custom colors with an older version of napari-spatialdata. Currently I am using the 0.5.4.dev2+gf84b79b version of napari-spatialdata on napari 0.5.4 in python 3.12.3 on an ubuntu machine. I am still a beginner with python, can anyone give me any advice on how to solve this? Thank you in advance!