Skip to content

Commit 34bf558

Browse files
committed
Merge branch 'master' of github.com:poldracklab/nitransforms into sty/pep8
2 parents c7c38e7 + 221a43a commit 34bf558

File tree

4 files changed

+31
-23
lines changed

4 files changed

+31
-23
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# vim ft=yaml
22
language: python
33
python:
4-
# - 2.7
54
- 3.5
65
- 3.6
76
- 3.7
@@ -10,4 +9,4 @@ install:
109
- pip install -U -e .[test]
1110

1211
script:
13-
- pytest --doctest-modules nitransforms
12+
- pytest -v --doctest-modules nitransforms

nitransforms/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
from .nonlinear import DeformationFieldTransform
2121

2222

23-
__all__ = ['Affine', 'DeformationFieldTransform']
23+
__all__ = ['Affine', 'DeformationFieldTransform']

nitransforms/nonlinear.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(self, field, reference=None):
2929
self._field = field.get_data()
3030

3131
ndim = self._field.ndim - 1
32-
if self._field.shape[:-1] != ndim:
32+
if len(self._field.shape[:-1]) != ndim:
3333
raise ValueError(
3434
'Number of components of the deformation field does '
3535
'not match the number of dimensions')
@@ -116,7 +116,7 @@ def resample(self, moving, order=3, mode='constant', cval=0.0, prefilter=True,
116116
>>> field = np.zeros(tuple(list(ref.shape) + [3]))
117117
>>> field[..., 0] = 4.0
118118
>>> fieldimg = nb.Nifti1Image(field, ref.affine, ref.header)
119-
>>> xfm = DeformationFieldTransform(fieldimg)
119+
>>> xfm = DeformationFieldTransform(fieldimg)
120120
>>> resampled = xfm.resample(moving, order=0).get_fdata()
121121
>>> resampled[1, 5, 5]
122122
1.0
@@ -241,7 +241,7 @@ def resample(self, moving, order=3, mode='constant', cval=0.0, prefilter=True,
241241
... ref.header.get_zooms()[:3]) / 6.0
242242
... )
243243
>>> coeffsimg = nb.Nifti1Image(coeffs, ref.affine, ref.header)
244-
>>> xfm = BSplineFieldTransform(ref, coeffsimg)
244+
>>> xfm = BSplineFieldTransform(ref, coeffsimg) # doctest: +SKIP
245245
>>> new = xfm.resample(ref) # doctest: +SKIP
246246
247247
"""

nitransforms/tests/test_transform.py

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66
import numpy as np
77
from subprocess import check_call
8+
import shutil
89

910
import nibabel as nb
1011
from nibabel.eulerangles import euler2mat
@@ -30,6 +31,7 @@
3031
}
3132

3233

34+
@pytest.mark.xfail(reason="Not fully implemented")
3335
@pytest.mark.parametrize('image_orientation', [
3436
'RAS', 'LAS', 'LPS', # 'oblique',
3537
])
@@ -52,25 +54,26 @@ def test_linear_load(tmpdir, data_path, get_data, image_orientation, sw_tool):
5254

5355
fname = 'affine-%s.%s%s' % (image_orientation, sw_tool, ext)
5456
xfm_fname = os.path.join(data_path, fname)
57+
fmt = fname.split('.')[-1]
5558

5659
if sw_tool == 'fsl':
57-
with pytest.raises("ValueError"):
58-
loaded = nbl.load(xfm_fname, fmt=fname.split('.')[-1])
59-
with pytest.raises("ValueError"):
60-
loaded = nbl.load(xfm_fname, fmt=fname.split('.')[-1],
61-
reference='img.nii.gz')
62-
with pytest.raises("ValueError"):
63-
loaded = nbl.load(xfm_fname, fmt=fname.split('.')[-1],
64-
moving='img.nii.gz')
65-
66-
loaded = nbl.load(xfm_fname, fmt=fname.split('.')[-1],
67-
moving='img.nii.gz', reference='img.nii.gz')
68-
if sw_tool == 'afni':
69-
with pytest.raises("ValueError"):
70-
loaded = nbl.load(xfm_fname, fmt=fname.split('.')[-1])
71-
72-
loaded = nbl.load(xfm_fname, fmt=fname.split('.')[-1],
73-
reference='img.nii.gz')
60+
with pytest.raises(ValueError):
61+
loaded = nbl.load(xfm_fname, fmt=fmt)
62+
with pytest.raises(ValueError):
63+
loaded = nbl.load(xfm_fname, fmt=fmt, reference='img.nii.gz')
64+
with pytest.raises(ValueError):
65+
loaded = nbl.load(xfm_fname, fmt=fmt, moving='img.nii.gz')
66+
67+
loaded = nbl.load(
68+
xfm_fname, fmt=fmt, moving='img.nii.gz', reference='img.nii.gz'
69+
)
70+
elif sw_tool == 'afni':
71+
with pytest.raises(ValueError):
72+
loaded = nbl.load(xfm_fname, fmt=fmt)
73+
74+
loaded = nbl.load(xfm_fname, fmt=fmt, reference='img.nii.gz')
75+
elif sw_tool == 'itk':
76+
loaded = nbl.load(xfm_fname, fmt=fmt)
7477

7578
assert loaded == xfm
7679

@@ -132,6 +135,12 @@ def test_apply_linear_transform(
132135
transform=os.path.abspath(xfm_fname),
133136
reference=os.path.abspath('img.nii.gz'),
134137
moving=os.path.abspath('img.nii.gz'))
138+
139+
# skip test if command is not available on host
140+
exe = cmd.split(" ", 1)[0]
141+
if not shutil.which(exe):
142+
pytest.skip("Command {} not found on host".format(exe))
143+
135144
exit_code = check_call([cmd], shell=True)
136145
assert exit_code == 0
137146
sw_moved = nb.load('resampled.nii.gz')

0 commit comments

Comments
 (0)