66
77
88from .. externals .six .moves import xrange
9+ from ..openers import Opener
910
1011
1112def _fread3 (fobj ):
@@ -160,8 +161,8 @@ def read_morph_data(filepath):
160161 return curv
161162
162163
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 `
165166
166167 Equivalent to FreeSurfer's `write_curv.m`_
167168
@@ -173,8 +174,9 @@ def write_morph_data(filepath, values, fnum=0):
173174
174175 Parameters
175176 ----------
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)
178180 values : array-like
179181 Surface morphometry values
180182 fnum : int, optional
@@ -193,13 +195,13 @@ def write_morph_data(filepath, values, fnum=0):
193195 if len (array .shape ) > 1 :
194196 raise ValueError ("Multi-dimensional values not supported" )
195197
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 )
198200
199201 # 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' ))
201203
202- array . tofile ( fobj )
204+ fobj . write ( array )
203205
204206
205207def read_annot (filepath , orig_ids = False ):
0 commit comments