def test_pdb_from_fg(): """ Test writing a fiber-group to file """ coords1 = np.arange(900).reshape(3,300) coords2 = np.arange(900).reshape(3,300) + 100 fiber_stats = dict(foo=1,bar=2) node_stats = dict(ecc=np.arange(300)) fg = mtf.FiberGroup([mtf.Fiber(coords1, fiber_stats=fiber_stats, node_stats=node_stats), mtf.Fiber(coords2, fiber_stats=fiber_stats, node_stats=node_stats)]) temp_dir = tempfile.gettempdir() mio.pdb_from_fg(fg, os.path.join(temp_dir,'fg.pdb')) # Test that the properties are preserved upon reloading: fg2 = mio.fg_from_pdb(os.path.join(temp_dir,'fg.pdb')) npt.assert_equal(fg2[0].coords, fg[0].coords) npt.assert_equal(fg2[1].coords, fg[1].coords) npt.assert_equal(fg2[0].node_stats, fg[0].node_stats) npt.assert_equal(fg2[1].node_stats, fg[1].node_stats) npt.assert_equal(fg2.fiber_stats, fg.fiber_stats)
def test_fg_from_pdb(): """ Test initialization of the FiberGroup from pdb file Benchmark was generated using vistasoft in Matlab as follows: >> fg = mtrImportFibers('FG_w_stats.pdb') """ pdb_files = ['FG_w_stats.pdb', 'pdb_version2.pdb'] mat_files = ['fg_from_matlab.mat', 'pdb_version2.mat'] for ii in range(len(pdb_files)): file_name = data_path + pdb_files[ii] fg = mio.fg_from_pdb(file_name) # Get the same fiber group as saved in matlab: mat_fg = sio.loadmat(data_path + mat_files[ii], squeeze_me=True)["fg"] k = [d[0] for d in mat_fg.dtype.descr] v = mat_fg.item() mat_fg_dict = dict(zip(k,v)) npt.assert_equal(fg.name, mat_fg_dict["name"]) npt.assert_equal(fg.fibers[0].coords, mat_fg_dict["fibers"][0]) if ii==0: npt.assert_equal(fg.fibers[0].node_stats["eccentricity"], mat_fg_dict["params"][0].item()[-1][0]) mio.pdb_from_fg(fg, data_path + 'fg_new.pdb')
def test_pdb_from_fg(): """ Test writing a fiber-group to file """ coords1 = np.arange(900).reshape(3, 300) coords2 = np.arange(900).reshape(3, 300) + 100 fiber_stats = dict(foo=1, bar=2) node_stats = dict(ecc=np.arange(300)) fg = mtf.FiberGroup([ mtf.Fiber(coords1, fiber_stats=fiber_stats, node_stats=node_stats), mtf.Fiber(coords2, fiber_stats=fiber_stats, node_stats=node_stats) ]) temp_dir = tempfile.gettempdir() mio.pdb_from_fg(fg, os.path.join(temp_dir, 'fg.pdb')) # Test that the properties are preserved upon reloading: fg2 = mio.fg_from_pdb(os.path.join(temp_dir, 'fg.pdb')) npt.assert_equal(fg2[0].coords, fg[0].coords) npt.assert_equal(fg2[1].coords, fg[1].coords) npt.assert_equal(fg2[0].node_stats, fg[0].node_stats) npt.assert_equal(fg2[1].node_stats, fg[1].node_stats) npt.assert_equal(fg2.fiber_stats, fg.fiber_stats)
def test_fg_from_pdb(): """ Test initialization of the FiberGroup from pdb file Benchmark was generated using vistasoft in Matlab as follows: >> fg = mtrImportFibers('FG_w_stats.pdb') """ pdb_files = ['FG_w_stats.pdb', 'pdb_version2.pdb'] mat_files = ['fg_from_matlab.mat', 'pdb_version2.mat'] for ii in range(len(pdb_files)): file_name = data_path + pdb_files[ii] fg = mio.fg_from_pdb(file_name) # Get the same fiber group as saved in matlab: mat_fg = sio.loadmat(data_path + mat_files[ii], squeeze_me=True)["fg"] k = [d[0] for d in mat_fg.dtype.descr] v = mat_fg.item() mat_fg_dict = dict(zip(k, v)) npt.assert_equal(fg.name, mat_fg_dict["name"]) npt.assert_equal(fg.fibers[0].coords, mat_fg_dict["fibers"][0]) if ii == 0: npt.assert_equal(fg.fibers[0].node_stats["eccentricity"], mat_fg_dict["params"][0].item()[-1][0]) mio.pdb_from_fg(fg, data_path + 'fg_new.pdb')
def test_fg2volume(): data_path = os.path.split(oz.__file__)[0] + '/data/' pdb_file = data_path + 'FG_w_stats.pdb' nii_file = data_path + 'fp20110912_ecc.nii.gz' fg = ozv.nii2fg(oio.fg_from_pdb(pdb_file), nii_file) # Smoke testing this: vol = ozv.fg2volume(fg, 'fp20110912_ecc.nii.gz', shape=ni.load(nii_file).get_shape())
def test_nii2fg(): """ Testing the addition of information from a nifti volume to fiber groups nii2fg """ data_path = os.path.split(oz.__file__)[0] + '/data/' pdb_file = data_path + 'FG_w_stats.pdb' nii_file = data_path + 'fp20110912_ecc.nii.gz' # Smoke testing this: fg = ozv.nii2fg(oio.fg_from_pdb(pdb_file), nii_file)
def test_FiberModel(): """ Test the initialization of FiberModel class instances """ ad = 1.5 rd = 0.5 FG = mio.fg_from_pdb(data_path + "FG_w_stats.pdb", verbose=False) M = FiberModel(data_path + "dwi.nii.gz", data_path + "dwi.bvecs", data_path + "dwi.bvals", FG, ad, rd) npt.assert_equal(M.matrix[0].shape[0], np.prod(M.voxel_signal.shape)) npt.assert_equal(M.matrix[0].shape[-1], len(FG.fibers)) npt.assert_equal(M.matrix[1].shape[0], np.prod(M.voxel_signal.shape)) npt.assert_equal(M.matrix[1].shape[-1], len(M.fg_idx_unique.T))
def test_FiberModel(): """ Test the initialization of FiberModel class instances """ ad = 1.5 rd = 0.5 FG = mio.fg_from_pdb(data_path + 'FG_w_stats.pdb', verbose=False) M = FiberModel(data_path + 'dwi.nii.gz', data_path + 'dwi.bvecs', data_path + 'dwi.bvals', FG, ad, rd) npt.assert_equal(M.matrix[0].shape[0], np.prod(M.voxel_signal.shape)) npt.assert_equal(M.matrix[0].shape[-1], len(FG.fibers)) npt.assert_equal(M.matrix[1].shape[0], np.prod(M.voxel_signal.shape)) npt.assert_equal(M.matrix[1].shape[-1], len(M.fg_idx_unique.T))