def test_eximia_nxe(): """Test reading Eximia NXE files""" fname = op.join(data_path(), 'eximia', 'test_eximia.nxe') raw = read_raw_eximia(fname, preload=True) assert_true('RawEximia' in repr(raw)) _test_raw_reader(read_raw_eximia, fname=fname) fname_mat = op.join(data_path(), 'eximia', 'test_eximia.mat') mc = sio.loadmat(fname_mat) m_data = mc['data'] m_header = mc['header'] assert_equal(raw._data.shape, m_data.shape) assert_equal(m_header['Fs'][0, 0][0, 0], raw.info['sfreq']) m_names = [x[0][0] for x in m_header['label'][0, 0]] m_names = list( map(lambda x: x.replace('GATE', 'GateIn').replace('TRIG', 'Trig'), m_names)) assert_equal(raw.ch_names, m_names) m_ch_types = [x[0][0] for x in m_header['chantype'][0, 0]] m_ch_types = list( map(lambda x: x.replace('unknown', 'stim').replace('trigger', 'stim'), m_ch_types)) types_dict = {2: 'eeg', 3: 'stim', 202: 'eog'} ch_types = [ types_dict[raw.info['chs'][x]['kind']] for x in range(len(raw.ch_names)) ] assert_equal(ch_types, m_ch_types) assert_array_equal(m_data, raw._data)
def test_brainvision_data(): """Test reading raw Brain Vision files.""" pytest.raises(IOError, read_raw_brainvision, vmrk_path) pytest.raises(ValueError, read_raw_brainvision, vhdr_path, preload=True, scale="foo") raw_py = _test_raw_reader(read_raw_brainvision, vhdr_fname=vhdr_path, eog=eog, misc='auto') assert ('RawBrainVision' in repr(raw_py)) assert_equal(raw_py.info['highpass'], 0.) assert_equal(raw_py.info['lowpass'], 250.) picks = pick_types(raw_py.info, meg=False, eeg=True, exclude='bads') data_py, times_py = raw_py[picks] # compare with a file that was generated using MNE-C raw_bin = read_raw_fif(eeg_bin, preload=True) picks = pick_types(raw_py.info, meg=False, eeg=True, exclude='bads') data_bin, times_bin = raw_bin[picks] assert_array_almost_equal(data_py, data_bin) assert_array_almost_equal(times_py, times_bin) # Make sure EOG channels are marked correctly for ch in raw_py.info['chs']: if ch['ch_name'] in eog: assert_equal(ch['kind'], FIFF.FIFFV_EOG_CH) elif ch['ch_name'] == 'STI 014': assert_equal(ch['kind'], FIFF.FIFFV_STIM_CH) elif ch['ch_name'] in ('CP5', 'CP6'): assert_equal(ch['kind'], FIFF.FIFFV_MISC_CH) assert_equal(ch['unit'], FIFF.FIFF_UNIT_NONE) elif ch['ch_name'] == 'ReRef': assert_equal(ch['kind'], FIFF.FIFFV_MISC_CH) assert_equal(ch['unit'], FIFF.FIFF_UNIT_CEL) elif ch['ch_name'] in raw_py.info['ch_names']: assert_equal(ch['kind'], FIFF.FIFFV_EEG_CH) assert_equal(ch['unit'], FIFF.FIFF_UNIT_V) else: raise RuntimeError("Unknown Channel: %s" % ch['ch_name']) # test loading v2 read_raw_brainvision(vhdr_v2_path, eog=eog, preload=True, verbose='error') # For the nanovolt unit test we use the same data file with a different # header file. raw_nV = _test_raw_reader(read_raw_brainvision, vhdr_fname=vhdr_nV_path, eog=eog, misc='auto') assert_equal(raw_nV.info['chs'][0]['ch_name'], 'FP1') assert_equal(raw_nV.info['chs'][0]['kind'], FIFF.FIFFV_EEG_CH) data_nanovolt, _ = raw_nV[0] assert_array_almost_equal(data_py[0, :], data_nanovolt[0, :])
def test_gdf2_data(): """Test reading raw GDF 2.x files.""" raw = read_raw_edf(gdf2_path + '.gdf', eog=None, misc=None, preload=True, stim_channel='STATUS') nchan = raw.info['nchan'] ch_names = raw.ch_names # Renamed STATUS -> STI 014. picks = pick_types(raw.info, meg=False, eeg=True, exclude='bads') data, _ = raw[picks] # This .mat was generated using the official biosig matlab package mat = sio.loadmat(gdf2_path + '_biosig.mat') data_biosig = mat['dat'] * 1e-6 # data are stored in microvolts data_biosig = data_biosig[picks] # Assert data are almost equal assert_array_almost_equal(data, data_biosig, 8) # Find events events = find_events(raw, verbose=1) events[:, 2] >>= 8 # last 8 bits are system events in biosemi files assert_equal(events.shape[0], 2) # 2 events in file assert_array_equal(events[:, 2], [20, 28]) with pytest.warns(RuntimeWarning, match='No events found'): # header contains no events raw = read_raw_edf(gdf2_path + '.gdf', stim_channel='auto') assert_equal(nchan, raw.info['nchan']) # stim channel not constructed assert_array_equal(ch_names[1:], raw.ch_names[1:]) # gh-5604 assert raw.info['meas_date'] == DATE_NONE _test_raw_reader(read_raw_edf, input_fname=gdf2_path + '.gdf', eog=None, misc=None, stim_channel='STATUS')
def test_gdf_data(): """Test reading raw GDF 1.x files.""" with pytest.warns(RuntimeWarning, match='Overlapping events'): raw = read_raw_edf(gdf1_path + '.gdf', eog=None, misc=None, preload=True, stim_channel='auto') picks = pick_types(raw.info, meg=False, eeg=True, exclude='bads') data, _ = raw[picks] # this .npy was generated using the official biosig python package raw_biosig = np.load(gdf1_path + '_biosig.npy') raw_biosig = raw_biosig * 1e-6 # data are stored in microvolts data_biosig = raw_biosig[picks] # Assert data are almost equal assert_array_almost_equal(data, data_biosig, 8) # Test for stim channel events = find_events(raw, shortest_event=1) # The events are overlapping. assert_array_equal(events[:, 0], raw._raw_extras[0]['events'][1][::2]) # Test events are encoded to stim channel. events = find_events(raw) evs = raw.find_edf_events() assert (all([event in evs[1] for event in events[:, 0]])) # gh-5604 assert raw.info['meas_date'] == DATE_NONE with pytest.warns(RuntimeWarning, match='Overlapping events'): _test_raw_reader(read_raw_edf, input_fname=gdf1_path + '.gdf', eog=None, misc=None, stim_channel='auto')
def test_io_set_raw_2021(): """Test reading new default file format (no EEG struct).""" assert "EEG" not in io.loadmat(raw_fname_2021) _test_raw_reader(reader=read_raw_eeglab, input_fname=raw_fname_2021, test_preloading=False, preload=True)
def test_gdf2_data(): """Test reading raw GDF 2.x files.""" raw = read_raw_edf(gdf2_path + '.gdf', eog=None, misc=None, preload=True) picks = pick_types(raw.info, meg=False, eeg=True, exclude='bads') data, _ = raw[picks] # This .mat was generated using the official biosig matlab package mat = sio.loadmat(gdf2_path + '_biosig.mat') data_biosig = mat['dat'] * 1e-6 # data are stored in microvolts data_biosig = data_biosig[picks] # Assert data are almost equal assert_array_almost_equal(data, data_biosig, 8) # Find events events = find_events(raw, verbose=1) events[:, 2] >>= 8 # last 8 bits are system events in biosemi files assert_equal(events.shape[0], 2) # 2 events in file assert_array_equal(events[:, 2], [20, 28]) # gh-5604 assert raw.info['meas_date'] == DATE_NONE _test_raw_reader(read_raw_edf, input_fname=gdf2_path + '.gdf', eog=None, misc=None)
def test_eximia_nxe(): """Test reading Eximia NXE files""" fname = op.join(data_path(), 'eximia', 'test_eximia.nxe') raw = read_raw_eximia(fname, preload=True) assert_true('RawEximia' in repr(raw)) _test_raw_reader(read_raw_eximia, fname=fname) fname_mat = op.join(data_path(), 'eximia', 'test_eximia.mat') mc = sio.loadmat(fname_mat) m_data = mc['data'] m_header = mc['header'] assert_equal(raw._data.shape, m_data.shape) assert_equal(m_header['Fs'][0, 0][0, 0], raw.info['sfreq']) m_names = [x[0][0] for x in m_header['label'][0, 0]] m_names = list( map(lambda x: x.replace('GATE', 'GateIn').replace('TRIG', 'Trig'), m_names)) assert_equal(raw.ch_names, m_names) m_ch_types = [x[0][0] for x in m_header['chantype'][0, 0]] m_ch_types = list( map(lambda x: x.replace('unknown', 'stim').replace('trigger', 'stim'), m_ch_types)) types_dict = {2: 'eeg', 3: 'stim', 202: 'eog'} ch_types = [types_dict[raw.info['chs'][x]['kind']] for x in range(len(raw.ch_names))] assert_equal(ch_types, m_ch_types) assert_array_equal(m_data, raw._data)
def test_edf_data(): """Test edf files""" _test_raw_reader(read_raw_edf, input_fname=edf_path, stim_channel=None) raw_py = read_raw_edf(edf_path, preload=True) # Test saving and loading when annotations were parsed. tempdir = _TempDir() raw_file = op.join(tempdir, 'test-raw.fif') raw_py.save(raw_file, overwrite=True, buffer_size_sec=1) Raw(raw_file, preload=True) edf_events = find_events(raw_py, output='step', shortest_event=0, stim_channel='STI 014') # onset, duration, id events = [[0.1344, 0.2560, 2], [0.3904, 1.0000, 2], [2.0000, 0.0000, 3], [2.5000, 2.5000, 2]] events = np.array(events) events[:, :2] *= 512 # convert time to samples events = np.array(events, dtype=int) events[:, 1] -= 1 events[events[:, 1] <= 0, 1] = 1 events[:, 1] += events[:, 0] onsets = events[:, [0, 2]] offsets = events[:, [1, 2]] events = np.zeros((2 * events.shape[0], 3), dtype=int) events[0::2, [0, 2]] = onsets events[1::2, [0, 1]] = offsets assert_array_equal(edf_events, events)
def test_bdf_data(): """Test reading raw bdf files.""" raw_py = _test_raw_reader(read_raw_edf, input_fname=bdf_path, eog=eog, misc=misc, exclude=['M2', 'IEOG']) assert len(raw_py.ch_names) == 71 raw_py = _test_raw_reader(read_raw_edf, input_fname=bdf_path, montage=montage_path, eog=eog, misc=misc, exclude=['M2', 'IEOG']) assert len(raw_py.ch_names) == 71 assert 'RawEDF' in repr(raw_py) picks = pick_types(raw_py.info, meg=False, eeg=True, exclude='bads') data_py, _ = raw_py[picks] # this .mat was generated using the EEG Lab Biosemi Reader raw_eeglab = loadmat(bdf_eeglab_path) raw_eeglab = raw_eeglab['data'] * 1e-6 # data are stored in microvolts data_eeglab = raw_eeglab[picks] # bdf saved as a single, resolution to seven decimal points in matlab assert_array_almost_equal(data_py, data_eeglab, 8) # Manually checking that float coordinates are imported assert (raw_py.info['chs'][0]['loc']).any() assert (raw_py.info['chs'][25]['loc']).any() assert (raw_py.info['chs'][63]['loc']).any()
def test_gdf2_data(): """Test reading raw GDF 2.x files.""" raw = read_raw_gdf(gdf2_path + '.gdf', eog=None, misc=None, preload=True) assert raw._raw_extras[0]['subject_info']['age'] is None picks = pick_types(raw.info, meg=False, eeg=True, exclude='bads') data, _ = raw[picks] # This .mat was generated using the official biosig matlab package mat = sio.loadmat(gdf2_path + '_biosig.mat') data_biosig = mat['dat'] * 1e-6 # data are stored in microvolts data_biosig = data_biosig[picks] # Assert data are almost equal assert_array_almost_equal(data, data_biosig, 8) # Find events events = find_events(raw, verbose=1) events[:, 2] >>= 8 # last 8 bits are system events in biosemi files assert_equal(events.shape[0], 2) # 2 events in file assert_array_equal(events[:, 2], [20, 28]) # gh-5604 assert raw.info['meas_date'] is None _test_raw_reader(read_raw_gdf, input_fname=gdf2_path + '.gdf', eog=None, misc=None, test_scaling=False, # XXX this should be True )
def test_snirf_standard(fname, boundary_decimal, test_scaling, test_rank): """Test standard operations.""" _test_raw_reader(read_raw_snirf, fname=fname, boundary_decimal=boundary_decimal, test_scaling=test_scaling, test_rank=test_rank) # low fs
def test_io_egi_pns_mff(): """Test importing EGI MFF with PNS data""" egi_fname_mff = op.join(data_path(), 'EGI', 'test_egi_pns.mff') raw = read_raw_egi(egi_fname_mff, include=None, preload=True, verbose='error') assert_true('RawMff' in repr(raw)) pns_chans = pick_types(raw.info, ecg=True, bio=True, emg=True) assert_equal(len(pns_chans), 7) names = [raw.ch_names[x] for x in pns_chans] pns_names = [ 'Resp. Temperature'[:15], 'Resp. Pressure', 'ECG', 'Body Position', 'Resp. Effort Chest'[:15], 'Resp. Effort Abdomen'[:15], 'EMG-Leg' ] _test_raw_reader(read_raw_egi, input_fname=egi_fname_mff, channel_naming='EEG %03d', verbose='error') assert_equal(names, pns_names) mat_names = [ 'Resp_Temperature'[:15], 'Resp_Pressure', 'ECG', 'Body_Position', 'Resp_Effort_Chest'[:15], 'Resp_Effort_Abdomen'[:15], 'EMGLeg' ] egi_fname_mat = op.join(data_path(), 'EGI', 'test_egi_pns.mat') mc = sio.loadmat(egi_fname_mat) for ch_name, ch_idx, mat_name in zip(pns_names, pns_chans, mat_names): print('Testing {}'.format(ch_name)) mc_key = [x for x in mc.keys() if mat_name in x][0] cal = raw.info['chs'][ch_idx]['cal'] mat_data = mc[mc_key] * cal raw_data = raw[ch_idx][0] assert_array_equal(mat_data, raw_data)
def test_bdf_data(): """Test reading raw bdf files.""" raw_py = _test_raw_reader(read_raw_bdf, input_fname=bdf_path, eog=eog, misc=misc, exclude=['M2', 'IEOG']) assert len(raw_py.ch_names) == 71 raw_py = _test_raw_reader(read_raw_bdf, input_fname=bdf_path, montage='biosemi64', eog=eog, misc=misc, exclude=['M2', 'IEOG']) assert len(raw_py.ch_names) == 71 assert 'RawEDF' in repr(raw_py) picks = pick_types(raw_py.info, meg=False, eeg=True, exclude='bads') data_py, _ = raw_py[picks] # this .mat was generated using the EEG Lab Biosemi Reader raw_eeglab = loadmat(bdf_eeglab_path) raw_eeglab = raw_eeglab['data'] * 1e-6 # data are stored in microvolts data_eeglab = raw_eeglab[picks] # bdf saved as a single, resolution to seven decimal points in matlab assert_array_almost_equal(data_py, data_eeglab, 8) # Manually checking that float coordinates are imported assert (raw_py.info['chs'][0]['loc']).any() assert (raw_py.info['chs'][25]['loc']).any() assert (raw_py.info['chs'][63]['loc']).any()
def test_brainvision_data_highpass_filters(): """Test reading raw Brain Vision files with amplifier filter settings.""" # Homogeneous highpass in seconds (default measurement unit) raw = _test_raw_reader(read_raw_brainvision, vhdr_fname=vhdr_highpass_path, eog=eog) assert_equal(raw.info['highpass'], 1. / (2 * np.pi * 10)) assert_equal(raw.info['lowpass'], 250.) # Heterogeneous highpass in seconds (default measurement unit) with pytest.warns(RuntimeWarning, match='different .*pass filters') as w: raw = _test_raw_reader(read_raw_brainvision, vhdr_fname=vhdr_mixed_highpass_path, eog=eog) lowpass_warning = [ 'different lowpass filters' in str(ww.message) for ww in w ] highpass_warning = [ 'different highpass filters' in str(ww.message) for ww in w ] expected_warnings = zip(lowpass_warning, highpass_warning) assert (all(any([lp, hp]) for lp, hp in expected_warnings)) assert_equal(raw.info['highpass'], 1. / (2 * np.pi * 10)) assert_equal(raw.info['lowpass'], 250.) # Homogeneous highpass in Hertz raw = _test_raw_reader(read_raw_brainvision, vhdr_fname=vhdr_highpass_hz_path, eog=eog) assert_equal(raw.info['highpass'], 10.) assert_equal(raw.info['lowpass'], 250.) # Heterogeneous highpass in Hertz with pytest.warns(RuntimeWarning, match='different .*pass filters') as w: raw = _test_raw_reader(read_raw_brainvision, vhdr_fname=vhdr_mixed_highpass_hz_path, eog=eog) trigger_warning = ['will be dropped' in str(ww.message) for ww in w] lowpass_warning = [ 'different lowpass filters' in str(ww.message) for ww in w ] highpass_warning = [ 'different highpass filters' in str(ww.message) for ww in w ] expected_warnings = zip(trigger_warning, lowpass_warning, highpass_warning) assert (all(any([trg, lp, hp]) for trg, lp, hp in expected_warnings)) assert_equal(raw.info['highpass'], 5.) assert_equal(raw.info['lowpass'], 250.)
def test_brainvision_data_highpass_filters(): """Test reading raw Brain Vision files with amplifier filter settings.""" # Homogeneous highpass in seconds (default measurement unit) with warnings.catch_warnings(record=True) as w: # event parsing raw = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_highpass_path, montage=montage, eog=eog) assert_true(all('parse triggers that' in str(ww.message) for ww in w)) assert_equal(raw.info['highpass'], 1. / (2 * np.pi * 10)) assert_equal(raw.info['lowpass'], 250.) # Heterogeneous highpass in seconds (default measurement unit) with warnings.catch_warnings(record=True) as w: # event parsing raw = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_mixed_highpass_path, montage=montage, eog=eog, event_id=event_id) lowpass_warning = ['different lowpass filters' in str(ww.message) for ww in w] highpass_warning = ['different highpass filters' in str(ww.message) for ww in w] expected_warnings = zip(lowpass_warning, highpass_warning) assert_true(all(any([lp, hp]) for lp, hp in expected_warnings)) assert_equal(raw.info['highpass'], 1. / (2 * np.pi * 10)) assert_equal(raw.info['lowpass'], 250.) # Homogeneous highpass in Hertz with warnings.catch_warnings(record=True): # filter settings raw = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_highpass_hz_path, montage=montage, eog=eog, event_id=event_id) assert_equal(raw.info['highpass'], 10.) assert_equal(raw.info['lowpass'], 250.) # Heterogeneous highpass in Hertz with warnings.catch_warnings(record=True): # filter settings raw = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_mixed_highpass_hz_path, montage=montage, eog=eog, event_id=event_id) trigger_warning = ['parse triggers that' in str(ww.message) for ww in w] lowpass_warning = ['different lowpass filters' in str(ww.message) for ww in w] highpass_warning = ['different highpass filters' in str(ww.message) for ww in w] expected_warnings = zip(trigger_warning, lowpass_warning, highpass_warning) assert_true(all(any([trg, lp, hp]) for trg, lp, hp in expected_warnings)) assert_equal(raw.info['highpass'], 5.) assert_equal(raw.info['lowpass'], 250.)
def test_brainvision_data_highpass_filters(): """Test reading raw Brain Vision files with amplifier filter settings.""" # Homogeneous highpass in seconds (default measurement unit) with warnings.catch_warnings(record=True) as w: # event parsing raw = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_highpass_path, montage=montage, eog=eog) assert_true(all('parse triggers that' in str(ww.message) for ww in w)) assert_equal(raw.info['highpass'], 0.1) assert_equal(raw.info['lowpass'], 250.) # Heterogeneous highpass in seconds (default measurement unit) with warnings.catch_warnings(record=True) as w: # event parsing raw = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_mixed_highpass_path, montage=montage, eog=eog, event_id=event_id) lowpass_warning = ['different lowpass filters' in str(ww.message) for ww in w] highpass_warning = ['different highpass filters' in str(ww.message) for ww in w] expected_warnings = zip(lowpass_warning, highpass_warning) assert_true(all(any([lp, hp]) for lp, hp in expected_warnings)) assert_equal(raw.info['highpass'], 0.1) assert_equal(raw.info['lowpass'], 250.) # Homogeneous highpass in Hertz with warnings.catch_warnings(record=True): # filter settings raw = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_highpass_hz_path, montage=montage, eog=eog, event_id=event_id) assert_equal(raw.info['highpass'], 10.) assert_equal(raw.info['lowpass'], 250.) # Heterogeneous highpass in Hertz with warnings.catch_warnings(record=True): # filter settings raw = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_mixed_highpass_hz_path, montage=montage, eog=eog, event_id=event_id) trigger_warning = ['parse triggers that' in str(ww.message) for ww in w] lowpass_warning = ['different lowpass filters' in str(ww.message) for ww in w] highpass_warning = ['different highpass filters' in str(ww.message) for ww in w] expected_warnings = zip(trigger_warning, lowpass_warning, highpass_warning) assert_true(all(any([trg, lp, hp]) for trg, lp, hp in expected_warnings)) assert_equal(raw.info['highpass'], 5.) assert_equal(raw.info['lowpass'], 250.)
def test_brainvision_data(): """Test reading raw Brain Vision files.""" pytest.raises(IOError, read_raw_brainvision, vmrk_path) pytest.raises(ValueError, read_raw_brainvision, vhdr_path, montage, preload=True, scale="foo") raw_py = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_path, montage=montage, eog=eog, misc='auto', event_id=event_id) assert ('RawBrainVision' in repr(raw_py)) assert_equal(raw_py.info['highpass'], 0.) assert_equal(raw_py.info['lowpass'], 250.) picks = pick_types(raw_py.info, meg=False, eeg=True, exclude='bads') data_py, times_py = raw_py[picks] # compare with a file that was generated using MNE-C raw_bin = read_raw_fif(eeg_bin, preload=True) picks = pick_types(raw_py.info, meg=False, eeg=True, exclude='bads') data_bin, times_bin = raw_bin[picks] assert_array_almost_equal(data_py, data_bin) assert_array_almost_equal(times_py, times_bin) # Make sure EOG channels are marked correctly for ch in raw_py.info['chs']: if ch['ch_name'] in eog: assert_equal(ch['kind'], FIFF.FIFFV_EOG_CH) elif ch['ch_name'] == 'STI 014': assert_equal(ch['kind'], FIFF.FIFFV_STIM_CH) elif ch['ch_name'] in ('CP5', 'CP6'): assert_equal(ch['kind'], FIFF.FIFFV_MISC_CH) assert_equal(ch['unit'], FIFF.FIFF_UNIT_NONE) elif ch['ch_name'] == 'ReRef': assert_equal(ch['kind'], FIFF.FIFFV_MISC_CH) assert_equal(ch['unit'], FIFF.FIFF_UNIT_CEL) elif ch['ch_name'] in raw_py.info['ch_names']: assert_equal(ch['kind'], FIFF.FIFFV_EEG_CH) assert_equal(ch['unit'], FIFF.FIFF_UNIT_V) else: raise RuntimeError("Unknown Channel: %s" % ch['ch_name']) # test loading v2 read_raw_brainvision(vhdr_v2_path, eog=eog, preload=True, event_id=event_id, trig_shift_by_type={'response': 1000}, verbose='error') # For the nanovolt unit test we use the same data file with a different # header file. raw_nV = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_nV_path, montage=montage, eog=eog, misc='auto', event_id=event_id) assert_equal(raw_nV.info['chs'][0]['ch_name'], 'FP1') assert_equal(raw_nV.info['chs'][0]['kind'], FIFF.FIFFV_EEG_CH) data_nanovolt, _ = raw_nV[0] assert_array_almost_equal(data_py[0, :], data_nanovolt[0, :])
def test_data(): """Test reading raw Artemis123 files.""" _test_raw_reader(read_raw_artemis123, input_fname=short_no_HPI_fname) # test a random selected point raw = read_raw_artemis123(short_no_HPI_fname, preload=True) meg_picks = pick_types(raw.info, meg=True, eeg=False) # checked against matlab reader. assert_allclose(raw[meg_picks[12]][0][0][123], 3.072510659694672e-11)
def test_brainvision_data_lowpass_filters(): """Test files with amplifier LP filter settings.""" # Homogeneous lowpass in Hertz (default measurement unit) raw = _test_raw_reader(read_raw_brainvision, vhdr_fname=vhdr_lowpass_path, eog=eog) assert_equal(raw.info['highpass'], 1. / (2 * np.pi * 10)) assert_equal(raw.info['lowpass'], 250.) # Heterogeneous lowpass in Hertz (default measurement unit) with pytest.warns(RuntimeWarning) as w: # event parsing raw = _test_raw_reader(read_raw_brainvision, vhdr_fname=vhdr_mixed_lowpass_path, eog=eog) lowpass_warning = [ 'different lowpass filters' in str(ww.message) for ww in w ] highpass_warning = [ 'different highpass filters' in str(ww.message) for ww in w ] expected_warnings = zip(lowpass_warning, highpass_warning) assert (all(any([lp, hp]) for lp, hp in expected_warnings)) assert_equal(raw.info['highpass'], 1. / (2 * np.pi * 10)) assert_equal(raw.info['lowpass'], 250.) # Homogeneous lowpass in seconds raw = _test_raw_reader(read_raw_brainvision, vhdr_fname=vhdr_lowpass_s_path, eog=eog) assert_equal(raw.info['highpass'], 1. / (2 * np.pi * 10)) assert_equal(raw.info['lowpass'], 1. / (2 * np.pi * 0.004)) # Heterogeneous lowpass in seconds with pytest.warns(RuntimeWarning) as w: # filter settings raw = _test_raw_reader(read_raw_brainvision, vhdr_fname=vhdr_mixed_lowpass_s_path, eog=eog) lowpass_warning = [ 'different lowpass filters' in str(ww.message) for ww in w ] highpass_warning = [ 'different highpass filters' in str(ww.message) for ww in w ] expected_warnings = zip(lowpass_warning, highpass_warning) assert (all(any([lp, hp]) for lp, hp in expected_warnings)) assert_equal(raw.info['highpass'], 1. / (2 * np.pi * 10)) assert_equal(raw.info['lowpass'], 1. / (2 * np.pi * 0.004))
def test_data(): """Test reading raw nicolet files.""" _test_raw_reader(read_raw_nicolet, input_fname=fname, ch_type='eeg', ecg='auto', eog='auto', emg='auto', misc=['PHO'])
def test_data(): """Test reading raw kit files """ assert_raises(TypeError, read_raw_kit, epochs_path) assert_raises(TypeError, read_epochs_kit, sqd_path) assert_raises(ValueError, read_raw_kit, sqd_path, mrk_path, elp_path) assert_raises(ValueError, read_raw_kit, sqd_path, None, None, None, list(range(200, 190, -1))) assert_raises(ValueError, read_raw_kit, sqd_path, None, None, None, list(range(167, 159, -1)), '*', 1, True) # check functionality raw_mrk = read_raw_kit(sqd_path, [mrk2_path, mrk3_path], elp_path, hsp_path) raw_py = _test_raw_reader(read_raw_kit, input_fname=sqd_path, mrk=mrk_path, elp=elp_path, hsp=hsp_path, stim=list(range(167, 159, -1)), slope='+', stimthresh=1) assert_true('RawKIT' in repr(raw_py)) assert_equal(raw_mrk.info['kit_system_id'], KIT.SYSTEM_NYU_2010) assert_true(KIT_CONSTANTS[raw_mrk.info['kit_system_id']] is KIT_NY) # Test stim channel raw_stim = read_raw_kit(sqd_path, mrk_path, elp_path, hsp_path, stim='<', preload=False) for raw in [raw_py, raw_stim, raw_mrk]: stim_pick = pick_types(raw.info, meg=False, ref_meg=False, stim=True, exclude='bads') stim1, _ = raw[stim_pick] stim2 = np.array(raw.read_stim_ch(), ndmin=2) assert_array_equal(stim1, stim2) # Binary file only stores the sensor channels py_picks = pick_types(raw_py.info, exclude='bads') raw_bin = op.join(data_dir, 'test_bin_raw.fif') raw_bin = Raw(raw_bin, preload=True) bin_picks = pick_types(raw_bin.info, stim=True, exclude='bads') data_bin, _ = raw_bin[bin_picks] data_py, _ = raw_py[py_picks] # this .mat was generated using the Yokogawa MEG Reader data_Ykgw = op.join(data_dir, 'test_Ykgw.mat') data_Ykgw = scipy.io.loadmat(data_Ykgw)['data'] data_Ykgw = data_Ykgw[py_picks] assert_array_almost_equal(data_py, data_Ykgw) py_picks = pick_types(raw_py.info, stim=True, ref_meg=False, exclude='bads') data_py, _ = raw_py[py_picks] assert_array_almost_equal(data_py, data_bin) # KIT-UMD data _test_raw_reader(read_raw_kit, input_fname=sqd_umd_path) raw = read_raw_kit(sqd_umd_path) assert_equal(raw.info['kit_system_id'], KIT.SYSTEM_UMD_2014_12) assert_true(KIT_CONSTANTS[raw.info['kit_system_id']] is KIT_UMD_2014)
def test_brainvision_data_highpass_filters(): """Test reading raw Brain Vision files with amplifier filter settings.""" # Homogeneous highpass in seconds (default measurement unit) raw = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_highpass_path, montage=montage, eog=eog) assert_equal(raw.info['highpass'], 1. / (2 * np.pi * 10)) assert_equal(raw.info['lowpass'], 250.) # Heterogeneous highpass in seconds (default measurement unit) with pytest.warns(RuntimeWarning, match='different .*pass filters') as w: raw = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_mixed_highpass_path, montage=montage, eog=eog) lowpass_warning = ['different lowpass filters' in str(ww.message) for ww in w] highpass_warning = ['different highpass filters' in str(ww.message) for ww in w] expected_warnings = zip(lowpass_warning, highpass_warning) assert (all(any([lp, hp]) for lp, hp in expected_warnings)) assert_equal(raw.info['highpass'], 1. / (2 * np.pi * 10)) assert_equal(raw.info['lowpass'], 250.) # Homogeneous highpass in Hertz raw = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_highpass_hz_path, montage=montage, eog=eog) assert_equal(raw.info['highpass'], 10.) assert_equal(raw.info['lowpass'], 250.) # Heterogeneous highpass in Hertz with pytest.warns(RuntimeWarning, match='different .*pass filters') as w: raw = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_mixed_highpass_hz_path, montage=montage, eog=eog) trigger_warning = ['will be dropped' in str(ww.message) for ww in w] lowpass_warning = ['different lowpass filters' in str(ww.message) for ww in w] highpass_warning = ['different highpass filters' in str(ww.message) for ww in w] expected_warnings = zip(trigger_warning, lowpass_warning, highpass_warning) assert (all(any([trg, lp, hp]) for trg, lp, hp in expected_warnings)) assert_equal(raw.info['highpass'], 5.) assert_equal(raw.info['lowpass'], 250.)
def test_nihon_eeg(): """Test reading Nihon Kohden EEG files.""" fname = data_path / 'NihonKohden' / 'MB0400FU.EEG' raw = read_raw_nihon(fname.as_posix(), preload=True) assert 'RawNihon' in repr(raw) _test_raw_reader(read_raw_nihon, fname=fname, test_scaling=False) fname_edf = data_path / 'NihonKohden' / 'MB0400FU.EDF' raw_edf = read_raw_edf(fname_edf, preload=True) assert raw._data.shape == raw_edf._data.shape assert raw.info['sfreq'] == raw.info['sfreq'] # ch names and order are switched in the EDF edf_ch_names = { x: x.split(' ')[1].replace('-Ref', '') for x in raw_edf.ch_names } raw_edf.rename_channels(edf_ch_names) assert raw.ch_names == raw_edf.ch_names for i, an1 in enumerate(raw.annotations): # EDF has some weird annotations, which are not in the LOG file an2 = raw_edf.annotations[i * 2 + 1] assert an1['onset'] == an2['onset'] assert an1['duration'] == an2['duration'] # Also, it prepends 'Segment: ' to some annotations t_desc = an2['description'].replace('Segment: ', '') assert an1['description'] == t_desc assert_array_almost_equal(raw._data, raw_edf._data) with pytest.raises(ValueError, match='Not a valid Nihon Kohden EEG file'): raw = read_raw_nihon(fname_edf, preload=True) with pytest.raises(ValueError, match='Not a valid Nihon Kohden EEG file'): raw = _read_nihon_header(fname_edf) bad_fname = data_path / 'eximia' / 'text_eximia.nxe' msg = 'No PNT file exists. Metadata will be blank' with pytest.warns(RuntimeWarning, match=msg): meta = _read_nihon_metadata(bad_fname) assert len(meta) == 0 msg = 'No LOG file exists. Annotations will not be read' with pytest.warns(RuntimeWarning, match=msg): annot = _read_nihon_annotations(bad_fname) assert all(len(x) == 0 for x in annot.values()) # the nihon test file has $A1 and $A2 in it, which are not EEG assert '$A1' in raw.ch_names # assert that channels with $ are 'misc' picks = [ch for ch in raw.ch_names if ch.startswith('$')] ch_types = raw.get_channel_types(picks=picks) assert all(ch == 'misc' for ch in ch_types)
def test_io_set(): """Test importing EEGLAB .set files""" from scipy import io _test_raw_reader(read_raw_eeglab, input_fname=raw_fname, montage=montage) with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') _test_raw_reader(read_raw_eeglab, input_fname=raw_fname_onefile, montage=montage) raw = read_raw_eeglab(input_fname=raw_fname_onefile, montage=montage) raw2 = read_raw_eeglab(input_fname=raw_fname, montage=montage) assert_array_equal(raw[:][0], raw2[:][0]) # one warning per each preload=False or str with raw_fname_onefile assert_equal(len(w), 3) with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') epochs = read_epochs_eeglab(epochs_fname) epochs2 = read_epochs_eeglab(epochs_fname_onefile) # 3 warnings for each read_epochs_eeglab because there are 3 epochs # associated with multiple events assert_equal(len(w), 6) assert_array_equal(epochs.get_data(), epochs2.get_data()) # test different combinations of events and event_ids temp_dir = _TempDir() out_fname = op.join(temp_dir, 'test-eve.fif') write_events(out_fname, epochs.events) event_id = {'S255/S8': 1, 'S8': 2, 'S255/S9': 3} epochs = read_epochs_eeglab(epochs_fname, epochs.events, event_id) epochs = read_epochs_eeglab(epochs_fname, out_fname, event_id) assert_raises(ValueError, read_epochs_eeglab, epochs_fname, None, event_id) assert_raises(ValueError, read_epochs_eeglab, epochs_fname, epochs.events, None) # test if .dat file raises an error eeg = io.loadmat(epochs_fname, struct_as_record=False, squeeze_me=True)['EEG'] eeg.data = 'epochs_fname.dat' bad_epochs_fname = op.join(temp_dir, 'test_epochs.set') io.savemat(bad_epochs_fname, {'EEG': {'trials': eeg.trials, 'srate': eeg.srate, 'nbchan': eeg.nbchan, 'data': eeg.data, 'epoch': eeg.epoch, 'event': eeg.event, 'chanlocs': eeg.chanlocs}}) shutil.copyfile(op.join(base_dir, 'test_epochs.fdt'), op.join(temp_dir, 'test_epochs.dat')) with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') assert_raises(NotImplementedError, read_epochs_eeglab, bad_epochs_fname) assert_equal(len(w), 3)
def test_data(): """Test reading raw Artemis123 files.""" _test_raw_reader(read_raw_artemis123, input_fname=short_hpi_1kz_fname, pos_fname=dig_fname, verbose='error') # test a random selected point raw = read_raw_artemis123(short_hpi_1kz_fname, preload=True, add_head_trans=False) meg_picks = pick_types(raw.info, meg=True, eeg=False) # checked against matlab reader. assert_allclose(raw[meg_picks[12]][0][0][123], 1.08239606023e-11) dev_head_t_1 = np.array([[9.713e-01, 2.340e-01, -4.164e-02, 1.302e-04], [-2.371e-01, 9.664e-01, -9.890e-02, 1.977e-03], [1.710e-02, 1.059e-01, 9.942e-01, -8.159e-03], [0.0, 0.0, 0.0, 1.0]]) dev_head_t_2 = np.array([[9.890e-01, 1.475e-01, -8.090e-03, 4.997e-04], [-1.476e-01, 9.846e-01, -9.389e-02, 1.962e-03], [-5.888e-03, 9.406e-02, 9.955e-01, -1.610e-02], [0.0, 0.0, 0.0, 1.0]]) expected_dev_hpi_rr = np.array([[-0.01579644, 0.06527367, 0.00152648], [0.06666813, 0.0148956, 0.00545488], [-0.06699212, -0.01732376, 0.0112027]]) # test with head loc no digitization raw = read_raw_artemis123(short_HPI_dip_fname, add_head_trans=True) _assert_trans(raw.info['dev_head_t']['trans'], dev_head_t_1) assert_equal(raw.info['sfreq'], 5000.0) # test with head loc and digitization with pytest.warns(RuntimeWarning, match='Large difference'): raw = read_raw_artemis123(short_HPI_dip_fname, add_head_trans=True, pos_fname=dig_fname) _assert_trans(raw.info['dev_head_t']['trans'], dev_head_t_1) # test cHPI localization.. dev_hpi_rr = np.array([ p['r'] for p in raw.info['dig'] if p['coord_frame'] == FIFF.FIFFV_COORD_DEVICE ]) # points should be within 0.1 mm (1e-4m) and within 1% assert_allclose(dev_hpi_rr, expected_dev_hpi_rr, atol=1e-4, rtol=0.01) # test 1kz hpi head loc (different freq) raw = read_raw_artemis123(short_hpi_1kz_fname, add_head_trans=True) _assert_trans(raw.info['dev_head_t']['trans'], dev_head_t_2) assert_equal(raw.info['sfreq'], 1000.0)
def test_brainvision_data_lowpass_filters(): """Test files with amplifier LP filter settings.""" # Homogeneous lowpass in Hertz (default measurement unit) raw = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_lowpass_path, montage=montage, eog=eog) assert_equal(raw.info['highpass'], 1. / (2 * np.pi * 10)) assert_equal(raw.info['lowpass'], 250.) # Heterogeneous lowpass in Hertz (default measurement unit) with pytest.warns(RuntimeWarning) as w: # event parsing raw = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_mixed_lowpass_path, montage=montage, eog=eog) lowpass_warning = ['different lowpass filters' in str(ww.message) for ww in w] highpass_warning = ['different highpass filters' in str(ww.message) for ww in w] expected_warnings = zip(lowpass_warning, highpass_warning) assert (all(any([lp, hp]) for lp, hp in expected_warnings)) assert_equal(raw.info['highpass'], 1. / (2 * np.pi * 10)) assert_equal(raw.info['lowpass'], 250.) # Homogeneous lowpass in seconds raw = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_lowpass_s_path, montage=montage, eog=eog) assert_equal(raw.info['highpass'], 1. / (2 * np.pi * 10)) assert_equal(raw.info['lowpass'], 1. / (2 * np.pi * 0.004)) # Heterogeneous lowpass in seconds with pytest.warns(RuntimeWarning) as w: # filter settings raw = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_mixed_lowpass_s_path, montage=montage, eog=eog) lowpass_warning = ['different lowpass filters' in str(ww.message) for ww in w] highpass_warning = ['different highpass filters' in str(ww.message) for ww in w] expected_warnings = zip(lowpass_warning, highpass_warning) assert (all(any([lp, hp]) for lp, hp in expected_warnings)) assert_equal(raw.info['highpass'], 1. / (2 * np.pi * 10)) assert_equal(raw.info['lowpass'], 1. / (2 * np.pi * 0.004))
def test_data(): """Test reading raw nicolet files.""" _test_raw_reader(read_raw_nicolet, input_fname=fname_data, ch_type='eeg', ecg='auto', eog='auto', emg='auto', misc=['PHO']) with pytest.raises(ValueError, match='File name should end with .data not ".head".'): read_raw_nicolet(fname_head, 'eeg')
def test_io_set_raw(fname): """Test importing EEGLAB .set files.""" _test_raw_reader(read_raw_eeglab, input_fname=fname, montage=montage) # test that preloading works raw0 = read_raw_eeglab(input_fname=fname, montage=montage, preload=True) raw0.filter(1, None, l_trans_bandwidth='auto', filter_length='auto', phase='zero') # test that using uint16_codec does not break stuff raw0 = read_raw_eeglab(input_fname=fname, montage=montage, preload=False, uint16_codec='ascii')
def test_io_egi_pns_mff(tmpdir): """Test importing EGI MFF with PNS data.""" raw = read_raw_egi(egi_mff_pns_fname, include=None, preload=True, verbose='error') assert ('RawMff' in repr(raw)) pns_chans = pick_types(raw.info, ecg=True, bio=True, emg=True) assert_equal(len(pns_chans), 7) names = [raw.ch_names[x] for x in pns_chans] pns_names = ['Resp. Temperature'[:15], 'Resp. Pressure', 'ECG', 'Body Position', 'Resp. Effort Chest'[:15], 'Resp. Effort Abdomen'[:15], 'EMG-Leg'] _test_raw_reader(read_raw_egi, input_fname=egi_mff_pns_fname, channel_naming='EEG %03d', verbose='error', test_rank='less', test_scaling=False, # XXX probably some bug ) assert_equal(names, pns_names) mat_names = [ 'Resp_Temperature'[:15], 'Resp_Pressure', 'ECG', 'Body_Position', 'Resp_Effort_Chest'[:15], 'Resp_Effort_Abdomen'[:15], 'EMGLeg' ] egi_fname_mat = op.join(data_path(), 'EGI', 'test_egi_pns.mat') mc = sio.loadmat(egi_fname_mat) for ch_name, ch_idx, mat_name in zip(pns_names, pns_chans, mat_names): print('Testing {}'.format(ch_name)) mc_key = [x for x in mc.keys() if mat_name in x][0] cal = raw.info['chs'][ch_idx]['cal'] mat_data = mc[mc_key] * cal raw_data = raw[ch_idx][0] assert_array_equal(mat_data, raw_data) # EEG missing new_mff = str(tmpdir.join('temp.mff')) shutil.copytree(egi_mff_pns_fname, new_mff) read_raw_egi(new_mff, verbose='error') os.remove(op.join(new_mff, 'info1.xml')) os.remove(op.join(new_mff, 'signal1.bin')) with pytest.raises(FileNotFoundError, match='Could not find any EEG'): read_raw_egi(new_mff, verbose='error')
def test_edf_data(): """Test edf files.""" raw = _test_raw_reader(read_raw_edf, input_fname=edf_path, stim_channel=None, exclude=['Ergo-Left', 'H10']) raw_py = read_raw_edf(edf_path, preload=True) assert_equal(len(raw.ch_names) + 2, len(raw_py.ch_names)) # Test saving and loading when annotations were parsed. edf_events = find_events(raw_py, output='step', shortest_event=0, stim_channel='STI 014') # onset, duration, id events = [[0.1344, 0.2560, 2], [0.3904, 1.0000, 2], [2.0000, 0.0000, 3], [2.5000, 2.5000, 2]] events = np.array(events) events[:, :2] *= 512 # convert time to samples events = np.array(events, dtype=int) events[:, 1] -= 1 events[events[:, 1] <= 0, 1] = 1 events[:, 1] += events[:, 0] onsets = events[:, [0, 2]] offsets = events[:, [1, 2]] events = np.zeros((2 * events.shape[0], 3), dtype=int) events[0::2, [0, 2]] = onsets events[1::2, [0, 1]] = offsets assert_array_equal(edf_events, events)
def test_data(): """Test reading raw cnt files.""" raw = _test_raw_reader(read_raw_cnt, montage=None, input_fname=fname, eog='auto', misc=['NA1', 'LEFT_EAR']) eog_chs = mne.pick_types(raw.info, eog=True, exclude=[]) assert_equal(len(eog_chs), 2) # test eog='auto' assert_equal(raw.info['bads'], ['LEFT_EAR', 'VEOGR']) # test bads
def test_io_egi_mff(): """Test importing EGI MFF simple binary files.""" egi_fname_mff = op.join(data_path(), 'EGI', 'test_egi.mff') raw = read_raw_egi(egi_fname_mff, include=None) assert ('RawMff' in repr(raw)) include = ['DIN1', 'DIN2', 'DIN3', 'DIN4', 'DIN5', 'DIN7'] raw = _test_raw_reader(read_raw_egi, input_fname=egi_fname_mff, include=include, channel_naming='EEG %03d') assert_equal('eeg' in raw, True) eeg_chan = [c for c in raw.ch_names if 'EEG' in c] assert_equal(len(eeg_chan), 129) picks = pick_types(raw.info, eeg=True) assert_equal(len(picks), 129) assert_equal('STI 014' in raw.ch_names, True) events = find_events(raw, stim_channel='STI 014') assert_equal(len(events), 8) assert_equal(np.unique(events[:, 1])[0], 0) assert (np.unique(events[:, 0])[0] != 0) assert (np.unique(events[:, 2])[0] != 0) pytest.raises(ValueError, read_raw_egi, egi_fname_mff, include=['Foo'], preload=False) pytest.raises(ValueError, read_raw_egi, egi_fname_mff, exclude=['Bar'], preload=False) for ii, k in enumerate(include, 1): assert (k in raw.event_id) assert (raw.event_id[k] == ii)
def test_brainvision_data(): """Test reading raw Brain Vision files """ assert_raises(IOError, read_raw_brainvision, vmrk_path) assert_raises(ValueError, read_raw_brainvision, vhdr_path, montage, preload=True, scale="foo") raw_py = _test_raw_reader(read_raw_brainvision, test_preloading=True, vhdr_fname=vhdr_path, montage=montage, eog=eog) assert_true('RawBrainVision' in repr(raw_py)) assert_equal(raw_py.info['highpass'], 0.) assert_equal(raw_py.info['lowpass'], 250.) picks = pick_types(raw_py.info, meg=False, eeg=True, exclude='bads') data_py, times_py = raw_py[picks] # compare with a file that was generated using MNE-C raw_bin = Raw(eeg_bin, preload=True) picks = pick_types(raw_py.info, meg=False, eeg=True, exclude='bads') data_bin, times_bin = raw_bin[picks] assert_array_almost_equal(data_py, data_bin) assert_array_almost_equal(times_py, times_bin) # Make sure EOG channels are marked correctly for ch in raw_py.info['chs']: if ch['ch_name'] in eog: assert_equal(ch['kind'], FIFF.FIFFV_EOG_CH) elif ch['ch_name'] == 'STI 014': assert_equal(ch['kind'], FIFF.FIFFV_STIM_CH) elif ch['ch_name'] in raw_py.info['ch_names']: assert_equal(ch['kind'], FIFF.FIFFV_EEG_CH) else: raise RuntimeError("Unknown Channel: %s" % ch['ch_name'])
def test_brainvision_data_partially_disabled_hw_filters(): """Test reading raw Brain Vision files with heterogeneous amplifier filter settings including non-numeric values """ with warnings.catch_warnings(record=True) as w: # event parsing raw = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_partially_disabled_hw_filter_path, montage=montage, eog=eog) trigger_warning = ['parse triggers that' in str(ww.message) for ww in w] lowpass_warning = [ 'different lowpass filters' in str(ww.message) for ww in w ] highpass_warning = [ 'different highpass filters' in str(ww.message) for ww in w ] expected_warnings = zip(trigger_warning, lowpass_warning, highpass_warning) assert_true(all(any([trg, lp, hp]) for trg, lp, hp in expected_warnings)) assert_equal(raw.info['highpass'], 0.) assert_equal(raw.info['lowpass'], 500.)
def test_edf_data_broken(tmp_path): """Test edf files.""" raw = _test_raw_reader(read_raw_edf, input_fname=edf_path, exclude=['Ergo-Left', 'H10'], verbose='error') raw_py = read_raw_edf(edf_path) data = raw_py.get_data() assert_equal(len(raw.ch_names) + 2, len(raw_py.ch_names)) # Test with number of records not in header (-1). broken_fname = op.join(tmp_path, 'broken.edf') with open(edf_path, 'rb') as fid_in: fid_in.seek(0, 2) n_bytes = fid_in.tell() fid_in.seek(0, 0) rbytes = fid_in.read() with open(broken_fname, 'wb') as fid_out: fid_out.write(rbytes[:236]) fid_out.write(b'-1 ') fid_out.write(rbytes[244:244 + int(n_bytes * 0.4)]) with pytest.warns(RuntimeWarning, match='records .* not match the file size'): raw = read_raw_edf(broken_fname, preload=True) read_raw_edf(broken_fname, exclude=raw.ch_names[:132], preload=True) # Test with \x00's in the data with open(broken_fname, 'wb') as fid_out: fid_out.write(rbytes[:184]) assert rbytes[184:192] == b'36096 ' fid_out.write(rbytes[184:192].replace(b' ', b'\x00')) fid_out.write(rbytes[192:]) raw_py = read_raw_edf(broken_fname) data_new = raw_py.get_data() assert_allclose(data, data_new)
def test_bdf_stim_channel(): """Test BDF stim channel.""" # test if last channel is detected as STIM by default raw_py = _test_raw_reader(read_raw_edf, input_fname=bdf_path, stim_channel='auto') assert channel_type(raw_py.info, raw_py.info["nchan"] - 1) == 'stim' # test BDF file with wrong scaling info in header - this should be ignored # for BDF stim channels events = [[242, 0, 4], [310, 0, 2], [952, 0, 1], [1606, 0, 1], [2249, 0, 1], [2900, 0, 1], [3537, 0, 1], [4162, 0, 1], [4790, 0, 1]] with pytest.deprecated_call(match='stim_channel'): raw = read_raw_edf(bdf_stim_channel_path, preload=True) bdf_events = find_events(raw) assert_array_equal(events, bdf_events) raw = read_raw_edf(bdf_stim_channel_path, preload=False, stim_channel='auto') bdf_events = find_events(raw) assert_array_equal(events, bdf_events)
def test_io_egi_mff(): """Test importing EGI MFF simple binary files.""" raw = read_raw_egi(egi_mff_fname, include=None) assert ('RawMff' in repr(raw)) include = ['DIN1', 'DIN2', 'DIN3', 'DIN4', 'DIN5', 'DIN7'] raw = _test_raw_reader(read_raw_egi, input_fname=egi_mff_fname, include=include, channel_naming='EEG %03d', test_scaling=False, # XXX probably some bug ) assert raw.info['sfreq'] == 1000. assert_equal('eeg' in raw, True) eeg_chan = [c for c in raw.ch_names if 'EEG' in c] assert_equal(len(eeg_chan), 129) picks = pick_types(raw.info, eeg=True) assert_equal(len(picks), 129) assert_equal('STI 014' in raw.ch_names, True) events = find_events(raw, stim_channel='STI 014') assert_equal(len(events), 8) assert_equal(np.unique(events[:, 1])[0], 0) assert (np.unique(events[:, 0])[0] != 0) assert (np.unique(events[:, 2])[0] != 0) pytest.raises(ValueError, read_raw_egi, egi_mff_fname, include=['Foo'], preload=False) pytest.raises(ValueError, read_raw_egi, egi_mff_fname, exclude=['Bar'], preload=False) for ii, k in enumerate(include, 1): assert (k in raw.event_id) assert (raw.event_id[k] == ii)
def test_edf_data(): """Test edf files.""" raw = _test_raw_reader(read_raw_edf, input_fname=edf_path, exclude=['Ergo-Left', 'H10'], verbose='error') raw_py = read_raw_edf(edf_path, preload=True) assert_equal(len(raw.ch_names) + 2, len(raw_py.ch_names)) # Test with number of records not in header (-1). tempdir = _TempDir() broken_fname = op.join(tempdir, 'broken.edf') with open(edf_path, 'rb') as fid_in: fid_in.seek(0, 2) n_bytes = fid_in.tell() fid_in.seek(0, 0) rbytes = fid_in.read(int(n_bytes * 0.4)) with open(broken_fname, 'wb') as fid_out: fid_out.write(rbytes[:236]) fid_out.write(b'-1 ') fid_out.write(rbytes[244:]) with pytest.warns(RuntimeWarning, match='records .* not match the file size'): raw = read_raw_edf(broken_fname, preload=True) read_raw_edf(broken_fname, exclude=raw.ch_names[:132], preload=True)
def test_io_set_raw(fname): """Test importing EEGLAB .set files.""" montage = _read_eeglab_montage(montage_path) montage.ch_names = [ 'EEG {0:03d}'.format(ii) for ii in range(len(montage.ch_names)) ] kws = dict(reader=read_raw_eeglab, input_fname=fname) if fname.endswith('test_raw_chanloc.set'): with pytest.warns(RuntimeWarning, match="The data contains 'boundary' events"): raw0 = _test_raw_reader(**kws) elif '_h5' in fname: # should be safe enough, and much faster raw0 = read_raw_eeglab(fname, preload=True) else: raw0 = _test_raw_reader(**kws) # test that preloading works if fname.endswith('test_raw_chanloc.set'): raw0.set_montage(montage, on_missing='ignore') # crop to check if the data has been properly preloaded; we cannot # filter as the snippet of raw data is very short raw0.crop(0, 1) else: raw0.set_montage(montage) raw0.filter(1, None, l_trans_bandwidth='auto', filter_length='auto', phase='zero') # test that using uint16_codec does not break stuff read_raw_kws = dict(input_fname=fname, preload=False, uint16_codec='ascii') if fname.endswith('test_raw_chanloc.set'): with pytest.warns(RuntimeWarning, match="The data contains 'boundary' events"): raw0 = read_raw_eeglab(**read_raw_kws) raw0.set_montage(montage, on_missing='ignore') else: raw0 = read_raw_eeglab(**read_raw_kws) raw0.set_montage(montage) # Annotations if fname != raw_fname_chanloc: assert len(raw0.annotations) == 154 assert set(raw0.annotations.description) == {'rt', 'square'} assert_array_equal(raw0.annotations.duration, 0.)
def test_io_egi(): """Test importing EGI simple binary files.""" # test default with open(egi_txt_fname) as fid: data = np.loadtxt(fid) t = data[0] data = data[1:] data *= 1e-6 # µV with pytest.warns(RuntimeWarning, match='Did not find any event code'): raw = read_raw_egi(egi_fname, include=None) assert 'RawEGI' in repr(raw) data_read, t_read = raw[:256] assert_allclose(t_read, t) assert_allclose(data_read, data, atol=1e-10) include = ['TRSP', 'XXX1'] raw = _test_raw_reader( read_raw_egi, input_fname=egi_fname, include=include, test_rank='less', test_scaling=False, # XXX probably some bug ) assert_equal('eeg' in raw, True) eeg_chan = [c for c in raw.ch_names if c.startswith('E')] assert_equal(len(eeg_chan), 256) picks = pick_types(raw.info, eeg=True) assert_equal(len(picks), 256) assert_equal('STI 014' in raw.ch_names, True) events = find_events(raw, stim_channel='STI 014') assert_equal(len(events), 2) # ground truth assert_equal(np.unique(events[:, 1])[0], 0) assert (np.unique(events[:, 0])[0] != 0) assert (np.unique(events[:, 2])[0] != 0) triggers = np.array([[0, 1, 1, 0], [0, 0, 1, 0]]) # test trigger functionality triggers = np.array([[0, 1, 0, 0], [0, 0, 1, 0]]) events_ids = [12, 24] new_trigger = _combine_triggers(triggers, events_ids) assert_array_equal(np.unique(new_trigger), np.unique([0, 12, 24])) pytest.raises(ValueError, read_raw_egi, egi_fname, include=['Foo'], preload=False) pytest.raises(ValueError, read_raw_egi, egi_fname, exclude=['Bar'], preload=False) for ii, k in enumerate(include, 1): assert (k in raw.event_id) assert (raw.event_id[k] == ii)
def test_data(): """Test reading raw cnt files.""" with pytest.warns(RuntimeWarning, match='number of bytes'): raw = _test_raw_reader(read_raw_cnt, montage=None, input_fname=fname, eog='auto', misc=['NA1', 'LEFT_EAR']) eog_chs = pick_types(raw.info, eog=True, exclude=[]) assert len(eog_chs) == 2 # test eog='auto' assert raw.info['bads'] == ['LEFT_EAR', 'VEOGR'] # test bads
def test_brainvision_data_filters(): """Test reading raw Brain Vision files """ raw = _test_raw_reader(read_raw_brainvision, vhdr_fname=vhdr_highpass_path, montage=montage, eog=eog) assert_equal(raw.info['highpass'], 0.1) assert_equal(raw.info['lowpass'], 250.)
def test_brainvision_data(): """Test reading raw Brain Vision files.""" assert_raises(IOError, read_raw_brainvision, vmrk_path) assert_raises(ValueError, read_raw_brainvision, vhdr_path, montage, preload=True, scale="foo") with warnings.catch_warnings(record=True) as w: # event parsing raw_py = _test_raw_reader(read_raw_brainvision, vhdr_fname=vhdr_path, montage=montage, eog=eog, misc='auto') assert_true(all('parse triggers that' in str(ww.message) for ww in w)) assert_true('RawBrainVision' in repr(raw_py)) assert_equal(raw_py.info['highpass'], 0.) assert_equal(raw_py.info['lowpass'], 250.) picks = pick_types(raw_py.info, meg=False, eeg=True, exclude='bads') data_py, times_py = raw_py[picks] # compare with a file that was generated using MNE-C raw_bin = read_raw_fif(eeg_bin, preload=True) picks = pick_types(raw_py.info, meg=False, eeg=True, exclude='bads') data_bin, times_bin = raw_bin[picks] assert_array_almost_equal(data_py, data_bin) assert_array_almost_equal(times_py, times_bin) # Make sure EOG channels are marked correctly for ch in raw_py.info['chs']: if ch['ch_name'] in eog: assert_equal(ch['kind'], FIFF.FIFFV_EOG_CH) elif ch['ch_name'] == 'STI 014': assert_equal(ch['kind'], FIFF.FIFFV_STIM_CH) elif ch['ch_name'] in ('CP5', 'CP6'): assert_equal(ch['kind'], FIFF.FIFFV_MISC_CH) assert_equal(ch['unit'], FIFF.FIFF_UNIT_NONE) elif ch['ch_name'] == 'ReRef': assert_equal(ch['kind'], FIFF.FIFFV_MISC_CH) assert_equal(ch['unit'], FIFF.FIFF_UNIT_CEL) elif ch['ch_name'] in raw_py.info['ch_names']: assert_equal(ch['kind'], FIFF.FIFFV_EEG_CH) assert_equal(ch['unit'], FIFF.FIFF_UNIT_V) else: raise RuntimeError("Unknown Channel: %s" % ch['ch_name']) # test loading v2 read_raw_brainvision(vhdr_v2_path, eog=eog, preload=True, response_trig_shift=1000)
def test_brainvision_data_software_filters_latin1_global_units(): """Test reading raw Brain Vision files.""" with pytest.warns(RuntimeWarning, match='software filter'): raw = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_old_path, eog=("VEOGo", "VEOGu", "HEOGli", "HEOGre"), misc=("A2",)) assert_equal(raw.info['highpass'], 1. / (2 * np.pi * 0.9)) assert_equal(raw.info['lowpass'], 50.)
def test_data(): """Test reading raw cnt files.""" with warnings.catch_warnings(record=True) as w: raw = _test_raw_reader(read_raw_cnt, montage=None, input_fname=fname, eog='auto', misc=['NA1', 'LEFT_EAR']) assert_true(all('meas date' in str(ww.message) for ww in w)) eog_chs = mne.pick_types(raw.info, eog=True, exclude=[]) assert_equal(len(eog_chs), 2) # test eog='auto' assert_equal(raw.info['bads'], ['LEFT_EAR', 'VEOGR']) # test bads
def test_brainvision_data_software_filters_latin1_global_units(): """Test reading raw Brain Vision files.""" with pytest.warns(RuntimeWarning, match='software filter'): raw = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_old_path, eog=("VEOGo", "VEOGu", "HEOGli", "HEOGre"), misc=("A2",)) assert_equal(raw.info['highpass'], 1. / (2 * np.pi * 0.9)) assert_equal(raw.info['lowpass'], 50.) # test sensor name with spaces (#9299) with pytest.warns(RuntimeWarning, match='software filter'): raw = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_old_longname_path, eog=("VEOGo", "VEOGu", "HEOGli", "HEOGre"), misc=("A2",)) assert_equal(raw.info['highpass'], 1. / (2 * np.pi * 0.9)) assert_equal(raw.info['lowpass'], 50.)
def test_io_set_raw(fname): """Test importing EEGLAB .set files.""" montage = _read_eeglab_montage(montage_path) montage.ch_names = [ 'EEG {0:03d}'.format(ii) for ii in range(len(montage.ch_names)) ] _test_raw_reader(read_raw_eeglab, input_fname=fname) # test that preloading works raw0 = read_raw_eeglab(input_fname=fname, preload=True) raw0.set_montage(montage) raw0.filter(1, None, l_trans_bandwidth='auto', filter_length='auto', phase='zero') # test that using uint16_codec does not break stuff raw0 = read_raw_eeglab(input_fname=fname, preload=False, uint16_codec='ascii') raw0.set_montage(montage)
def test_io_set_raw(fname): """Test importing EEGLAB .set files.""" montage = _read_eeglab_montage(montage_path) montage.ch_names = [ 'EEG {0:03d}'.format(ii) for ii in range(len(montage.ch_names)) ] kws = dict(reader=read_raw_eeglab, input_fname=fname) if fname.endswith('test_raw_chanloc.set'): with pytest.warns(RuntimeWarning, match="The data contains 'boundary' events"): _test_raw_reader(**kws) else: _test_raw_reader(**kws) # test that preloading works read_raw_kws = dict(input_fname=fname, preload=True) if fname.endswith('test_raw_chanloc.set'): with pytest.warns(RuntimeWarning, match="The data contains 'boundary' events"): raw0 = read_raw_eeglab(**read_raw_kws) raw0.set_montage(montage, on_missing='ignore') # crop to check if the data has been properly preloaded; we cannot # filter as the snippet of raw data is very short raw0.crop(0, 1) else: raw0 = read_raw_eeglab(**read_raw_kws) raw0.set_montage(montage) raw0.filter(1, None, l_trans_bandwidth='auto', filter_length='auto', phase='zero') # test that using uint16_codec does not break stuff read_raw_kws = dict(input_fname=fname, preload=False, uint16_codec='ascii') if fname.endswith('test_raw_chanloc.set'): with pytest.warns(RuntimeWarning, match="The data contains 'boundary' events"): raw0 = read_raw_eeglab(**read_raw_kws) raw0.set_montage(montage, on_missing='ignore') else: raw0 = read_raw_eeglab(**read_raw_kws) raw0.set_montage(montage)
def test_brainvision_data_software_filters_latin1_global_units(): """Test reading raw Brain Vision files""" with warnings.catch_warnings(record=True) as w: # event parsing raw = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_old_path, eog=("VEOGo", "VEOGu", "HEOGli", "HEOGre"), misc=("A2",)) assert_true(all('software filter detected' in str(ww.message) for ww in w)) assert_equal(raw.info['highpass'], 1. / 0.9) assert_equal(raw.info['lowpass'], 50.)
def test_brainvision_data_filters(): """Test reading raw Brain Vision files """ with warnings.catch_warnings(record=True) as w: # event parsing raw = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_highpass_path, montage=montage, eog=eog) assert_true(all('parse triggers that' in str(ww.message) for ww in w)) assert_equal(raw.info['highpass'], 0.1) assert_equal(raw.info['lowpass'], 250.)
def test_io_egi(): """Test importing EGI simple binary files""" # test default with open(egi_txt_fname) as fid: data = np.loadtxt(fid) t = data[0] data = data[1:] data *= 1e-6 # μV with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always') raw = read_raw_egi(egi_fname, include=None) assert_true('RawEGI' in repr(raw)) assert_equal(len(w), 1) assert_true(w[0].category == RuntimeWarning) msg = 'Did not find any event code with more than one event.' assert_true(msg in '%s' % w[0].message) data_read, t_read = raw[:256] assert_allclose(t_read, t) assert_allclose(data_read, data, atol=1e-10) include = ['TRSP', 'XXX1'] with warnings.catch_warnings(record=True): # preload=None raw = _test_raw_reader(read_raw_egi, input_fname=egi_fname, include=include) assert_equal('eeg' in raw, True) eeg_chan = [c for c in raw.ch_names if 'EEG' in c] assert_equal(len(eeg_chan), 256) picks = pick_types(raw.info, eeg=True) assert_equal(len(picks), 256) assert_equal('STI 014' in raw.ch_names, True) events = find_events(raw, stim_channel='STI 014') assert_equal(len(events), 2) # ground truth assert_equal(np.unique(events[:, 1])[0], 0) assert_true(np.unique(events[:, 0])[0] != 0) assert_true(np.unique(events[:, 2])[0] != 0) triggers = np.array([[0, 1, 1, 0], [0, 0, 1, 0]]) # test trigger functionality triggers = np.array([[0, 1, 0, 0], [0, 0, 1, 0]]) events_ids = [12, 24] new_trigger = _combine_triggers(triggers, events_ids) assert_array_equal(np.unique(new_trigger), np.unique([0, 12, 24])) assert_raises(ValueError, read_raw_egi, egi_fname, include=['Foo'], preload=False) assert_raises(ValueError, read_raw_egi, egi_fname, exclude=['Bar'], preload=False) for ii, k in enumerate(include, 1): assert_true(k in raw.event_id) assert_true(raw.event_id[k] == ii)
def test_crop_append(): """Test crop and append raw.""" raw = _test_raw_reader( read_raw_bti, pdf_fname=pdf_fnames[0], config_fname=config_fnames[0], head_shape_fname=hs_fnames[0]) y, t = raw[:] t0, t1 = 0.25 * t[-1], 0.75 * t[-1] mask = (t0 <= t) * (t <= t1) raw_ = raw.copy().crop(t0, t1) y_, _ = raw_[:] assert_true(y_.shape[1] == mask.sum()) assert_true(y_.shape[0] == y.shape[0])
def test_io_egi_pns_mff(): """Test importing EGI MFF with PNS data.""" egi_fname_mff = op.join(data_path(), 'EGI', 'test_egi_pns.mff') raw = read_raw_egi(egi_fname_mff, include=None, preload=True, verbose='error') assert ('RawMff' in repr(raw)) pns_chans = pick_types(raw.info, ecg=True, bio=True, emg=True) assert_equal(len(pns_chans), 7) names = [raw.ch_names[x] for x in pns_chans] pns_names = ['Resp. Temperature'[:15], 'Resp. Pressure', 'ECG', 'Body Position', 'Resp. Effort Chest'[:15], 'Resp. Effort Abdomen'[:15], 'EMG-Leg'] _test_raw_reader(read_raw_egi, input_fname=egi_fname_mff, channel_naming='EEG %03d', verbose='error') assert_equal(names, pns_names) mat_names = [ 'Resp_Temperature'[:15], 'Resp_Pressure', 'ECG', 'Body_Position', 'Resp_Effort_Chest'[:15], 'Resp_Effort_Abdomen'[:15], 'EMGLeg' ] egi_fname_mat = op.join(data_path(), 'EGI', 'test_egi_pns.mat') mc = sio.loadmat(egi_fname_mat) for ch_name, ch_idx, mat_name in zip(pns_names, pns_chans, mat_names): print('Testing {}'.format(ch_name)) mc_key = [x for x in mc.keys() if mat_name in x][0] cal = raw.info['chs'][ch_idx]['cal'] mat_data = mc[mc_key] * cal raw_data = raw[ch_idx][0] assert_array_equal(mat_data, raw_data)
def test_data(): """Test reading raw Artemis123 files.""" _test_raw_reader(read_raw_artemis123, input_fname=short_hpi_1kz_fname, pos_fname=dig_fname, verbose='error') # test a random selected point raw = read_raw_artemis123(short_hpi_1kz_fname, preload=True, add_head_trans=False) meg_picks = pick_types(raw.info, meg=True, eeg=False) # checked against matlab reader. assert_allclose(raw[meg_picks[12]][0][0][123], 1.08239606023e-11) dev_head_t_1 = np.array([[9.713e-01, 2.340e-01, -4.164e-02, 1.302e-04], [-2.371e-01, 9.664e-01, -9.890e-02, 1.977e-03], [1.710e-02, 1.059e-01, 9.942e-01, -8.159e-03], [0.0, 0.0, 0.0, 1.0]]) dev_head_t_2 = np.array([[9.890e-01, 1.475e-01, -8.090e-03, 4.997e-04], [-1.476e-01, 9.846e-01, -9.389e-02, 1.962e-03], [-5.888e-03, 9.406e-02, 9.955e-01, -1.610e-02], [0.0, 0.0, 0.0, 1.0]]) # test with head loc no digitization raw = read_raw_artemis123(short_HPI_dip_fname, add_head_trans=True) _assert_trans(raw.info['dev_head_t']['trans'], dev_head_t_1) assert_equal(raw.info['sfreq'], 5000.0) # test with head loc and digitization with pytest.warns(RuntimeWarning, match='Large difference'): raw = read_raw_artemis123(short_HPI_dip_fname, add_head_trans=True, pos_fname=dig_fname) _assert_trans(raw.info['dev_head_t']['trans'], dev_head_t_1) # test 1kz hpi head loc (different freq) raw = read_raw_artemis123(short_hpi_1kz_fname, add_head_trans=True) _assert_trans(raw.info['dev_head_t']['trans'], dev_head_t_2) assert_equal(raw.info['sfreq'], 1000.0)
def test_brainvision_data(): """Test reading raw Brain Vision files """ assert_raises(IOError, read_raw_brainvision, vmrk_path) assert_raises(ValueError, read_raw_brainvision, vhdr_path, montage, preload=True, scale="foo") with warnings.catch_warnings(record=True) as w: # event parsing raw_py = _test_raw_reader( read_raw_brainvision, vhdr_fname=vhdr_path, montage=montage, eog=eog, misc='auto') assert_true(all('parse triggers that' in str(ww.message) for ww in w)) assert_true('RawBrainVision' in repr(raw_py)) assert_equal(raw_py.info['highpass'], 0.) assert_equal(raw_py.info['lowpass'], 250.) picks = pick_types(raw_py.info, meg=False, eeg=True, exclude='bads') data_py, times_py = raw_py[picks] # compare with a file that was generated using MNE-C raw_bin = Raw(eeg_bin, preload=True) picks = pick_types(raw_py.info, meg=False, eeg=True, exclude='bads') data_bin, times_bin = raw_bin[picks] assert_array_almost_equal(data_py, data_bin) assert_array_almost_equal(times_py, times_bin) # Make sure EOG channels are marked correctly for ch in raw_py.info['chs']: if ch['ch_name'] in eog: assert_equal(ch['kind'], FIFF.FIFFV_EOG_CH) elif ch['ch_name'] == 'STI 014': assert_equal(ch['kind'], FIFF.FIFFV_STIM_CH) elif ch['ch_name'] == 'CP6': assert_equal(ch['kind'], FIFF.FIFFV_MISC_CH) assert_equal(ch['unit'], FIFF.FIFF_UNIT_NONE) elif ch['ch_name'] == 'ReRef': assert_equal(ch['kind'], FIFF.FIFFV_MISC_CH) assert_equal(ch['unit'], FIFF.FIFF_UNIT_CEL) elif ch['ch_name'] in raw_py.info['ch_names']: assert_equal(ch['kind'], FIFF.FIFFV_EEG_CH) assert_equal(ch['unit'], FIFF.FIFF_UNIT_V) else: raise RuntimeError("Unknown Channel: %s" % ch['ch_name']) # test loading v2 read_raw_brainvision(vhdr_v2_path, eog=eog, preload=True, response_trig_shift=1000)
def test_crop_append(): """ Test crop and append raw """ with warnings.catch_warnings(record=True): # preload warning warnings.simplefilter('always') raw = _test_raw_reader( read_raw_bti, pdf_fname=pdf_fnames[0], config_fname=config_fnames[0], head_shape_fname=hs_fnames[0]) y, t = raw[:] t0, t1 = 0.25 * t[-1], 0.75 * t[-1] mask = (t0 <= t) * (t <= t1) raw_ = raw.crop(t0, t1) y_, _ = raw_[:] assert_true(y_.shape[1] == mask.sum()) assert_true(y_.shape[0] == y.shape[0])