Skip to content

Commit 5c4ff83

Browse files
committed
BF: acq_str/run_str will not break if no acq/run label present
Also, fixes minor bug in ignoring `_sbref` images.
1 parent 7117659 commit 5c4ff83

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

heudiconv/bids.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ def populate_intended_for(path_to_bids_session):
520520
j for j in glob(op.join(path_to_bids_session, '*/*.json')) if not (
521521
j in fmap_jsons
522522
# j[:-5] removes the '.json' from the end
523-
or j[-5].endswith('_sbref')
523+
or j[:-5].endswith('_sbref')
524524
)
525525
)
526526

@@ -568,9 +568,11 @@ def populate_intended_for(path_to_bids_session):
568568
jsons_accounted_for.add(image_json)
569569
if len(intended_for) > 0:
570570
fm_json_name = op.basename(fm_json)
571-
# get from "_acq-"/"_run-" to the next "_":
572-
acq_str = '_acq-' + fm_json_name.split('_acq-')[1].split('_')[0]
573-
run_str = '_run-' + fm_json_name.split('_run-')[1].split('_')[0]
571+
# get <acq> and <run> labels:
572+
acq_match = re.findall('([/_]acq-([a-zA-Z0-9]*))', fm_json_name)
573+
acq_str = acq_match[0][0] if acq_match else ''
574+
run_match = re.findall('([/_]run-([a-zA-Z0-9]*))', fm_json_name)
575+
run_str = run_match[0][0] if run_match else ''
574576
# Loop through all the files that have the same "acq-" and "run-"
575577
intended_for = sorted([str(f) for f in intended_for])
576578
for other_fm_json in glob(op.join(path_to_bids_session, 'fmap/*' + acq_str + '*' + run_str + '*.json')):

0 commit comments

Comments
 (0)