Skip to content

Commit 948ac54

Browse files
committed
Fixed tests.
1 parent ebdbf21 commit 948ac54

File tree

3 files changed

+49
-31
lines changed

3 files changed

+49
-31
lines changed

nipype/algorithms/confounds.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -651,22 +651,22 @@ def compute_dvars(in_file, in_mask, remove_zerovariance=False,
651651
idx = np.where(mask > 0)
652652
mfunc = func[idx[0], idx[1], idx[2], :]
653653

654-
# Demean
655-
mfunc = regress_poly(0, mfunc, remove_mean=True).astype(np.float32)
656-
657654
if intensity_normalization != 0:
658655
mfunc = (mfunc / np.median(mfunc)) * intensity_normalization
659656

660-
# Robust standard deviation
661-
func_sd = (np.percentile(mfunc, 75, axis=1) -
662-
np.percentile(mfunc, 25, axis=1)) / 1.349
657+
# Robust standard deviation (we are using "lower" interpolation
658+
# because this is what FSL is doing
659+
func_sd = (np.percentile(mfunc, 75, axis=1, interpolation="lower") -
660+
np.percentile(mfunc, 25, axis=1, interpolation="lower")) / 1.349
663661

664662
if remove_zerovariance:
665663
mfunc = mfunc[func_sd != 0, :]
666664
func_sd = func_sd[func_sd != 0]
667665

668666
# Compute (non-robust) estimate of lag-1 autocorrelation
669-
ar1 = np.apply_along_axis(AR_est_YW, 1, mfunc, 1)[:, 0]
667+
ar1 = np.apply_along_axis(AR_est_YW, 1,
668+
regress_poly(0, mfunc, remove_mean=True).astype(
669+
np.float32), 1)[:, 0]
670670

671671
# Compute (predicted) standard deviation of temporal difference time series
672672
diff_sdhat = np.squeeze(np.sqrt(((1 - ar1) * 2).tolist())) * func_sd
@@ -681,11 +681,12 @@ def compute_dvars(in_file, in_mask, remove_zerovariance=False,
681681
# standardization
682682
dvars_stdz = dvars_nstd / diff_sd_mean
683683

684-
with warnings.catch_warnings(): # catch, e.g., divide by zero errors
684+
with warnings.catch_warnings(): # catch, e.g., divide by zero errors
685685
warnings.filterwarnings('error')
686686

687687
# voxelwise standardization
688-
diff_vx_stdz = np.square(func_diff) / np.array([diff_sdhat] * func_diff.shape[-1]).T
688+
diff_vx_stdz = np.square(
689+
func_diff / np.array([diff_sdhat] * func_diff.shape[-1]).T)
689690
dvars_vx_stdz = np.sqrt(diff_vx_stdz.mean(axis=0))
690691

691692
return (dvars_stdz, dvars_nstd, dvars_vx_stdz)

nipype/algorithms/tests/test_confounds.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,26 @@ def test_dvars(tmpdir):
4040
dvars = ComputeDVARS(in_file=example_data('ds003_sub-01_mc.nii.gz'),
4141
in_mask=example_data('ds003_sub-01_mc_brainmask.nii.gz'),
4242
save_all=True,
43-
intensity_normalization=False)
43+
intensity_normalization=0)
4444
os.chdir(str(tmpdir))
4545
res = dvars.run()
4646

47-
dv1 = np.loadtxt(res.outputs.out_std)
48-
assert (np.abs(dv1 - ground_truth).sum()/ len(dv1)) < 0.05
47+
dv1 = np.loadtxt(res.outputs.out_all, skiprows=1)
48+
assert (np.abs(dv1[:, 0] - ground_truth[:, 0]).sum()/ len(dv1)) < 0.05
49+
50+
assert (np.abs(dv1[:, 1] - ground_truth[:, 1]).sum() / len(dv1)) < 0.05
51+
52+
assert (np.abs(dv1[:, 2] - ground_truth[:, 2]).sum() / len(dv1)) < 0.05
53+
54+
dvars = ComputeDVARS(in_file=example_data('ds003_sub-01_mc.nii.gz'),
55+
in_mask=example_data(
56+
'ds003_sub-01_mc_brainmask.nii.gz'),
57+
save_all=True)
58+
res = dvars.run()
59+
60+
dv1 = np.loadtxt(res.outputs.out_all, skiprows=1)
61+
assert (np.abs(dv1[:, 0] - ground_truth[:, 0]).sum() / len(dv1)) < 0.05
62+
63+
assert (np.abs(dv1[:, 1] - ground_truth[:, 1]).sum() / len(dv1)) > 0.05
64+
65+
assert (np.abs(dv1[:, 2] - ground_truth[:, 2]).sum() / len(dv1)) < 0.05
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
2.02915
2-
1.54871
3-
0.921419
4-
1.26058
5-
1.00079
6-
0.929074
7-
0.741207
8-
1.07913
9-
1.2969
10-
0.767387
11-
0.847059
12-
0.984061
13-
0.852897
14-
0.927778
15-
0.857544
16-
0.780098
17-
1.05496
18-
1.32099
19-
0.691529
1+
2.02915 5.2016 1.74221
2+
1.54871 3.97002 1.18108
3+
0.921419 2.362 0.784497
4+
1.26058 3.23142 0.734119
5+
1.00079 2.56548 0.787452
6+
0.929074 2.38163 0.828835
7+
0.741207 1.90004 0.746263
8+
1.07913 2.7663 0.779829
9+
1.2969 3.32452 0.73856
10+
0.767387 1.96715 0.772047
11+
0.847059 2.17138 0.774103
12+
0.984061 2.52258 0.88097
13+
0.852897 2.18635 0.794655
14+
0.927778 2.3783 0.756786
15+
0.857544 2.19826 0.796125
16+
0.780098 1.99973 0.731265
17+
1.05496 2.70434 0.788584
18+
1.32099 3.38628 0.831803
19+
0.691529 1.77269 0.738788

0 commit comments

Comments
 (0)