Skip to content

Commit 36bf5b7

Browse files
committed
Add default timestamp behavior to write_geometry
1 parent d05d270 commit 36bf5b7

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

nibabel/freesurfer/io.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from __future__ import with_statement
22

33
import numpy as np
4-
4+
import os
5+
import time
56

67
def _fread3(fobj):
78
"""Read a 3-byte int from an open binary file object
@@ -92,21 +93,25 @@ def read_geometry(filepath):
9293
coords = coords.astype(np.float) # XXX: due to mayavi bug on mac 32bits
9394
return coords, faces
9495

95-
def write_geometry(filepath, create_stamp, coords, faces):
96+
def write_geometry(filepath, coords, faces, create_stamp=None):
9697
"""Write a triangular format Freesurfer surface mesh.
9798
9899
Parameters
99100
----------
100101
filepath : str
101102
Path to surface file
102-
create_stamp : str
103-
User/time stamp
104103
coords : numpy array
105104
nvtx x 3 array of vertex (x, y, z) coordinates
106105
faces : numpy array
107106
nfaces x 3 array of defining mesh triangles
107+
create_stamp : str
108+
User/time stamp (default: "created by <user> on <ctime>")
108109
"""
109110
magic_bytes = np.array([255,255,254],dtype=np.uint8)
111+
112+
if create_stamp is None:
113+
create_stamp = "created by %s on %s" % (os.getlogin(), time.ctime())
114+
110115
with open(filepath, 'wb') as fobj:
111116
magic_bytes.tofile(fobj)
112117
fobj.write("%s\n\n" % create_stamp)

nibabel/freesurfer/tests/test_io.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ def test_geometry():
4444
ntf.close()
4545

4646
surf_path = ntf.name
47-
create_stamp = "created by %s on %s" % (os.getlogin(), time.ctime())
4847
write_geometry(surf_path, create_stamp, coords, faces)
4948

5049
coords2, faces2 = read_geometry(surf_path)

0 commit comments

Comments
 (0)