You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Apologies, I fixed the bug in get_values() and the PR is now merged scverse/spatialdata#367.
The bug was due to the fact that the labels element contains the background (value 0), but not the table. I fixed this and the values returned by get_values() now never contain the background.
Anyway, this leads to another bug now, which I think it's due to the fact that spatialdata-plot expects a value also for the background.
Can you make your code ignore the background and not display anything for it (like showing a color with alpha = 0)?
Note, to make the task easier, and also to take into account that the labels element could contain non-continuous labels, this new PR (merged) ensures that the dataframe returned by get_values() has the instance_key values in its index. scverse/spatialdata#368
This is the traceback of the new bug:
------------------
ax = plt.gca()
sdata.pl.render_images("blobs_image", cmap="viridis", channel=1).pl.show(ax=ax)
sdata_im.pl.render_labels(color="channel_1_mean", fill_alpha=0.5).pl.show(ax=ax)
------------------
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
File /mnt/repos/spatialdata-plot/src/spatialdata_plot/pl/utils.py:899, in _map_color_seg(seg, cell_id, color_vector, color_source_vector, cmap_params, seg_erosionpx, seg_boundaries, na_color)
898 try:
--> 899 cols = cmap_params.cmap(cmap_params.norm(color_vector))
900 except TypeError:
TypeError: 'NoneType' object is not callable
During handling of the above exception, another exception occurred:
AssertionError Traceback (most recent call last)
Cell In[8], line 3
1 ax = plt.gca()
2 sdata.pl.render_images("blobs_image", cmap="viridis", channel=1).pl.show(ax=ax)
----> 3 sdata_im.pl.render_labels(color="channel_1_mean", fill_alpha=0.5).pl.show(ax=ax)
File /mnt/repos/spatialdata-plot/src/spatialdata_plot/pl/basic.py:704, in PlotAccessor.show(self, coordinate_systems, legend_fontsize, legend_fontweight, legend_loc, legend_fontoutline, na_in_legend, colorbar, wspace, hspace, ncols, frameon, figsize, dpi, fig, title, share_extent, pad_extent, ax, return_ax, save)
697 if is_categorical_dtype(colors):
698 _maybe_set_colors(
699 source=sdata.table,
700 target=sdata.table,
701 key=params.color,
702 palette=params.palette,
703 )
--> 704 _render_labels(
705 sdata=sdata,
706 render_params=params,
707 coordinate_system=cs,
708 ax=ax,
709 fig_params=fig_params,
710 scalebar_params=scalebar_params,
711 legend_params=legend_params,
712 )
714 if title is not None:
715 if len(title) == 1:
File /mnt/repos/spatialdata-plot/src/spatialdata_plot/pl/render.py:508, in _render_labels(sdata, render_params, coordinate_system, ax, fig_params, scalebar_params, legend_params)
493 color_source_vector, color_vector, categorical = _set_color_source_vec(
494 sdata=sdata_filt,
495 element=sdata_filt.labels[label_key],
(...)
503 cmap_params=render_params.cmap_params,
504 )
506 if (render_params.fill_alpha != render_params.outline_alpha) and render_params.contour_px is not None:
507 # First get the labels infill and plot them
--> 508 labels_infill = _map_color_seg(
509 seg=label.values,
510 cell_id=instance_id,
511 color_vector=color_vector,
512 color_source_vector=color_source_vector,
513 cmap_params=render_params.cmap_params,
514 seg_erosionpx=None,
515 seg_boundaries=render_params.outline,
516 na_color=render_params.cmap_params.na_color,
517 )
519 _cax = ax.imshow(
520 labels_infill,
521 rasterized=True,
(...)
526 # zorder=3,
527 )
528 cax = ax.add_image(_cax)
File /mnt/repos/spatialdata-plot/src/spatialdata_plot/pl/utils.py:901, in _map_color_seg(seg, cell_id, color_vector, color_source_vector, cmap_params, seg_erosionpx, seg_boundaries, na_color)
899 cols = cmap_params.cmap(cmap_params.norm(color_vector))
900 except TypeError:
--> 901 assert all(colors.is_color_like(c) for c in color_vector), "Not all values are color-like."
902 cols = colors.to_rgba_array(color_vector)
904 if seg_erosionpx is not None:
AssertionError: Not all values are color-like.
Finally in this PR scverse/spatialdata#369, I ensure that for labels, get_values() returns a table whose row are sorted by ascending labels value. Anyway, the safe way to match the returned dataframe to the labels is by looking at the index of the returned dataframe, not by looking at the order.
The current error AssertionError: Not all values are color-like is also appearing in the last plot of the mibitof notebook (I have just fixed the bug with get_values() in scverse/spatialdata#376.
I'd love to wait for @Sonja-Stockhaus' #164 to get started on this because we pulled the get_extent refactor on our end into her multi-scale PR because they had quite some otherwise-conflicting overlap. Once that's merged can follow up with a) figuring out if downstream bugs still exist and b) then solve the ones that do.
Activity
LucaMarconato commentedon Sep 29, 2023
My mistake, I had to use the parameter
color, notkey. This leads to another bug:AttributeError: 'SpatialImage' object has no attribute 'index'timtreis commentedon Oct 4, 2023
This error is in
spatialdatathough, I'm fighting with it in like 3 different issues :DLucaMarconato commentedon Oct 8, 2023
Apologies, I fixed the bug in
get_values()and the PR is now merged scverse/spatialdata#367.The bug was due to the fact that the labels element contains the background (value 0), but not the table. I fixed this and the values returned by
get_values()now never contain the background.Anyway, this leads to another bug now, which I think it's due to the fact that spatialdata-plot expects a value also for the background.
Can you make your code ignore the background and not display anything for it (like showing a color with alpha = 0)?
Note, to make the task easier, and also to take into account that the labels element could contain non-continuous labels, this new PR (merged) ensures that the dataframe returned by
get_values()has the instance_key values in its index. scverse/spatialdata#368This is the traceback of the new bug:
LucaMarconato commentedon Oct 8, 2023
Finally in this PR scverse/spatialdata#369, I ensure that for labels, get_values() returns a table whose row are sorted by ascending labels value. Anyway, the safe way to match the returned dataframe to the labels is by looking at the index of the returned dataframe, not by looking at the order.
LucaMarconato commentedon Oct 10, 2023
Setting medium priority since it shows up in the documentation notebooks.
LucaMarconato commentedon Oct 10, 2023
The current error
AssertionError: Not all values are color-likeis also appearing in the last plot of themibitofnotebook (I have just fixed the bug withget_values()in scverse/spatialdata#376.timtreis commentedon Oct 11, 2023
I'd love to wait for @Sonja-Stockhaus' #164 to get started on this because we pulled the
get_extentrefactor on our end into her multi-scale PR because they had quite some otherwise-conflicting overlap. Once that's merged can follow up with a) figuring out if downstream bugs still exist and b) then solve the ones that do.LucaMarconato commentedon Oct 11, 2023
Ok perfect, thanks a lot!
timtreis commentedon Nov 28, 2023
Update: Issue persists, will tackle next.