def __init__(self, units: Units): """ Visualize PSTH with the ability to select electrodes from clicking within the grid. Parameters ---------- units : Units Units Table of an NWBFile. """ super().__init__() self.electrodes = units.get_ancestor("NWBFile").electrodes self.tuning_curve = TuningCurveWidget(units) self.electrode_position_selector = ElectrodePositionSelector( self.electrodes, pre_alignment_window=[ 0, -self.tuning_curve.children[0].start_ft.value ], post_alignment_window=[ 0, self.tuning_curve.children[0].end_ft.value ], event_name=self.tuning_curve.children[0].trial_event_controller. value) self.electrode_position_selector.scatter.on_click(self.update_point) self.children = [self.tuning_curve, self.electrode_position_selector] self.tuning_curve.children[0].unit_controller.observe( self.handle_unit_controller, "value") self.tuning_curve.children[0].start_ft.observe(self.handle_response, "value") self.tuning_curve.children[0].end_ft.observe(self.handle_response, "value") self.tuning_curve.children[0].trial_event_controller.observe( self.handle_response, "value")
def raster_grid_widget(units: Units): trials = units.get_ancestor('NWBFile').trials if trials is None: return widgets.HTML('No trials present') groups = infer_categorical_columns(trials) control_widgets = widgets.VBox(children=[]) rows_controller = widgets.Dropdown(options=[None] + list(groups), description='rows: ', layout=Layout(width='95%')) cols_controller = widgets.Dropdown(options=[None] + list(groups), description='cols: ', layout=Layout(width='95%')) control_widgets.children = list( control_widgets.children) + [rows_controller, cols_controller] trial_event_controller = make_trial_event_controller(trials) control_widgets.children = list( control_widgets.children) + [trial_event_controller] unit_controller = int_controller(len(units['spike_times'].data) - 1) control_widgets.children = list( control_widgets.children) + [unit_controller] before_slider = widgets.FloatSlider(.5, min=0, max=5., description='before (s)', continuous_update=False) control_widgets.children = list(control_widgets.children) + [before_slider] after_slider = widgets.FloatSlider(2., min=0, max=5., description='after (s)', continuous_update=False) control_widgets.children = list(control_widgets.children) + [after_slider] controls = { 'units': fixed(units), 'trials': fixed(trials), 'index': unit_controller.children[0], 'after': after_slider, 'before': before_slider, 'align_by': trial_event_controller, 'rows_label': rows_controller, 'cols_label': cols_controller } out_fig = widgets.interactive_output(raster_grid, controls) vbox = widgets.VBox(children=[control_widgets, out_fig]) return vbox
def psth_widget(units: Units, unit_controller=None, after_slider=None, before_slider=None, trial_event_controller=None, trial_order_controller=None, trial_group_controller=None, sigma_in_secs=.05, ntt=1000): """ Parameters ---------- units: pynwb.misc.Units unit_controller after_slider before_slider trial_event_controller trial_order_controller trial_group_controller sigma_in_secs: float ntt: int Number of timepoints to use for smoothed PSTH Returns ------- """ trials = units.get_ancestor('NWBFile').trials if trials is None: return widgets.HTML('No trials present') control_widgets = widgets.VBox(children=[]) if unit_controller is None: nunits = len(units['spike_times'].data) #unit_controller = int_controller(nunits) unit_controller = widgets.Dropdown(options=[x for x in range(nunits)], description='unit: ') control_widgets.children = list( control_widgets.children) + [unit_controller] if trial_event_controller is None: trial_event_controller = make_trial_event_controller(trials) control_widgets.children = list( control_widgets.children) + [trial_event_controller] if trial_order_controller is None: trials = units.get_ancestor('NWBFile').trials trial_order_controller = widgets.Dropdown(options=trials.colnames, value='start_time', description='order by: ') control_widgets.children = list( control_widgets.children) + [trial_order_controller] if trial_group_controller is None: trials = units.get_ancestor('NWBFile').trials trial_group_controller = widgets.Dropdown(options=[None] + list(trials.colnames), description='group by') control_widgets.children = list( control_widgets.children) + [trial_group_controller] if before_slider is None: before_slider = widgets.FloatSlider(.5, min=0, max=5., description='before (s)', continuous_update=False) control_widgets.children = list( control_widgets.children) + [before_slider] if after_slider is None: after_slider = widgets.FloatSlider(2., min=0, max=5., description='after (s)', continuous_update=False) control_widgets.children = list( control_widgets.children) + [after_slider] controls = { 'units': fixed(units), 'sigma_in_secs': fixed(sigma_in_secs), 'ntt': fixed(ntt), 'index': unit_controller, 'after': after_slider, 'before': before_slider, 'start_label': trial_event_controller, 'order_by': trial_order_controller, 'group_by': trial_group_controller } out_fig = widgets.interactive_output(trials_psth, controls) vbox = widgets.VBox(children=[control_widgets, out_fig]) return vbox