Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update icephys accordions with AlignedDynamicTable and renamings #107

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 16 additions & 16 deletions nwbwidgets/icephys.py
Expand Up @@ -2,20 +2,20 @@
from .timeseries import show_timeseries_mpl
from ipywidgets import widgets
import matplotlib.pyplot as plt
from ndx_icephys_meta.icephys import SweepSequences
from ndx_icephys_meta.icephys import SequentialRecordingsTable
from functools import partial
import numpy as np
from matplotlib.pyplot import Figure
import pandas as pd


def show_single_sweep_sequence(sweep_sequence, axs=None, title=None, **kwargs) -> Figure:
def show_single_sequential_recording(sequential_recording, axs=None, title=None, **kwargs) -> Figure:
"""
Show a single rep of a single stimulus sequence

Parameters
----------
sweep_sequence
sequential_recording
axs: [matplotlib.pyplot.Axes, matplotlib.pyplot.Axes], optional
title: str, optional
kwargs: dict
Expand All @@ -28,57 +28,57 @@ def show_single_sweep_sequence(sweep_sequence, axs=None, title=None, **kwargs) -

"""

nsweeps = len(sweep_sequence)
nsweeps = len(sequential_recording)
if axs is None:
fig, axs = plt.subplots(2, 1, sharex=True)
else:
fig = axs[0].get_figure()
for i in range(nsweeps):
start, stop, ts = sweep_sequence['recordings'].iloc[i]['response'].iloc[0]
start, stop, ts = sequential_recording['recordings'].iloc[i]['responses']['response'].iloc[0]
show_timeseries_mpl(ts, istart=start, istop=stop, ax=axs[0], zero_start=True, xlabel='', title=title, **kwargs)

start, stop, ts = sweep_sequence['recordings'].iloc[i]['stimulus'].iloc[0]
start, stop, ts = sequential_recording['recordings'].iloc[i]['stimuli']['stimulus'].iloc[0]
show_timeseries_mpl(ts, istart=start, istop=stop, ax=axs[1], zero_start=True, **kwargs)
return fig


def show_sweep_sequence_reps(stim_df: pd.DataFrame, **kwargs) -> Figure:
def show_sequential_recordings_reps(stim_df: pd.DataFrame, **kwargs) -> Figure:
"""
Show data from multiple reps of the same stimulus type
Show data from multiple repetitions of the same stimulus type

Parameters
----------
stim_df: pandas.DataFrame
kwargs: dict
passed to show_single_sweep_sequence
passed to show_single_sequential_recording

Returns
-------
matplotlib.pyplot.Figure

"""
nsweeps = len(stim_df['sweeps'])
nsweeps = len(stim_df['simultaneous_recordings'])

if 'repetition' in stim_df:
stim_df = stim_df.sort_values('repetition')
fig, axs = plt.subplots(2, nsweeps, sharex='col', sharey='row', figsize=[6.4 * nsweeps, 4.8])
if nsweeps == 1:
axs = np.array([axs]).T
for i, (sweep, sweep_axs) in enumerate(zip(stim_df['sweeps'], axs.T)):
for i, (sweep, sweep_axs) in enumerate(zip(stim_df['simultaneous_recordings'], axs.T)):
if i:
kwargs.update(ylabel='')
show_single_sweep_sequence(sweep, axs=sweep_axs, title='rep {}'.format(i+1), **kwargs)
show_single_sequential_recording(sweep, axs=sweep_axs, title='Repetition {}'.format(i+1), **kwargs)
return fig


def show_sweep_sequences(node: SweepSequences, *args, style: GroupingWidget = widgets.Accordion, **kwargs) -> \
def show_sequential_recordings(node: SequentialRecordingsTable, *args, style: GroupingWidget = widgets.Accordion, **kwargs) -> \
GroupingWidget:
"""
Visualize the sweep sequences table with a lazy accordion of sweep sequence repetitions
Visualize the sequential recordings table with a lazy accordion of stimulus types

Parameters
----------
node: SweepSequences
node: SequentialRecordingsTable
style: widgets.Accordion or widgets.Tabs

Returns
Expand All @@ -89,7 +89,7 @@ def show_sweep_sequences(node: SweepSequences, *args, style: GroupingWidget = wi
if 'stimulus_type' in node:
labels, data = zip(*[(stim_label, stim_df)
for stim_label, stim_df in node.to_dataframe().groupby('stimulus_type')])
func_ = show_sweep_sequence_reps
func_ = show_sequential_recordings_reps
else:
data = node['sweeps']
labels = None
Expand Down
4 changes: 2 additions & 2 deletions nwbwidgets/view.py
Expand Up @@ -4,12 +4,12 @@
from nwbwidgets import behavior, misc, base, ecephys, image, ophys, icephys, timeseries, file
import hdmf
from functools import partial
from ndx_icephys_meta.icephys import SweepSequences
from ndx_icephys_meta.icephys import SequentialRecordingsTable


default_neurodata_vis_spec = {
pynwb.NWBFile: file.show_nwbfile,
SweepSequences: icephys.show_sweep_sequences,
SequentialRecordingsTable: icephys.show_sequential_recordings,
pynwb.behavior.BehavioralEvents: behavior.show_behavioral_events,
pynwb.ecephys.LFP: ecephys.show_lfp,
pynwb.misc.Units: OrderedDict({
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -28,7 +28,7 @@
'plotly',
'scikit-image',
'tqdm>=4.36.0',
'ndx-icephys-meta'],
'ndx-icephys-meta>0.1.0'],
license='MIT',
keywords=['jupyter', 'hdf5', 'notebook', 'nwb'],
long_description=long_description,
Expand Down