Skip to content
2 changes: 1 addition & 1 deletion doc/source/python_reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Classes
:template: class.rst

io.Raw
io.RawFIFF
io.RawFIF
Epochs
Evoked
SourceSpaces
Expand Down
9 changes: 7 additions & 2 deletions doc/source/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ Changelog

- `evoked.pick_types`, `epochs.pick_types`, and `tfr.pick_types` added by `Eric Larson`_

- `rename_channels` and `set_channel_types` added as methods to `Raw`, `Epochs` and `Evoked` objects by `Teon Brooks`_


BUG
~~~

Expand Down Expand Up @@ -141,13 +144,13 @@ API
- find_events and read_events functions have a new parameter `mask` to set some bits to a don't care state by `Teon Brooks`_

- New channels module including layouts, electrode montages, and neighbor definitions of sensors which deprecates
``mne.layouts`` by `Denis Engemann`_
`mne.layouts` by `Denis Engemann`_

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you check doc renders fine?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i tried. can't render docs b/c I can't get pygraphviz to install; there was a compilation error :/

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check the doc Makefile, there is an option that allows you to skip building the pygraphviz visual. IIRC it also skips running examples, so if you want to run examples but not build the visual, just make a new entry in the Makefile (the formula can be inferred from the other entries).

What OS are you on, anyway? In Ubuntu it's just sudo apt-get install graphviz and then pygraphviz installs easily, maybe also by apt-get but I don't remember for sure.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using OSX. I dled the package and installed it but pygraphviz just yelled a lot. I tried this command from the source folder:

sphinx-build -D plot_gallery=0 -D make_flow_diagram=0 -b html . build/html

but it errors (can't find the helmet images because it is looking for it here: 'source/_images/mne_helmet.png'). I tried to move up a level to try to get the right location for the helmet but it yells and says that the conf.py isn't in that directory

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should build docs from the mne/doc directory. Did you try adding a line to the Makefile with appropriate arguments such that you can just do make html_dev-noflow or whatever our naming convention is?


- `read_raw_brainvision`, `read_raw_edf`, `read_raw_egi` all use a standard montage import by `Teon Brooks`_

- Fix missing calibration factors for ``mne.io.egi.read_raw_egi`` by `Denis Engemann`_ and `Federico Raimondo`_

- Allow multiple filename patterns as a list (e.g., *raw.fif and *-eve.fif) to be parsed by mne report in ``Report.parse_folder()`` by `Mainak Jas`_
- Allow multiple filename patterns as a list (e.g., *raw.fif and *-eve.fif) to be parsed by mne report in `Report.parse_folder()` by `Mainak Jas`_

- `read_hsp`, `read_elp`, and `write_hsp`, `write_mrk` were removed and made private by `Teon Brooks`_

Expand All @@ -174,6 +177,8 @@ API

- `pick_types_evoked` has been deprecated in favor of `evoked.pick_types`.

- Deprecated changing the sensor type of channels in `rename_channels` by `Teon Brooks`_

- CUDA is no longer initialized at module import, but only when first used.

.. _changes_0_8:
Expand Down
3 changes: 1 addition & 2 deletions mne/channels/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@
from .layout import (Layout, make_eeg_layout, make_grid_layout, read_layout,
find_layout, read_montage, apply_montage)

from .channels import (equalize_channels, rename_channels,
read_ch_connectivity)
from .channels import (equalize_channels, rename_channels, read_ch_connectivity)
103 changes: 96 additions & 7 deletions mne/channels/channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import os
import os.path as op
import warnings

import numpy as np
from scipy.io import loadmat
Expand Down Expand Up @@ -185,6 +186,89 @@ def set_channel_positions(self, pos, names):
% name)
raise ValueError(msg)

def set_channel_types(self, mapping):
"""Define the sensor type of channels.

Note: The following sensor types are accepted:
ecg, eeg, emg, eog, exci, ias, misc, resp, seeg, stim, syst

Parameters
----------
mapping : dict
a dictionary mapping a channel to a sensor type (str)
{'EEG061': 'eog'}.
"""
human2fiff = {'ecg': FIFF.FIFFV_ECG_CH,
'eeg': FIFF.FIFFV_EEG_CH,
'emg': FIFF.FIFFV_EMG_CH,
'eog': FIFF.FIFFV_EOG_CH,
'exci': FIFF.FIFFV_EXCI_CH,
'ias': FIFF.FIFFV_IAS_CH,
'misc': FIFF.FIFFV_MISC_CH,
'resp': FIFF.FIFFV_RESP_CH,
'seeg': FIFF.FIFFV_SEEG_CH,
'stim': FIFF.FIFFV_STIM_CH,
'syst': FIFF.FIFFV_SYST_CH}

