Skip to content

Commit 47655ca

Browse files
committed
Merge remote-tracking branch 'upstream/master' into fix/dcm2niix
* upstream/master: (42 commits) removing default value from out_intensity_fusion_name_format removing gen_file and using a default value in ICA_AROMA fix test [skip ci] improve description forgot make specs make threshold mandatory without default TEST: Test xor, requires constraints on name_source traits FIX: Remove -mcmap argument in absence of -nodv FIX: Only find paths for created files FIX: Do not generate filename when required fields are missing fixing the test changinf freesurfer test_preprocess (default number of iterat) changinf freesurfer test_preprocess (default number of iterat) removing usedefault=False from traits (for traits were default was set i also remove this value) warnings for usedefault=False suggestions from chris increasing atol in the test adding tests that checks pos/neg for normal distribution changing hash in test_core correcting traits to remove warnings ...
2 parents dd6ab0b + 615964c commit 47655ca

File tree

94 files changed

+727
-313
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+727
-313
lines changed

nipype/algorithms/confounds.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,12 @@ class CompCorInputSpec(BaseInterfaceInputSpec):
390390
desc='Detrend time series prior to component '
391391
'extraction')
392392
use_regress_poly = traits.Bool(
393-
True,
394393
deprecated='0.15.0',
395394
new_name='pre_filter',
396395
desc=('use polynomial regression '
397396
'pre-component extraction'))
398397
regress_poly_degree = traits.Range(
399-
low=1, default=1, usedefault=True, desc='the degree polynomial to use')
398+
low=1, value=1, usedefault=True, desc='the degree polynomial to use')
400399
header_prefix = traits.Str(
401400
desc=('the desired header for the output tsv '
402401
'file (one column). If undefined, will '

nipype/algorithms/mesh.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ class MeshWarpMathsInputSpec(BaseInterfaceInputSpec):
289289
float_trait,
290290
File(exists=True),
291291
default=1.0,
292+
usedefault=True,
292293
mandatory=True,
293294
desc='image, float or tuple of floats to act as operator')
294295

nipype/algorithms/rapidart.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,9 @@ class ArtifactDetectInputSpec(BaseInterfaceInputSpec):
234234
desc=("Mask threshold to be used if mask_type"
235235
" is 'thresh'."))
236236
intersect_mask = traits.Bool(
237-
True, desc=("Intersect the masks when computed from "
238-
"spm_global."))
237+
True, usedefault=True,
238+
desc=("Intersect the masks when computed from "
239+
"spm_global."))
239240
save_plot = traits.Bool(
240241
True, desc="save plots containing outliers", usedefault=True)
241242
plot_type = traits.Enum(

nipype/algorithms/stats.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# -*- coding: utf-8 -*-
2+
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
3+
# vi: set ft=python sts=4 ts=4 sw=4 et:
4+
"""
5+
Managing statistical maps
6+
"""
7+
from __future__ import (print_function, division, unicode_literals,
8+
absolute_import)
9+
import os
10+
import nibabel as nb
11+
import numpy as np
12+
13+
from ..interfaces.base import (
14+
BaseInterfaceInputSpec, TraitedSpec, SimpleInterface,
15+
traits, InputMultiPath, File
16+
)
17+
from ..utils.filemanip import split_filename
18+
19+
20+
class ActivationCountInputSpec(BaseInterfaceInputSpec):
21+
in_files = InputMultiPath(File(exists=True), mandatory=True,
22+
desc='input file, generally a list of z-stat maps')
23+
threshold = traits.Float(
24+
mandatory=True, desc='binarization threshold. E.g. a threshold of 1.65 '
25+
'corresponds to a two-sided Z-test of p<.10')
26+
27+
28+
class ActivationCountOutputSpec(TraitedSpec):
29+
out_file = File(exists=True, desc='output activation count map')
30+
acm_pos = File(exists=True, desc='positive activation count map')
31+
acm_neg = File(exists=True, desc='negative activation count map')
32+
33+
34+
class ActivationCount(SimpleInterface):
35+
"""
36+
Calculate a simple Activation Count Maps
37+
38+
Adapted from: https://github.com/poldracklab/CNP_task_analysis/\
39+
blob/61c27f5992db9d8800884f8ffceb73e6957db8af/CNP_2nd_level_ACM.py
40+
"""
41+
input_spec = ActivationCountInputSpec
42+
output_spec = ActivationCountOutputSpec
43+
44+
def _run_interface(self, runtime):
45+
allmaps = nb.concat_images(self.inputs.in_files).get_data()
46+
acm_pos = np.mean(allmaps > self.inputs.threshold,
47+
axis=3, dtype=np.float32)
48+
acm_neg = np.mean(allmaps < -1.0 * self.inputs.threshold,
49+
axis=3, dtype=np.float32)
50+
acm_diff = acm_pos - acm_neg
51+
52+
template_fname = self.inputs.in_files[0]
53+
ext = split_filename(template_fname)[2]
54+
fname_fmt = os.path.join(runtime.cwd, 'acm_{}' + ext).format
55+
56+
self._results['out_file'] = fname_fmt('diff')
57+
self._results['acm_pos'] = fname_fmt('pos')
58+
self._results['acm_neg'] = fname_fmt('neg')
59+
60+
img = nb.load(template_fname)
61+
img.__class__(acm_diff, img.affine, img.header).to_filename(
62+
self._results['out_file'])
63+
img.__class__(acm_pos, img.affine, img.header).to_filename(
64+
self._results['acm_pos'])
65+
img.__class__(acm_neg, img.affine, img.header).to_filename(
66+
self._results['acm_neg'])
67+
68+
return runtime
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
2+
from __future__ import unicode_literals
3+
from ..stats import ActivationCount
4+
5+
6+
def test_ActivationCount_inputs():
7+
input_map = dict(
8+
ignore_exception=dict(
9+
deprecated='1.0.0',
10+
nohash=True,
11+
usedefault=True,
12+
),
13+
in_files=dict(mandatory=True, ),
14+
threshold=dict(mandatory=True, ),
15+
)
16+
inputs = ActivationCount.input_spec()
17+
18+
for key, metadata in list(input_map.items()):
19+
for metakey, value in list(metadata.items()):
20+
assert getattr(inputs.traits()[key], metakey) == value
21+
def test_ActivationCount_outputs():
22+
output_map = dict(
23+
acm_neg=dict(),
24+
acm_pos=dict(),
25+
out_file=dict(),
26+
)
27+
outputs = ActivationCount.output_spec()
28+
29+
for key, metadata in list(output_map.items()):
30+
for metakey, value in list(metadata.items()):
31+
assert getattr(outputs.traits()[key], metakey) == value

nipype/algorithms/tests/test_auto_ArtifactDetect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def test_ArtifactDetect_inputs():
1212
nohash=True,
1313
usedefault=True,
1414
),
15-
intersect_mask=dict(),
15+
intersect_mask=dict(usedefault=True, ),
1616
mask_file=dict(),
1717
mask_threshold=dict(),
1818
mask_type=dict(mandatory=True, ),

