Skip to content

Commit 0ed5f0c

Browse files
committed
Set the 'TaskName' field in the json file for multiecho func data
1 parent 756fd80 commit 0ed5f0c

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

heudiconv/convert.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,8 @@ def convert(items, converter, scaninfo_suffix, custom_callable, with_prov,
322322
)
323323

324324
if len(bids_outfiles) > 1:
325-
lgr.warning("For now not embedding BIDS and info generated "
326-
".nii.gz itself since sequence produced "
327-
"multiple files")
325+
for bids_outfile in bids_outfiles:
326+
add_taskname_to_infofile( bids_outfile )
328327
elif not bids_outfiles:
329328
lgr.debug("No BIDS files were produced, nothing to embed to then")
330329
elif outname:
@@ -628,3 +627,29 @@ def save_converted_files(res, item_dicoms, bids_options, outtype, prefix, outnam
628627
except TypeError as exc: ##catch lists
629628
raise TypeError("Multiple BIDS sidecars detected.")
630629
return bids_outfiles
630+
631+
632+
def add_taskname_to_infofile(infofile):
633+
"""Add the "TaskName" field to json files corresponding to func images.
634+
635+
Parameters
636+
----------
637+
infofile : filename of json file
638+
639+
Returns
640+
-------
641+
"""
642+
643+
import re
644+
645+
meta_info = load_json(infofile)
646+
647+
try:
648+
meta_info['TaskName'] = (re.search('(?<=_task-)\w+',
649+
op.basename(infofile))
650+
.group(0).split('_')[0])
651+
except AttributeError:
652+
pass
653+
654+
# write to outfile
655+
save_json(infofile, meta_info)

0 commit comments

Comments
 (0)