@@ -160,23 +160,27 @@ def read_morph_data(filepath):
160
160
return curv
161
161
162
162
163
- def write_morph_data (filename , values ):
164
- '''
165
- '''
166
- with open (filename , 'wb' ) as f :
167
-
168
- # magic number
169
- np .array ([255 ], dtype = '>u1' ).tofile (f )
170
- np .array ([255 ], dtype = '>u1' ).tofile (f )
171
- np .array ([255 ], dtype = '>u1' ).tofile (f )
172
-
173
- # vertices number and two un-used int4
174
- np .array ([len (values )], dtype = '>i4' ).tofile (f )
175
- np .array ([0 ], dtype = '>i4' ).tofile (f )
176
- np .array ([1 ], dtype = '>i4' ).tofile (f )
177
-
178
- # now the data
179
- np .array (values , dtype = '>f4' ).tofile (f )
163
+ def write_morph_data (filepath , values ):
164
+ """Write out a Freesurfer morphometry data file.
165
+
166
+ See:
167
+ http://www.grahamwideman.com/gw/brain/fs/surfacefileformats.htm#CurvNew
168
+
169
+ Parameters
170
+ ----------
171
+ filepath : str
172
+ Path to annotation file to be written
173
+ values : ndarray, shape (n_vertices,)
174
+ Surface morphometry values
175
+ """
176
+ magic_bytes = np .array ([255 , 255 , 255 ], dtype = np .uint8 )
177
+ with open (filepath , 'wb' ) as fobj :
178
+ magic_bytes .tofile (fobj )
179
+
180
+ # vertex count, face count (unused), vals per vertex (only 1 supported)
181
+ np .array ([len (values ), 0 , 1 ], dtype = '>i4' ).tofile (fobj )
182
+
183
+ np .array (values , dtype = '>f4' ).tofile (fobj )
180
184
181
185
182
186
def read_annot (filepath , orig_ids = False ):
0 commit comments