Skip to content

Commit cdaa931

Browse files
committed
add ipywidget
1 parent 00052e5 commit cdaa931

File tree

1 file changed

+49
-14
lines changed

1 file changed

+49
-14
lines changed
Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,70 @@
1-
from ipywidgets import widgets as wg
1+
import ipywidgets
22
from .. import ephys_report
33
import matplotlib.image as mpimg
44
import matplotlib.pyplot as plt
55
import pathlib
6+
import typing as T
7+
from IPython.display import display
68

79

8-
def probe_widget(func):
9-
10-
probe_dropdown = wg.Dropdown(
11-
options=ephys_report.ProbeLevelReport.fetch("KEY", as_dict=True),
12-
description="Select Probe Insertion : ",
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,
1316
disabled=False,
14-
layout=wg.Layout(
15-
width="80%",
17+
layout=ipywidgets.Layout(
18+
width=f"{width}%",
1619
display="flex",
1720
flex_flow="row",
1821
justify_content="space-between",
1922
grid_area="processed_dropdown",
2023
),
21-
style={"description_width": "150px"},
24+
style={"description_width": f"{description_width}px"},
2225
)
2326

24-
return wg.interact(func, key=probe_dropdown)
2527

26-
27-
@probe_widget
28-
def plot_probe_level_report(key: dict):
29-
fig_name = (ephys_report.ProbeLevelReport & key).fetch1("drift_map_plot")
28+
def plot_probe_level_report(probe_key: T.Dict[str, T.Any]) -> None:
29+
fig_name = (ephys_report.ProbeLevelReport & probe_key).fetch1("drift_map_plot")
3030
fig, ax = plt.subplots(1, 1, figsize=(10, 5))
3131
img = mpimg.imread(fig_name)
3232
ax.imshow(img)
3333
ax.axis("off")
3434
plt.show()
3535
pathlib.Path(fig_name).unlink()
36+
37+
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+
48+
def plot_unit_level_report(unit_key: T.Dict[str, T.Any]) -> None:
49+
waveform_fig, autocorrelogram_fig, depth_waveform_fig = (
50+
ephys_report.UnitLevelReport & unit_key
51+
).fetch1("waveform_plotly", "autocorrelogram_plotly", "depth_waveform_plotly")
52+
waveform_fig = go.FigureWidget(waveform_fig)
53+
autocorrelogram_fig = go.FigureWidget(autocorrelogram_fig)
54+
depth_waveform_fig = go.FigureWidget(depth_waveform_fig)
55+
56+
display(
57+
ipywidgets.HBox(
58+
[ipywidgets.VBox([waveform_fig, autocorrelogram_fig]), depth_waveform_fig]
59+
)
60+
)
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)