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

adding widget for adding points layer #20

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/napari_brainbow_diagnose/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
)
from ._tooltip_pointer import tooltip_pointer_widget
from ._widget import DiagnoseWidget
from ._read_csv_widget import read_csv_widget

__all__ = (
"tooltip_pointer_widget",
"make_rgb_cube_data",
"fetch_chroms_data",
"load_chroms_data_sample",
"DiagnoseWidget",
"read_csv_widget",
)
33 changes: 33 additions & 0 deletions src/napari_brainbow_diagnose/_read_csv_widget.py
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):
Copy link
Contributor

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 explicit rgb_to_maxwell_triangle. You can also add a small docstring.

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()
Copy link
Contributor

Choose a reason for hiding this comment

The 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'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe x and y can be renamed x-maxwell-triangle, y-maxwell-triangle to be explicit

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
6 changes: 6 additions & 0 deletions src/napari_brainbow_diagnose/napari.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Loading