6
6
7
7
8
8
from .. externals .six .moves import xrange
9
+ from ..openers import Opener
9
10
10
11
11
12
def _fread3 (fobj ):
@@ -160,8 +161,8 @@ def read_morph_data(filepath):
160
161
return curv
161
162
162
163
163
- def write_morph_data (filepath , values , fnum = 0 ):
164
- """Write Freesurfer morphometry data `values` to file `filepath `
164
+ def write_morph_data (file_like , values , fnum = 0 ):
165
+ """Write Freesurfer morphometry data `values` to file-like `file_like `
165
166
166
167
Equivalent to FreeSurfer's `write_curv.m`_
167
168
@@ -173,8 +174,9 @@ def write_morph_data(filepath, values, fnum=0):
173
174
174
175
Parameters
175
176
----------
176
- filepath : str
177
- Path to annotation file to be written
177
+ file_like : file-like
178
+ String containing path of file to be written, or file-like object, open
179
+ in binary write (`'wb'` mode, implementing the `write` method)
178
180
values : array-like
179
181
Surface morphometry values
180
182
fnum : int, optional
@@ -193,13 +195,13 @@ def write_morph_data(filepath, values, fnum=0):
193
195
if len (array .shape ) > 1 :
194
196
raise ValueError ("Multi-dimensional values not supported" )
195
197
196
- with open ( filepath , 'wb' ) as fobj :
197
- magic_bytes . tofile ( fobj )
198
+ with Opener ( file_like , 'wb' ) as fobj :
199
+ fobj . write ( magic_bytes )
198
200
199
201
# vertex count, face count (unused), vals per vertex (only 1 supported)
200
- np .array ([len (values ), fnum , 1 ], dtype = '>i4' ). tofile ( fobj )
202
+ fobj . write ( np .array ([len (values ), fnum , 1 ], dtype = '>i4' ))
201
203
202
- array . tofile ( fobj )
204
+ fobj . write ( array )
203
205
204
206
205
207
def read_annot (filepath , orig_ids = False ):
0 commit comments