Skip to content

Commit f2fbaf5

Browse files
committed
Generate _scans.json and the test
1 parent 99c686f commit f2fbaf5

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

heudiconv/bids.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,8 @@ def save_scans_key(item, bids_files):
332332

333333
def add_rows_to_scans_keys_file(fn, newrows):
334334
"""
335-
Add new rows to file fn for scans key filename
335+
Add new rows to file fn for scans key filename and generate accompanying json
336+
descriptor to make BIDS validator happy.
336337
337338
Parameters
338339
----------
@@ -355,6 +356,25 @@ def add_rows_to_scans_keys_file(fn, newrows):
355356
os.unlink(fn)
356357
else:
357358
fnames2info = newrows
359+
# Populate _scans.json (an optional file to describe column names in
360+
# _scans.tsv). This auto generation will make BIDS-validator happy.
361+
scans_json = '.'.join(fn.split('.')[:-1] + ['json'])
362+
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,
377+
indent=2)
358378

359379
header = ['filename', 'acq_time', 'operator', 'randstr']
360380
# prepare all the data rows

heudiconv/tests/test_main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from os.path import join as opj
2323
from six.moves import StringIO
2424
import stat
25+
import os.path as op
2526

2627

2728
@patch('sys.stdout', new_callable=StringIO)
@@ -205,6 +206,7 @@ def _check_rows(fn, rows):
205206
assert dates == sorted(dates)
206207

207208
_check_rows(fn, rows)
209+
assert op.exists(opj(tmpdir.strpath, 'file.json'))
208210
# add a new one
209211
extra_rows = {
210212
'a_new_file.nii.gz': ['2016adsfasd23', '', 'fasadfasdf'],

0 commit comments

Comments
 (0)