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

NaN values colored if non-NaN values are only one #238

Open
aeisenbarth opened this issue Apr 29, 2024 · 2 comments
Open

NaN values colored if non-NaN values are only one #238

aeisenbarth opened this issue Apr 29, 2024 · 2 comments

Comments

@aeisenbarth
Copy link
Contributor

aeisenbarth commented Apr 29, 2024

When the table misses some instances or contains NaN values, colors are not mapped. Specifically if:

  • The table contains less instances than the segmentation image in labels
  • Or an observation column or X column contains NaN (because missing values have been filled up).

Actual behavior:

If an obs/X column contains NaN and the non-NaN values are all the same, all labels are visualized with color, as if it ignores the fact that some are NaN.

Expected behavior:

It does not color values that are NaN.

@aeisenbarth aeisenbarth changed the title No color mapped when annotations incomplete NaN values colored if non-NaN values are only one Apr 29, 2024
@aeisenbarth
Copy link
Contributor Author

aeisenbarth commented Apr 29, 2024

Sorry, the initial observation actually is working correctly.

Except in one edge case:

  • If a column's non-NaN values have a single value (all same or NaN), all labels receive the same color (yellow) although the NaN labels should be transparent.

This is specifically the case when n_obs == 2 (so rather a rare case, not a critical issue):

import anndata as ad
import numpy as np
import pandas as pd
import spatialdata as sd
from napari_spatialdata import Interactive

labels = sd.models.Labels2DModel.parse(np.array([[0, 1], [2, 0]]), dims=("y", "x"))
adata = ad.AnnData(obs=pd.DataFrame({"col1": [0.5, np.nan], "region": "region1", "instance_id": [1, 2]}))
table = sd.models.TableModel.parse(adata, region=["region1"], region_key="region", instance_key="instance_id")
sdata = sd.SpatialData(labels={"region1": labels}, table=table)
Interactive(sdata=sdata)
# Expected: obs "col1" is yellow for label 1 (top right) and transparent for label 2 (bottom left)
# Actual: label 1 and label 2 are yellow

image

@melonora
Copy link
Collaborator

Thanks for reporting! Will look into it

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

No branches or pull requests

2 participants