|
4 | 4 | import logging
|
5 | 5 | import shutil
|
6 | 6 | import sys
|
| 7 | +import re |
7 | 8 |
|
8 | 9 | from .utils import (
|
9 | 10 | read_config,
|
@@ -321,9 +322,13 @@ def convert(items, converter, scaninfo_suffix, custom_callable, with_prov,
|
321 | 322 | % (outname)
|
322 | 323 | )
|
323 | 324 |
|
| 325 | + # add the taskname field to the json file(s): |
| 326 | + add_taskname_to_infofile( bids_outfiles ) |
| 327 | + |
324 | 328 | if len(bids_outfiles) > 1:
|
325 |
| - for bids_outfile in bids_outfiles: |
326 |
| - add_taskname_to_infofile( bids_outfile ) |
| 329 | + lgr.warning("For now not embedding BIDS and info generated " |
| 330 | + ".nii.gz itself since sequence produced " |
| 331 | + "multiple files") |
327 | 332 | elif not bids_outfiles:
|
328 | 333 | lgr.debug("No BIDS files were produced, nothing to embed to then")
|
329 | 334 | elif outname:
|
@@ -629,28 +634,30 @@ def save_converted_files(res, item_dicoms, bids_options, outtype, prefix, outnam
|
629 | 634 | return bids_outfiles
|
630 | 635 |
|
631 | 636 |
|
632 |
| -def add_taskname_to_infofile(infofile): |
| 637 | +def add_taskname_to_infofile(infofiles): |
633 | 638 | """Add the "TaskName" field to json files corresponding to func images.
|
634 | 639 |
|
635 | 640 | Parameters
|
636 | 641 | ----------
|
637 |
| - infofile : filename of json file |
| 642 | + infofiles : list with json filenames or single filename |
638 | 643 |
|
639 | 644 | Returns
|
640 | 645 | -------
|
641 | 646 | """
|
642 | 647 |
|
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 |
| - lgr.warning("Failed to find task field in {0}.".format(infofile)) |
653 |
| - return |
| 648 | + # in case they pass a string with a path: |
| 649 | + if not isinstance(infofiles, list): |
| 650 | + infofiles = [infofiles] |
| 651 | + |
| 652 | + for infofile in infofiles: |
| 653 | + meta_info = load_json(infofile) |
| 654 | + try: |
| 655 | + meta_info['TaskName'] = (re.search('(?<=_task-)\w+', |
| 656 | + op.basename(infofile)) |
| 657 | + .group(0).split('_')[0]) |
| 658 | + except AttributeError: |
| 659 | + lgr.warning("Failed to find task field in {0}.".format(infofile)) |
| 660 | + continue |
654 | 661 |
|
655 |
| - # write to outfile |
656 |
| - save_json(infofile, meta_info) |
| 662 | + # write to outfile |
| 663 | + save_json(infofile, meta_info) |
0 commit comments