Skip to content

Commit 5cfb6f2

Browse files
authored
Merge pull request #366 from tsalo/multi-echo
FIX: Determine multi-echo echo numbers from EchoTimes
2 parents fd6d413 + 4bc9eee commit 5cfb6f2

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

heudiconv/convert.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -518,11 +518,11 @@ def save_converted_files(res, item_dicoms, bids_options, outtype, prefix, outnam
518518
# echo times for all bids_files and see if they are all the same or not.
519519

520520
# Check for varying echo times
521-
echo_times = set(
521+
echo_times = sorted(list(set(
522522
load_json(b).get('EchoTime', None)
523523
for b in bids_files
524524
if b
525-
)
525+
)))
526526

527527
is_multiecho = len(echo_times) > 1
528528

@@ -574,9 +574,11 @@ def save_converted_files(res, item_dicoms, bids_options, outtype, prefix, outnam
574574
# For multi-echo sequences, we have to specify the echo number in
575575
# the file name:
576576
if bids_file and is_multiecho:
577-
# Get the EchoNumber from json file info. If not present, it's echo-1
578-
echo_number = fileinfo.get('EchoNumber', 1)
579-
577+
# Get the EchoNumber from json file info. If not present, use EchoTime
578+
if 'EchoNumber' in fileinfo.keys():
579+
echo_number = fileinfo['EchoNumber']
580+
else:
581+
echo_number = echo_times.index(fileinfo['EchoTime']) + 1
580582

581583
supported_multiecho = ['_bold', '_epi', '_sbref', '_T1w', '_PDT2']
582584
# Now, decide where to insert it.

0 commit comments

Comments
 (0)