Skip to content

Commit ead67ce

Browse files
committed
RF: extracted functionality into a dedicated populate_aggregated_jsons
PyCharm also introduced minor code reformattings to avoid too long lines
1 parent 3f0e3d9 commit ead67ce

File tree

1 file changed

+29
-6
lines changed

1 file changed

+29
-6
lines changed

heudiconv/bids.py

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,37 @@ def populate_bids_templates(path, defaults={}):
6969
"TODO: Provide description for the dataset -- basic details about the "
7070
"study, possibly pointing to pre-registration (if public or embargoed)")
7171

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+
"""
7290
# TODO: collect all task- .json files for func files to
7391
tasks = {}
7492
# way too many -- let's just collect all which are the same!
7593
# FIELDS_TO_TRACK = {'RepetitionTime', 'FlipAngle', 'EchoTime',
7694
# 'Manufacturer', 'SliceTiming', ''}
7795
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)/"):
7998
#
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
82103
task = re.sub('.*_(task-[^_\.]*(_acq-[^_\.]*)?)_.*', r'\1', fpath)
83104
json_ = load_json(fpath)
84105
if task not in tasks:
@@ -97,8 +118,10 @@ def populate_bids_templates(path, defaults={}):
97118
if not op.lexists(events_file):
98119
lgr.debug("Generating %s", events_file)
99120
with open(events_file, 'w') as f:
100-
f.write("onset\tduration\ttrial_type\tresponse_time\tstim_file\tTODO -- fill in rows and add more tab-separated columns if desired")
101-
121+
f.write(
122+
"onset\tduration\ttrial_type\tresponse_time\tstim_file"
123+
"\tTODO -- fill in rows and add more tab-separated "
124+
"columns if desired")
102125
# extract tasks files stubs
103126
for task_acq, fields in tasks.items():
104127
task_file = op.join(path, task_acq + '_bold.json')
@@ -110,7 +133,7 @@ def populate_bids_templates(path, defaults={}):
110133
# to be populated from the file if it already exists
111134
placeholders = {
112135
"TaskName": ("TODO: full task name for %s" %
113-
task_acq.split('_')[0].split('-')[1]),
136+
task_acq.split('_')[0].split('-')[1]),
114137
"CogAtlasID": "TODO",
115138
}
116139
if op.lexists(task_file):

0 commit comments

Comments
 (0)