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

RF+BF: make code a bit more pythonic, and change comparison > 1 not >=1 for deciding multi-echo #339

Merged
merged 1 commit into from
May 20, 2019
Merged
Changes from all 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
19 changes: 7 additions & 12 deletions heudiconv/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,19 +506,14 @@ def save_converted_files(res, item_dicoms, bids, outtype, prefix, outname_bids,
# series. To do that, the most straightforward way is to read the
# echo times for all bids_files and see if they are all the same or not.

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

for bids_file in bids_files:
if bids_file:
# check for varying EchoTimes
echot = load_json(bids_file).get('EchoTime', None)
if echot is not None:
echo_times.add(echot)

# To see if the echo times are the same, convert it to a set and see if
# only one remains:
is_multiecho = len(echo_times) >= 1 if echo_times else False
is_multiecho = len(echo_times) > 1
Copy link
Member Author

Choose a reason for hiding this comment

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

FWIW:
original condition for >=1 was added in 266de4a changing previous, IMHO also incorrect test:

         # To see if the echo times are the same, convert it to a set and see if
-        #   only one remains:
-        multiecho = False
-        if echo_times:
-            multiecho = len(set(echo_times)) == 1
+        # only one remains:
+        is_multiecho = len(echo_times) >= 1 if echo_times else False

which gives me some more confidence that my change is correct or my understanding is completely flawed ;)


### Loop through the bids_files, set the output name and save files
for fl, suffix, bids_file in zip(res_files, suffixes, bids_files):
Expand Down