Skip to content

Commit daa15a8

Browse files
committed
FIX: Allow optional fields to be missing in the middle of a file
1 parent 955cd38 commit daa15a8

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

nitransforms/io/lta.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -266,21 +266,20 @@ def from_string(klass, string):
266266
klass._inner_type.from_string('\n'.join(lines[:25])))
267267
lta._xforms[-1].structarr['type'] = sa['type']
268268
lines = lines[25:]
269-
if lines:
270-
for key in ('subject', 'fscale'):
271-
# Optional keys
272-
if not lines[0].startswith(key):
273-
continue
274-
try:
275-
label, valstring = lines.pop(0).split(' ')
276-
except ValueError:
277-
sa[key] = ''
278-
else:
279-
assert label.strip() == key
280-
281-
val = np.genfromtxt([valstring.encode()],
282-
dtype=klass.dtype[key])
283-
sa[key] = val.reshape(sa[key].shape) if val.size else ''
269+
for key in ('subject', 'fscale'):
270+
# Optional keys
271+
if not (lines and lines[0].startswith(key)):
272+
continue
273+
try:
274+
label, valstring = lines.pop(0).split(' ')
275+
except ValueError:
276+
sa[key] = ''
277+
else:
278+
assert label.strip() == key
279+
280+
val = np.genfromtxt([valstring.encode()],
281+
dtype=klass.dtype[key])
282+
sa[key] = val.reshape(sa[key].shape) if val.size else ''
284283

285284
assert len(lta._xforms) == sa['nxforms']
286285
return lta

0 commit comments

Comments
 (0)