Skip to content

Commit

Permalink
Merge 0f57aed into a692c58
Browse files Browse the repository at this point in the history
  • Loading branch information
jpgill86 committed Jan 19, 2020
2 parents a692c58 + 0f57aed commit cb2d1ed
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 20 deletions.
12 changes: 9 additions & 3 deletions docs/metadata.rst
Expand Up @@ -341,7 +341,9 @@ Plot Parameters
---------------

Use the ``plots`` parameter to specify which signal channels from ``data_file``
you want plotted and how to scale them.
you want plotted and how to scale them. Optionally, a color may be specified
for channels using a single letter color code (e.g., ``'b'`` for blue or
``'k'`` for black) or a hexadecimal color code (e.g., ``'1b9e77'``).

Consider the following example, and notice the use of hyphens and indentation
for each channel.
Expand All @@ -357,11 +359,13 @@ for each channel.
ylabel: Buccal nerve 2 (BN2)
units: uV
ylim: [-150, 150]
color: r
- channel: Intracellular
ylabel: B3 neuron
units: mV
ylim: [-100, 50]
color: '666666'
- channel: Force
units: mN
Expand Down Expand Up @@ -564,7 +568,8 @@ burst detection algorithm that relies on firing rate thresholds can be run to
detect periods of intense activity. Note that burst detectors are only applied
if fast loading is off (``lazy=False``).

Detected bursts are plotted as epochs.
Detected bursts are plotted as epochs. Colors are inherited from
``amplitude_discriminators``, if they are provided there.

Burst detectors are specified in metadata like this:

Expand Down Expand Up @@ -614,7 +619,8 @@ The signal is then rectified (absolute value) and divided into non-overlapping
bins of fixed duration. Finally, the integral is calculated within each bin.
The result is a new time series that represents the overall activity of the
original signal. RAUC time series are plotted separately from the original
signals in a second tab.
signals in a second tab. Colors are inherited from ``plots``, if they are
provided there.

The choice of baseline is controlled by the ``rauc_baseline`` metadata
parameter, which may have the value ``None`` (default), ``'mean'``, or
Expand Down
2 changes: 1 addition & 1 deletion neurotic/datasets/metadata.py
Expand Up @@ -388,7 +388,7 @@ def _defaults_for_key(key):
'video_rate_correction': None,

# list the channels in the order they should be plotted
# - e.g. [{'channel': 'Channel A', 'ylabel': 'My channel', 'ylim': [-120, 120], 'units': 'uV'}, ...]
# - e.g. [{'channel': 'Channel A', 'ylabel': 'My channel', 'ylim': [-120, 120], 'units': 'uV', 'color': 'ff0000'}, ...]
'plots': None,

# amount of time in seconds to plot initially
Expand Down
68 changes: 52 additions & 16 deletions neurotic/gui/config.py
Expand Up @@ -272,6 +272,21 @@ def create_ephyviewer_window(self, theme='light', support_increased_line_width=F
# delete on close so that memory and file resources are released
win.setAttribute(ephyviewer.QT.WA_DeleteOnClose, True)

########################################################################
# COLORS

# colors for signals given explicitly in plots, used for raw signals
# and RAUC
sig_colors = {}
if self.metadata['plots'] is not None:
sig_colors = {p['channel']: p['color'] for p in self.metadata['plots'] if 'color' in p}

# colors for units given explicitly in amplitude_discriminators, used
# for scatter markers, spike trains, and burst epochs
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}

########################################################################
# TRACES WITH SCATTER PLOTS

Expand Down Expand Up @@ -347,11 +362,8 @@ def create_ephyviewer_window(self, theme='light', support_increased_line_width=F
# 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}
# override colors for units that have been explicitly set in
# amplitude_discriminators (done here)
sources['signal'][-1].scatter_colors.update(unit_colors)

# useOpenGL=True eliminates the extremely poor performance associated
Expand Down Expand Up @@ -382,6 +394,15 @@ def create_ephyviewer_window(self, theme='light', support_increased_line_width=F
trace_view.params_controller.combo_cmap.setCurrentText(self.themes[theme]['cmap'])
trace_view.params_controller.on_automatic_color()

# set explicitly assigned signal colors
for name, color in sig_colors.items():
try:
index = [p['channel'] for p in self.metadata['plots']].index(name)
trace_view.by_channel_params['ch{}'.format(index), 'color'] = color
except ValueError:
# sig name may not have been found in the trace list
pass

# adjust plot range, scaling, and positioning
trace_view.params['ylim_max'] = 0.5
trace_view.params['ylim_min'] = -trace_view.source.nb_channel + 0.5
Expand Down Expand Up @@ -428,6 +449,15 @@ def create_ephyviewer_window(self, theme='light', support_increased_line_width=F
trace_rauc_view.params_controller.combo_cmap.setCurrentText(self.themes[theme]['cmap'])
trace_rauc_view.params_controller.on_automatic_color()

# set explicitly assigned signal colors
for name, color in sig_colors.items():
try:
index = [p['channel'] for p in self.metadata['plots']].index(name)
trace_rauc_view.by_channel_params['ch{}'.format(index), 'color'] = color
except ValueError:
# sig name may not have been found in the rauc trace list
pass

# adjust plot range
trace_rauc_view.params['ylim_max'] = 0.5
trace_rauc_view.params['ylim_min'] = -trace_rauc_view.source.nb_channel + 0.5
Expand Down Expand Up @@ -486,17 +516,14 @@ 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
# set explicitly assigned unit colors
for name, color in unit_colors.items():
try:
index = [st.name for st in seg.spiketrains].index(name)
spike_train_view.by_channel_params['ch{}'.format(index), 'color'] = color
except ValueError:
# unit name may not have been found in the spike train list
pass

########################################################################
# EPOCHS
Expand All @@ -514,6 +541,15 @@ def create_ephyviewer_window(self, theme='light', support_increased_line_width=F
epoch_view.params_controller.combo_cmap.setCurrentText(self.themes[theme]['cmap'])
epoch_view.params_controller.on_automatic_color()

# set explicitly assigned unit colors
for name, color in unit_colors.items():
try:
index = [ep['name'] for ep in sources['epoch'][0].all].index(name + ' burst')
epoch_view.by_channel_params['ch{}'.format(index), 'color'] = color
except ValueError:
# unit burst name may not have been found in the epoch list
pass

########################################################################
# EPOCH ENCODER

Expand Down

0 comments on commit cb2d1ed

Please sign in to comment.