def _fake_montage(ch_names): return Montage( pos=np.random.RandomState(42).randn(len(ch_names), 3), ch_names=ch_names, # kind=4, kind='foo', selection=np.arange(len(ch_names)))
def xyz_to_montage(path): """Convert xyz positions to a mne montage type""" n = int(open(path).readline().split(' ')[0]) coord = np.loadtxt(path, skiprows=1, usecols=(0, 1, 2), max_rows=n) names = np.loadtxt(path, skiprows=1, usecols=3, max_rows=n, dtype=np.dtype(str)).tolist() montage = Montage(coord, names, 'standard_1005', selection=[i for i in range(n)]) return(montage)
def xyz_to_montage(path, kind=''): """Reads and convert xyz positions to a mne montage type""" from mne.channels import Montage import numpy as np n = int(open(path).readline().lstrip().split(' ')[0]) coord = np.loadtxt(path, skiprows=1, usecols=(0, 1, 2), max_rows=n) names = np.loadtxt(path, skiprows=1, usecols=3, max_rows=n, dtype=np.dtype(str)) names = names.tolist() return Montage(coord, names, kind, selection=[i for i in range(n)])
def eeg_to_montage(eeg): """Returns an instance of montage from an eeg file""" from numpy import array, isnan from mne.channels import Montage pos = array( [eeg.info['chs'][i]['loc'][:3] for i in range(eeg.info['nchan'])]) if not isnan(pos).all(): selection = [i for i in range(eeg.info['nchan'])] montage = Montage(pos, eeg.info['ch_names'], selection=selection, kind='') return montage else: return None
def test_montage(): """Test setting up one of the default montages.""" with pytest.warns(RuntimeWarning, match='number of bytes'): raw = read_raw_cnt(fname, montage=None, eog='auto', misc=['NA1', 'LEFT_EAR']) assert raw.info['dig'] is None original_chs = deepcopy(raw.info['chs']) n_channels = len(raw.ch_names) pos = np.random.RandomState(42).randn(n_channels, 3) ch_names = map(str, range(n_channels)) kind = 'random' selection = np.arange(n_channels) montage = Montage(pos, ch_names, kind, selection) raw.set_montage(montage) # set a random montage of same num channels assert isinstance(raw.info['dig'], Digitization) assert raw.info['dig'] assert object_diff(raw.info['chs'], original_chs)
def read_xyz_montage(path, kind=''): """Reads and convert xyz positions to a mne montage type Parameters ---------- path : str The filepath of the xyz file. Returns ------- montage : mne.channels.montage.Montage Montage for EEG electrode locations. """ n = int(open(path).readline().lstrip().split(' ')[0]) coord = np.loadtxt(path, skiprows=1, usecols=(0, 1, 2), max_rows=n) names = np.loadtxt(path, skiprows=1, usecols=3, max_rows=n, dtype=np.dtype(str)) names = names.tolist() montage = Montage(coord, names, kind, selection=[i for i in range(n)]) return (montage)