How to use nwbwidgets - 10 common examples

To help you get started, we’ve selected a few nwbwidgets examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NeurodataWithoutBorders / nwb-jupyter-widgets / nwbwidgets / timeseries.py View on Github external
def show_timeseries(node: TimeSeries, neurodata_vis_spec=None, istart=0, istop=None, ax=None, zero_start=False,
                    **kwargs):
    fig = show_timeseries_mpl(node, neurodata_vis_spec, istart, istop, ax, zero_start, **kwargs)

    info = []
    for key in ('description', 'comments', 'unit', 'resolution', 'conversion'):
        info.append(widgets.Text(value=repr(getattr(node, key)), description=key, disabled=True))
    children = [widgets.VBox(info)]

    children.append(fig2widget(fig))

    return widgets.HBox(children=children)
github NeurodataWithoutBorders / nwb-jupyter-widgets / nwbwidgets / behavior.py View on Github external
ax.set_ylabel('x ({})'.format(unit))
        else:
            ax.set_ylabel('x')

    else:
        fig, axs = plt.subplots(ndims, 1, sharex=True)

        for i, (ax, dim_label) in enumerate(zip(axs, ('x', 'y', 'z'))):
            ax.plot(tt, data[:, i], **kwargs)
            if unit:
                ax.set_ylabel(dim_label + ' ({})'.format(unit))
            else:
                ax.set_ylabel(dim_label)
        ax.set_xlabel('t (sec)')

    return widgets.HBox([text_widget, base.fig2widget(fig)])
github NeurodataWithoutBorders / nwb-jupyter-widgets / nwbwidgets / image.py View on Github external
def show_image(index=0):
        fig, ax = plt.subplots(subplot_kw={'xticks': [], 'yticks': []})
        ax.imshow(image_series.data[index, :, :], cmap='gray')
        plt.show()
        return fig2widget(fig)
github NeurodataWithoutBorders / nwb-jupyter-widgets / nwbwidgets / ecephys.py View on Github external
def control_plot(spk_ind):
        fig, ax = plt.subplots(figsize=(9, 5))
        data = ses.data[spk_ind]
        if nChannels > 1:
            for ch in range(nChannels):
                ax.plot(data[:, ch], color='#d9d9d9')
        else:
            ax.plot(data[:], color='#d9d9d9')
        ax.plot(np.mean(data, axis=1), color='k')
        ax.set_xlabel('Time')
        ax.set_ylabel('Amplitude')
        plt.show()
        return fig2widget(fig)
github NeurodataWithoutBorders / nwb-jupyter-widgets / nwbwidgets / allen.py View on Github external
def make_group_and_sort(self, window=False):
        discard_rows = np.where(self.trials['stimulus_name'][:] != 'drifting_gratings')[0]
        gas = GroupAndSortController(self.trials, window=window, start_discard_rows=discard_rows)

        return gas
github NeurodataWithoutBorders / nwb-jupyter-widgets / nwbwidgets / misc.py View on Github external
def make_group_and_sort(self, group_by=None):
        return GroupAndSortController(self.units, group_by=group_by)
github NeurodataWithoutBorders / nwb-jupyter-widgets / nwbwidgets / allen.py View on Github external
self.children = [self.stimulus_type_dd] + list(self.children)

    def get_trials(self):
        return self.units.get_ancestor('NWBFile').epochs

    def stimulus_type_dd_callback(self, change):
        self.gas.discard_rows = np.where(self.trials['stimulus_name'][:] != self.stimulus_type_dd.value)[0]

    def make_group_and_sort(self, window=False):
        discard_rows = np.where(self.trials['stimulus_name'][:] != 'drifting_gratings')[0]
        gas = GroupAndSortController(self.trials, window=window, start_discard_rows=discard_rows)

        return gas


class AllenRasterGroupAndSortController(GroupAndSortController):

    def get_groups(self):

        self.electrodes = self.dynamic_table.get_ancestor('NWBFile').electrodes

        groups = super().get_groups()
        groups.update({name: np.unique(self.electrodes[name][:]) for name in self.electrodes.colnames})
        return groups

    def get_orderable_cols(self):
        units_orderable_cols = super().get_orderable_cols()
        candidate_cols = [x for x in self.electrodes.colnames
                          if not (isinstance(self.electrodes[x][0], Iterable) or
                                  isinstance(self.electrodes[x][0], str))]
        return units_orderable_cols + [x for x in candidate_cols
                                       if len(robust_unique(self.electrodes[x][:])) > 1]
github NeurodataWithoutBorders / nwb-jupyter-widgets / nwbwidgets / misc.py View on Github external
def make_group_and_sort(self, window=None):
        return GroupAndSortController(self.trials, window=window)
github NeurodataWithoutBorders / nwb-jupyter-widgets / nwbwidgets / misc.py View on Github external
progress_bar: FloatProgress, optional

    Returns
    -------

    """

    data = np.asarray(data)
    if ax is None:
        fig, ax = plt.subplots(figsize=(12, 6))
    if group_inds is not None:
        ugroup_inds = np.unique(group_inds)
        handles = []

        if progress_bar is not None:
            this_iter = ProgressBar(enumerate(ugroup_inds), desc='plotting spikes', leave=False, total=len(ugroup_inds))
            progress_bar = this_iter.container
        else:
            this_iter = enumerate(ugroup_inds)

        for i, ui in this_iter:
            color = colors[ugroup_inds[i] % len(colors)]
            lineoffsets = np.where(group_inds == ui)[0] + offset
            event_collection = ax.eventplot(data[group_inds == ui],
                                            orientation='horizontal',
                                            lineoffsets=lineoffsets,
                                            color=color)
            handles.append(event_collection[0])
        if show_legend:
            ax.legend(handles=handles[::-1], labels=list(labels[ugroup_inds][::-1]), loc='upper left',
                      bbox_to_anchor=(1.01, 1))
    else:
github NeurodataWithoutBorders / nwb-jupyter-widgets / nwbwidgets / misc.py View on Github external
-------
    matplotlib.pyplot.Figure

    """

    if time_window is None:
        time_window = [get_min_spike_time(units), get_max_spike_time(units)]

    if units_window is None:
        units_window = [0, len(units)]

    if order is None:
        order = np.arange(len(units), dtype='int')

    if progress_bar:
        this_iter = ProgressBar(order, desc='reading spike data', leave=False)
        progress_bar = this_iter.container
    else:
        this_iter = order
    data = []
    for unit in this_iter:
        data.append(get_spike_times(units, unit, time_window))

    if show_obs_intervals:
        unobserved_intervals_list = get_unobserved_intervals(units, time_window, order)
    else:
        unobserved_intervals_list = None

    ax = plot_grouped_events(data, time_window, group_inds=group_inds, labels=labels, show_legend=show_legend,
                             offset=units_window[0], unobserved_intervals_list=unobserved_intervals_list,
                             progress_bar=progress_bar)
    ax.set_ylabel('unit #')