Skip to content

Commit c5fe64f

Browse files
committed
RF: centralize definition of columns in the _scans files
That allows to remove code duplication of header column names
1 parent d3e247c commit c5fe64f

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

heudiconv/bids.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@
2626

2727
lgr = logging.getLogger(__name__)
2828

29+
# Fields to be populated in _scans files. Order matters
30+
SCANS_FILE_FIELDS = OrderedDict([
31+
("filename", OrderedDict([
32+
("Description", "Name of the nifti file")])),
33+
("acq_time", OrderedDict([
34+
("LongName", "Acquisition time"),
35+
("Description", "Acquisition time of the particular scan")])),
36+
("operator", OrderedDict([
37+
("Description", "Name of the operator")])),
38+
("randstr", OrderedDict([
39+
("LongName", "Random string"),
40+
("Description", "md5 hash of UIDs")])),
41+
])
2942

3043
class BIDSError(Exception):
3144
pass
@@ -360,22 +373,9 @@ def add_rows_to_scans_keys_file(fn, newrows):
360373
# _scans.tsv). This auto generation will make BIDS-validator happy.
361374
scans_json = '.'.join(fn.split('.')[:-1] + ['json'])
362375
if not op.lexists(scans_json):
363-
save_json(scans_json,
364-
OrderedDict([
365-
("filename", OrderedDict([
366-
("Description", "Name of the nifti file")])),
367-
("acq_time", OrderedDict([
368-
("LongName", "Acquisition time"),
369-
("Description", "Acquisition time of the particular scan")])),
370-
("operator", OrderedDict([
371-
("Description", "Name of the operator")])),
372-
("randstr", OrderedDict([
373-
("LongName", "Random string"),
374-
("Description", "md5 hash of UIDs")])),
375-
]),
376-
sort_keys=False)
376+
save_json(scans_json, SCANS_FILE_FIELDS, sort_keys=False)
377377

378-
header = ['filename', 'acq_time', 'operator', 'randstr']
378+
header = SCANS_FILE_FIELDS
379379
# prepare all the data rows
380380
data_rows = [[k] + v for k, v in fnames2info.items()]
381381
# sort by the date/filename

0 commit comments

Comments
 (0)