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

Enhancement: Selected point in layer could be an interactive cluster in "Clustering" options #363

Open
ClementCaporal opened this issue Jan 26, 2025 · 3 comments

Comments

@ClementCaporal
Copy link

ClementCaporal commented Jan 26, 2025

Motivation

Using the plugin I can find objects from the PlotterWidget to the layer using the MANUAL_CLUSTER_ID.
I would like to also find objects from the layer.selected_data to the PlotterWidget.

For example what are the features of the left part of the annotations.

If this is in the scope of this plugin, I can try to make a PR.

Workaround

If this is out of scope of this plugin, one can use this code to reproduce the described behaviour using point_layer

import napari
import numpy as np
import pandas as pd

viewer = napari.Viewer()

n_points = 200
points = np.random.rand(n_points, 2) * 100

features = pd.DataFrame({
    'feature1': np.linspace(0, 1, n_points),
    'feature2': np.random.rand(n_points),
    'SELECTED_CLUSTER': 0,
})

point_layer = viewer.add_points(points, features=features)

def on_selection_change(selected):
    point_layer.features['SELECTED_CLUSTER'] = 0
    point_layer.features.loc[selected, 'SELECTED_CLUSTER'] = 1

point_layer.selected_data.events.items_changed.connect(on_selection_change)

from napari_clusters_plotter import PlotterWidget

pw = PlotterWidget(viewer)
pw.plot_x_axis.setCurrentIndex(0)
pw.plot_y_axis.setCurrentIndex(1)
pw.plot_cluster_id.setCurrentIndex(1)
viewer.window.add_dock_widget(pw)


point_layer.selected_data = np.arange(40)


pw.run(point_layer.features, "feature1", "feature2", "SELECTED_CLUSTER")

Image

@jo-mueller
Copy link
Collaborator

Hi @ClementCaporal ,

That's a cool idea that would give the clusters plotter a sort of bi-directionality which could be very helpful. Similar to #104, I would put this feature into 0.9.0 where it should be easier to implement, anyway.

Your code snippet should already be half the work :)

@ClementCaporal
Copy link
Author

Cool! Thank you very much.
Tell me if you think I can participate!

@jo-mueller
Copy link
Collaborator

I'd say PRs are always welcome :)

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