Skip to content

Commit 62d1e52

Browse files
Ben Cipollinieffigies
authored andcommitted
Add a write_morph_data function.
1 parent b66d63b commit 62d1e52

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

nibabel/freesurfer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Reading functions for freesurfer files
22
"""
33

4-
from .io import read_geometry, read_morph_data, \
4+
from .io import read_geometry, read_morph_data, write_morph_data, \
55
read_annot, read_label, write_geometry, write_annot
66
from .mghformat import load, save, MGHImage

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)