Skip to content

Commit fb48db6

Browse files
committed
add ephys widget
1 parent a41d7ba commit fb48db6

File tree

1 file changed

+71
-93
lines changed

1 file changed

+71
-93
lines changed
Lines changed: 71 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,69 @@
11
import ipywidgets as widgets
2-
from .. import ephys_report
3-
import matplotlib.image as mpimg
4-
import matplotlib.pyplot as plt
52
import pathlib
6-
import typing as T
7-
from IPython.display import display, clear_output
3+
from IPython.display import display
4+
from .. import ephys_report
85
from .. import ephys_no_curation as ephys
6+
import plotly.graph_objs as go
7+
import plotly.express as px
98
from skimage import io
109

1110

12-
# Build selection widgets
13-
probe_dropdown_wg = widgets.Dropdown(
14-
options=ephys.CuratedClustering & ephys_report.ProbeLevelReport.fetch("KEY"),
15-
description="Select Probe Insertion : ",
16-
disabled=False,
17-
layout=widgets.Layout(
18-
width="80%",
19-
),
20-
style={"description_width": "150px"},
21-
)
22-
23-
shank_dropdown_wg = widgets.Dropdown(
24-
options=(ephys_report.ProbeLevelReport & probe_dropdown_wg.value).fetch("shank"),
25-
description="Select Shank : ",
26-
disabled=False,
27-
layout=widgets.Layout(
28-
width="15%",
29-
),
30-
style={"description_width": "100px"},
31-
)
32-
33-
shank_toggle_wg = widgets.ToggleButtons(
34-
options=(ephys_report.ProbeLevelReport & probe_dropdown_wg.value).fetch("shank"),
35-
description="Select Shank : ",
36-
layout=widgets.Layout(width="auto"),
37-
style={"button_width": "50px"},
38-
)
39-
40-
unit_dropdown_wg = widgets.Dropdown(
41-
options=(
42-
(ephys_report.UnitLevelReport & probe_dropdown_wg.value)
43-
& "cluster_quality_label='good'"
44-
).fetch("unit"),
45-
description="Select Units : ",
46-
disabled=False,
47-
layout=widgets.Layout(
48-
width="15%",
49-
),
50-
style={"description_width": "100px"},
51-
)
52-
53-
54-
def probe_widget():
55-
def plot_probe_figure(probe_key, shank):
11+
def ephys_widget():
12+
13+
# Build dropdown widgets
14+
probe_dropdown_wg = widgets.Dropdown(
15+
options=ephys.CuratedClustering & ephys_report.ProbeLevelReport,
16+
description="Select Probe Insertion : ",
17+
disabled=False,
18+
layout=widgets.Layout(
19+
width="80%",
20+
),
21+
style={"description_width": "150px"},
22+
)
23+
24+
shank_dropdown_wg = widgets.Dropdown(
25+
options=(ephys_report.ProbeLevelReport & probe_dropdown_wg.value).fetch(
26+
"shank"
27+
),
28+
description="Select Shank : ",
29+
disabled=False,
30+
layout=widgets.Layout(
31+
width="15%",
32+
),
33+
style={"description_width": "100px"},
34+
)
35+
36+
unit_dropdown_wg = widgets.Dropdown(
37+
options=(
38+
(ephys_report.UnitLevelReport & probe_dropdown_wg.value)
39+
& "cluster_quality_label='good'"
40+
).fetch("unit"),
41+
description="Select Units : ",
42+
disabled=False,
43+
layout=widgets.Layout(
44+
width="15%",
45+
),
46+
style={"description_width": "100px"},
47+
)
48+
49+
def probe_dropdown_evt(change):
50+
"""Change in probe dropdown option triggers this function"""
51+
52+
probe_key = change.new
53+
54+
shank_dropdown_wg.options = (
55+
ephys_report.ProbeLevelReport & probe_key.value
56+
).fetch("shank")
57+
58+
unit_dropdown_wg.options = (
59+
(
60+
ephys_report.UnitLevelReport
61+
& probe_key.value
62+
& "cluster_quality_label='good'"
63+
).fetch("unit"),
64+
)
65+
66+
def plot_probe_widget(probe_key, shank):
5667

5768
fig_name = (
5869
ephys_report.ProbeLevelReport & probe_key & f"shank={shank}"
@@ -75,46 +86,11 @@ def plot_probe_figure(probe_key, shank):
7586
xaxis_visible=False,
7687
yaxis_visible=False,
7788
)
78-
7989
pathlib.Path(fig_name).unlink()
80-
return go.FigureWidget(probe_fig)
81-
82-
def probe_dropdown_evt(change):
83-
probe_key = change.new
84-
shank_dropdown_wg.options = (
85-
ephys_report.ProbeLevelReport & probe_key.value
86-
).fetch("shank")
87-
unit_dropdown_wg.options = (
88-
(
89-
(ephys_report.UnitLevelReport & probe_key.value)
90-
& "cluster_quality_label='good'"
91-
).fetch("unit"),
92-
)
93-
clear_output()
94-
display(
95-
widgets.VBox(
96-
[
97-
probe_dropdown_wg,
98-
shank_dropdown_wg,
99-
plot_probe_figure(probe_key, shank_dropdown_wg.value),
100-
]
101-
)
102-
)
90+
display(go.FigureWidget(probe_fig))
10391

104-
probe_dropdown_wg.observe(probe_dropdown_evt, "value")
105-
106-
return widgets.VBox(
107-
[
108-
probe_dropdown_wg,
109-
shank_dropdown_wg,
110-
plot_probe_figure(probe_dropdown_wg.value, shank_dropdown_wg.value),
111-
]
112-
)
92+
def plot_unit_widget(unit):
11393

114-
115-
def unit_widget():
116-
def plot_unit_figure(unit):
117-
# Build a unit widgets
11894
waveform_fig, autocorrelogram_fig, depth_waveform_fig = (
11995
ephys_report.UnitLevelReport & probe_dropdown_wg.value & f"unit={unit}"
12096
).fetch1("waveform_plotly", "autocorrelogram_plotly", "depth_waveform_plotly")
@@ -136,12 +112,14 @@ def plot_unit_figure(unit):
136112
[widgets.VBox([waveform_fig, autocorrelogram_fig]), depth_waveform_fig],
137113
layout=widgets.Layout(margin="0 0 0 100px"),
138114
)
139-
return unit_fig_wg
115+
display(unit_fig_wg)
116+
117+
probe_dropdown_wg.observe(probe_dropdown_evt, "value")
118+
119+
probe_widget = widgets.interactive(
120+
plot_probe_widget, probe_key=probe_dropdown_wg, shank=shank_dropdown_wg
121+
)
140122

141-
def unit_dropdown_evt(change):
142-
unit = change.new
143-
clear_output()
144-
display(unit_dropdown_wg, plot_unit_figure(unit))
123+
unit_widget = widgets.interactive(plot_unit_widget, unit=unit_dropdown_wg)
145124

146-
unit_dropdown_wg.observe(unit_dropdown_evt, "value")
147-
return widgets.VBox([unit_dropdown_wg, plot_unit_figure(unit_dropdown_wg.value)])
125+
return widgets.VBox([probe_widget, unit_widget])

0 commit comments

Comments
 (0)