-
Notifications
You must be signed in to change notification settings - Fork 2
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
adding widget for adding points layer #20
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import napari | ||
|
||
import pandas as pd | ||
import numpy as np | ||
|
||
from magicgui import magicgui | ||
from magicgui import magic_factory | ||
import pathlib | ||
|
||
def rgb_to_xy(r, g, b): | ||
s = r+g+b | ||
r = r/s | ||
g = g/s | ||
b = b/s | ||
x = (r-b)/np.sqrt(3) | ||
y = g | ||
return x, y | ||
|
||
@magic_factory(call_button="Create a Points layer", auto_call=False) | ||
def read_csv_widget(filename = pathlib.Path('/path/to/csv/file.csv')): | ||
# Getting the current viewer | ||
viewer = napari.current_viewer() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't know this existed! Cool! |
||
# Import data | ||
df = pd.read_csv(filename, names=['axis-0', 'axis-1', 'axis-2', 'red', 'green', 'blue']) | ||
# Create points layer | ||
coordinates = df[['axis-0', 'axis-1', 'axis-2']].values | ||
colors = df[['red', 'green', 'blue']].values | ||
points_layer = viewer.add_points(coordinates, name='points', face_color=colors, edge_color=colors, size=20, out_of_slice_display=True) | ||
|
||
# Add Maxwell coordinates | ||
df['x'], df['y'] = rgb_to_xy(df['red'], df['green'], df['blue']) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe |
||
features_table = {'red': df['red'].values, 'green': df['green'].values, 'blue': df['blue'].values, 'x': df['x'].values, 'y': df['y'].values} | ||
points_layer.features = features_table |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,9 @@ contributions: | |
- id: napari-brainbow-diagnose.DiagnoseWidget | ||
python_name: napari_brainbow_diagnose._widget:DiagnoseWidget | ||
title: Diagnose Brainbow Image | ||
- id: napari-brainbow-diagnose.read_csv_widget | ||
python_name: napari_brainbow_diagnose._read_csv_widget:read_csv_widget | ||
title: Load a Points layer | ||
sample_data: | ||
- command: napari-brainbow-diagnose.make_rgb_cube_data | ||
display_name: RGB Cube | ||
|
@@ -26,3 +29,6 @@ contributions: | |
display_name: Diagnose Brainbow Image | ||
- command: napari-brainbow-diagnose.tooltip_pointer_widget | ||
display_name: Brainbow Tooltip | ||
- command: napari-brainbow-diagnose.read_csv_widget | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can reorder the widget list so your contribution comes first (It should be first step as it is a loading step) |
||
display_name: Load a Points layer | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this function name could go to
_utils_channel_space.py
.I also suggest to rename to something more specific that
rgb_to_xy
with something more explicitrgb_to_maxwell_triangle
. You can also add a small docstring.