Skip to content

Commit

Permalink
Merge pull request #3216 from choldgraf/add_ch_types_auto_scale
Browse files Browse the repository at this point in the history
adding support for other channel types with auto-scale
  • Loading branch information
larsoner committed May 9, 2016
2 parents 5a71c71 + 7ae9baa commit ee8ac19
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
3 changes: 2 additions & 1 deletion mne/viz/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ def test_auto_scale():

for inst in [raw, epochs]:
scale_grad = 1e10
scalings_def = dict([('eeg', 'auto'), ('grad', scale_grad)])
scalings_def = dict([('eeg', 'auto'), ('grad', scale_grad),
('stim', 'auto')])

# Test for wrong inputs
assert_raises(ValueError, inst.plot, scalings='foo')
Expand Down
14 changes: 6 additions & 8 deletions mne/viz/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1058,19 +1058,19 @@ def _compute_scalings(scalings, inst):
A scalings dictionary with updated values
"""
from ..io.base import _BaseRaw
from ..io.pick import _picks_by_type
from ..epochs import _BaseEpochs
if not isinstance(inst, (_BaseRaw, _BaseEpochs)):
raise ValueError('Must supply either Raw or Epochs')
if scalings is None:
# If scalings is None just return it and do nothing
return scalings

ch_types = _picks_by_type(inst.info)
unique_ch_types = [i_type[0] for i_type in ch_types]
ch_types = channel_indices_by_type(inst.info)
ch_types = dict([(i_type, i_ixs)
for i_type, i_ixs in ch_types.items() if len(i_ixs) != 0])
if scalings == 'auto':
# If we want to auto-compute everything
scalings = dict((i_type, 'auto') for i_type in unique_ch_types)
scalings = dict((i_type, 'auto') for i_type in ch_types.keys())
if not isinstance(scalings, dict):
raise ValueError('scalings must be a dictionary of ch_type: val pairs,'
' not type %s ' % type(scalings))
Expand All @@ -1096,15 +1096,13 @@ def _compute_scalings(scalings, inst):
data = inst._data
if isinstance(inst, _BaseEpochs):
data = inst._data.reshape([len(inst.ch_names), -1])

# Iterate through ch types and update scaling if ' auto'
for key, value in scalings.items():
if value != 'auto':
continue
if key not in unique_ch_types:
if key not in ch_types.keys():
raise ValueError("Sensor {0} doesn't exist in data".format(key))
this_ixs = [i_ixs for key_, i_ixs in ch_types if key_ == key]
this_data = data[this_ixs]
this_data = data[ch_types[key]]
scale_factor = np.percentile(this_data.ravel(), [0.5, 99.5])
scale_factor = np.max(np.abs(scale_factor))
scalings[key] = scale_factor
Expand Down

0 comments on commit ee8ac19

Please sign in to comment.