human2unit = {'ecg': FIFF.FIFF_UNIT_V,
'eeg': FIFF.FIFF_UNIT_V,
'emg': FIFF.FIFF_UNIT_V,
'eog': FIFF.FIFF_UNIT_V,
'exci': FIFF.FIFF_UNIT_NONE,
'ias': FIFF.FIFF_UNIT_NONE,
'misc': FIFF.FIFF_UNIT_NONE,
'resp': FIFF.FIFF_UNIT_NONE,
'seeg': FIFF.FIFF_UNIT_V,
'stim': FIFF.FIFF_UNIT_NONE,
'syst': FIFF.FIFF_UNIT_NONE}

unit2human = {FIFF.FIFF_UNIT_V: 'V',
FIFF.FIFF_UNIT_NONE: 'NA'}
ch_names = self.info['ch_names']

# first check and assemble clean mappings of index and name
for ch_name, ch_type in mapping.items():
if ch_name not in ch_names:
raise ValueError("This channel name (%s) doesn't exist in "
"info." % ch_name)

c_ind = ch_names.index(ch_name)
if ch_type not in human2fiff:
raise ValueError('This function cannot change to this '
'channel type: %s. Accepted channel types '
'are %s.' % (ch_type,
", ".join(human2unit.keys())))
# Set sensor type
self.info['chs'][c_ind]['kind'] = human2fiff[ch_type]
unit_old = self.info['chs'][c_ind]['unit']
unit_new = human2unit[ch_type]
if unit_old != human2unit[ch_type]:
warnings.warn("The unit for Channel %s has changed "
"from %s to %s." % (ch_name,
unit2human[unit_old],
unit2human[unit_new]))
self.info['chs'][c_ind]['unit'] = human2unit[ch_type]
if ch_type in ['eeg', 'seeg']:
self.info['chs'][c_ind]['coil_type'] = FIFF.FIFFV_COIL_EEG
else:
self.info['chs'][c_ind]['coil_type'] = FIFF.FIFFV_COIL_NONE

def rename_channels(self, mapping):
"""Rename channels.

Note : The ability to change sensor types has been deprecated in favor
of `set_channel_types`. Please use this function if you would changing
or defining sensor type.


Parameters
----------
mapping : dict
a dictionary mapping the old channel to a new channel name
e.g. {'EEG061' : 'EEG161'}.
"""
rename_channels(self.info, mapping)


class PickDropChannelsMixin(object):
"""Mixin class for Raw, Evoked, Epochs, AverageTFR
Expand Down Expand Up @@ -341,20 +425,20 @@ def interpolate_bads_eeg(self):


def rename_channels(info, mapping):
"""Rename channels and optionally change the sensor type.
"""Rename channels.

Note : The ability to change sensor types has been deprecated in favor of
`set_channel_types` method for Raw, Epochs, Evoked . Please use this
method if you would changing or defining sensor type.

Note: This only changes between the following sensor types: eeg, eog,
emg, ecg, and misc. It also cannot change to eeg.

Parameters
----------
info : dict
Measurement info.
mapping : dict
a dictionary mapping the old channel to a new channel name {'EEG061' :
'EEG161'}. If changing the sensor type, make the new name a tuple with
the name (str) and the new channel type (str)
{'EEG061':('EOG061','eog')}.
a dictionary mapping the old channel to a new channel name
e.g. {'EEG061' : 'EEG161'}.
"""
human2fiff = {'eog': FIFF.FIFFV_EOG_CH,
'emg': FIFF.FIFFV_EMG_CH,
Expand All @@ -378,6 +462,8 @@ def rename_channels(info, mapping):
'Please see the help: mne.rename_channels?')

