Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Determine multi-echo echo numbers from EchoTimes #366

Merged
merged 3 commits into from
Aug 21, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions heudiconv/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,11 +518,11 @@ def save_converted_files(res, item_dicoms, bids_options, outtype, prefix, outnam
# echo times for all bids_files and see if they are all the same or not.

# Check for varying echo times
echo_times = set(
echo_times = sorted(list(set(
load_json(b).get('EchoTime', None)
for b in bids_files
if b
)
)))

is_multiecho = len(echo_times) > 1

Expand Down Expand Up @@ -574,9 +574,11 @@ def save_converted_files(res, item_dicoms, bids_options, outtype, prefix, outnam
# For multi-echo sequences, we have to specify the echo number in
# the file name:
if bids_file and is_multiecho:
# Get the EchoNumber from json file info. If not present, it's echo-1
echo_number = fileinfo.get('EchoNumber', 1)

# Get the EchoNumber from json file info. If not present, use EchoTime
if 'EchoNumber' in fileinfo.keys():
echo_number = fileinfo['EchoNumber']
else:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should ensure echotime is available

Suggested change
else:
elif fileinfo.get('EchoTime'):

and just set echo_number to None if neither are defined.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that, since this line should only be reached if the data are multi-echo, it should raise an error if EchoTime is unavailable. What was happening before (in #347) was that the real cause of the error (missing EchoNumber field) was being obscured because the value was defaulting to 1. The error I was getting there was from copying files, which was hard to interpret.

That said, maybe defaulting to None will make the resulting error clearer, while defaulting to 1 made it confusing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way is fine to me - let's keep it as you have it. Could you merge with master - the CI problem should be fixed now

echo_number = echo_times.index(fileinfo['EchoTime']) + 1

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