From 1940e0a1615db161fb9c631a7c5fc1d705d736fe Mon Sep 17 00:00:00 2001 From: Camilo Diaz Date: Mon, 20 May 2024 10:17:36 -0400 Subject: [PATCH] ENH: Added tonic input to GUI drivers tab --- hnn_core/gui/gui.py | 73 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 70 insertions(+), 3 deletions(-) diff --git a/hnn_core/gui/gui.py b/hnn_core/gui/gui.py index 6d4975ef2e..ebd90b42e4 100644 --- a/hnn_core/gui/gui.py +++ b/hnn_core/gui/gui.py @@ -29,7 +29,7 @@ import base64 import zipfile import numpy as np - +import debugpy class _OutputWidgetHandler(logging.Handler): def __init__(self, output_widget, *args, **kwargs): @@ -248,7 +248,7 @@ def __init__(self, theme_color="#8A2BE2", layout={'width': '15%'}) # Drive selection self.widget_drive_type_selection = RadioButtons( - options=['Evoked', 'Poisson', 'Rhythmic'], + options=['Evoked', 'Poisson', 'Rhythmic','Tonic'], value='Evoked', description='Drive:', disabled=False, @@ -1014,6 +1014,62 @@ def _get_evoked_widget(name, layout, style, location, data=None, drive.update(widgets_dict) return drive, drive_box +def _get_tonic_widget(name, layout, style, data=None): + + from copy import deepcopy + default_data = { + 'amplitude': 0, + 't0': 0, + 'tstop': 0, + 'seedcore': 14, + } + + cell_types = ['L5_pyramidal', 'L2_pyramidal', 'L5_basket', 'L2_basket'] + + if isinstance(data, dict): + default_data.update(data) + kwargs = dict(layout=layout, style=style) + + amplitudes, start_times, stop_times = dict(), dict(), dict() + for ct_idx, cell_type in enumerate(cell_types): + if cell_type in data: + default_data.update(data[cell_type]) + amplitudes[cell_type] = BoundedFloatText( + value=deepcopy(default_data['amplitude']), + description=cell_type, min=0, max=1e6, step=0.01, **kwargs) + start_times[cell_type] = BoundedFloatText( + value=deepcopy(default_data['t0']), description=cell_type, + min=0, max=1e6, step=0.01, **kwargs) + stop_times[cell_type] = BoundedFloatText( + value=deepcopy(default_data['tstop']), description=cell_type, + min=-1, max=1e6, step=0.01, **kwargs) + + # # link all t0 and tstop + # if ct_idx > 0: + # ipywidgets.link((start_times[cell_type], 'value'), + # (start_times[cell_types[ct_idx - 1]], 'value')) + # ipywidgets.link((stop_times[cell_type], 'value'), + # (stop_times[cell_types[ct_idx - 1]], 'value')) + + widgets_dict = { + 'amplitude': amplitudes, + 't0': start_times, + 'tstop': stop_times + } + widgets_list = ([HTML(value="Amplitude (nA):")] + + list(amplitudes.values()) + + [HTML(value="Start time (ms):")] + + list(start_times.values()) + + [HTML(value="Stop time (ms):")] + + list(stop_times.values())) + + drive_box = VBox(widgets_list) + drive = dict(type='Tonic', + name=name, + sync_within_trial=False) + drive.update(widgets_dict) + return drive, drive_box + def add_drive_widget(drive_type, drive_boxes, drive_widgets, drives_out, tstop_widget, location, layout, @@ -1075,9 +1131,17 @@ def add_drive_widget(drive_type, drive_boxes, drive_widgets, drives_out, default_delays=prespecified_delays, sync_evinput=sync_evinput ) + elif drive_type == 'Tonic': + name = drive_type + str(len(drive_boxes)) + drive, drive_box = _get_tonic_widget( + name, + layout, + style, + data=prespecified_drive_data + ) if drive_type in [ - 'Evoked', 'Poisson', 'Rhythmic', 'Bursty', 'Gaussian' + 'Evoked', 'Poisson', 'Rhythmic', 'Bursty', 'Gaussian','Tonic' ]: drive_boxes.append(drive_box) drive_widgets.append(drive) @@ -1512,5 +1576,8 @@ def launch(): You can pass voila commandline parameters as usual. """ from voila.app import main + debugpy.listen(5678) + print("Waiting for debugger attach") + debugpy.wait_for_client() notebook_path = Path(__file__).parent / 'hnn_widget.ipynb' main([str(notebook_path.resolve()), *sys.argv[1:]])