Skip to content

Commit 5bb9bcb

Browse files
committed
ENH: restrict splitting to only 2 components while parsing for _echo
1 parent 83fdd1d commit 5bb9bcb

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

heudiconv/bids.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,17 @@ def populate_aggregated_jsons(path):
119119
suf = '_bold.json'
120120
assert fpath.endswith(suf)
121121
# specify the name of the '_events.tsv' file:
122-
if ( '_echo-' in fpath ):
122+
if '_echo-' in fpath:
123123
# multi-echo sequence: bids (1.1.0) specifies just one '_events.tsv'
124124
# file, common for all echoes. The name will not include _echo-.
125+
# TODO: RF to use re.match for better readability/robustness
125126
# So, find out the echo number:
126-
fpath_split = fpath.split('_echo-') # split fpath using '_echo-'
127-
fpath_split_2 = fpath_split[1].split('_') # split the second part of fpath_split using '_'
128-
echoNo = fpath_split_2[0] # get echo number
129-
if ( echoNo == '1' ):
127+
fpath_split = fpath.split('_echo-', 1) # split fpath using '_echo-'
128+
fpath_split_2 = fpath_split[1].split('_', 1) # split the second part of fpath_split using '_'
129+
echoNo = fpath_split_2[0] # get echo number
130+
if echoNo == '1':
131+
if len(fpath_split_2) != 2:
132+
raise ValueError("Found no trailer after _echo-")
130133
# we modify fpath to exclude '_echo-' + echoNo:
131134
fpath = fpath_split[0] + '_' + fpath_split_2[1]
132135
else:

0 commit comments

Comments
 (0)