def test_read_write_info(): """Test IO of info """ tempdir = _TempDir() info = read_info(raw_fname) temp_file = op.join(tempdir, 'info.fif') # check for bug `#1198` info['dev_head_t']['trans'] = np.eye(4) t1 = info['dev_head_t']['trans'] write_info(temp_file, info) info2 = read_info(temp_file) t2 = info2['dev_head_t']['trans'] assert_true(len(info['chs']) == len(info2['chs'])) assert_array_equal(t1, t2) # proc_history (e.g., GH#1875) creator = u'é' info = read_info(chpi_fname) info['proc_history'][0]['creator'] = creator info['hpi_meas'][0]['creator'] = creator info['subject_info']['his_id'] = creator write_info(temp_file, info) info = read_info(temp_file) assert_equal(info['proc_history'][0]['creator'], creator) assert_equal(info['hpi_meas'][0]['creator'], creator) assert_equal(info['subject_info']['his_id'], creator)
def test_read_write_info(): """Test IO of info.""" tempdir = _TempDir() info = read_info(raw_fname) temp_file = op.join(tempdir, 'info.fif') # check for bug `#1198` info['dev_head_t']['trans'] = np.eye(4) t1 = info['dev_head_t']['trans'] write_info(temp_file, info) info2 = read_info(temp_file) t2 = info2['dev_head_t']['trans'] assert_true(len(info['chs']) == len(info2['chs'])) assert_array_equal(t1, t2) # proc_history (e.g., GH#1875) creator = u'é' info = read_info(chpi_fname) info['proc_history'][0]['creator'] = creator info['hpi_meas'][0]['creator'] = creator info['subject_info']['his_id'] = creator if info['gantry_angle'] is None: # future testing data may include it info['gantry_angle'] = 0. # Elekta supine position gantry_angle = info['gantry_angle'] write_info(temp_file, info) info = read_info(temp_file) assert_equal(info['proc_history'][0]['creator'], creator) assert_equal(info['hpi_meas'][0]['creator'], creator) assert_equal(info['subject_info']['his_id'], creator) assert_equal(info['gantry_angle'], gantry_angle)
def test_csr_csc(tmpdir): """Test CSR and CSC.""" info = read_info(sss_ctc_fname) info = pick_info(info, pick_types(info, meg=True, exclude=[])) sss_ctc = info['proc_history'][0]['max_info']['sss_ctc'] ct = sss_ctc['decoupler'].copy() # CSC assert isinstance(ct, sparse.csc_matrix) fname = tmpdir.join('test.fif') write_info(fname, info) info_read = read_info(fname) ct_read = info_read['proc_history'][0]['max_info']['sss_ctc']['decoupler'] assert isinstance(ct_read, sparse.csc_matrix) assert_array_equal(ct_read.toarray(), ct.toarray()) # Now CSR csr = ct.tocsr() assert isinstance(csr, sparse.csr_matrix) assert_array_equal(csr.toarray(), ct.toarray()) info['proc_history'][0]['max_info']['sss_ctc']['decoupler'] = csr fname = tmpdir.join('test1.fif') write_info(fname, info) info_read = read_info(fname) ct_read = info_read['proc_history'][0]['max_info']['sss_ctc']['decoupler'] assert isinstance(ct_read, sparse.csc_matrix) # this gets cast to CSC assert_array_equal(ct_read.toarray(), ct.toarray())
def test_csr_csc(): """Test CSR and CSC.""" info = read_info(sss_ctc_fname) info = pick_info(info, pick_types(info, meg=True, exclude=[])) sss_ctc = info['proc_history'][0]['max_info']['sss_ctc'] ct = sss_ctc['decoupler'].copy() # CSC assert isinstance(ct, sparse.csc_matrix) tempdir = _TempDir() fname = op.join(tempdir, 'test.fif') write_info(fname, info) info_read = read_info(fname) ct_read = info_read['proc_history'][0]['max_info']['sss_ctc']['decoupler'] assert isinstance(ct_read, sparse.csc_matrix) assert_array_equal(ct_read.toarray(), ct.toarray()) # Now CSR csr = ct.tocsr() assert isinstance(csr, sparse.csr_matrix) assert_array_equal(csr.toarray(), ct.toarray()) info['proc_history'][0]['max_info']['sss_ctc']['decoupler'] = csr fname = op.join(tempdir, 'test1.fif') write_info(fname, info) info_read = read_info(fname) ct_read = info_read['proc_history'][0]['max_info']['sss_ctc']['decoupler'] assert isinstance(ct_read, sparse.csc_matrix) # this gets cast to CSC assert_array_equal(ct_read.toarray(), ct.toarray())
def test_io_coord_frame(tmp_path): """Test round trip for coordinate frame.""" fname = tmp_path / 'test.fif' for ch_type in ('eeg', 'seeg', 'ecog', 'dbs', 'hbo', 'hbr'): info = create_info( ch_names=['Test Ch'], sfreq=1000., ch_types=[ch_type]) info['chs'][0]['loc'][:3] = [0.05, 0.01, -0.03] write_info(fname, info) info2 = read_info(fname) assert info2['chs'][0]['coord_frame'] == FIFF.FIFFV_COORD_HEAD
def test_read_write_info(): """Test IO of info """ info = io.read_info(raw_fname) temp_file = op.join(tempdir, 'info.fif') # check for bug `#1198` info['dev_head_t']['trans'] = np.eye(4) t1 = info['dev_head_t']['trans'] io.write_info(temp_file, info) info2 = io.read_info(temp_file) t2 = info2['dev_head_t']['trans'] assert_true(len(info['chs']) == len(info2['chs'])) assert_array_equal(t1, t2)
def test_field_round_trip(tmpdir): """Test round-trip for new fields.""" info = create_info(1, 1000., 'eeg') for key in ('file_id', 'meas_id'): info[key] = _generate_meas_id() info['device_info'] = dict( type='a', model='b', serial='c', site='d') info['helium_info'] = dict( he_level_raw=1., helium_level=2., orig_file_guid='e', meas_date=(1, 2)) fname = tmpdir.join('temp-info.fif') write_info(fname, info) info_read = read_info(fname) info_read['dig'] = None # XXX eventually this should go away assert_object_equal(info, info_read)
def test_field_round_trip(tmp_path): """Test round-trip for new fields.""" info = create_info(1, 1000., 'eeg') with info._unlock(): for key in ('file_id', 'meas_id'): info[key] = _generate_meas_id() info['device_info'] = dict(type='a', model='b', serial='c', site='d') info['helium_info'] = dict(he_level_raw=1., helium_level=2., orig_file_guid='e', meas_date=(1, 2)) fname = tmp_path / 'temp-info.fif' write_info(fname, info) info_read = read_info(fname) assert_object_equal(info, info_read)
def test_read_write_info(): """Test IO of info.""" tempdir = _TempDir() info = read_info(raw_fname) temp_file = op.join(tempdir, "info.fif") # check for bug `#1198` info["dev_head_t"]["trans"] = np.eye(4) t1 = info["dev_head_t"]["trans"] write_info(temp_file, info) info2 = read_info(temp_file) t2 = info2["dev_head_t"]["trans"] assert_true(len(info["chs"]) == len(info2["chs"])) assert_array_equal(t1, t2) # proc_history (e.g., GH#1875) creator = u"é" info = read_info(chpi_fname) info["proc_history"][0]["creator"] = creator info["hpi_meas"][0]["creator"] = creator info["subject_info"]["his_id"] = creator write_info(temp_file, info) info = read_info(temp_file) assert_equal(info["proc_history"][0]["creator"], creator) assert_equal(info["hpi_meas"][0]["creator"], creator) assert_equal(info["subject_info"]["his_id"], creator)
def test_read_write_info(): """Test IO of info.""" tempdir = _TempDir() info = read_info(raw_fname) temp_file = op.join(tempdir, 'info.fif') # check for bug `#1198` info['dev_head_t']['trans'] = np.eye(4) t1 = info['dev_head_t']['trans'] write_info(temp_file, info) info2 = read_info(temp_file) t2 = info2['dev_head_t']['trans'] assert (len(info['chs']) == len(info2['chs'])) assert_array_equal(t1, t2) # proc_history (e.g., GH#1875) creator = u'é' info = read_info(chpi_fname) info['proc_history'][0]['creator'] = creator info['hpi_meas'][0]['creator'] = creator info['subject_info']['his_id'] = creator info['subject_info']['weight'] = 11.1 info['subject_info']['height'] = 2.3 if info['gantry_angle'] is None: # future testing data may include it info['gantry_angle'] = 0. # Elekta supine position gantry_angle = info['gantry_angle'] meas_id = info['meas_id'] write_info(temp_file, info) info = read_info(temp_file) assert info['proc_history'][0]['creator'] == creator assert info['hpi_meas'][0]['creator'] == creator assert info['subject_info']['his_id'] == creator assert info['gantry_angle'] == gantry_angle assert info['subject_info']['height'] == 2.3 assert info['subject_info']['weight'] == 11.1 for key in ['secs', 'usecs', 'version']: assert info['meas_id'][key] == meas_id[key] assert_array_equal(info['meas_id']['machid'], meas_id['machid']) # Test that writing twice produces the same file m1 = hashlib.md5() with open(temp_file, 'rb') as fid: m1.update(fid.read()) m1 = m1.hexdigest() temp_file_2 = op.join(tempdir, 'info2.fif') assert temp_file_2 != temp_file write_info(temp_file_2, info) m2 = hashlib.md5() with open(temp_file_2, 'rb') as fid: m2.update(fid.read()) m2 = m2.hexdigest() assert m1 == m2
def test_read_write_info(tmpdir): """Test IO of info.""" info = read_info(raw_fname) temp_file = str(tmpdir.join('info.fif')) # check for bug `#1198` info['dev_head_t']['trans'] = np.eye(4) t1 = info['dev_head_t']['trans'] write_info(temp_file, info) info2 = read_info(temp_file) t2 = info2['dev_head_t']['trans'] assert (len(info['chs']) == len(info2['chs'])) assert_array_equal(t1, t2) # proc_history (e.g., GH#1875) creator = u'é' info = read_info(chpi_fname) info['proc_history'][0]['creator'] = creator info['hpi_meas'][0]['creator'] = creator info['subject_info']['his_id'] = creator info['subject_info']['weight'] = 11.1 info['subject_info']['height'] = 2.3 if info['gantry_angle'] is None: # future testing data may include it info['gantry_angle'] = 0. # Elekta supine position gantry_angle = info['gantry_angle'] meas_id = info['meas_id'] write_info(temp_file, info) info = read_info(temp_file) assert info['proc_history'][0]['creator'] == creator assert info['hpi_meas'][0]['creator'] == creator assert info['subject_info']['his_id'] == creator assert info['gantry_angle'] == gantry_angle assert info['subject_info']['height'] == 2.3 assert info['subject_info']['weight'] == 11.1 for key in ['secs', 'usecs', 'version']: assert info['meas_id'][key] == meas_id[key] assert_array_equal(info['meas_id']['machid'], meas_id['machid']) # Test that writing twice produces the same file m1 = hashlib.md5() with open(temp_file, 'rb') as fid: m1.update(fid.read()) m1 = m1.hexdigest() temp_file_2 = tmpdir.join('info2.fif') assert temp_file_2 != temp_file write_info(temp_file_2, info) m2 = hashlib.md5() with open(str(temp_file_2), 'rb') as fid: m2.update(fid.read()) m2 = m2.hexdigest() assert m1 == m2 info = read_info(raw_fname) info['meas_date'] = None anonymize_info(info, verbose='error') assert info['meas_date'] is None tmp_fname_3 = tmpdir.join('info3.fif') write_info(tmp_fname_3, info) assert info['meas_date'] is None info2 = read_info(tmp_fname_3) assert info2['meas_date'] is None # Check that having a very old date in fine until you try to save it to fif info['meas_date'] = datetime(1800, 1, 1, 0, 0, 0, tzinfo=timezone.utc) info._check_consistency() fname = tmpdir.join('test.fif') with pytest.raises(RuntimeError, match='must be between '): write_info(fname, info)