Skip to content

Commit 534d5a3

Browse files
committed
enh: add ability to read json file for info
1 parent a23f47a commit 534d5a3

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

examples/fmri_ants_openfmri.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -562,13 +562,22 @@ def get_subjectinfo(subject_id, base_dir, task_id, model_id):
562562
'task%03d_run*' % (idx + 1))))
563563
runs = [int(val[-3:]) for val in files]
564564
run_ids.insert(idx, runs)
565-
task_scan_key = os.path.join(base_dir, subject_id, 'BOLD',
565+
json_info = os.path.join(base_dir, subject_id, 'BOLD',
566566
'task%03d_run%03d' % (task_id, run_ids[0]),
567-
'scan_key.txt')
568-
if os.path.exists(task_scan_key):
569-
TR = np.genfromtxt(task_scan_key)[1]
567+
'bold_scaninfo.json')
568+
if os.path.exists(json_info):
569+
import json
570+
with open(json_info, 'rt') as fp:
571+
data = json.loads(fp)
572+
TR = data['global']['const']['RepetitionTime']/1000.
570573
else:
571-
TR = np.genfromtxt(os.path.join(base_dir, 'scan_key.txt'))[1]
574+
task_scan_key = os.path.join(base_dir, subject_id, 'BOLD',
575+
'task%03d_run%03d' % (task_id, run_ids[0]),
576+
'scan_key.txt')
577+
if os.path.exists(task_scan_key):
578+
TR = np.genfromtxt(task_scan_key)[1]
579+
else:
580+
TR = np.genfromtxt(os.path.join(base_dir, 'scan_key.txt'))[1]
572581
return run_ids[task_id - 1], conds[task_id - 1], TR
573582

574583
"""

0 commit comments

Comments
 (0)