def test_edf_stim_ch_pick_up(test_input, EXPECTED): """Test stim_channel.""" # This is fragile for EEG/EEG-CSD, so just omit csd KIND_DICT = get_channel_type_constants() TYPE_LUT = {v['kind']: k for k, v in KIND_DICT.items() if k not in ('csd', 'chpi')} # chpi not needed, and unhashable (a list) fname = op.join(data_dir, 'test_stim_channel.edf') raw = read_raw_edf(fname, stim_channel=test_input) ch_types = {ch['ch_name']: TYPE_LUT[ch['kind']] for ch in raw.info['chs']} assert ch_types == EXPECTED
def _channel_type_old(info, idx): """Get channel type using old, slower scheme.""" ch = info['chs'][idx] # iterate through all defined channel types until we find a match with ch # go in order from most specific (most rules entries) to least specific channel_types = sorted( get_channel_type_constants().items(), key=lambda x: len(x[1]))[::-1] for t, rules in channel_types: for key, vals in rules.items(): # all keys must match the values if ch.get(key, None) not in np.array(vals): break # not channel type t, go to next iteration else: return t raise ValueError('Unknown channel type for {}'.format(ch["ch_name"]))
def test_array_raw(): """Test creating raw from array.""" # creating raw = read_raw_fif(fif_fname).crop(2, 5) data, times = raw[:, :] sfreq = raw.info['sfreq'] ch_names = [(ch[4:] if 'STI' not in ch else ch) for ch in raw.info['ch_names']] # change them, why not types = list() for ci in range(101): types.extend(('grad', 'grad', 'mag')) types.extend(['ecog', 'seeg', 'hbo']) # really 4 meg channels types.extend(['stim'] * 9) types.extend(['dbs']) # really eeg channel types.extend(['eeg'] * 60) picks = np.concatenate([ pick_types(raw.info, meg=True)[::20], pick_types(raw.info, meg=False, stim=True), pick_types(raw.info, meg=False, eeg=True)[::20] ]) del raw data = data[picks] ch_names = np.array(ch_names)[picks].tolist() types = np.array(types)[picks].tolist() types.pop(-1) # wrong length pytest.raises(ValueError, create_info, ch_names, sfreq, types) # bad entry types.append('foo') pytest.raises(KeyError, create_info, ch_names, sfreq, types) types[-1] = 'eog' # default type info = create_info(ch_names, sfreq) assert_equal(info['chs'][0]['kind'], get_channel_type_constants()['misc']['kind']) # use real types info = create_info(ch_names, sfreq, types) raw2 = _test_raw_reader(RawArray, test_preloading=False, data=data, info=info, first_samp=2 * data.shape[1]) data2, times2 = raw2[:, :] assert_allclose(data, data2) assert_allclose(times, times2) assert ('RawArray' in repr(raw2)) pytest.raises(TypeError, RawArray, info, data) # filtering picks = pick_types(raw2.info, meg=True, misc=True, exclude='bads')[:4] assert_equal(len(picks), 4) raw_lp = raw2.copy() kwargs = dict(fir_design='firwin', picks=picks) raw_lp.filter(None, 4.0, h_trans_bandwidth=4., **kwargs) raw_hp = raw2.copy() raw_hp.filter(16.0, None, l_trans_bandwidth=4., **kwargs) raw_bp = raw2.copy() raw_bp.filter(8.0, 12.0, l_trans_bandwidth=4., h_trans_bandwidth=4., **kwargs) raw_bs = raw2.copy() raw_bs.filter(16.0, 4.0, l_trans_bandwidth=4., h_trans_bandwidth=4., **kwargs) data, _ = raw2[picks, :] lp_data, _ = raw_lp[picks, :] hp_data, _ = raw_hp[picks, :] bp_data, _ = raw_bp[picks, :] bs_data, _ = raw_bs[picks, :] sig_dec = 15 assert_array_almost_equal(data, lp_data + bp_data + hp_data, sig_dec) assert_array_almost_equal(data, bp_data + bs_data, sig_dec) # plotting raw2.plot() raw2.plot_psd(tmax=2., average=True, n_fft=1024, spatial_colors=False) plt.close('all') # epoching events = find_events(raw2, stim_channel='STI 014') events[:, 2] = 1 assert len(events) > 2 epochs = Epochs(raw2, events, 1, -0.2, 0.4, preload=True) evoked = epochs.average() assert_equal(evoked.nave, len(events) - 1) # complex data rng = np.random.RandomState(0) data = rng.randn(1, 100) + 1j * rng.randn(1, 100) raw = RawArray(data, create_info(1, 1000., 'eeg')) assert_allclose(raw._data, data) # Using digital montage to give MNI electrode coordinates n_elec = 10 ts_size = 10000 Fs = 512. ch_names = [str(i) for i in range(n_elec)] ch_pos_loc = np.random.randint(60, size=(n_elec, 3)).tolist() data = np.random.rand(n_elec, ts_size) montage = make_dig_montage(ch_pos=dict(zip(ch_names, ch_pos_loc)), coord_frame='head') info = create_info(ch_names, Fs, 'ecog') raw = RawArray(data, info) raw.set_montage(montage) raw.plot_psd(average=False) # looking for nonexistent layout raw.plot_psd_topo()
# Authors: Clemens Brunner <*****@*****.**> # # License: BSD (3-clause) from qtpy.QtWidgets import (QDialog, QVBoxLayout, QDialogButtonBox, QComboBox, QAbstractItemView, QTableView, QStyledItemDelegate) from qtpy.QtGui import QStandardItemModel, QStandardItem from qtpy.QtCore import Qt, QSortFilterProxyModel, Slot from mne.io.pick import channel_type, get_channel_type_constants channel_types = [k.upper() for k in get_channel_type_constants().keys()] class ChannelPropertiesDialog(QDialog): def __init__(self, parent, info, title="Channel Properties"): super().__init__(parent) self.setWindowTitle(title) self.model = QStandardItemModel(info["nchan"], 4) self.model.setHorizontalHeaderLabels(["#", "Label", "Type", "Bad"]) for index, ch in enumerate(info["chs"]): item = QStandardItem() item.setData(index, Qt.DisplayRole) item.setFlags(item.flags() & ~Qt.ItemIsEditable) self.model.setItem(index, 0, item) self.model.setItem(index, 1, QStandardItem(ch["ch_name"])) kind = channel_type(info, index).upper() self.model.setItem(index, 2, QStandardItem(str(kind))) bad = QStandardItem() bad.setData(ch["ch_name"] in info["bads"], Qt.UserRole)