@@ -69,16 +69,37 @@ def populate_bids_templates(path, defaults={}):
69
69
"TODO: Provide description for the dataset -- basic details about the "
70
70
"study, possibly pointing to pre-registration (if public or embargoed)" )
71
71
72
+ populate_aggregated_jsons (path )
73
+
74
+
75
+ def populate_aggregated_jsons (path ):
76
+ """Aggregate across the entire BIDS dataset .json's into top level .json's
77
+
78
+ Top level .json files would contain only the fields which are
79
+ common to all subject[/session]/type/*_modality.json's.
80
+
81
+ ATM aggregating only for *_task*_bold.json files. Only the task- and
82
+ OPTIONAL _acq- field is retained within the aggregated filename. The other
83
+ BIDS _key-value pairs are "aggregated over".
84
+
85
+ Parameters
86
+ ----------
87
+ path: str
88
+ Path to the top of the BIDS dataset
89
+ """
72
90
# TODO: collect all task- .json files for func files to
73
91
tasks = {}
74
92
# way too many -- let's just collect all which are the same!
75
93
# FIELDS_TO_TRACK = {'RepetitionTime', 'FlipAngle', 'EchoTime',
76
94
# 'Manufacturer', 'SliceTiming', ''}
77
95
for fpath in find_files ('.*_task-.*\_bold\.json' , topdir = path ,
78
- exclude_vcs = True , exclude = "/\.(datalad|heudiconv)/" ):
96
+ exclude_vcs = True ,
97
+ exclude = "/\.(datalad|heudiconv)/" ):
79
98
#
80
- # According to BIDS spec I think both _task AND _acq (may be more? _rec, _dir, ...?) should be retained?
81
- # TODO: if we are to fix it, then old ones (without _acq) should be removed first
99
+ # According to BIDS spec I think both _task AND _acq (may be more?
100
+ # _rec, _dir, ...?) should be retained?
101
+ # TODO: if we are to fix it, then old ones (without _acq) should be
102
+ # removed first
82
103
task = re .sub ('.*_(task-[^_\.]*(_acq-[^_\.]*)?)_.*' , r'\1' , fpath )
83
104
json_ = load_json (fpath )
84
105
if task not in tasks :
@@ -97,8 +118,10 @@ def populate_bids_templates(path, defaults={}):
97
118
if not op .lexists (events_file ):
98
119
lgr .debug ("Generating %s" , events_file )
99
120
with open (events_file , 'w' ) as f :
100
- f .write ("onset\t duration\t trial_type\t response_time\t stim_file\t TODO -- fill in rows and add more tab-separated columns if desired" )
101
-
121
+ f .write (
122
+ "onset\t duration\t trial_type\t response_time\t stim_file"
123
+ "\t TODO -- fill in rows and add more tab-separated "
124
+ "columns if desired" )
102
125
# extract tasks files stubs
103
126
for task_acq , fields in tasks .items ():
104
127
task_file = op .join (path , task_acq + '_bold.json' )
@@ -110,7 +133,7 @@ def populate_bids_templates(path, defaults={}):
110
133
# to be populated from the file if it already exists
111
134
placeholders = {
112
135
"TaskName" : ("TODO: full task name for %s" %
113
- task_acq .split ('_' )[0 ].split ('-' )[1 ]),
136
+ task_acq .split ('_' )[0 ].split ('-' )[1 ]),
114
137
"CogAtlasID" : "TODO" ,
115
138
}
116
139
if op .lexists (task_file ):
0 commit comments