@@ -132,6 +132,38 @@ def read_aseg_stats(seg_stats_file,
132
132
return out_data
133
133
134
134
135
+ def read_aparc_stats (file_path ):
136
+ """Read statistics on cortical features (such as thickness, curvature etc) produced by Freesurfer.
137
+
138
+ file_path would contain whether it is from the right or left hemisphere.
139
+
140
+ """
141
+
142
+ # ColHeaders StructName NumVert SurfArea GrayVol ThickAvg ThickStd MeanCurv GausCurv FoldInd CurvInd
143
+ aparc_roi_dtype = [('StructName' , 'S50' ), ('NumVert' , '<i4' ), ('SurfArea' , '<i4' ), ('GrayVol' , '<i4' ),
144
+ ('ThickAvg' , '<f4' ), ('ThickStd' , '<f4' ), ('MeanCurv' , '<f4' ), ('GausCurv' , '<f4' ),
145
+ ('FoldInd' , '<f4' ), ('CurvInd' , '<f4' )]
146
+ roi_stats = np .genfromtxt (file_path , dtype = aparc_roi_dtype , filling_values = np .NaN )
147
+ subset = ['SurfArea' , 'GrayVol' , 'ThickAvg' , 'ThickStd' , 'MeanCurv' , 'GausCurv' , 'FoldInd' , 'CurvInd' ]
148
+ roi_stats_values = np .full ((len (roi_stats ), len (subset )), np .NaN )
149
+ for idx , stat in enumerate (roi_stats ):
150
+ roi_stats_values [idx ,:] = [ stat [feat ] for feat in subset ]
151
+
152
+ # whole cortex
153
+ # Measure Cortex, NumVert, Number of Vertices, 120233, unitless
154
+ # Measure Cortex, WhiteSurfArea, White Surface Total Area, 85633.5, mm^2
155
+ # Measure Cortex, MeanThickness, Mean Thickness, 2.59632, mm
156
+ wb_regex_pattern = r'# Measure Cortex, ([\w/+_\- ]+), ([\w/+_\- ]+), ([\d\.]+), ([\w/+_\-^]+)'
157
+ wb_aparc_dtype = np .dtype ('U100,U100,f8,U10' )
158
+ # wb_aparc_dtype = [('f0', '<U100'), ('f1', '<U100'), ('f2', '<f8'), ('f3', '<U10')]
159
+ wb_stats = np .fromregex (file_path , wb_regex_pattern , dtype = wb_aparc_dtype )
160
+
161
+ # concatenating while surf total area and global mean thickness
162
+ stats = np .hstack ((roi_stats_values .flatten (), (wb_stats [1 ][2 ], wb_stats [2 ][2 ])))
163
+
164
+ return stats
165
+
166
+
135
167
def _read_volume_info (fobj ):
136
168
"""Helper for reading the footer from a surface file."""
137
169
volume_info = OrderedDict ()
0 commit comments