Skip to content

Commit ea3d325

Browse files
committed
Merge pull request #187 from matthew-brett/py25-compat
RF: making code compatible with python 2.5 Adding ``__future__`` import for with_statement. Making relative imports specific (avoiding from .something import *) Some general cleanup of nipy/labs/bindings/tests/test_numpy.py Two instances of kwargs after *args changed to use **kwargs.
2 parents 7821a24 + 0caed3a commit ea3d325

File tree

16 files changed

+69
-31
lines changed

16 files changed

+69
-31
lines changed

nipy/algorithms/graph/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
3-
from .graph import *
3+
from .graph import (Graph, WeightedGraph, wgraph_from_coo_matrix,
4+
wgraph_from_adjacency, complete_graph, mst, knn, eps_nn,
5+
lil_cc, graph_3d_grid, wgraph_from_3d_grid,
6+
concatenate_graphs)
47

58
from nipy.testing import Tester
69
test = Tester().test
7-
bench = Tester().bench
10+
bench = Tester().bench

nipy/algorithms/registration/__init__.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
3-
from .resample import *
4-
from .histogram_registration import *
5-
from .affine import *
6-
from .groupwise_registration import *
3+
from .resample import resample
4+
from .histogram_registration import (HistogramRegistration, clamp,
5+
ideal_spacing, interp_methods)
6+
from .affine import (threshold, rotation_mat2vec, rotation_vec2mat, matrix44,
7+
preconditioner, inverse_affine, subgrid_affine, Affine,
8+
Affine2D, Rigid, Rigid2D, Similarity, Similarity2D,
9+
affine_transforms)
10+
from .groupwise_registration import (interp_slice_order, scanner_coords,
11+
make_grid, Image4d, Realign4dAlgorithm,
12+
resample4d, adjust_subsampling,
13+
single_run_realign4d, realign4d, Realign4d,
14+
FmriRealign4d)
715

816
from nipy.testing import Tester
917
test = Tester().test
1018
bench = Tester().bench
11-

nipy/algorithms/registration/histogram_registration.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,8 @@ def callback(tc):
282282
# Output
283283
if VERBOSE:
284284
print ('Optimizing using %s' % fmin.__name__)
285-
Tv.param = fmin(cost, tc0, *args, callback=callback, **kwargs)
285+
kwargs['callback'] = callback
286+
Tv.param = fmin(cost, tc0, *args, **kwargs)
286287
return Tv.optimizable
287288

288289
def explore(self, T0, *args):

nipy/algorithms/segmentation/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from .brain_segmentation import *
2-
from .vem import *
1+
from .brain_segmentation import (initialize_parameters, brain_segmentation)
2+
from .vem import (gauss_dist, laplace_dist, vm_step_gauss, weighted_median,
3+
vm_step_laplace, VEM)
34

45
from nipy.testing import Tester
56
test = Tester().test

nipy/core/reference/coordinate_map.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1641,9 +1641,9 @@ def function(x):
16411641
return yy
16421642

16431643
incoords = coordsys_product(*[cmap.function_domain for cmap in cmaps],
1644-
name = input_name)
1644+
**{'name': input_name})
16451645
outcoords = coordsys_product(*[cmap.function_range for cmap in cmaps],
1646-
name = output_name)
1646+
**{'name': output_name})
16471647
return CoordinateMap(incoords, outcoords, function)
16481648

16491649

nipy/io/tests/test_image_io.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
3+
from __future__ import with_statement
34

45
import numpy as np
56

nipy/io/tests/test_save.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
3+
from __future__ import with_statement
4+
35
import numpy as np
46

57
from nibabel.affines import from_matvec

nipy/labs/bindings/benchmarks/bench_numpy.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import numpy as np
66

7-
from ....testing import *
87
from .. import copy_vector
98

109

nipy/labs/bindings/tests/test_numpy.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,15 @@
33
# Test numpy bindings
44

55
import numpy as np
6-
from ....testing import *
7-
from .. import (c_types, fff_type, npy_type, copy_vector,
8-
pass_vector, pass_vector_via_iterator)
96

7+
from .. import (c_types, fff_type, npy_type, copy_vector, pass_matrix,
8+
pass_vector, pass_array, pass_vector_via_iterator,
9+
sum_via_iterators, copy_via_iterators)
1010

1111

