Skip to content

Commit bbaf70c

Browse files
committed
Merge pull request #54 from matthew-brett/trackvis-scalar-fix
BF+TST - fix failed scalar write for float32
2 parents 4c4c2be + 691397a commit bbaf70c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

nibabel/tests/test_trackvis.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ def test_write_scalars_props():
8585
for actual, expected in zip(streams, back_streams):
8686
for a_el, e_el in zip(actual, expected):
8787
assert_array_equal(a_el, e_el)
88+
# Also so if the datatype of points, scalars is already float32 (github
89+
# issue #53)
90+
out_f.seek(0)
91+
streams = [(points.astype('f4'),
92+
scalars.astype('f4'),
93+
props.astype('f4'))]
94+
tv.write(out_f, streams)
95+
out_f.seek(0)
96+
back_streams, hdr = tv.read(out_f)
97+
for actual, expected in zip(streams, back_streams):
98+
for a_el, e_el in zip(actual, expected):
99+
assert_array_almost_equal(a_el, e_el)
88100

89101

90102
def streams_equal(stream1, stream2):

nibabel/trackvis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ def write(fileobj, streamlines, hdr_mapping=None, endianness=None,
399399
% (n_pts, n_s))
400400
if scalars.dtype != f4dt:
401401
scalars = scalars.astype(f4dt)
402-
pts = np.c_[pts, scalars]
402+
pts = np.c_[pts, scalars]
403403
fileobj.write(pts.tostring())
404404
if n_p == 0:
405405
if not (props is None or len(props) == 0):

0 commit comments

Comments
 (0)