1
2
3
4
5
6
7
8
9 """Unit tests for PyMVPA atlases"""
10
11 import unittest, re
12 import numpy as N
13
14 from mvpa.base import externals, warning
15
16 if externals.exists('nifti', raiseException=True):
17 from mvpa.atlases import *
18 else:
19 raise RuntimeError, "Don't run me if no nifti is present"
20
21 import os
22 from mvpa import pymvpa_dataroot
23
25 """Basic tests for support of atlases such as the ones
26 shipped with FSL
27 """
31
33 """Basic testing of atlases"""
34
35 tested = 0
36 for name in KNOWN_ATLASES.keys():
37
38 try:
39 atlas = Atlas(name=name)
40 tested += 1
41 except IOError:
42
43 continue
44
45
46
47
48 coord = (-63, -12, 22)
49
50
51
52 self.failUnless(len(atlas.levels_dict[0].labels) > 0)
53
54 for res in [ atlas[coord],
55 atlas.labelPoint(coord) ]:
56 self.failUnless(res.get('coord_queried', None) == coord,
57 '%s: Comparison failed. Got %s and %s'
58 % (name, res.get('coord_queried', None), coord))
59 self.failUnless('labels' in res)
60
61 self.failUnless('voxel_queried' in res)
62
63
64
65
66 res0 = atlas[coord, range(atlas.Nlevels)]
67 self.failUnless(res0 == res)
68
69
70
71
72
73
74 if not tested:
75 warning("No atlases were found -- thus no testing was done")
76
78 if not externals.exists('atlas_fsl'): return
79 tshape = (182, 218, 182)
80 atl = Atlas(name='HarvardOxford-Cortical')
81 atl.levels_dict[0].find('Frontal Pole')
82 self.failUnlessEqual(
83 len(atl.find(re.compile('Fusiform'), unique=False)),
84 4)
85
86 m = atl.getMap(1)
87 self.failUnlessEqual(m.shape, tshape)
88 self.failUnless(N.max(m)==100)
89 self.failUnless(N.min(m)==0)
90
91 ms = atl.getMaps('Fusiform')
92 self.failUnlessEqual(len(ms), 4)
93 self.failUnlessEqual(ms[0].shape, tshape)
94
95 ms = atl.getMaps('ZaZaZa')
96 self.failUnless(not len(ms))
97
98 self.failUnlessRaises(ValueError, atl.getMap, 'Fusiform')
99 self.failUnless(len(atl.find('Fusiform', unique=False)) == 4)
100 self.failUnlessEqual(atl.getMap('Fusiform', strategy='max').shape,
101 tshape)
102
103
104
105 atl2 = Atlas(name='HarvardOxford-Cortical',
106 image_file=atl._image_file)
107
108
109 self.failUnless((atl.getMap('Frontal Pole') ==
110 atl2.getMap('Frontal Pole')).all())
111
112
113
114 atl2 = Atlas(name='HarvardOxford-Cortical',
115 image_file=os.path.join(pymvpa_dataroot,
116 'example4d.nii.gz'))
117
118
119 self.failUnless(atl.getMap('Frontal Pole').shape
120 != atl2.getMap('Frontal Pole').shape)
121
122
125
126
127 if __name__ == '__main__':
128 import runner
129