12+
from nose.tools import assert_equal
13+
from numpy.testing import assert_almost_equal, assert_array_equal
14+
1215
MAX_TEST_SIZE = 30
1316
def random_shape(size):
1417
"""
@@ -20,7 +23,6 @@ def random_shape(size):
2023
else:
2124
return tuple(aux)
2225

23-
2426

2527
#
2628
# Test type conversions
@@ -80,17 +82,20 @@ def test_copy_vector_uint8():
8082

8183
def _test_pass_vector(x):
8284
y = pass_vector(x)
83-
assert_equal(y, x)
85+
assert_array_equal(y, x)
86+
8487

8588
def test_pass_vector():
8689
x = np.random.rand(random_shape(1))-.5
8790
_test_pass_vector(x)
8891

89-
def test_pass_vector_int32():
92+
93+
def test_pass_vector_int32():
9094
x = (1000*(np.random.rand(random_shape(1))-.5)).astype('int32')
9195
_test_pass_vector(x)
9296

93-
def test_pass_vector_uint8():
97+
98+
def test_pass_vector_uint8():
9499
x = (256*(np.random.rand(random_shape(1)))).astype('uint8')
95100
_test_pass_vector(x)
96101

@@ -101,16 +106,19 @@ def _test_pass_matrix(x):
101106
y = pass_matrix(x.T)
102107
yield assert_equal, y, x.T
103108

109+
104110
def test_pass_matrix():
105111
d0, d1 = random_shape(2)
106112
x = np.random.rand(d0, d1)-.5
107113
_test_pass_matrix(x)
108114

115+
109116
def test_pass_matrix_int32():
110117
d0, d1 = random_shape(2)
111118
x = (1000*(np.random.rand(d0, d1)-.5)).astype('int32')
112119
_test_pass_matrix(x)
113120

121+
114122
def test_pass_matrix_uint8():
115123
d0, d1 = random_shape(2)
116124
x = (256*(np.random.rand(d0, d1))).astype('uint8')
@@ -123,23 +131,24 @@ def _test_pass_array(x):
123131
y = pass_array(x.T)
124132
yield assert_equal, y, x.T
125133

134+
126135
def test_pass_array():
127136
d0, d1, d2, d3 = random_shape(4)
128137
x = np.random.rand(d0, d1, d2, d3)-.5
129138
_test_pass_array(x)
130139

140+
131141
def test_pass_array_int32():
132142
d0, d1, d2, d3 = random_shape(4)
133143
x = (1000*(np.random.rand(d0, d1, d2, d3)-.5)).astype('int32')
134144
_test_pass_array(x)
135145

146+
136147
def test_pass_array_uint8():
137148
d0, d1, d2, d3 = random_shape(4)
138149
x = (256*(np.random.rand(d0, d1, d2, d3))).astype('uint8')
139150
_test_pass_array(x)
140151

141-
142-
143152
#
144153
# Multi-iterator testing
145154
#
@@ -155,31 +164,37 @@ def _test_pass_vector_via_iterator(X, pos=0):
155164
x = pass_vector_via_iterator(X, axis=1, niters=pos)
156165
yield assert_equal, x, X[pos, :]
157166

167+
158168
def test_pass_vector_via_iterator():
159169
d0, d1 = random_shape(2)
160170
X = np.random.rand(d0, d1)-.5
161171
_test_pass_vector_via_iterator(X)
162172

173+
163174
def test_pass_vector_via_iterator_int32():
164175
d0, d1 = random_shape(2)
165176
X = (1000*(np.random.rand(d0, d1)-.5)).astype('int32')
166177
_test_pass_vector_via_iterator(X)
167178

179+
168180
def test_pass_vector_via_iterator_uint8():
169181
d0, d1 = random_shape(2)
170182
X = (100*(np.random.rand(d0, d1))).astype('uint8')
171183
_test_pass_vector_via_iterator(X)
172184

185+
173186
def test_pass_vector_via_iterator_shift():
174187
d0, d1 = random_shape(2)
175188
X = np.random.rand(d0, d1)-.5
176189
_test_pass_vector_via_iterator(X, pos=1)
177190

191+
178192
def test_pass_vector_via_iterator_shift_int32():
179193
d0, d1 = random_shape(2)
180194
X = (1000*(np.random.rand(d0, d1)-.5)).astype('int32')
181195
_test_pass_vector_via_iterator(X, pos=1)
182196

197+
183198
def test_pass_vector_via_iterator_shift_uint8():
184199
d0, d1 = random_shape(2)
185200
X = (100*(np.random.rand(d0, d1))).astype('uint8')
@@ -193,45 +208,51 @@ def _test_copy_via_iterators(Y):
193208
ZT = copy_via_iterators(Y.T, axis)
194209
yield assert_equal, ZT, Y.T
195210

211+
196212
def test_copy_via_iterators():
197213
d0, d1, d2, d3 = random_shape(4)
198214
Y = np.random.rand(d0, d1, d2, d3)
199215
_test_copy_via_iterators(Y)
200216

217+
201218
def test_copy_via_iterators_int32():
202219
d0, d1, d2, d3 = random_shape(4)
203220
Y = (1000*(np.random.rand(d0, d1, d2, d3)-.5)).astype('int32')
204221
_test_copy_via_iterators(Y)
205222

223+
206224
def test_copy_via_iterators_uint8():
207225
d0, d1, d2, d3 = random_shape(4)
208226
Y = (256*(np.random.rand(d0, d1, d2, d3))).astype('uint8')
209227
_test_copy_via_iterators(Y)
210228

229+
211230
def _test_sum_via_iterators(Y):
212231
for axis in range(4):
213232
Z = sum_via_iterators(Y, axis)
214233
yield assert_almost_equal, Z, Y.sum(axis)
215234
ZT = sum_via_iterators(Y.T, axis)
216235
yield assert_almost_equal, ZT, Y.T.sum(axis)
217236

237+
218238
def test_sum_via_iterators():
219239
d0, d1, d2, d3 = random_shape(4)
220240
Y = np.random.rand(d0, d1, d2, d3)
221241
_test_sum_via_iterators(Y)
222242

243+
223244
def test_sum_via_iterators_int32():
224245
d0, d1, d2, d3 = random_shape(4)
225246
Y = (1000*(np.random.rand(d0, d1, d2, d3)-.5)).astype('int32')
226247
_test_sum_via_iterators(Y)
227248

249+
228250
def test_sum_via_iterators_uint8():
229251
d0, d1, d2, d3 = random_shape(4)
230252
Y = (256*(np.random.rand(d0, d1, d2, d3))).astype('uint8')
231253
_test_sum_via_iterators(Y)
232-
254+
233255

234256
if __name__ == "__main__":
235257
import nose
236258
nose.run(argv=['', __file__])
237-

nipy/labs/glm/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
22
# vi: set ft=python sts=4 ts=4 sw=4 et:
3-
from .glm import *
3+
from .glm import models, contrast, ols, load
44

55
from nipy.testing import Tester
66
test = Tester().test

0 commit comments

Comments
 (0)