Skip to content

Commit

Permalink
Merge 91810f5 into ce9afe0
Browse files Browse the repository at this point in the history
  • Loading branch information
jpgill86 committed Feb 19, 2020
2 parents ce9afe0 + 91810f5 commit 815e982
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 30 deletions.
3 changes: 1 addition & 2 deletions docs/metadata.rst
Expand Up @@ -57,8 +57,7 @@ used.

Paths to individual files within the dataset are provided using keys listed
below. These paths should be given relative to ``data_dir``. If ``data_dir`` is
flat (no subdirectories), these should be simply the file names. Only
``data_file`` is required.
flat (no subdirectories), these should be simply the file names.

====================== ========================================================
Key Description
Expand Down
29 changes: 22 additions & 7 deletions neurotic/datasets/data.py
Expand Up @@ -31,7 +31,8 @@ def load_dataset(metadata, lazy=False, signal_group_mode='split-all', filter_eve
The ``data_file`` in ``metadata`` is read into a Neo :class:`Block
<neo.core.Block>` using an automatically detected :mod:`neo.io` class
if ``lazy=False`` or a :mod:`neo.rawio` class if ``lazy=True``.
if ``lazy=False`` or a :mod:`neo.rawio` class if ``lazy=True``. If
``data_file`` is unspecified, an empty Neo Block is created instead.
Epochs and events loaded from ``annotations_file`` and
``epoch_encoder_file`` and spike trains loaded from ``tridesclous_file``
Expand All @@ -44,8 +45,14 @@ def load_dataset(metadata, lazy=False, signal_group_mode='split-all', filter_eve
signal.
"""

# read in the electrophysiology data
blk = _read_data_file(metadata, lazy, signal_group_mode)
if metadata.get('data_file', None) is not None:
# read in the electrophysiology data
blk = _read_data_file(metadata, lazy, signal_group_mode)
else:
# create an empty Block
blk = neo.Block()
seg = neo.Segment()
blk.segments.append(seg)

# update the real-world start time of the data if provided
if metadata.get('rec_datetime', None) is not None:
Expand Down Expand Up @@ -80,11 +87,15 @@ def load_dataset(metadata, lazy=False, signal_group_mode='split-all', filter_eve
blk.segments[0].spiketrains += _run_amplitude_discriminators(metadata, blk)

# read in spikes identified by spike sorting using tridesclous
t_start = blk.segments[0].analogsignals[0].t_start
t_stop = blk.segments[0].analogsignals[0].t_stop
sampling_period = blk.segments[0].analogsignals[0].sampling_period
spikes_dataframe = _read_spikes_file(metadata, blk)
blk.segments[0].spiketrains += _create_neo_spike_trains_from_dataframe(spikes_dataframe, metadata, t_start, t_stop, sampling_period)
if spikes_dataframe is not None:
if blk.segments[0].analogsignals:
t_start = blk.segments[0].analogsignals[0].t_start # assuming all AnalogSignals start at the same time
t_stop = blk.segments[0].analogsignals[0].t_stop # assuming all AnalogSignals start at the same time
sampling_period = blk.segments[0].analogsignals[0].sampling_period # assuming all AnalogSignals have the same sampling rate
blk.segments[0].spiketrains += _create_neo_spike_trains_from_dataframe(spikes_dataframe, metadata, t_start, t_stop, sampling_period)
else:
logger.warning('Ignoring tridesclous_file because the sampling rate and start time could not be inferred from analog signals')

# calculate smoothed firing rates from spike trains if not using lazy
# loading of signals
Expand Down Expand Up @@ -189,6 +200,10 @@ def _read_data_file(metadata, lazy=False, signal_group_mode='split-all'):
# some IOs do not have signal_group_mode
blk = io.read_block(lazy=lazy)

if lazy and isinstance(io, neo.rawio.baserawio.BaseRawIO):
# store the rawio for use with AnalogSignalFromNeoRawIOSource
blk.rawio = io

# load all objects except analog signals
if lazy:

Expand Down
2 changes: 1 addition & 1 deletion neurotic/datasets/metadata.py
Expand Up @@ -338,7 +338,7 @@ def _defaults_for_key(key):
'epoch_encoder_file': None,

# list of labels for epoch encoder
'epoch_encoder_possible_labels': ['Type 1', 'Type 2', 'Type 3'],
'epoch_encoder_possible_labels': [],

# list of dicts giving name, channel, units, amplitude window, epoch window, color for each unit
# - e.g. [{'name': 'Unit X', 'channel': 'Channel A', 'units': 'uV', 'amplitude': [75, 150], 'epoch': 'Type 1', 'color': 'ff0000'}, ...]
Expand Down
58 changes: 38 additions & 20 deletions neurotic/gui/config.py
Expand Up @@ -15,7 +15,6 @@
import neo
import ephyviewer

from ..datasets.data import _get_io
from ..datasets.metadata import _abs_path
from ..gui.epochencoder import NeuroticWritableEpochSource

Expand Down Expand Up @@ -101,6 +100,10 @@ def __init__(self, metadata, blk, lazy = False):
}

# hide and disable viewers for which inputs are missing
if not self.blk.segments[0].analogsignals:
self.viewer_settings['traces']['show'] = False
self.viewer_settings['traces']['disabled'] = True
self.viewer_settings['traces']['reason'] = 'Cannot enable because there are no signals'
if not [sig.annotations['rauc_sig'] for sig in blk.segments[0].analogsignals if 'rauc_sig' in sig.annotations]:
self.viewer_settings['traces_rauc']['show'] = False
self.viewer_settings['traces_rauc']['disabled'] = True
Expand Down Expand Up @@ -304,13 +307,20 @@ def create_ephyviewer_window(self, theme='light', support_increased_line_width=F

if self.is_shown('traces'):

# get a Neo IO object appropriate for the data file type
io = _get_io(self.metadata)
lazy_load_signals = False
if self.lazy:
# check whether blk contains a rawio, which would have been put
# there by _read_data_file if lazy=True and if Neo has a RawIO
# that supports the file format
if hasattr(self.blk, 'rawio') and isinstance(self.blk.rawio, neo.rawio.baserawio.BaseRawIO):
io = self.blk.rawio
if io.support_lazy:
lazy_load_signals = True

if self.lazy and io.support_lazy:
if lazy_load_signals:

# Intan-specific tricks
if type(io) is neo.io.IntanIO:
if isinstance(io, neo.io.IntanIO):
# dirty trick for getting ungrouped channels into a single source
io.header['signal_channels']['group_id'] = 0

Expand All @@ -326,7 +336,7 @@ def create_ephyviewer_window(self, theme='light', support_increased_line_width=F
ylabel = p['ylabel']

# Intan-specific tricks
if type(io) is neo.io.IntanIO:
if isinstance(io, neo.io.IntanIO):
# append custom channel names stored in data file to ylabels
if custom_channel_names[p['channel']] != ylabel:
ylabel += ' ({})'.format(custom_channel_names[p['channel']])
Expand Down Expand Up @@ -625,7 +635,7 @@ def create_ephyviewer_window(self, theme='light', support_increased_line_width=F

if self.is_shown('epoch_encoder') and self.metadata.get('epoch_encoder_file', None) is not None:

possible_labels = self.metadata['epoch_encoder_possible_labels']
possible_labels = self.metadata.get('epoch_encoder_possible_labels', [])

# append labels found in the epoch encoder file but not in the
# epoch_encoder_possible_labels list, preserving the original
Expand All @@ -635,21 +645,29 @@ def create_ephyviewer_window(self, theme='light', support_increased_line_width=F
if label not in possible_labels:
possible_labels.append(label)

writable_epoch_source = NeuroticWritableEpochSource(
filename = _abs_path(self.metadata, 'epoch_encoder_file'),
possible_labels = possible_labels,
)
if not possible_labels:

epoch_encoder = ephyviewer.EpochEncoder(source = writable_epoch_source, name = 'epoch encoder')
epoch_encoder.params['exclusive_mode'] = False
win.add_view(epoch_encoder)
# an empty epoch encoder file and an empty list of possible
# labels were provided
logger.warning('Ignoring epoch_encoder_file because epoch_encoder_possible_labels was unspecified')

# set the theme
if theme != 'original':
epoch_encoder.params['background_color'] = self.themes[theme]['background_color']
epoch_encoder.params['vline_color'] = self.themes[theme]['vline_color']
epoch_encoder.params['label_fill_color'] = self.themes[theme]['label_fill_color']
# TODO add support for combo_cmap
else:

writable_epoch_source = NeuroticWritableEpochSource(
filename = _abs_path(self.metadata, 'epoch_encoder_file'),
possible_labels = possible_labels,
)

epoch_encoder = ephyviewer.EpochEncoder(source = writable_epoch_source, name = 'epoch encoder')
epoch_encoder.params['exclusive_mode'] = False
win.add_view(epoch_encoder)

# set the theme
if theme != 'original':
epoch_encoder.params['background_color'] = self.themes[theme]['background_color']
epoch_encoder.params['vline_color'] = self.themes[theme]['vline_color']
epoch_encoder.params['label_fill_color'] = self.themes[theme]['label_fill_color']
# TODO add support for combo_cmap

########################################################################
# VIDEO
Expand Down

0 comments on commit 815e982

Please sign in to comment.