Skip to content

Commit 1c4591b

Browse files
author
Ben Cipollini
committed
Add a write_morph_data function.
1 parent 03b60d9 commit 1c4591b

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

nibabel/freesurfer/io.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,25 @@ def read_morph_data(filepath):
160160
return curv
161161

162162

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)
180+
181+
163182
def read_annot(filepath, orig_ids=False):
164183
"""Read in a Freesurfer annotation from a .annot file.
165184

0 commit comments

Comments
 (0)