|
1 |
| -from ipywidgets import widgets as wg |
| 1 | +import ipywidgets |
2 | 2 | from .. import ephys_report
|
3 | 3 | import matplotlib.image as mpimg
|
4 | 4 | import matplotlib.pyplot as plt
|
5 | 5 | import pathlib
|
| 6 | +import typing as T |
| 7 | +from IPython.display import display |
6 | 8 |
|
7 | 9 |
|
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, |
13 | 16 | disabled=False,
|
14 |
| - layout=wg.Layout( |
15 |
| - width="80%", |
| 17 | + layout=ipywidgets.Layout( |
| 18 | + width=f"{width}%", |
16 | 19 | display="flex",
|
17 | 20 | flex_flow="row",
|
18 | 21 | justify_content="space-between",
|
19 | 22 | grid_area="processed_dropdown",
|
20 | 23 | ),
|
21 |
| - style={"description_width": "150px"}, |
| 24 | + style={"description_width": f"{description_width}px"}, |
22 | 25 | )
|
23 | 26 |
|
24 |
| - return wg.interact(func, key=probe_dropdown) |
25 | 27 |
|
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") |
30 | 30 | fig, ax = plt.subplots(1, 1, figsize=(10, 5))
|
31 | 31 | img = mpimg.imread(fig_name)
|
32 | 32 | ax.imshow(img)
|
33 | 33 | ax.axis("off")
|
34 | 34 | plt.show()
|
35 | 35 | 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