Skip to content

Commit f7905ed

Browse files
committed
RF: populate singular scans.json at top level, and not one per sub/ses
Breeding those identical files is not useful at all: - causes some pains for datalad (git-annex) since committed under annex, and if published online and identical -- there might be thousands of urls associated with that file annex key - BIDS is not explicit (yet) about possibility to have scans.json on top but it seems to follow nicely from inheritance principles. See bids-standard/bids-specification#789 and references there-in - so why waste inodes and clutter the file tree?
1 parent 753e6b2 commit f7905ed

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

heudiconv/bids.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
load_json,
1919
save_json,
2020
create_file_if_missing,
21-
json_dumps_pretty,
21+
json_dumps,
2222
set_readonly,
2323
is_readonly,
2424
get_datetime,
@@ -120,6 +120,9 @@ def populate_bids_templates(path, defaults={}):
120120
create_file_if_missing(op.join(path, 'README'),
121121
"TODO: Provide description for the dataset -- basic details about the "
122122
"study, possibly pointing to pre-registration (if public or embargoed)")
123+
create_file_if_missing(op.join(path, 'scans.json'),
124+
json_dumps(SCANS_FILE_FIELDS, sort_keys=False)
125+
)
123126

124127
populate_aggregated_jsons(path)
125128

@@ -404,11 +407,6 @@ def add_rows_to_scans_keys_file(fn, newrows):
404407
os.unlink(fn)
405408
else:
406409
fnames2info = newrows
407-
# Populate _scans.json (an optional file to describe column names in
408-
# _scans.tsv). This auto generation will make BIDS-validator happy.
409-
scans_json = '.'.join(fn.split('.')[:-1] + ['json'])
410-
if not op.lexists(scans_json):
411-
save_json(scans_json, SCANS_FILE_FIELDS, sort_keys=False)
412410

413411
header = SCANS_FILE_FIELDS
414412
# prepare all the data rows

heudiconv/tests/test_main.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
from heudiconv.main import workflow
55
from heudiconv import __version__
66
from heudiconv.utils import (create_file_if_missing,
7+
load_json,
78
set_readonly,
89
is_readonly)
910
from heudiconv.bids import (populate_bids_templates,
1011
add_participant_record,
1112
get_formatted_scans_key_row,
1213
add_rows_to_scans_keys_file,
13-
find_subj_ses)
14+
find_subj_ses,
15+
SCANS_FILE_FIELDS,
16+
)
1417
from heudiconv.external.dlad import MIN_VERSION, add_to_datalad
1518

1619
from .utils import TESTS_DATA_PATH
@@ -81,6 +84,8 @@ def test_populate_bids_templates(tmpdir):
8184
assert "something" not in description_file.read()
8285
assert "TODO" in description_file.read()
8386

87+
assert load_json(tmpdir / "scans.json") == SCANS_FILE_FIELDS
88+
8489

8590
def test_add_participant_record(tmpdir):
8691
tf = tmpdir.join('participants.tsv')
@@ -127,6 +132,7 @@ def test_prepare_for_datalad(tmpdir):
127132
'.gitattributes',
128133
'.datalad/config', '.datalad/.gitattributes',
129134
'dataset_description.json',
135+
'scans.json',
130136
'CHANGES', 'README'}
131137
assert set(ds.repo.get_indexed_files()) == target_files
132138
# and all are under git
@@ -217,7 +223,9 @@ def _check_rows(fn, rows):
217223
assert dates == sorted(dates)
218224

219225
_check_rows(fn, rows)
220-
assert op.exists(opj(tmpdir.strpath, 'file.json'))
226+
# we no longer produce a sidecar .json file there and only generate
227+
# it while populating templates for BIDS
228+
assert not op.exists(opj(tmpdir.strpath, 'file.json'))
221229
# add a new one
222230
extra_rows = {
223231
'a_new_file.nii.gz': ['2016adsfasd23', '', 'fasadfasdf'],

0 commit comments

Comments
 (0)