本文整理汇总了Python中neurosynth.base.dataset.Dataset.get_ids_by_mask方法的典型用法代码示例。如果您正苦于以下问题:Python Dataset.get_ids_by_mask方法的具体用法?Python Dataset.get_ids_by_mask怎么用?Python Dataset.get_ids_by_mask使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类neurosynth.base.dataset.Dataset
的用法示例。
在下文中一共展示了Dataset.get_ids_by_mask方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestBase
# 需要导入模块: from neurosynth.base.dataset import Dataset [as 别名]
# 或者: from neurosynth.base.dataset.Dataset import get_ids_by_mask [as 别名]
class TestBase(unittest.TestCase):
def setUp(self):
""" Create a new Dataset and add features. """
self.dataset = Dataset('data/test_dataset.txt')
self.dataset.add_features('data/test_features.txt')
def test_dataset_initializes(self):
""" Test whether dataset initializes properly. """
self.assertIsNotNone(self.dataset.volume)
self.assertIsNotNone(self.dataset.image_table)
self.assertEqual(len(self.dataset.mappables), 5)
self.assertIsNotNone(self.dataset.volume)
self.assertIsNotNone(self.dataset.r)
def test_image_table_loads(self):
""" Test ImageTable initialization. """
self.assertIsNotNone(self.dataset.image_table)
it = self.dataset.image_table
self.assertEqual(len(it.ids), 5)
self.assertIsNotNone(it.volume)
self.assertIsNotNone(it.r)
self.assertEqual(it.data.shape, (228453, 5))
# Add tests for values in table
def test_feature_table_loads(self):
""" Test FeatureTable initialization. """
tt = self.dataset.feature_table
self.assertIsNotNone(tt)
self.assertEqual(len(self.dataset.list_features()), 5)
self.assertEqual(tt.data.shape, (5,5))
self.assertEqual(tt.feature_names[3], 'f4')
self.assertEqual(tt.data[0,0], 0.0003)
def test_feature_search(self):
""" Test feature-based Mappable search. Tests both the FeatureTable method
and the Dataset wrapper. """
tt = self.dataset.feature_table
features = tt.search_features(['f*'])
self.assertEqual(len(features), 4)
d = self.dataset
ids = d.get_ids_by_features(['f*'], threshold=0.001)
self.assertEqual(len(ids), 4)
img_data = d.get_ids_by_features(['f1', 'f3', 'g1'], 0.001, func='max', get_image_data=True)
self.assertEqual(img_data.shape, (228453, 5))
def test_selection_by_mask(self):
""" Test mask-based Mappable selection.
Only one peak in the test dataset (in study5) should be within the sgACC. """
ids = self.dataset.get_ids_by_mask('data/sgacc_mask.nii.gz')
self.assertEquals(len(ids), 1)
self.assertEquals('study5', ids[0])
def test_selection_by_peaks(self):
""" Test peak-based Mappable selection. """
ids = self.dataset.get_ids_by_peaks(np.array([[3, 30, -9]]))
self.assertEquals(len(ids), 1)
self.assertEquals('study5', ids[0])
# def test_invalid_coordinates_ignored(self):
""" Test dataset contains 3 valid coordinates and one outside mask. But this won't work
示例2: cluster2masks
# 需要导入模块: from neurosynth.base.dataset import Dataset [as 别名]
# 或者: from neurosynth.base.dataset.Dataset import get_ids_by_mask [as 别名]
xfm2vol.inputs.identity = 'fsaverage4'
xfm2vol.inputs.hemi = 'lh'
xfm2vol.inputs.transformed_file = volume_file
xfm2vol.inputs.template_file = template
xfm2vol.run()
#make masks to input into neurosynth
def cluster2masks(clusterfile):
clustermap = nb.load(clusterfile).get_data()
for x in range(1,clustermap.max()+1):
clustermask = (clustermap==x).astype(int)
nImg = nb.Nifti1Image(clustermask, None)
nb.save(nImg, os.path.abspath(clusterfile+'_clustermask'+str(x)+'.nii'))
cluster2masks(volume_file)
dataset_file = '/home/raid3/watanabe/neurosynth/data/dataset.pkl'
if not os.path.exists(dataset_file):
dataset = Dataset('/home/raid3/watanabe/neurosynth/data/database.txt')
dataset.add_features('/home/raid3/watanabe/neurosynth/data/features.txt')
dataset.save(dataset_file)
else:
dataset = cPickle.load(open(dataset_file,'rb'))
clustermask = volume_file+'_clustermask'+str(3)+'.nii'
ids = dataset.get_ids_by_mask(clustermask)
features = dataset.feature_table.get_features_by_ids(ids)
#mri_surf2vol --identity fsaverage4 --surfval /scr/ilz1/Data/attemptsurface.nii --hemi 'lh' --o /scr/ilz1/Data/results/surf2volume.nii --template /scr/ilz1/Data/freesurfer/fsaverage4/mri/orig.mgz