Skip to content

Commit

Permalink
Merge pull request #166 from jpgill86/spike-colors
Browse files Browse the repository at this point in the history
Add color option for amplitude_discriminators
  • Loading branch information
jpgill86 authored Jan 7, 2020
2 parents babb882 + 3125e1d commit 6155f22
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 3 deletions.
6 changes: 5 additions & 1 deletion docs/metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,9 @@ the basis of amplitude alone. Note that amplitude discriminators are only
applied if fast loading is off (``lazy=False``).

Detected spikes are indicated on the signals with markers, and spike trains are
displayed in a raster plot.
displayed in a raster plot. Optionally, a color may be specified for an
amplitude discriminator using a single letter color code (e.g., ``'b'`` for
blue or ``'k'`` for black) or a hexadecimal color code (e.g., ``'1b9e77'``).

In addition to restricting spike detection for a given unit to an amplitude
window, detection can also be limited in time to overlap with epochs with a
Expand All @@ -471,12 +473,14 @@ for each amplitude discriminator.
channel: Extracellular
units: uV
amplitude: [50, 150]
color: r
- name: Unit 2
channel: Extracellular
units: uV
amplitude: [20, 50]
epoch: Unit 2 activity
color: 'e6ab02'
Here two units are detected on the same channel with different amplitude
windows. Any peaks between 50 and 150 microvolts on the "Extracellular" channel
Expand Down
4 changes: 2 additions & 2 deletions neurotic/datasets/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,8 @@ def _defaults_for_key(key):
# list of labels for epoch encoder
'epoch_encoder_possible_labels': ['Type 1', 'Type 2', 'Type 3'],

# list of dicts giving name, channel, units, amplitude window, epoch window for each unit
# - e.g. [{'name': 'Unit X', 'channel': 'Channel A', 'units': 'uV', 'amplitude': [75, 150], 'epoch': 'Type 1'}, ...]
# 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'}, ...]
'amplitude_discriminators': None,

# list of dicts giving name of a spiketrain, start and stop firing rate
Expand Down
3 changes: 3 additions & 0 deletions neurotic/example/metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,20 @@ example dataset:
channel: BN2
units: uV
amplitude: [50, 150]
color: '1b9e77'

- name: B38
channel: BN2
units: uV
amplitude: [17, 26]
epoch: B38 activity
color: '7570b3'

- name: B4/B5
channel: BN3
units: uV
amplitude: [85, 200]
color: 'e6ab02'

burst_detectors: # used only if fast loading is off (lazy=False)

Expand Down
22 changes: 22 additions & 0 deletions neurotic/gui/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,16 @@ def create_ephyviewer_window(self, theme='light', support_increased_line_width=F
scatter_channels = spike_channels,
))

# instead of passing colors into AnalogSignalSourceWithScatter
# constructor with scatter_colors, first let the constructor
# choose reasonable default colors (done above), and only then
# override colors for spike trains that have been explicitly
# set in amplitude_discriminators (done here)
unit_colors = {}
if self.metadata['amplitude_discriminators'] is not None:
unit_colors = {d['name']: d['color'] for d in self.metadata['amplitude_discriminators'] if 'color' in d}
sources['signal'][-1].scatter_colors.update(unit_colors)

# useOpenGL=True eliminates the extremely poor performance associated
# with TraceViewer's line_width > 1.0, but it also degrades overall
# performance somewhat and is reportedly unstable
Expand Down Expand Up @@ -470,6 +480,18 @@ def create_ephyviewer_window(self, theme='light', support_increased_line_width=F
spike_train_view.params_controller.combo_cmap.setCurrentText(self.themes[theme]['cmap'])
spike_train_view.params_controller.on_automatic_color()

# set explicitly assigned spike train colors
if self.metadata['amplitude_discriminators'] is not None:
for d in self.metadata['amplitude_discriminators']:
if 'color' in d:
try:
index = [st.name for st in seg.spiketrains].index(d['name'])
spike_train_view.by_channel_params['ch{}'.format(index), 'color'] = d['color']
except ValueError:
# the amplitude discriminator name may not have
# been found in the spike train list
pass

########################################################################
# EPOCHS

Expand Down

0 comments on commit 6155f22

Please sign in to comment.