Skip to content

Commit d2b07d5

Browse files
committed
add widget event handler
1 parent cdaa931 commit d2b07d5

File tree

2 files changed

+59
-38
lines changed

2 files changed

+59
-38
lines changed

element_array_ephys/plotting/unit_level.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ def plot_correlogram(
6565
template="simple_white",
6666
width=350,
6767
height=350,
68+
yaxis_range=[0, None]
6869
)
6970
return fig
7071

element_array_ephys/plotting/widget.py

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,70 @@
1-
import ipywidgets
1+
import ipywidgets as widgets
22
from .. import ephys_report
33
import matplotlib.image as mpimg
44
import matplotlib.pyplot as plt
55
import pathlib
66
import typing as T
77
from IPython.display import display
8+
from .. import ephys_no_curation as ephys
9+
from skimage import io
810

911

10-
def _drop_down_wg(
11-
dj_table, *, description="", width=100, description_width=100
12-
) -> ipywidgets.Dropdown:
13-
return ipywidgets.Dropdown(
14-
options=dj_table.fetch("KEY", as_dict=True),
15-
description=description,
16-
disabled=False,
17-
layout=ipywidgets.Layout(
18-
width=f"{width}%",
19-
display="flex",
20-
flex_flow="row",
21-
justify_content="space-between",
22-
grid_area="processed_dropdown",
23-
),
24-
style={"description_width": f"{description_width}px"},
12+
# 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+
unit_dropdown_wg = widgets.Dropdown(
34+
options=(
35+
(ephys_report.UnitLevelReport & probe_dropdown_wg.value)
36+
& "cluster_quality_label='good'"
37+
).fetch("unit"),
38+
description="Select Units : ",
39+
disabled=False,
40+
layout=widgets.Layout(
41+
width="15%",
42+
),
43+
style={"description_width": "100px"},
44+
)
45+
46+
# Update shank & unit dropdown according to probe change
47+
def update_shank_options(change):
48+
probe_key = change.new
49+
shank_dropdown_wg.options = (ephys_report.ProbeLevelReport & probe_key.value).fetch(
50+
"shank"
2551
)
2652

2753

54+
def update_unit_dropdown(change):
55+
probe_key = change.new
56+
unit_dropdown_wg.options = (
57+
(
58+
(ephys_report.UnitLevelReport & probe_key.value)
59+
& "cluster_quality_label='good'"
60+
).fetch("unit"),
61+
)
62+
63+
64+
probe_dropdown_wg.observe(update_shank_options, "value")
65+
probe_dropdown_wg.observe(update_unit_dropdown, "value")
66+
67+
2868
def plot_probe_level_report(probe_key: T.Dict[str, T.Any]) -> None:
2969
fig_name = (ephys_report.ProbeLevelReport & probe_key).fetch1("drift_map_plot")
3070
fig, ax = plt.subplots(1, 1, figsize=(10, 5))
@@ -35,16 +75,6 @@ def plot_probe_level_report(probe_key: T.Dict[str, T.Any]) -> None:
3575
pathlib.Path(fig_name).unlink()
3676

3777

38-
def probe_widget() -> ipywidgets.interactive:
39-
drop_down_wg = _drop_down_wg(
40-
ephys_report.ProbeLevelReport,
41-
description="Select Probe Insertion : ",
42-
width=85,
43-
description_width=150,
44-
)
45-
return ipywidgets.interactive(plot_probe_level_report, probe_key=drop_down_wg)
46-
47-
4878
def plot_unit_level_report(unit_key: T.Dict[str, T.Any]) -> None:
4979
waveform_fig, autocorrelogram_fig, depth_waveform_fig = (
5080
ephys_report.UnitLevelReport & unit_key
@@ -54,17 +84,7 @@ def plot_unit_level_report(unit_key: T.Dict[str, T.Any]) -> None:
5484
depth_waveform_fig = go.FigureWidget(depth_waveform_fig)
5585

5686
display(
57-
ipywidgets.HBox(
58-
[ipywidgets.VBox([waveform_fig, autocorrelogram_fig]), depth_waveform_fig]
87+
widgets.HBox(
88+
[widgets.VBox([waveform_fig, autocorrelogram_fig]), depth_waveform_fig]
5989
)
6090
)
61-
62-
63-
def unit_widget() -> ipywidgets.interactive:
64-
drop_down_wg = _drop_down_wg(
65-
ephys_report.UnitLevelReport & "cluster_quality_label='good'",
66-
description="Select Units : ",
67-
width=85,
68-
description_width=150,
69-
)
70-
return ipywidgets.interactive(plot_unit_level_report, unit_key=drop_down_wg)

0 commit comments

Comments
 (0)