Skip to content

Commit 74f8ceb

Browse files
committed
fix+tst: --files heuristic flexiblility
1 parent f30fc92 commit 74f8ceb

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

heudiconv/parser.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -167,20 +167,6 @@ def get_study_sessions(dicom_dir_template, files_opt, heuristic, outdir,
167167
dcmfilter=getattr(heuristic, 'filter_dicom', None),
168168
grouping=grouping)
169169

170-
if not getattr(heuristic, 'infotoids', None):
171-
lgr.warn("Heuristic is missing an `infotoids` method, assigning "
172-
"empty method. For best results, define an `infotoids`")
173-
def infotoids(seqinfos, outdir):
174-
return {
175-
'locator': None,
176-
'session': None,
177-
'subject': None
178-
}
179-
heuristic.infotoids = infotoids
180-
# raise NotImplementedError(
181-
# "For now, if no subj template is provided, requiring "
182-
# "heuristic to have infotoids")
183-
184170
if sids:
185171
if not (len(sids) == 1 and len(seqinfo_dict) == 1):
186172
raise RuntimeError(
@@ -193,6 +179,23 @@ def infotoids(seqinfos, outdir):
193179
else:
194180
sid = None
195181

182+
if not getattr(heuristic, 'infotoids', None):
183+
# allow bypass with subject override
184+
if not sid:
185+
raise NotImplementedError("Cannot guarantee subject id - add "
186+
"`infotoids` to heuristic file or "
187+
"provide `--subject` argument")
188+
lgr.warn("Heuristic is missing an `infotoids` method, assigning "
189+
"empty method and using provided subject id", sid,
190+
"Provide `session` and `locator` fields for best results.")
191+
def infotoids(seqinfos, outdir):
192+
return {
193+
'locator': None,
194+
'session': None,
195+
'subject': None
196+
}
197+
heuristic.infotoids = infotoids
198+
196199
for studyUID, seqinfo in seqinfo_dict.items():
197200
# so we have a single study, we need to figure out its
198201
# locator, session, subject

heudiconv/tests/test_heuristics.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,12 @@ def test_reproin_largely_smoke(tmpdir, heuristic, invocation):
6464
runner(args + ['--subjects', 'sub1', 'sub2'])
6565

6666
if heuristic != 'reproin':
67-
# none other heuristic has mighty infotoids atm
67+
# if subject is not overriden, raise error
6868
with pytest.raises(NotImplementedError):
6969
runner(args)
70+
71+
# but run successful when provided
72+
runner(args + ['--subjects', 'sub1'])
7073
return
7174
runner(args)
7275
ds = Dataset(str(tmpdir))

0 commit comments

Comments
 (0)