def test_read_raw_curry(fname, tol, preload, bdf_curry_ref): """Test reading CURRY files.""" with pytest.warns(None) as wrn: raw = read_raw_curry(fname, preload=preload) if not check_version('numpy', '1.16') and preload and fname.endswith('ASCII.dat'): assert len(wrn) > 0 else: assert len(wrn) == 0 assert hasattr(raw, '_data') == preload assert raw.n_times == bdf_curry_ref.n_times assert raw.info['sfreq'] == bdf_curry_ref.info['sfreq'] for field in ['kind', 'ch_name']: assert_array_equal([ch[field] for ch in raw.info['chs']], [ch[field] for ch in bdf_curry_ref.info['chs']]) raw.verbose = 'error' # don't emit warnings about slow reading assert_allclose(raw.get_data(), bdf_curry_ref.get_data(), atol=tol) picks, start, stop = ["C3", "C4"], 200, 800 assert_allclose(raw.get_data(picks=picks, start=start, stop=stop), bdf_curry_ref.get_data(picks=picks, start=start, stop=stop), rtol=tol) assert raw.info['dev_head_t'] is None
def test_meas_date(fname, expected_meas_date): """Test reading acquisition start datetime info info['meas_date'].""" # This for Git issue #8398. The 'info' (.dap) file includes acquisition # start date & time. Test that this goes into raw.info['meas_date']. # If the information is not valid, raw.info['meas_date'] should be None raw = read_raw_curry(fname, preload=False) assert raw.info['meas_date'] == expected_meas_date
def test_read_events_curry_are_same_as_bdf(fname): """Test events from curry annotations recovers the right events.""" EVENT_ID = {str(ii): ii for ii in range(5)} REF_EVENTS = find_events(read_raw_bdf(bdf_file, preload=True)) raw = read_raw_curry(fname) events, _ = events_from_annotations(raw, event_id=EVENT_ID) assert_allclose(events, REF_EVENTS)
def test_read_files_missing_channel(fname, expected_channel_list): """Test reading data files that has an omitted channel.""" # This for Git issue #8391. In some cases, the 'labels' (.rs3 file will # list channels that are not actually saved in the datafile (such as the # 'Ref' channel). These channels are denoted in the 'info' (.dap) file # in the CHAN_IN_FILE section with a '0' as their index. # If the CHAN_IN_FILE section is present, the code also assures that the # channels are sorted in the prescribed order. # This test makes sure the data load correctly, and that we end up with # the proper channel list. raw = read_raw_curry(fname, preload=True) assert raw.ch_names == expected_channel_list
def test_read_raw_curry_rfDC(fname, tol): """Test reading CURRY files.""" # check data bti_rfDC = read_raw_bti(pdf_fname=bti_rfDC_file, head_shape_fname=None) raw = read_raw_curry(fname) # test on the eeg chans, since these were not renamed by curry eeg_names = [ch["ch_name"] for ch in raw.info["chs"] if ch["kind"] == FIFF.FIFFV_EEG_CH] assert_allclose(raw.get_data(eeg_names), bti_rfDC.get_data(eeg_names), rtol=tol)
def test_read_raw_curry(fname, tol, preload, bdf_curry_ref): """Test reading CURRY files.""" raw = read_raw_curry(fname, preload=preload) if preload: isinstance(getattr(raw, '_data'), np.ndarray) else: with pytest.raises(AttributeError, match="no attribute '_data'"): getattr(raw, '_data') assert raw.n_times == bdf_curry_ref.n_times assert raw.info['sfreq'] == bdf_curry_ref.info['sfreq'] for field in ['kind', 'ch_name']: assert_array_equal([ch[field] for ch in raw.info['chs']], [ch[field] for ch in bdf_curry_ref.info['chs']]) assert_allclose(raw.get_data(), bdf_curry_ref.get_data(), atol=tol) picks, start, stop = ["C3", "C4"], 200, 800 assert_allclose(raw.get_data(picks=picks, start=start, stop=stop), bdf_curry_ref.get_data(picks=picks, start=start, stop=stop), rtol=tol)
def test_sfreq(sfreq_testing_data): """Test sfreq and time_step.""" raw = read_raw_curry(sfreq_testing_data, preload=False) assert raw.info['sfreq'] == 500
def test_read_raw_curry_rfDC(fname, tol, mock_dev_head_t, tmpdir): """Test reading CURRY files.""" if mock_dev_head_t: if 'Curry 7' in fname: # not supported yet return # copy files to tmpdir base = op.splitext(fname)[0] for ext in ('.cdt', '.cdt.dpa'): src = base + ext dst = op.join(tmpdir, op.basename(base) + ext) copyfile(src, dst) if ext == '.cdt.dpa': with open(dst, 'a') as fid: fid.write(LM_CONTENT) fname = op.join(tmpdir, op.basename(fname)) with open(fname + '.hpi', 'w') as fid: fid.write(HPI_CONTENT) # check data bti_rfDC = read_raw_bti(pdf_fname=bti_rfDC_file, head_shape_fname=None) with catch_logging() as log: raw = read_raw_curry(fname, verbose=True) log = log.getvalue() if mock_dev_head_t: assert 'Composing device' in log else: assert 'Leaving device' in log assert 'no landmark' in log # test on the eeg chans, since these were not renamed by curry eeg_names = [ ch["ch_name"] for ch in raw.info["chs"] if ch["kind"] == FIFF.FIFFV_EEG_CH ] assert_allclose(raw.get_data(eeg_names), bti_rfDC.get_data(eeg_names), rtol=tol) assert bti_rfDC.info['dev_head_t'] is not None # XXX probably a BTI bug if mock_dev_head_t: assert raw.info['dev_head_t'] is not None assert_allclose(raw.info['dev_head_t']['trans'], WANT_TRANS, atol=1e-5) else: assert raw.info['dev_head_t'] is None # check that most MEG sensors are approximately oriented outward from # the device origin n_meg = n_eeg = n_other = 0 pos = list() nn = list() for ch in raw.info['chs']: if ch['kind'] == FIFF.FIFFV_MEG_CH: assert ch['coil_type'] == FIFF.FIFFV_COIL_CTF_GRAD t = _loc_to_coil_trans(ch['loc']) pos.append(t[:3, 3]) nn.append(t[:3, 2]) assert_allclose(np.linalg.norm(nn[-1]), 1.) n_meg += 1 elif ch['kind'] == FIFF.FIFFV_EEG_CH: assert ch['coil_type'] == FIFF.FIFFV_COIL_EEG n_eeg += 1 else: assert ch['coil_type'] == FIFF.FIFFV_COIL_NONE n_other += 1 assert n_meg == 148 assert n_eeg == 31 assert n_other == 15 pos = np.array(pos) nn = np.array(nn) rad, origin = _fit_sphere(pos, disp=False) assert 0.11 < rad < 0.13 pos -= origin pos /= np.linalg.norm(pos, axis=1, keepdims=True) angles = np.abs(np.rad2deg(np.arccos((pos * nn).sum(-1)))) assert (angles < 20).sum() > 100