@@ -160,27 +160,46 @@ def read_morph_data(filepath):
160
160
return curv
161
161
162
162
163
- def write_morph_data (filepath , values ):
164
- """Write out a Freesurfer morphometry data file.
163
+ def write_morph_data (filepath , values , fnum = 0 ):
164
+ """Write Freesurfer morphometry data `values` to file `filepath`
165
165
166
- See:
166
+ Equivalent to FreeSurfer's `write_curv.m`_
167
+
168
+ See also:
167
169
http://www.grahamwideman.com/gw/brain/fs/surfacefileformats.htm#CurvNew
168
170
171
+ .. _write_curv.m: \
172
+ https://github.com/neurodebian/freesurfer/blob/debian-sloppy/matlab/write_curv.m
173
+
169
174
Parameters
170
175
----------
171
176
filepath : str
172
177
Path to annotation file to be written
173
- values : ndarray, shape (n_vertices,)
178
+ values : array-like
174
179
Surface morphometry values
180
+ fnum : int, optional
181
+ Number of faces in the associated surface
175
182
"""
176
183
magic_bytes = np .array ([255 , 255 , 255 ], dtype = np .uint8 )
184
+
185
+ i4info = np .iinfo ('i4' )
186
+ if len (values ) > i4info .max :
187
+ raise ValueError ("Too many values for morphometry file" )
188
+ if not i4info .min <= fnum <= i4info .max :
189
+ raise ValueError ("Argument fnum must be between {0} and {1}" .format (
190
+ i4info .min , i4info .max ))
191
+
192
+ array = np .asarray (values ).astype ('>f4' )
193
+ if len (array .shape ) > 1 :
194
+ raise ValueError ("Multi-dimensional values not supported" )
195
+
177
196
with open (filepath , 'wb' ) as fobj :
178
197
magic_bytes .tofile (fobj )
179
198
180
199
# vertex count, face count (unused), vals per vertex (only 1 supported)
181
- np .array ([len (values ), 0 , 1 ], dtype = '>i4' ).tofile (fobj )
200
+ np .array ([len (values ), fnum , 1 ], dtype = '>i4' ).tofile (fobj )
182
201
183
- np . array ( values , dtype = '>f4' ) .tofile (fobj )
202
+ array .tofile (fobj )
184
203
185
204
186
205
def read_annot (filepath , orig_ids = False ):
0 commit comments