Skip to content

Commit 2a47927

Browse files
authored
[ENH] create useful error message when images are not found (#246)
* pin dependencies relative to niworkflows * add more informative error message when preprocessed images are not found * add tests to make sure error is raised - also refactor other test in test_base * increase number of testing scenerios
1 parent 62efa23 commit 2a47927

File tree

3 files changed

+57
-53
lines changed

3 files changed

+57
-53
lines changed

setup.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ keywords =
2828
[options]
2929
python_requires = >=3.5
3030
install_requires =
31-
nipype ~= 1.1.5
31+
nipype ~= 1.3.0
3232
pybids ~= 0.9.3
33-
nibabel ~= 2.3.0
33+
nibabel ~= 2.4.0
3434
nistats == 0.0.1b1
3535
nilearn ~= 0.4.2
3636
pandas ~= 0.24.0
3737
numpy
38-
niworkflows
38+
niworkflows ~= 1.0.2
3939
duecredit ~= 0.6.4
4040
scikit-learn ~= 0.19.2
4141
matplotlib ~= 2.2.4
Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import os.path as op
22
from nipype import config as ncfg
3+
import pytest
34

45
from ..base import init_nibetaseries_participant_wf
56

67

7-
def test_init_nibetaseries_participant_wf(
8+
@pytest.mark.parametrize("estimator,fir_delays,hrf_model",
9+
[('lsa', None, 'spm'),
10+
('lss', None, 'spm'),
11+
('lss', [0, 1, 2, 3, 4], 'fir')])
12+
def test_valid_init_nibetaseries_participant_wf(
813
bids_dir, deriv_dir, sub_fmriprep, sub_metadata, bold_file, preproc_file,
914
sub_events, confounds_file, brainmask_file, atlas_file, atlas_lut,
10-
):
15+
estimator, fir_delays, hrf_model):
1116

1217
output_dir = op.join(str(bids_dir), 'derivatives', 'atlasCorr')
1318
work_dir = op.join(str(bids_dir), 'derivatives', 'work')
@@ -19,16 +24,16 @@ def test_init_nibetaseries_participant_wf(
1924
'crashfile_format': 'txt',
2025
'parameterize_dirs': False},
2126
})
22-
# LSS test
27+
2328
test_np_wf = init_nibetaseries_participant_wf(
24-
estimator='lss',
25-
fir_delays=None,
29+
estimator=estimator,
30+
fir_delays=fir_delays,
2631
atlas_img=str(atlas_file),
2732
atlas_lut=str(atlas_lut),
2833
bids_dir=str(bids_dir),
2934
derivatives_pipeline_dir=deriv_dir,
3035
exclude_description_label=None,
31-
hrf_model='spm',
36+
hrf_model=hrf_model,
3237
high_pass=0.008,
3338
output_dir=output_dir,
3439
run_label=None,
@@ -43,50 +48,45 @@ def test_init_nibetaseries_participant_wf(
4348

4449
assert test_np_wf.run()
4550

46-
# FS test
47-
test_np_wf = init_nibetaseries_participant_wf(
48-
estimator='lss',
49-
fir_delays=[0, 1, 2, 3, 4],
50-
atlas_img=str(atlas_file),
51-
atlas_lut=str(atlas_lut),
52-
bids_dir=str(bids_dir),
53-
derivatives_pipeline_dir=deriv_dir,
54-
exclude_description_label=None,
55-
hrf_model='fir',
56-
high_pass=0.008,
57-
output_dir=output_dir,
58-
run_label=None,
59-
selected_confounds=['WhiteMatter', 'CSF'],
60-
session_label=None,
61-
smoothing_kernel=None,
62-
space_label=None,
63-
subject_list=["01"],
64-
task_label=None,
65-
description_label=None,
66-
work_dir=work_dir)
6751

68-
assert test_np_wf.run()
52+
@pytest.mark.parametrize("session_label,task_label,run_label,space_label,description_label",
53+
[('these', 'are', 'not', 'valid', 'filters'),
54+
(123, 123, 123, 123, 123)])
55+
def test_filters_init_nibetaseries_participant_wf(
56+
bids_dir, deriv_dir, sub_fmriprep, sub_metadata, bold_file, preproc_file,
57+
sub_events, confounds_file, brainmask_file,
58+
session_label, task_label, run_label, space_label, description_label):
6959

70-
# LSA test
71-
test_np_wf = init_nibetaseries_participant_wf(
72-
estimator='lsa',
73-
fir_delays=None,
74-
atlas_img=None,
75-
atlas_lut=None,
76-
bids_dir=str(bids_dir),
77-
derivatives_pipeline_dir=deriv_dir,
78-
exclude_description_label=None,
79-
hrf_model='spm',
80-
high_pass=0.008,
81-
output_dir=output_dir,
82-
run_label=None,
83-
selected_confounds=['WhiteMatter', 'CSF'],
84-
session_label=None,
85-
smoothing_kernel=None,
86-
space_label=None,
87-
subject_list=["01"],
88-
task_label=None,
89-
description_label=None,
90-
work_dir=work_dir)
60+
output_dir = op.join(str(bids_dir), 'derivatives', 'atlasCorr')
61+
work_dir = op.join(str(bids_dir), 'derivatives', 'work')
62+
deriv_dir = op.join(str(bids_dir), 'derivatives', 'fmriprep')
63+
ncfg.update_config({
64+
'logging': {'log_directory': work_dir,
65+
'log_to_file': True},
66+
'execution': {'crashdump_dir': work_dir,
67+
'crashfile_format': 'txt',
68+
'parameterize_dirs': False},
69+
})
70+
with pytest.raises(ValueError) as val_err:
71+
init_nibetaseries_participant_wf(
72+
estimator='lsa',
73+
fir_delays=None,
74+
atlas_img=None,
75+
atlas_lut=None,
76+
bids_dir=str(bids_dir),
77+
derivatives_pipeline_dir=deriv_dir,
78+
exclude_description_label=None,
79+
hrf_model='spm',
80+
high_pass=0.008,
81+
output_dir=output_dir,
82+
run_label=run_label,
83+
selected_confounds=['WhiteMatter', 'CSF'],
84+
session_label=session_label,
85+
smoothing_kernel=None,
86+
space_label=space_label,
87+
subject_list=["01"],
88+
task_label=task_label,
89+
description_label=description_label,
90+
work_dir=work_dir)
9191

92-
assert test_np_wf.run()
92+
assert "could not find preprocessed outputs:" in str(val_err.value)

src/nibetaseries/workflows/utils.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ def collect_data(layout, participant_label, ses=None,
3737

3838
preprocs = layout.get(**preproc_query)
3939

40+
if not preprocs:
41+
msg = "could not find preprocessed outputs: " + str(preproc_query)
42+
raise ValueError(msg)
43+
4044
# get the relevant files for each preproc
4145
preproc_collector = []
4246
# common across all queries

0 commit comments

Comments
 (0)