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

Feature request: support for MultiScaleData #212

Open
will-moore opened this issue Mar 17, 2023 · 6 comments
Open

Feature request: support for MultiScaleData #212

will-moore opened this issue Mar 17, 2023 · 6 comments
Labels
enhancement New feature or request

Comments

@will-moore
Copy link

Hi - thanks for the plugin - looks great!
I've just started looking at this for displaying the features on labels (passed into napari as a dataframe using the features attribute of a new labels layer).

The plotting works fine, but I'm missing the extra layer that shows the colors of selected/unselected labels:
This screenshot is with only the original labels layer visible, having made a selection in the plot with the lasso:

Screenshot 2023-03-17 at 10 55 55

From the user guide, I was expecting to see an addition layer with blue/orange labels.

I see this in the Terminal where I launched napari:

Traceback (most recent call last):
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/matplotlib/cbook/__init__.py", line 304, in process
    func(*args, **kwargs)
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/matplotlib/widgets.py", line 2351, in release
    self._release(event)
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/matplotlib/widgets.py", line 3826, in _release
    self.onselect(self.verts)
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/napari_clusters_plotter/_Qt_code.py", line 268, in onselect
    self.parent.manual_clustering_method(self.ind_mask)
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/napari_clusters_plotter/_plotter.py", line 72, in manual_clustering_method
    self.run(
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/napari_clusters_plotter/_plotter.py", line 396, in run
    cluster_image = generate_cluster_image(
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/napari_clusters_plotter/_utilities.py", line 135, in generate_cluster_image
    return relabel(label_image, list(predictionlist_new)).astype("uint64")
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/deprecated/classic.py", line 285, in wrapper_function
    return wrapped_(*args_, **kwargs_)
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/napari_skimage_regionprops/_parametric_images.py", line 172, in relabel
    return relabel_numpy(image, measurements)
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/deprecated/classic.py", line 285, in wrapper_function
    return wrapped_(*args_, **kwargs_)
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/napari_skimage_regionprops/_parametric_images.py", line 181, in relabel_numpy
    return numpy.take(np.insert(np.array(measurements), 0, 0), image)
  File "<__array_function__ internals>", line 180, in take
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 190, in take
    return _wrapfunc(a, 'take', indices, axis=axis, out=out, mode=mode)
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 66, in _wrapfunc
    return _wrapit(obj, method, *args, **kwds)
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/numpy/core/fromnumeric.py", line 43, in _wrapit
    result = getattr(asarray(obj), method)(*args, **kwds)
TypeError: __array__() takes 1 positional argument but 2 were given

FYI: the data was loaded as described at ome/napari-ome-zarr#85

@will-moore
Copy link
Author

In case this is caused by my in-flux dev environment:

napari info:

napari: 0.5.0a2.dev43+g45044be5
Platform: macOS-12.2.1-x86_64-i386-64bit
System: MacOS 12.2.1
Python: 3.9.16 | packaged by conda-forge | (main, Feb 1 2023, 21:42:20) [Clang 14.0.6 ]
Qt: 5.15.2
PyQt5: 5.15.9
NumPy: 1.22.4
SciPy: 1.9.1
Dask: 2023.2.1
VisPy: 0.12.1
magicgui: 0.7.0
superqt: unknown
in-n-out: 0.1.7
app-model: 0.1.1
npe2: 0.6.2

OpenGL:
- GL version: 2.1 Metal - 76.3
- MAX_TEXTURE_SIZE: 16384

Screens:
- screen 1: resolution 2560x1440, scale 1.0
- screen 2: resolution 1512x982, scale 2.0

Settings path:
- /Users/wmoore/Library/Application Support/napari/SSBD_755716e081b808298b07ad27a8c28c5acf003923/settings.yaml
$ pip freeze | grep napari
napari @ git+https://github.com/napari/napari.git@45044be5c04f79a7a59e2ce229e8ee97248ef4fc
napari-arboretum==0.1.1
napari-clusters-plotter==0.6.1
napari-console==0.0.7
napari-matplotlib==0.2.1
-e git+ssh://[email protected]/ome/napari-ome-zarr.git@19eaf19cc5a04868c428f4ec88dc87f4bf8e1746#egg=napari_ome_zarr
napari-plugin-engine==0.2.0
napari-properties-viewer==0.0.2
napari-skimage-regionprops==0.10.0
napari-svg==0.1.6
napari-tools-menu==0.1.19
napari-workflows==0.2.8

@lazigu
Copy link
Collaborator

lazigu commented Mar 17, 2023

Hi @will-moore,

Thanks a lot for the feedback and for using the plugin!
I just made a new release of the plugin, which might be fixing the issue you have encountered. Could you please update the version of the plugin, try again on your data and report back whether the error still persist?

pip install --upgrade napari-clusters-plotter

Best,
Laura

@lazigu lazigu added the bug Something isn't working label Mar 17, 2023
@will-moore
Copy link
Author

Thanks for looking at this...
Unfortunately I get a different error after upgrade:

Traceback (most recent call last):
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/matplotlib/cbook/__init__.py", line 304, in process
    func(*args, **kwargs)
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/matplotlib/widgets.py", line 2351, in release
    self._release(event)
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/matplotlib/widgets.py", line 3826, in _release
    self.onselect(self.verts)
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/napari_clusters_plotter/_Qt_code.py", line 410, in onselect
    self.parent.manual_clustering_method(self.ind_mask)
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/napari_clusters_plotter/_plotter.py", line 89, in manual_clustering_method
    self.run(
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/napari_clusters_plotter/_plotter.py", line 380, in run
    self.label_ids = features["label"]
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/pandas/core/frame.py", line 3807, in __getitem__
    indexer = self.columns.get_loc(key)
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/pandas/core/indexes/base.py", line 3804, in get_loc
    raise KeyError(key) from err
KeyError: 'label'

@lazigu
Copy link
Collaborator

lazigu commented Mar 17, 2023

This error tells you that a column named "label" is missing from your csv file/features of your labels layer. I assume you are uploading your own csv file, right? Typically if you use plugins like napari-skimage-regionprops, such column would be added automatically. Otherwise, we used to have a check for this, but it seems that after the measurements widget was removed from the plugin, this check whether such column really exists also disappeared. Thanks for catching this bug!

Typically, if "label" column is missing, we would add it to layer's features with the assumption that the measurements start at label 1 and each row describes the next label. If it is true for your data, you can do this in napari like this -> open napari terminal and type these commands with exchanged "labels_layer" to the name of your labels layer:
image

import pandas as pd
import numpy as np
viewer.layers["labels_layer"].features["label"] = np.array(range(1, (len(viewer.layers["labels_layer"].features.index)) + 1))

Please tell me how it goes :)

@will-moore
Copy link
Author

Yes, the labels layer is added with code that also adds "features" dataframe, so I've added a "label" column to that (and I also tried it with your code example), but in both cases I get a new error...

Traceback (most recent call last):
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/matplotlib/cbook/__init__.py", line 304, in process
    func(*args, **kwargs)
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/matplotlib/widgets.py", line 2351, in release
    self._release(event)
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/matplotlib/widgets.py", line 3826, in _release
    self.onselect(self.verts)
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/napari_clusters_plotter/_Qt_code.py", line 410, in onselect
    self.parent.manual_clustering_method(self.ind_mask)
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/napari_clusters_plotter/_plotter.py", line 89, in manual_clustering_method
    self.run(
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/napari_clusters_plotter/_plotter.py", line 474, in run
    cluster_image = generate_cluster_image(
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/napari_clusters_plotter/_utilities.py", line 238, in generate_cluster_image
    return map_array(label_image, label_list, predictionlist_new).astype("uint64")
  File "/Users/wmoore/opt/anaconda3/envs/SSBD/lib/python3.9/site-packages/skimage/util/_map_array.py", line 35, in map_array
    input_arr = input_arr.reshape(-1)
AttributeError: 'MultiScaleData' object has no attribute 'reshape'

@lazigu
Copy link
Collaborator

lazigu commented Mar 17, 2023

Ah I see, your labels layer is a multiscale layer in napari. The support of such data is not implemented yet in the clusters-plotter. The plugin expects the image to be a numpy multidimensional array, which is the default data type when you open e.g. tif format image with

viewer = napari.Viewer()
viewer.add_labels(labels_image)

And simply adding the conversion of MultiScaleData to a numpy array is not a solution because it ruins the data structure of the image. I will create an issue to implement the support for such data.

In the mean time, would it maybe be possible to open your data not as multiscale in napari?

@lazigu lazigu changed the title Colors update error on plot selection Feature request: support for MultiScaleData Mar 20, 2023
@lazigu lazigu added enhancement New feature or request and removed bug Something isn't working labels Mar 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants