Skip to content

Commit 4fef052

Browse files
authored
Merge branch 'master' into fix/ref
2 parents 0ce70ad + 24665ae commit 4fef052

File tree

5 files changed

+45
-18
lines changed

5 files changed

+45
-18
lines changed

heudiconv/cli/run.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def process_extra_commands(outdir, args):
5656
args : Namespace
5757
arguments
5858
"""
59-
if args.command == 'treat-json':
59+
if args.command == 'treat-jsons':
6060
for f in args.files:
6161
treat_infofile(f)
6262
elif args.command == 'ls':
@@ -174,7 +174,8 @@ def get_parser():
174174
help='Do not catch exceptions and show exception '
175175
'traceback')
176176
parser.add_argument('--command',
177-
choices=('treat-json', 'ls', 'populate-templates'),
177+
choices=('ls', 'populate-templates',
178+
'treat-jsons', 'sanitize-jsons'),
178179
help='custom actions to be performed on provided '
179180
'files instead of regular operation.')
180181
parser.add_argument('-g', '--grouping', default='studyUID',

heudiconv/convert.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ def convert_dicom(item_dicoms, bids, prefix,
375375

376376
def nipype_convert(item_dicoms, prefix, with_prov, bids, tmpdir):
377377
""" """
378+
import nipype
378379
if with_prov:
379380
from nipype import config
380381
config.enable_provenance()
@@ -387,6 +388,11 @@ def nipype_convert(item_dicoms, prefix, with_prov, bids, tmpdir):
387388
convertnode.base_dir = tmpdir
388389
convertnode.inputs.source_names = item_dicoms
389390
convertnode.inputs.out_filename = op.basename(op.dirname(prefix))
391+
if nipype.__version__.split('.')[0] == '0':
392+
# deprecated since 1.0, might be needed(?) before
393+
convertnode.inputs.terminal_output = 'allatonce'
394+
else:
395+
convertnode.terminal_output = 'allatonce'
390396
convertnode.inputs.bids_format = bids
391397
eg = convertnode.run()
392398

tests/test_heuristics.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import re
1111

1212
import pytest
13+
from .utils import HEURISTICS_PATH, TESTS_DATA_PATH
1314

1415
import logging
1516
lgr = logging.getLogger(__name__)
@@ -23,22 +24,25 @@
2324
# this will fail if not in project's root directory
2425
def test_smoke_converall(tmpdir):
2526
runner(
26-
("-f heuristics/convertall.py -c dcm2niix -o %s -b --datalad "
27-
"-s fmap_acq-3mm -d tests/data/{subject}/*" % tmpdir).split(' ')
27+
("-f %s/convertall.py -c dcm2niix -o %s -b --datalad "
28+
"-s fmap_acq-3mm -d %s/{subject}/*"
29+
% (HEURISTICS_PATH, tmpdir, TESTS_DATA_PATH)
30+
).split(' ')
2831
)
2932

3033

3134
@pytest.mark.parametrize('heuristic', ['dbic_bids', 'convertall'])
3235
@pytest.mark.parametrize(
3336
'invocation', [
34-
"--files tests/data", # our new way with automated groupping
35-
"-d tests/data/{subject}/* -s 01-fmap_acq-3mm" # "old" way specifying subject
37+
"--files %s" % TESTS_DATA_PATH, # our new way with automated groupping
38+
"-d %s/{subject}/* -s 01-fmap_acq-3mm" % TESTS_DATA_PATH # "old" way specifying subject
3639
# should produce the same results
3740
])
3841
@pytest.mark.skipif(Dataset is None, reason="no datalad")
3942
def test_dbic_bids_largely_smoke(tmpdir, heuristic, invocation):
4043
is_bids = True if heuristic == 'dbic_bids' else False
41-
arg = "--random-seed 1 -f heuristics/%s.py -c dcm2niix -o %s" % (heuristic, tmpdir)
44+
arg = "--random-seed 1 -f %s/%s.py -c dcm2niix -o %s" \
45+
% (HEURISTICS_PATH, heuristic, tmpdir)
4246
if is_bids:
4347
arg += " -b"
4448
arg += " --datalad "
@@ -47,7 +51,7 @@ def test_dbic_bids_largely_smoke(tmpdir, heuristic, invocation):
4751
).split(' ')
4852

4953
# Test some safeguards
50-
if invocation == '--files tests/data':
54+
if invocation == "--files %s" % TESTS_DATA_PATH:
5155
# Multiple subjects must not be specified -- only a single one could
5256
# be overridden from the command line
5357
with pytest.raises(ValueError):
@@ -87,10 +91,10 @@ def test_dbic_bids_largely_smoke(tmpdir, heuristic, invocation):
8791

8892
@pytest.mark.parametrize(
8993
'invocation', [
90-
"--files tests/data", # our new way with automated groupping
94+
"--files %s" % TESTS_DATA_PATH, # our new way with automated groupping
9195
])
9296
def test_scans_keys_dbic_bids(tmpdir, invocation):
93-
args = "-f heuristics/dbic_bids.py -c dcm2niix -o %s -b " % tmpdir
97+
args = "-f %s/dbic_bids.py -c dcm2niix -o %s -b " % (HEURISTICS_PATH, tmpdir)
9498
args += invocation
9599
runner(args.split())
96100
# for now check it exists
@@ -111,7 +115,10 @@ def test_scans_keys_dbic_bids(tmpdir, invocation):
111115

112116
@patch('sys.stdout', new_callable=StringIO)
113117
def test_ls(stdout):
114-
args = "-f heuristics/dbic_bids.py --command ls --files tests/data".split(' ')
118+
args = (
119+
"-f %s/dbic_bids.py --command ls --files %s"
120+
% (HEURISTICS_PATH, TESTS_DATA_PATH)
121+
).split(' ')
115122
runner(args)
116123
out = stdout.getvalue()
117124
assert 'StudySessionInfo(locator=' in out

tests/test_main.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
find_subj_ses)
1414
from heudiconv.external.dlad import MIN_VERSION, add_to_datalad
1515

16+
from .utils import TESTS_DATA_PATH
1617
import csv
1718
import os
1819
import pytest
@@ -58,7 +59,17 @@ def test_populate_bids_templates(tmpdir):
5859
for f in "README", "dataset_description.json", "CHANGES":
5960
# Just test that we have created them and they all have stuff TODO
6061
assert "TODO" in tmpdir.join(f).read()
61-
assert "something" in tmpdir.join('dataset_description.json').read()
62+
description_file = tmpdir.join('dataset_description.json')
63+
assert "something" in description_file.read()
64+
65+
# it should also be available as a command
66+
os.unlink(str(description_file))
67+
runner([
68+
'--command', 'populate-templates', '-f', 'heuristics/convertall.py',
69+
'--files', str(tmpdir)
70+
])
71+
assert "something" not in description_file.read()
72+
assert "TODO" in description_file.read()
6273

6374

6475
def test_add_participant_record(tmpdir):
@@ -154,9 +165,11 @@ def test_json_dumps_pretty():
154165

155166
def test_get_formatted_scans_key_row():
156167
item = [
157-
('tests/data/01-fmap_acq-3mm/1.3.12.2.1107.5.2.43.66112.2016101409263663466202201.dcm',
168+
('%s/01-fmap_acq-3mm/1.3.12.2.1107.5.2.43.66112.2016101409263663466202201.dcm'
169+
% TESTS_DATA_PATH,
158170
('nii.gz', 'dicom'),
159-
['tests/data/01-fmap_acq-3mm/1.3.12.2.1107.5.2.43.66112.2016101409263663466202201.dcm'])
171+
['%s/01-fmap_acq-3mm/1.3.12.2.1107.5.2.43.66112.2016101409263663466202201.dcm'
172+
% TESTS_DATA_PATH])
160173
]
161174
outname_bids_file = '/a/path/Halchenko/Yarik/950_bids_test4/sub-phantom1sid1/fmap/sub-phantom1sid1_acq-3mm_phasediff.json'
162175

tests/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import os.path as op
22
import heudiconv
33

4+
HEURISTICS_PATH = op.join(op.dirname(op.dirname(__file__)), 'heuristics')
5+
TESTS_DATA_PATH = op.join(op.dirname(__file__), 'data')
6+
47

58
def gen_heudiconv_args(datadir, outdir, subject, heuristic_file, xargs=None):
6-
heuristic = op.realpath(op.join(op.dirname(heudiconv.__file__),
7-
'..',
8-
'heuristics',
9-
heuristic_file))
9+
heuristic = op.realpath(op.join(HEURISTICS_PATH, heuristic_file))
1010
args = ["-d", op.join(datadir, 'sourcedata/{subject}/*/*/*.tgz'),
1111
"-c", "dcm2niix",
1212
"-o", outdir,

0 commit comments

Comments
 (0)