Skip to content

Commit

Permalink
Merge pull request #16 from MPI-Dortmund/add-magic-gui
Browse files Browse the repository at this point in the history
Add magicgui to requirements
  • Loading branch information
thorstenwagner authored Nov 16, 2023
2 parents 6e1c552 + 584fc67 commit c9e005a
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
1 change: 1 addition & 0 deletions pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extension-pkg-whitelist=pyqt, pyqt5, pyqt5-qt5
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ install_requires =
matplotlib
scipy
napari-clusters-plotter >= 0.7.2
magicgui
python_requires = >=3.10
include_package_data = True
package_dir =
Expand Down
19 changes: 13 additions & 6 deletions src/napari_tomotwin/load_umap.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
import numpy as np
from matplotlib.patches import Circle
from napari.utils import notifications

from qtpy.QtCore import Qt
from qtpy.QtGui import QGuiApplication # pylint: disable=E0611
from typing import List
plotter_widget: PlotterWidget = None
circle: Circle = None
circles: List[Circle] = []
umap: pd.DataFrame

def _draw_circle(data_coordinates, label_layer, umap):
global circle
global circles
global plotter_widget

label_layer.visible = 1
Expand All @@ -26,10 +28,15 @@ def _draw_circle(data_coordinates, label_layer, umap):
center = umap_coordinates.values.tolist()[0]
except IndexError:
return

if circle is not None:
circle.remove()
modifiers = QGuiApplication.keyboardModifiers()
if modifiers == Qt.ShiftModifier:
pass
else:
for c in circles[::-1]:
c.remove()
circles = []
circle = Circle(tuple(center), 0.5, fill=False, color='r')
circles.append(circle)
plotter_widget.graphics_widget.axes.add_patch(circle)
plotter_widget.graphics_widget.draw_idle()

Expand Down
3 changes: 2 additions & 1 deletion src/napari_tomotwin/make_targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ def _get_medoid_embedding(embeddings: pd.DataFrame, max_embeddings: int = 50000)
"""
if len(embeddings)>max_embeddings:
# For samples more than 50k it's way to slow and memory hungry.
embeddings = embeddings.sample(max_embeddings)
print(f"Your cluster size ({len(embeddings)}) is bigger then {max_embeddings}. Make a random sample to calculate medoid.")
embeddings = embeddings.sample(max_embeddings)

only_emb = embeddings.drop(columns=["X", "Y", "Z", "filepath"], errors="ignore").astype(np.float32)
distance_matrix=cdist(only_emb,only_emb,metric='cosine') # its not the cosine similarity, rather a distance (its 0 in case of same embeddings)
medoid_index = np.argmin(np.sum(distance_matrix,axis=0))
Expand Down

0 comments on commit c9e005a

Please sign in to comment.