Skip to content

Commit d05d270

Browse files
committed
Use more modern tempfile methods, ensure tests run, improve writing
Load write_geometry into __init__ file, replace vnum,fnum writing
1 parent 5909001 commit d05d270

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

nibabel/freesurfer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"""
33

44
from io import read_geometry, read_morph_data, \
5-
read_annot, read_label
5+
read_annot, read_label, write_geometry
66
from mghformat import load, save, MGHImage

nibabel/freesurfer/io.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,7 @@ def write_geometry(filepath, create_stamp, coords, faces):
111111
magic_bytes.tofile(fobj)
112112
fobj.write("%s\n\n" % create_stamp)
113113

114-
# On a Linux box, numpy uses opposite byte order to freesurfer
115-
np.int32(coords.shape[0]).byteswap().tofile(fobj)
116-
np.int32(faces.shape[0]).byteswap().tofile(fobj)
114+
np.array([coords.shape[0], faces.shape[0]], dtype='>i4').tofile(fobj)
117115

118116
# Coerce types, just to be safe
119117
coords.astype('>f4').reshape(-1).tofile(fobj)

nibabel/freesurfer/tests/test_io.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
from os.path import join as pjoin
33
import time
4+
import tempfile
45

56
from nose.tools import assert_true
67
import numpy as np
@@ -39,13 +40,16 @@ def test_geometry():
3940

4041
# Test equivalence of freesurfer- and nibabel-generated triangular files
4142
# with respect to read_geometry()
42-
surf_path = os.tmpnam()
43+
ntf = tempfile.NamedTemporaryFile(delete=False)
44+
ntf.close()
45+
46+
surf_path = ntf.name
4347
create_stamp = "created by %s on %s" % (os.getlogin(), time.ctime())
4448
write_geometry(surf_path, create_stamp, coords, faces)
4549

4650
coords2, faces2 = read_geometry(surf_path)
4751

48-
# Remove
52+
# Remove temporary file
4953
os.unlink(surf_path)
5054

5155
assert_equal(coords, coords2)

0 commit comments

Comments
 (0)