Skip to content

Commit d94625b

Browse files
committed
Merge remote-tracking branch 'nipy/master'
2 parents 1c27d99 + 0bb9561 commit d94625b

Some content is hidden

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

42 files changed

+3606
-477
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ install:
3131
- conda update --all -y python=$TRAVIS_PYTHON_VERSION
3232
# - if [[ "${INSTALL_DEB_DEPENDECIES}" == "true" && ${TRAVIS_PYTHON_VERSION:0:1} == "2" ]]; then
3333
# conda install -y vtk mayavi; fi
34-
- conda install -y nipype
34+
- conda install -y nipype matplotlib nitime
3535
- pip install python-coveralls coverage doctest-ignore-unicode
3636
- if [ ! -z "$DUECREDIT_ENABLE"]; then pip install duecredit; fi
3737
- rm -r /home/travis/miniconda/lib/python${TRAVIS_PYTHON_VERSION}/site-packages/nipype*
@@ -43,7 +43,7 @@ install:
4343
script:
4444
- python -W once:FSL:UserWarning:nipype `which nosetests` --with-doctest --with-doctest-ignore-unicode --with-cov --cover-package nipype --logging-level=DEBUG --verbosity=3
4545
after_success:
46-
- coveralls --config_file ${COVERAGE_PROCESS_START}
46+
- bash <(curl -s https://codecov.io/bash) -t ac172a50-8e66-42e5-8822-5373fcf54686 -cF unittests
4747
deploy:
4848
provider: pypi
4949
user: satra

CHANGES

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Upcoming release 0.13
22
=====================
33

4+
* ENH: Add a DVARS calculation interface (https://github.com/nipy/nipype/pull/1606)
5+
* ENH: Convenient load/save of interface inputs (https://github.com/nipy/nipype/pull/1591)
6+
* ENH: Add a Framewise Displacement calculation interface (https://github.com/nipy/nipype/pull/1604)
47
* FIX: Use builtins open and unicode literals for py3 compatibility (https://github.com/nipy/nipype/pull/1572)
58
* TST: reduce the size of docker images & use tags for images (https://github.com/nipy/nipype/pull/1564)
69
* ENH: Implement missing inputs/outputs in FSL AvScale (https://github.com/nipy/nipype/pull/1563)

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ NIPYPE: Neuroimaging in Python: Pipelines and Interfaces
88
.. image:: https://circleci.com/gh/nipy/nipype/tree/master.svg?style=svg
99
:target: https://circleci.com/gh/nipy/nipype/tree/master
1010

11-
.. image:: https://coveralls.io/repos/nipy/nipype/badge.png
12-
:target: https://coveralls.io/r/nipy/nipype
11+
.. image:: https://codecov.io/gh/nipy/nipype/branch/master/graph/badge.svg
12+
:target: https://codecov.io/gh/nipy/nipype
1313

1414
.. image:: https://www.codacy.com/project/badge/182f27944c51474490b369d0a23e2f32
1515
:target: https://www.codacy.com/app/krzysztof-gorgolewski/nipy_nipype

circle.yml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ dependencies:
2525
timeout: 1600
2626
- mkdir -p ~/docker; docker save nipype/nipype_test:py27 > ~/docker/image.tar :
2727
timeout: 1600
28-
- pip install xunitmerge
2928

3029
test:
3130
override:
@@ -50,13 +49,10 @@ test:
5049

5150
post:
5251
- bash docker/circleci/teardown.sh
52+
- for xml_f in ${CIRCLE_TEST_REPORTS}/nose/coverage*.xml; do bash <(curl -s https://codecov.io/bash) -f $xml_f -t ac172a50-8e66-42e5-8822-5373fcf54686 -F unittests; done
53+
- for xml_f in ${CIRCLE_TEST_REPORTS}/nose/smoketest*.xml; do bash <(curl -s https://codecov.io/bash) -f $xml_f -t ac172a50-8e66-42e5-8822-5373fcf54686 -F smoketests; done
5354

5455
general:
5556
artifacts:
5657
- "~/docs"
5758
- "~/logs"
58-
- "~/coverage_py27.xml"
59-
- "~/coverage_py35.xml"
60-
- "~/nosetests_py27.xml"
61-
- "~/nosetests_py35.xml"
62-
- "~/scratch"

codecov.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
coverage:
2+
range: "0...100"
3+
status:
4+
project:
5+
default:
6+
target: 0
7+
threshold: 100
8+
patch:
9+
target: 0
10+
threshold: 100
11+
unittests:
12+
target: 0
13+
threshold: 100
14+
flags:
15+
- "unittests"
16+
smoketests:
17+
target: 0
18+
threshold: 100
19+
flags:
20+
- "smoketests"

doc/users/interface_tutorial.rst

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@
44
Tutorial : Interfaces
55
=======================
66

7-
Specifying options
8-
------------------
7+
Specifying input settings
8+
-------------------------
99

1010
The nipype interface modules provide a Python interface to external
1111
packages like FSL_ and SPM_. Within the module are a series of Python
1212
classes which wrap specific package functionality. For example, in
1313
the fsl module, the class :class:`nipype.interfaces.fsl.Bet` wraps the
1414
``bet`` command-line tool. Using the command-line tool, one would
15-
specify options using flags like ``-o``, ``-m``, ``-f <f>``, etc...
15+
specify input settings using flags like ``-o``, ``-m``, ``-f <f>``, etc...
1616
However, in nipype, options are assigned to Python attributes and can
1717
be specified in the following ways:
1818

19-
Options can be assigned when you first create an interface object:
19+
Settings can be assigned when you first create an interface object:
2020

2121
.. testcode::
2222

2323
import nipype.interfaces.fsl as fsl
2424
mybet = fsl.BET(in_file='foo.nii', out_file='bar.nii')
2525
result = mybet.run()
2626

27-
Options can be assigned through the ``inputs`` attribute:
27+
Settings can be assigned through the ``inputs`` attribute:
2828

2929
.. testcode::
3030

@@ -34,14 +34,53 @@ Options can be assigned through the ``inputs`` attribute:
3434
mybet.inputs.out_file = 'bar.nii'
3535
result = mybet.run()
3636

37-
Options can be assigned when calling the ``run`` method:
37+
Settings can be assigned when calling the ``run`` method:
3838

3939
.. testcode::
4040

4141
import nipype.interfaces.fsl as fsl
4242
mybet = fsl.BET()
4343
result = mybet.run(in_file='foo.nii', out_file='bar.nii', frac=0.5)
4444

45+
Settings can be saved to a json file:
46+
47+
.. testcode::
48+
49+
import nipype.interfaces.fsl as fsl
50+
mybet = fsl.BET(in_file='foo.nii', out_file='bar.nii', frac=0.5)
51+
mybet.save_inputs_to_json('bet-settings.json')
52+
53+
Once saved, the three inputs set for ``mybet`` will be stored in a JSON
54+
file. These settings can also be loaded from a json file:
55+
56+
.. testcode::
57+
58+
import nipype.interfaces.fsl as fsl
59+
mybet = fsl.BET()
60+
mybet.load_inputs_from_json('bet-settings.json', overwrite=False)
61+
62+
63+
Loading settings will overwrite previously set inputs by default, unless
64+
the ``overwrite`` argument is ``False``. Conveniently, the settings can be
65+
also read during the interface instantiation:
66+
67+
.. testcode::
68+
69+
import nipype.interfaces.fsl as fsl
70+
mybet = fsl.BET(from_file='bet-settings.json')
71+
72+
If the user provides settings during interface creation, they will take
73+
precedence over those loaded using ``from_file``:
74+
75+
.. testcode::
76+
77+
import nipype.interfaces.fsl as fsl
78+
mybet = fsl.BET(from_file='bet-settings.json', frac=0.7)
79+
80+
In this case, ``mybet.inputs.frac`` will contain the value ``0.7`` regardless
81+
the value that could be stored in the ``bet-settings.json`` file.
82+
83+
4584
Getting Help
4685
------------
4786

docker/circleci/run_examples.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ echo 'filemanip_level = DEBUG' >> /root/.nipype/nipype.cfg
1111
echo 'log_to_file = true' >> /root/.nipype/nipype.cfg
1212
echo 'log_directory = /scratch/logs/' >> /root/.nipype/nipype.cfg
1313

14-
python /root/src/nipype/tools/run_examples.py $@
14+
coverage run /root/src/nipype/tools/run_examples.py $@
15+
arr=$@
16+
tmp_var=$( IFS=$' '; echo "${arr[*]}" )
17+
coverage xml -o "/scratch/smoketest_${tmp_var//[^A-Za-z0-9_-]/_}.xml"
1518

16-
chmod 777 -R /scratch/logs
19+
chmod 777 -R /scratch/logs

docker/circleci/teardown.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@ set -u
77
set -e
88

99
mkdir -p ${CIRCLE_TEST_REPORTS}/nose
10-
xunitmerge ~/scratch/nosetests*.xml ${CIRCLE_TEST_REPORTS}/nose/${CIRCLE_PROJECT_REPONAME}.xml
11-
sudo mv ~/scratch/coverage*.xml ~/
10+
sudo mv ~/scratch/*.xml ${CIRCLE_TEST_REPORTS}/nose
1211
mkdir -p ~/docs
1312
sudo mv ~/scratch/docs/* ~/docs/
1413
mkdir -p ~/logs
1514
sudo mv ~/scratch/builddocs.log ~/logs/builddocs.log
16-
sudo mv ~/scratch/logs/* ~/logs/
15+
sudo mv ~/scratch/logs/* ~/logs/

examples/README

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
A dataset for use with these scripts can be downloaded from the nipype
22
website. At the time of writing, it's at:
33

4-
http://nipy.org/nipype/users/pipeline_tutorial.html
4+
http://nipype.readthedocs.io/en/0.12.0/users/pipeline_tutorial.html

examples/rsfmri_vol_surface_preprocessing_nipy.py

Lines changed: 8 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@
5252
from nipype.interfaces.base import CommandLine
5353
CommandLine.set_default_terminal_output('allatonce')
5454

55+
# https://github.com/moloney/dcmstack
5556
from dcmstack.extract import default_extractor
57+
# pip install pydicom
5658
from dicom import read_file
5759

5860
from nipype.interfaces import (fsl, Function, ants, freesurfer, nipy)
@@ -64,6 +66,7 @@
6466

6567
from nipype.algorithms.rapidart import ArtifactDetect
6668
from nipype.algorithms.misc import TSNR
69+
from nipype.algorithms.compcor import ACompCor
6770
from nipype.interfaces.utility import Rename, Merge, IdentityInterface
6871
from nipype.utils.filemanip import filename_to_list
6972
from nipype.interfaces.io import DataSink, FreeSurferSource
@@ -228,51 +231,6 @@ def build_filter1(motion_params, comp_norm, outliers, detrend_poly=None):
228231
out_files.append(filename)
229232
return out_files
230233

231-
232-
def extract_noise_components(realigned_file, mask_file, num_components=5,
233-
extra_regressors=None):
234-
"""Derive components most reflective of physiological noise
235-
236-
Parameters
237-
----------
238-
realigned_file: a 4D Nifti file containing realigned volumes
239-
mask_file: a 3D Nifti file containing white matter + ventricular masks
240-
num_components: number of components to use for noise decomposition
241-
extra_regressors: additional regressors to add
242-
243-
Returns
244-
-------
245-
components_file: a text file containing the noise components
246-
"""
247-
imgseries = nb.load(realigned_file)
248-
components = None
249-
for filename in filename_to_list(mask_file):
250-
mask = nb.load(filename).get_data()
251-
if len(np.nonzero(mask > 0)[0]) == 0:
252-
continue
253-
voxel_timecourses = imgseries.get_data()[mask > 0]
254-
voxel_timecourses[np.isnan(np.sum(voxel_timecourses, axis=1)), :] = 0
255-
# remove mean and normalize by variance
256-
# voxel_timecourses.shape == [nvoxels, time]
257-
X = voxel_timecourses.T
258-
stdX = np.std(X, axis=0)
259-
stdX[stdX == 0] = 1.
260-
stdX[np.isnan(stdX)] = 1.
261-
stdX[np.isinf(stdX)] = 1.
262-
X = (X - np.mean(X, axis=0)) / stdX
263-
u, _, _ = sp.linalg.svd(X, full_matrices=False)
264-
if components is None:
265-
components = u[:, :num_components]
266-
else:
267-
components = np.hstack((components, u[:, :num_components]))
268-
if extra_regressors:
269-
regressors = np.genfromtxt(extra_regressors)
270-
components = np.hstack((components, regressors))
271-
components_file = os.path.join(os.getcwd(), 'noise_components.txt')
272-
np.savetxt(components_file, components, fmt=b"%.10f")
273-
return components_file
274-
275-
276234
def rename(in_files, suffix=None):
277235
from nipype.utils.filemanip import (filename_to_list, split_filename,
278236
list_to_filename)
@@ -592,7 +550,7 @@ def create_workflow(files,
592550
realign.inputs.slice_info = 2
593551
realign.plugin_args = {'sbatch_args': '-c%d' % 4}
594552

595-
# Comute TSNR on realigned data regressing polynomials upto order 2
553+
# Compute TSNR on realigned data regressing polynomials up to order 2
596554
tsnr = MapNode(TSNR(regress_poly=2), iterfield=['in_file'], name='tsnr')
597555
wf.connect(realign, "out_file", tsnr, "in_file")
598556

@@ -694,14 +652,10 @@ def merge_files(in1, in2):
694652
filter1, 'out_res_name')
695653
wf.connect(createfilter1, 'out_files', filter1, 'design')
696654

697-
createfilter2 = MapNode(Function(input_names=['realigned_file', 'mask_file',
698-
'num_components',
699-
'extra_regressors'],
700-
output_names=['out_files'],
701-
function=extract_noise_components,
702-
imports=imports),
655+
createfilter2 = MapNode(ACompCor(),
703656
iterfield=['realigned_file', 'extra_regressors'],
704657
name='makecompcorrfilter')
658+
createfilter2.inputs.components_file = 'noise_components.txt'
705659
createfilter2.inputs.num_components = num_components
706660

707661
wf.connect(createfilter1, 'out_files', createfilter2, 'extra_regressors')
@@ -717,7 +671,7 @@ def merge_files(in1, in2):
717671
wf.connect(filter1, 'out_res', filter2, 'in_file')
718672
wf.connect(filter1, ('out_res', rename, '_cleaned'),
719673
filter2, 'out_res_name')
720-
wf.connect(createfilter2, 'out_files', filter2, 'design')
674+
wf.connect(createfilter2, 'components_file', filter2, 'design')
721675
wf.connect(mask, 'mask_file', filter2, 'mask')
722676

723677
bandpass = Node(Function(input_names=['files', 'lowpass_freq',
@@ -923,7 +877,7 @@ def get_names(files, suffix):
923877
wf.connect(smooth, 'out_file', datasink, 'resting.timeseries.@smoothed')
924878
wf.connect(createfilter1, 'out_files',
925879
datasink, 'resting.regress.@regressors')
926-
wf.connect(createfilter2, 'out_files',
880+
wf.connect(createfilter2, 'components_file',
927881
datasink, 'resting.regress.@compcorr')
928882
wf.connect(maskts, 'out_file', datasink, 'resting.timeseries.target')
929883
wf.connect(sampleaparc, 'summary_file',

0 commit comments

Comments
 (0)