elif isinstance(new_name, tuple): # name and type change
warnings.warn("Changing sensor type is now deprecated. Please use "
"'set_channels_type' instead.", DeprecationWarning)
new_name, new_type = new_name # unpack
if new_type not in human2fiff:
raise ValueError('This function cannot change to this '
Expand All @@ -400,6 +486,9 @@ def rename_channels(info, mapping):
# it doesn't work)
info['ch_names'] = [c['ch_name'] for c in chs]

# assert channel names are unique
assert len(info['ch_names']) == np.unique(info['ch_names']).shape[0]


def _recursive_flatten(cell, dtype):
"""Helper to unpack mat files in Python"""
Expand Down
52 changes: 30 additions & 22 deletions mne/channels/tests/test_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,29 +56,37 @@ def test_rename_channels():
assert_true(info2['chs'][375]['ch_name'] == 'EOG061')
assert_true(info2['ch_names'][375] == 'EOG061')
assert_true('EOG061' in info2['bads'])


def test_set_channels_type():
"""Test Set Channels Type
"""
raw = Raw(raw_fname)
# Error Tests
# Test channel name exists in ch_names
mapping = {'EEG 160': 'EEG060'}
assert_raises(ValueError, raw.set_channel_types, mapping)
# Test change to illegal channel type
mapping = {'EOG 061': 'xxx'}
assert_raises(ValueError, raw.set_channel_types, mapping)
# Test type change
info2 = deepcopy(info)
info2['bads'] = ['EEG 059', 'EEG 060', 'EOG 061']
mapping = {'EEG 060': ('EOG 060', 'eog'), 'EEG 059': ('EOG 059', 'eog'),
'EOG 061': ("OT'7", 'seeg')}
rename_channels(info2, mapping)
assert_true(info2['chs'][374]['ch_name'] == 'EOG 060')
assert_true(info2['ch_names'][374] == 'EOG 060')
assert_true('EOG 060' in info2['bads'])
assert_true(info2['chs'][374]['kind'] == FIFF.FIFFV_EOG_CH)
assert_true(info2['chs'][373]['ch_name'] == 'EOG 059')
assert_true(info2['ch_names'][373] == 'EOG 059')
assert_true('EOG 059' in info2['bads'])
assert_true(info2['chs'][373]['kind'] == FIFF.FIFFV_EOG_CH)
assert_true(info2['chs'][375]['ch_name'] == "OT'7")
assert_true(info2['ch_names'][375] == "OT'7")
assert_true("OT'7" in info2['bads'])
assert_true(info2['chs'][375]['kind'] == FIFF.FIFFV_SEEG_CH)
# Test change of type without change of name
mapping = {'EEG 060': ('EEG 060', 'seeg')}
info2 = deepcopy(info)
rename_channels(info2, mapping)
assert_true(info2['chs'][374]['kind'] == FIFF.FIFFV_SEEG_CH)
raw2 = Raw(raw_fname)
raw2.info['bads'] = ['EEG 059', 'EEG 060', 'EOG 061']
mapping = {'EEG 060': 'eog', 'EEG 059': 'ecg', 'EOG 061': 'seeg'}
raw2.set_channel_types(mapping)
info = raw2.info
assert_true(info['chs'][374]['ch_name'] == 'EEG 060')
assert_true(info['chs'][374]['kind'] == FIFF.FIFFV_EOG_CH)
assert_true(info['chs'][374]['unit'] == FIFF.FIFF_UNIT_V)
assert_true(info['chs'][374]['coil_type'] == FIFF.FIFFV_COIL_NONE)
assert_true(info['chs'][373]['ch_name'] == 'EEG 059')
assert_true(info['chs'][373]['kind'] == FIFF.FIFFV_ECG_CH)
assert_true(info['chs'][373]['unit'] == FIFF.FIFF_UNIT_V)
assert_true(info['chs'][373]['coil_type'] == FIFF.FIFFV_COIL_NONE)
assert_true(info['chs'][375]['ch_name'] == 'EOG 061')
assert_true(info['chs'][375]['kind'] == FIFF.FIFFV_SEEG_CH)
assert_true(info['chs'][375]['unit'] == FIFF.FIFF_UNIT_V)
assert_true(info['chs'][375]['coil_type'] == FIFF.FIFFV_COIL_EEG)


def test_read_ch_connectivity():
Expand Down