Skip to content

Commit 0db1e50

Browse files
committed
Fixes.
1 parent 880152a commit 0db1e50

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

nibabel/freesurfer/io.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -182,18 +182,20 @@ def write_geometry(filepath, coords, faces, create_stamp=None,
182182
faces.astype('>i4').reshape(-1).tofile(fobj)
183183

184184
# Add volume info, if given
185-
if volume_info is not None and len(volume_info) > 0:
186-
for key, val in volume_info.items():
187-
if key == 'head':
188-
np.array(val, dtype='>i4').tofile(fobj)
189-
elif key in ('valid', 'filename'):
190-
fobj.write('{0} = {1}\n'.format(key, val).encode('utf-8'))
191-
elif key == 'volume':
192-
fobj.write('{0} = {1} {2} {3}\n'.format(
193-
key, val[0], val[1], val[2]).encode('utf-8'))
194-
else:
195-
fobj.write('{0} = {1:.4f} {2:.4f} {3:.4f}\n'.format(
196-
key.ljust(6), val[0], val[1], val[2]).encode('utf-8'))
185+
if volume_info is None or len(volume_info) == 0:
186+
return
187+
188+
for key, val in volume_info.items():
189+
if key == 'head':
190+
np.array(val, dtype='>i4').tofile(fobj)
191+
elif key in ('valid', 'filename'):
192+
fobj.write('{0} = {1}\n'.format(key, val).encode('utf-8'))
193+
elif key == 'volume':
194+
fobj.write('{0} = {1} {2} {3}\n'.format(
195+
key, val[0], val[1], val[2]).encode('utf-8'))
196+
else:
197+
fobj.write('{0} = {1:.4f} {2:.4f} {3:.4f}\n'.format(
198+
key.ljust(6), val[0], val[1], val[2]).encode('utf-8'))
197199

198200

199201
def read_morph_data(filepath):

nibabel/freesurfer/tests/test_io.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ def test_geometry():
5656
assert_equal(coords.shape[0], faces.max() + 1)
5757

5858
surf_path = pjoin(data_path, "surf", "%s.%s" % ("lh", "sphere"))
59-
warnings.filterwarnings('always', category=DeprecationWarning)
6059
coords, faces, volume_info, create_stamp = read_geometry(
6160
surf_path, read_metadata=True, read_stamp=True)
6261

@@ -91,6 +90,7 @@ def test_geometry():
9190
read_geometry(surf_path, read_metadata=True)
9291
assert_true(any('volume information contained' in str(ww.message)
9392
for ww in w))
93+
assert_true(any('extension code' in str(ww.message) for ww in w))
9494

9595
assert_equal(create_stamp, read_create_stamp)
9696

0 commit comments

Comments
 (0)