nipype/algorithms/tests/test_auto_MeshWarpMaths.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ def test_MeshWarpMaths_inputs():
1313
),
1414
in_surf=dict(mandatory=True, ),
1515
operation=dict(usedefault=True, ),
16-
operator=dict(mandatory=True, ),
16+
operator=dict(
17+
mandatory=True,
18+
usedefault=True,
19+
),
1720
out_file=dict(usedefault=True, ),
1821
out_warp=dict(usedefault=True, ),
1922
)

nipype/algorithms/tests/test_stats.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# -*- coding: utf-8 -*-
2+
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
3+
# vi: set ft=python sts=4 ts=4 sw=4 et:
4+
5+
import numpy as np
6+
import nibabel as nb
7+
from nipype.algorithms.stats import ActivationCount
8+
import pytest
9+
10+
11+
def test_ActivationCount(tmpdir):
12+
tmpdir.chdir()
13+
in_files = ['{:d}.nii'.format(i) for i in range(3)]
14+
for fname in in_files:
15+
nb.Nifti1Image(np.random.normal(size=(5, 5, 5)),
16+
np.eye(4)).to_filename(fname)
17+
18+
acm = ActivationCount(in_files=in_files, threshold=1.65)
19+
res = acm.run()
20+
diff = nb.load(res.outputs.out_file)
21+
pos = nb.load(res.outputs.acm_pos)
22+
neg = nb.load(res.outputs.acm_neg)
23+
assert np.allclose(diff.get_data(), pos.get_data() - neg.get_data())
24+
25+
26+
@pytest.mark.parametrize("threshold, above_thresh", [
27+
(1, 15.865), # above one standard deviation (one side)
28+
(2, 2.275), # above two standard deviations (one side)
29+
(3, 0.135) # above three standard deviations (one side)
30+
])
31+
def test_ActivationCount_normaldistr(tmpdir, threshold, above_thresh):
32+
tmpdir.chdir()
33+
in_files = ['{:d}.nii'.format(i) for i in range(3)]
34+
for fname in in_files:
35+
nb.Nifti1Image(np.random.normal(size=(100, 100, 100)),
36+
np.eye(4)).to_filename(fname)
37+
38+
acm = ActivationCount(in_files=in_files, threshold=threshold)
39+
res = acm.run()
40+
pos = nb.load(res.outputs.acm_pos)
41+
neg = nb.load(res.outputs.acm_neg)
42+
assert np.isclose(pos.get_data().mean(),
43+
above_thresh * 1.e-2, rtol=0.1, atol=1.e-4)
44+
assert np.isclose(neg.get_data().mean(),
45+
above_thresh * 1.e-2, rtol=0.1, atol=1.e-4)

nipype/interfaces/afni/preprocess.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,7 @@ class OutlierCountInputSpec(CommandLineInputSpec):
16061606
value=1e-3,
16071607
low=0.0,
16081608
high=1.0,
1609+
usedefault=True,
16091610
argstr='-qthr %.5f',
16101611
desc='indicate a value for q to compute alpha')
16111612
autoclip = traits.Bool(
@@ -1675,7 +1676,7 @@ class OutlierCount(CommandLine):
16751676
>>> toutcount = afni.OutlierCount()
16761677
>>> toutcount.inputs.in_file = 'functional.nii'
16771678
>>> toutcount.cmdline # doctest: +ELLIPSIS
1678-
'3dToutcount functional.nii'
1679+
'3dToutcount -qthr 0.00100 functional.nii'
16791680
>>> res = toutcount.run() # doctest: +SKIP
16801681
16811682
"""

nipype/interfaces/afni/tests/test_auto_Cat.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def test_Cat_inputs():
3838
argstr='> %s',
3939
mandatory=True,
4040
position=-1,
41+
usedefault=True,
4142
),
4243
out_fint=dict(
4344
argstr='-f',

0 commit comments

Comments
 (0)