Skip to content

Commit 126831e

Browse files
author
jakubk
committed
Merge remote-tracking branch 'upstream/master' into enh/circleci-neurodocker
2 parents 399fe16 + ca91455 commit 126831e

File tree

127 files changed

+994
-987
lines changed

Some content is hidden

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

127 files changed

+994
-987
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Upcoming release (0.14.0)
22
================
33

4+
* FIX: Testing maintainance and improvements (https://github.com/nipy/nipype/pull/2252)
45
* ENH: Add elapsed_time and final metric_value to ants.Registration (https://github.com/nipy/nipype/pull/1985)
56
* ENH: Improve terminal_output feature (https://github.com/nipy/nipype/pull/2209)
67
* ENH: Simple interface to FSL std2imgcoords (https://github.com/nipy/nipype/pull/2209, prev #1398)

conftest.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import pytest
2+
import numpy, os
3+
4+
@pytest.fixture(autouse=True)
5+
def add_np(doctest_namespace):
6+
doctest_namespace['np'] = numpy
7+
doctest_namespace['os'] = os
8+
9+
10+
filepath = os.path.dirname(os.path.realpath(__file__))
11+
datadir = os.path.realpath(os.path.join(filepath, 'nipype/testing/data'))
12+
doctest_namespace["datadir"] = datadir

nipype/algorithms/confounds.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
from ..utils import NUMPY_MMAP
3131
from ..utils.misc import normalize_mc_params
3232

33-
IFLOG = logging.getLogger('interface')
33+
IFLOGGER = logging.getLogger('interface')
3434

3535

3636
class ComputeDVARSInputSpec(BaseInterfaceInputSpec):
@@ -286,7 +286,7 @@ def _run_interface(self, runtime):
286286
tr = self.inputs.series_tr
287287

288288
if self.inputs.normalize and tr is None:
289-
IFLOG.warn('FD plot cannot be normalized if TR is not set')
289+
IFLOGGER.warn('FD plot cannot be normalized if TR is not set')
290290

291291
self._results['out_figure'] = op.abspath(self.inputs.out_figure)
292292
fig = plot_confound(fd_res, self.inputs.figsize, 'FD', units='mm',
@@ -601,8 +601,8 @@ def _process_masks(self, mask_images, timeseries=None):
601601
# save mask
602602
mask_file = os.path.abspath('mask_{:03d}.nii.gz'.format(i))
603603
out_image.to_filename(mask_file)
604-
IFLOG.debug('tCompcor computed and saved mask of shape {} to '
605-
'mask_file {}'.format(mask.shape, mask_file))
604+
IFLOGGER.debug('tCompcor computed and saved mask of shape %s to '
605+
'mask_file %s', str(mask.shape), mask_file)
606606
self._mask_files.append(mask_file)
607607
out_images.append(out_image)
608608
return out_images
@@ -919,7 +919,8 @@ def regress_poly(degree, data, remove_mean=True, axis=-1):
919919
:param int axis: numpy array axes along which regression is performed
920920
921921
"""
922-
IFLOG.debug('Performing polynomial regression on data of shape ' + str(data.shape))
922+
IFLOGGER.debug('Performing polynomial regression on data of shape %s',
923+
str(data.shape))
923924

924925
datashape = data.shape
925926
timepoints = datashape[axis]
@@ -1147,7 +1148,7 @@ def _full_rank(X, cmax=1e15):
11471148
c = smax / smin
11481149
if c < cmax:
11491150
return X, c
1150-
IFLOG.warn('Matrix is singular at working precision, regularizing...')
1151+
IFLOGGER.warn('Matrix is singular at working precision, regularizing...')
11511152
lda = (smax - cmax * smin) / (cmax - 1)
11521153
s = s + lda
11531154
X = np.dot(U, np.dot(np.diag(s), V))

nipype/algorithms/misc.py

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -362,26 +362,23 @@ def _run_interface(self, runtime):
362362
if isinstance(in_dict[key][0], np.ndarray):
363363
saved_variables.append(key)
364364
else:
365-
iflogger.info('One of the keys in the input file, {k}, is not a Numpy array'.format(k=key))
365+
iflogger.info('One of the keys in the input file, %s, is '
366+
'not a Numpy array', key)
366367

367368
if len(saved_variables) > 1:
368-
iflogger.info(
369-
'{N} variables found:'.format(N=len(saved_variables)))
369+
iflogger.info('%i variables found:', len(saved_variables))
370370
iflogger.info(saved_variables)
371371
for variable in saved_variables:
372-
iflogger.info(
373-
'...Converting {var} - type {ty} - to\
374-
CSV'.format(var=variable, ty=type(in_dict[variable]))
375-
)
376-
matlab2csv(
377-
in_dict[variable], variable, self.inputs.reshape_matrix)
372+
iflogger.info('...Converting %s - type %s - to CSV',
373+
variable, type(in_dict[variable]))
374+
matlab2csv(in_dict[variable], variable, self.inputs.reshape_matrix)
378375
elif len(saved_variables) == 1:
379376
_, name, _ = split_filename(self.inputs.in_file)
380377
variable = saved_variables[0]
381-
iflogger.info('Single variable found {var}, type {ty}:'.format(
382-
var=variable, ty=type(in_dict[variable])))
383-
iflogger.info('...Converting {var} to CSV from {f}'.format(
384-
var=variable, f=self.inputs.in_file))
378+
iflogger.info('Single variable found %s, type %s:', variable,
379+
type(in_dict[variable]))
380+
iflogger.info('...Converting %s to CSV from %s', variable,
381+
self.inputs.in_file)
385382
matlab2csv(in_dict[variable], name, self.inputs.reshape_matrix)
386383
else:
387384
iflogger.error('No values in the MATLAB file?!')
@@ -396,8 +393,8 @@ def _list_outputs(self):
396393
if isinstance(in_dict[key][0], np.ndarray):
397394
saved_variables.append(key)
398395
else:
399-
iflogger.error('One of the keys in the input file, {k}, is\
400-
not a Numpy array'.format(k=key))
396+
iflogger.error('One of the keys in the input file, %s, is '
397+
'not a Numpy array', key)
401398

402399
if len(saved_variables) > 1:
403400
outputs['csv_files'] = replaceext(saved_variables, '.csv')
@@ -555,28 +552,25 @@ def _run_interface(self, runtime):
555552
iflogger.info('Column headings have been provided:')
556553
headings = self.inputs.column_headings
557554
else:
558-
iflogger.info(
559-
'Column headings not provided! Pulled from input filenames:')
555+
iflogger.info('Column headings not provided! Pulled from input filenames:')
560556
headings = remove_identical_paths(self.inputs.in_files)
561557

562558
if isdefined(self.inputs.extra_field):
563559
if isdefined(self.inputs.extra_column_heading):
564560
extraheading = self.inputs.extra_column_heading
565-
iflogger.info('Extra column heading provided: {col}'.format(
566-
col=extraheading))
561+
iflogger.info('Extra column heading provided: %s', extraheading)
567562
else:
568563
extraheading = 'type'
569-
iflogger.info(
570-
'Extra column heading was not defined. Using "type"')
564+
iflogger.info('Extra column heading was not defined. Using "type"')
571565
headings.append(extraheading)
572566
extraheadingBool = True
573567

574568
if len(self.inputs.in_files) == 1:
575569
iflogger.warn('Only one file input!')
576570

577571
if isdefined(self.inputs.row_headings):
578-
iflogger.info('Row headings have been provided. Adding "labels"\
579-
column header.')
572+
iflogger.info('Row headings have been provided. Adding "labels"'
573+
'column header.')
580574
prefix = '"{p}","'.format(p=self.inputs.row_heading_title)
581575
csv_headings = prefix + '","'.join(itertools.chain(
582576
headings)) + '"\n'
@@ -1310,7 +1304,7 @@ def merge_rois(in_files, in_idxs, in_ref,
13101304
# to avoid memory errors
13111305
if op.splitext(in_ref)[1] == '.gz':
13121306
try:
1313-
iflogger.info('uncompress %i' % in_ref)
1307+
iflogger.info('uncompress %i', in_ref)
13141308
sp.check_call(['gunzip', in_ref], stdout=sp.PIPE, shell=True)
13151309
in_ref = op.splitext(in_ref)[0]
13161310
except:

nipype/algorithms/modelgen.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -374,9 +374,9 @@ def _generate_standard_design(self, infolist, functional_runs=None,
374374
for f in filename_to_list(sessinfo[i]['scans']):
375375
shape = load(f, mmap=NUMPY_MMAP).shape
376376
if len(shape) == 3 or shape[3] == 1:
377-
iflogger.warning(('You are using 3D instead of 4D '
378-
'files. Are you sure this was '
379-
'intended?'))
377+
iflogger.warning('You are using 3D instead of 4D '
378+
'files. Are you sure this was '
379+
'intended?')
380380
numscans += 1
381381
else:
382382
numscans += shape[3]
@@ -686,7 +686,7 @@ def _gen_regress(self, i_onsets, i_durations, i_amplitudes, nscans):
686686

687687
if dt < 1:
688688
raise Exception('Time multiple less than 1 ms')
689-
iflogger.info('Setting dt = %d ms\n' % dt)
689+
iflogger.info('Setting dt = %d ms\n', dt)
690690
npts = int(np.ceil(total_time / dt))
691691
times = np.arange(0, total_time, dt) * 1e-3
692692
timeline = np.zeros((npts))
@@ -705,9 +705,9 @@ def _gen_regress(self, i_onsets, i_durations, i_amplitudes, nscans):
705705
if isdefined(self.inputs.model_hrf) and self.inputs.model_hrf:
706706
response = np.convolve(boxcar, hrf)
707707
reg_scale = 1.0 / response.max()
708-
iflogger.info('response sum: %.4f max: %.4f' % (response.sum(),
709-
response.max()))
710-
iflogger.info('reg_scale: %.4f' % reg_scale)
708+
iflogger.info('response sum: %.4f max: %.4f', response.sum(),
709+
response.max())
710+
iflogger.info('reg_scale: %.4f', reg_scale)
711711

712712
for i, t in enumerate(onsets):
713713
idx = int(np.round(t / dt))

nipype/algorithms/tests/test_compcor.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@ class TestCompCor():
2121
@pytest.fixture(autouse=True)
2222
def setup_class(self, tmpdir):
2323
# setup
24-
self.temp_dir = str(tmpdir)
25-
os.chdir(self.temp_dir)
24+
tmpdir.chdir()
2625
noise = np.fromfunction(self.fake_noise_fun, self.fake_data.shape)
2726
self.realigned_file = utils.save_toy_nii(self.fake_data + noise,
2827
self.filenames['functionalnii'])

nipype/algorithms/tests/test_confounds.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121

2222
def test_fd(tmpdir):
23-
tempdir = str(tmpdir)
23+
tempdir = tmpdir.strpath
2424
ground_truth = np.loadtxt(example_data('fsl_motion_outliers_fd.txt'))
2525
fdisplacement = FramewiseDisplacement(in_file=example_data('fsl_mcflirt_movpar.txt'),
2626
out_file=tempdir + '/fd.txt',
@@ -43,7 +43,7 @@ def test_dvars(tmpdir):
4343
in_mask=example_data('ds003_sub-01_mc_brainmask.nii.gz'),
4444
save_all=True,
4545
intensity_normalization=0)
46-
os.chdir(str(tmpdir))
46+
tmpdir.chdir()
4747
res = dvars.run()
4848

4949
dv1 = np.loadtxt(res.outputs.out_all, skiprows=1)
@@ -66,7 +66,8 @@ def test_dvars(tmpdir):
6666

6767
assert (np.abs(dv1[:, 2] - ground_truth[:, 2]).sum() / len(dv1)) < 0.05
6868

69-
def test_outliers(tmpdir):
69+
70+
def test_outliers():
7071
np.random.seed(0)
7172
in_data = np.random.randn(100)
7273
in_data[0] += 10

nipype/algorithms/tests/test_errormap.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
def test_errormap(tmpdir):
1313

14-
tempdir = str(tmpdir)
1514
# Single-Spectual
1615
# Make two fake 2*2*2 voxel volumes
1716
volume1 = np.array([[[2.0, 8.0], [1.0, 2.0]], [[1.0, 9.0], [0.0, 3.0]]]) # John von Neumann's birthday
@@ -22,15 +21,15 @@ def test_errormap(tmpdir):
2221
img2 = nb.Nifti1Image(volume2, np.eye(4))
2322
maskimg = nb.Nifti1Image(mask, np.eye(4))
2423

25-
nb.save(img1, os.path.join(tempdir, 'von.nii.gz'))
26-
nb.save(img2, os.path.join(tempdir, 'alan.nii.gz'))
27-
nb.save(maskimg, os.path.join(tempdir, 'mask.nii.gz'))
24+
nb.save(img1, tmpdir.join('von.nii.gz').strpath)
25+
nb.save(img2, tmpdir.join('alan.nii.gz').strpath)
26+
nb.save(maskimg, tmpdir.join('mask.nii.gz').strpath)
2827

2928
# Default metric
3029
errmap = ErrorMap()
31-
errmap.inputs.in_tst = os.path.join(tempdir, 'von.nii.gz')
32-
errmap.inputs.in_ref = os.path.join(tempdir, 'alan.nii.gz')
33-
errmap.out_map = os.path.join(tempdir, 'out_map.nii.gz')
30+
errmap.inputs.in_tst = tmpdir.join('von.nii.gz').strpath
31+
errmap.inputs.in_ref = tmpdir.join('alan.nii.gz').strpath
32+
errmap.out_map = tmpdir.join('out_map.nii.gz').strpath
3433
result = errmap.run()
3534
assert result.outputs.distance == 1.125
3635

@@ -45,7 +44,7 @@ def test_errormap(tmpdir):
4544
assert result.outputs.distance == 0.875
4645

4746
# Masked
48-
errmap.inputs.mask = os.path.join(tempdir, 'mask.nii.gz')
47+
errmap.inputs.mask = tmpdir.join('mask.nii.gz').strpath
4948
result = errmap.run()
5049
assert result.outputs.distance == 1.0
5150

@@ -62,11 +61,11 @@ def test_errormap(tmpdir):
6261
msvolume2[:, :, :, 1] = volume1
6362
msimg2 = nb.Nifti1Image(msvolume2, np.eye(4))
6463

65-
nb.save(msimg1, os.path.join(tempdir, 'von-ray.nii.gz'))
66-
nb.save(msimg2, os.path.join(tempdir, 'alan-ray.nii.gz'))
64+
nb.save(msimg1, tmpdir.join('von-ray.nii.gz').strpath)
65+
nb.save(msimg2, tmpdir.join('alan-ray.nii.gz').strpath)
6766

68-
errmap.inputs.in_tst = os.path.join(tempdir, 'von-ray.nii.gz')
69-
errmap.inputs.in_ref = os.path.join(tempdir, 'alan-ray.nii.gz')
67+
errmap.inputs.in_tst = tmpdir.join('von-ray.nii.gz').strpath
68+
errmap.inputs.in_ref = tmpdir.join('alan-ray.nii.gz').strpath
7069
errmap.inputs.metric = 'sqeuclidean'
7170
result = errmap.run()
7271
assert result.outputs.distance == 5.5

nipype/algorithms/tests/test_mesh_ops.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@
1515

1616
@pytest.mark.skipif(VTKInfo.no_tvtk(), reason="tvtk is not installed")
1717
def test_ident_distances(tmpdir):
18-
tempdir = str(tmpdir)
19-
os.chdir(tempdir)
18+
tmpdir.chdir()
2019

2120
in_surf = example_data('surf01.vtk')
2221
dist_ident = m.ComputeMeshWarp()
2322
dist_ident.inputs.surface1 = in_surf
2423
dist_ident.inputs.surface2 = in_surf
25-
dist_ident.inputs.out_file = os.path.join(tempdir, 'distance.npy')
24+
dist_ident.inputs.out_file = tmpdir.join('distance.npy')
2625
res = dist_ident.run()
2726
assert res.outputs.distance == 0.0
2827

@@ -33,11 +32,11 @@ def test_ident_distances(tmpdir):
3332

3433
@pytest.mark.skipif(VTKInfo.no_tvtk(), reason="tvtk is not installed")
3534
def test_trans_distances(tmpdir):
36-
tempdir = str(tmpdir)
35+
tempdir = tmpdir.strpath
3736
from ...interfaces.vtkbase import tvtk
3837

3938
in_surf = example_data('surf01.vtk')
40-
warped_surf = os.path.join(tempdir, 'warped.vtk')
39+
warped_surf = tmpdir.join('warped.vtk')
4140

4241
inc = np.array([0.7, 0.3, -0.2])
4342

@@ -53,7 +52,7 @@ def test_trans_distances(tmpdir):
5352
dist = m.ComputeMeshWarp()
5453
dist.inputs.surface1 = in_surf
5554
dist.inputs.surface2 = warped_surf
56-
dist.inputs.out_file = os.path.join(tempdir, 'distance.npy')
55+
dist.inputs.out_file = tmpdir.join('distance.npy')
5756
res = dist.run()
5857
assert np.allclose(res.outputs.distance, np.linalg.norm(inc), 4)
5958
dist.inputs.weighting = 'area'
@@ -63,14 +62,14 @@ def test_trans_distances(tmpdir):
6362

6463
@pytest.mark.skipif(VTKInfo.no_tvtk(), reason="tvtk is not installed")
6564
def test_warppoints(tmpdir):
66-
os.chdir(str(tmpdir))
65+
tmpdir.chdir()
6766

6867
# TODO: include regression tests for when tvtk is installed
6968

7069

7170
@pytest.mark.skipif(VTKInfo.no_tvtk(), reason="tvtk is not installed")
7271
def test_meshwarpmaths(tmpdir):
73-
os.chdir(str(tmpdir))
72+
tmpdir.chdir()
7473

7574
# TODO: include regression tests for when tvtk is installed
7675

nipype/algorithms/tests/test_modelgen.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717

1818

1919
def test_modelgen1(tmpdir):
20-
tempdir = str(tmpdir)
21-
filename1 = os.path.join(tempdir, 'test1.nii')
22-
filename2 = os.path.join(tempdir, 'test2.nii')
20+
filename1 = tmpdir.join('test1.nii').strpath
21+
filename2 = tmpdir.join('test2.nii').strpath
2322
Nifti1Image(np.random.rand(10, 10, 10, 200), np.eye(4)).to_filename(filename1)
2423
Nifti1Image(np.random.rand(10, 10, 10, 200), np.eye(4)).to_filename(filename2)
2524
s = SpecifyModel()
@@ -56,9 +55,8 @@ def test_modelgen1(tmpdir):
5655

5756

5857
def test_modelgen_spm_concat(tmpdir):
59-
tempdir = str(tmpdir)
60-
filename1 = os.path.join(tempdir, 'test1.nii')
61-
filename2 = os.path.join(tempdir, 'test2.nii')
58+
filename1 = tmpdir.join('test1.nii').strpath
59+
filename2 = tmpdir.join('test2.nii').strpath
6260
Nifti1Image(np.random.rand(10, 10, 10, 30), np.eye(4)).to_filename(filename1)
6361
Nifti1Image(np.random.rand(10, 10, 10, 30), np.eye(4)).to_filename(filename2)
6462

@@ -97,7 +95,7 @@ def test_modelgen_spm_concat(tmpdir):
9795
npt.assert_almost_equal(np.array(res.outputs.session_info[0]['cond'][0]['onset']), np.array([2.0, 50.0, 100.0, 170.0]))
9896

9997
# Test case for variable number of events in separate runs, sometimes unique.
100-
filename3 = os.path.join(tempdir, 'test3.nii')
98+
filename3 = tmpdir.join('test3.nii').strpath
10199
Nifti1Image(np.random.rand(10, 10, 10, 30), np.eye(4)).to_filename(filename3)
102100
s.inputs.functional_runs = [filename1, filename2, filename3]
103101
info = [Bunch(conditions=['cond1', 'cond2'], onsets=[[2, 3], [2]], durations=[[1, 1], [1]]),
@@ -122,9 +120,8 @@ def test_modelgen_spm_concat(tmpdir):
122120

123121

124122
def test_modelgen_sparse(tmpdir):
125-
tempdir = str(tmpdir)
126-
filename1 = os.path.join(tempdir, 'test1.nii')
127-
filename2 = os.path.join(tempdir, 'test2.nii')
123+
filename1 = tmpdir.join('test1.nii').strpath
124+
filename2 = tmpdir.join('test2.nii').strpath
128125
Nifti1Image(np.random.rand(10, 10, 10, 50), np.eye(4)).to_filename(filename1)
129126
Nifti1Image(np.random.rand(10, 10, 10, 50), np.eye(4)).to_filename(filename2)
130127
s = SpecifySparseModel()

0 commit comments

Comments
 (0)