Skip to content

Commit ee4ce2a

Browse files
Merge pull request #591 from matthew-brett/fix-doctests
MRG: fix doctests for numpy 1.14 array printing. See commit message.
2 parents f824222 + 11818ba commit ee4ce2a

5 files changed

+64
-64
lines changed

doc/source/coordinate_systems.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ middle voxel in the EPI data array like this:
104104
(26, 30, 16)
105105
>>> center_vox_value = epi_img_data[center_i, center_j, center_k]
106106
>>> center_vox_value
107-
81.549287796020508
107+
81.5492877960205...
108108

109109
The values (26, 30, 16) are indices into the data array ``epi_img_data``. (26,
110110
30, 16) is therefore a 'voxel coordinate' - a coordinate into the voxel array.
@@ -776,7 +776,7 @@ center of the EPI image?
776776
:nofigs:
777777

778778
>>> apply_affine(epi_vox2anat_vox, epi_vox_center)
779-
array([ 28.364, 31.562, 36.165])
779+
array([28.364, 31.562, 36.165])
780780

781781
The voxel coordinate of the center voxel of the anatomical image is:
782782

@@ -786,7 +786,7 @@ The voxel coordinate of the center voxel of the anatomical image is:
786786

787787
>>> anat_vox_center = (np.array(anat_img_data.shape) - 1) / 2.
788788
>>> anat_vox_center
789-
array([ 28. , 33. , 27.5])
789+
array([28. , 33. , 27.5])
790790

791791
The voxel location in the anatomical image that matches the center voxel of
792792
the EPI image is nearly exactly half way across the first axis, a voxel or two

doc/source/image_orientation.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ Here is the affine (to two digits decimal precision):
5353

5454
>>> np.set_printoptions(precision=2, suppress=True)
5555
>>> img.affine
56-
array([[ -2. , 0. , 0. , 117.86],
57-
[ -0. , 1.97, -0.36, -35.72],
58-
[ 0. , 0.32, 2.17, -7.25],
59-
[ 0. , 0. , 0. , 1. ]])
56+
array([[ -2. , 0. , 0. , 117.86],
57+
[ -0. , 1.97, -0.36, -35.72],
58+
[ 0. , 0.32, 2.17, -7.25],
59+
[ 0. , 0. , 0. , 1. ]])
6060

6161
What are the orientations of the voxel axes here?
6262

doc/source/neuro_radio_conventions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ scanner RAS+ (see :doc:`coordinate_systems`):
6161
... [0, 0, 0, 1]])
6262
>>> ijk = [1, 0, 0] # moving one unit on the first voxel axis
6363
>>> apply_affine(diag_affine, ijk)
64-
array([ 3., 0., 0.])
64+
array([3., 0., 0.])
6565

6666
In this case the voxel axes are aligned to the output axes, in the sense that
6767
moving in a positive direction on the first voxel axis results in increasing

doc/source/nibabel_images.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ array to coordinates in some RAS+ world coordinate system
6262
>>> np.set_printoptions(precision=2, suppress=True)
6363

6464
>>> img.affine
65-
array([[ -2. , 0. , 0. , 117.86],
66-
[ -0. , 1.97, -0.36, -35.72],
67-
[ 0. , 0.32, 2.17, -7.25],
68-
[ 0. , 0. , 0. , 1. ]])
65+
array([[ -2. , 0. , 0. , 117.86],
66+
[ -0. , 1.97, -0.36, -35.72],
67+
[ 0. , 0.32, 2.17, -7.25],
68+
[ 0. , 0. , 0. , 1. ]])
6969

7070
``header`` contains the metadata for this inage. In this case it is
7171
specifically NIfTI metadata:
@@ -148,7 +148,7 @@ The header of any image will normally have the following methods:
148148
* ``get_zooms()`` to get the voxel sizes in millimeters:
149149

150150
>>> print(header.get_zooms())
151-
(2.0, 2.0, 2.1999991, 2000.0)
151+
(2.0, 2.0, 2.19999..., 2000.0)
152152

153153
The last value of ``header.get_zooms()`` is the time between scans in
154154
milliseconds; this is the equivalent of voxel size on the time axis.

doc/source/nifti_images.rst

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,10 @@ You can get and set individual fields in the header using dict (mapping-type)
151151
item access. For example:
152152

153153
>>> n1_header['cal_max']
154-
array(1162.0, dtype=float32)
154+
array(1162., dtype=float32)
155155
>>> n1_header['cal_max'] = 1200
156156
>>> n1_header['cal_max']
157-
array(1200.0, dtype=float32)
157+
array(1200., dtype=float32)
158158

159159
Check the attributes of the header for ``get_`` / ``set_`` methods to get and
160160
set various combinations of NIfTI header fields.
@@ -173,10 +173,10 @@ Like other nibabel image types, NIfTI images have an affine relating the voxel
173173
coordinates to world coordinates in RAS+ space:
174174

175175
>>> n1_img.affine
176-
array([[ -2. , 0. , 0. , 117.86],
177-
[ -0. , 1.97, -0.36, -35.72],
178-
[ 0. , 0.32, 2.17, -7.25],
179-
[ 0. , 0. , 0. , 1. ]])
176+
array([[ -2. , 0. , 0. , 117.86],
177+
[ -0. , 1.97, -0.36, -35.72],
178+
[ 0. , 0.32, 2.17, -7.25],
179+
[ 0. , 0. , 0. , 1. ]])
180180

181181
Unlike other formats, the NIfTI header format can specify this affine in one
182182
of three ways |--| the *sform* affine, the *qform* affine and the *fall-back
@@ -199,16 +199,16 @@ the image or the header.
199199
For example:
200200

201201
>>> print(n1_header['srow_x'])
202-
[ -2. 0. 0. 117.86]
202+
[ -2. 0. 0. 117.86]
203203
>>> print(n1_header['srow_y'])
204204
[ -0. 1.97 -0.36 -35.72]
205205
>>> print(n1_header['srow_z'])
206206
[ 0. 0.32 2.17 -7.25]
207207
>>> print(n1_header.get_sform())
208-
[[ -2. 0. 0. 117.86]
209-
[ -0. 1.97 -0.36 -35.72]
210-
[ 0. 0.32 2.17 -7.25]
211-
[ 0. 0. 0. 1. ]]
208+
[[ -2. 0. 0. 117.86]
209+
[ -0. 1.97 -0.36 -35.72]
210+
[ 0. 0.32 2.17 -7.25]
211+
[ 0. 0. 0. 1. ]]
212212

213213
This affine is valid only if the ``sform_code`` is not zero.
214214

@@ -234,29 +234,29 @@ You can get the affine and the code using the ``coded=True`` argument to
234234
``get_sform()``:
235235

236236
>>> print(n1_header.get_sform(coded=True))
237-
(array([[ -2. , 0. , 0. , 117.86],
238-
[ -0. , 1.97, -0.36, -35.72],
239-
[ 0. , 0.32, 2.17, -7.25],
240-
[ 0. , 0. , 0. , 1. ]]), 1)
237+
(array([[ -2. , 0. , 0. , 117.86],
238+
[ -0. , 1.97, -0.36, -35.72],
239+
[ 0. , 0.32, 2.17, -7.25],
240+
[ 0. , 0. , 0. , 1. ]]), 1)
241241

242242
You can set the sform with the ``set_sform()`` method of the header and
243243
the image.
244244

245245
>>> n1_header.set_sform(np.diag([2, 3, 4, 1]))
246246
>>> n1_header.get_sform()
247-
array([[ 2., 0., 0., 0.],
248-
[ 0., 3., 0., 0.],
249-
[ 0., 0., 4., 0.],
250-
[ 0., 0., 0., 1.]])
247+
array([[2., 0., 0., 0.],
248+
[0., 3., 0., 0.],
249+
[0., 0., 4., 0.],
250+
[0., 0., 0., 1.]])
251251

252252
Set the affine and code using the ``code`` parameter to ``set_sform()``:
253253

254254
>>> n1_header.set_sform(np.diag([3, 4, 5, 1]), code='mni')
255255
>>> n1_header.get_sform(coded=True)
256-
(array([[ 3., 0., 0., 0.],
257-
[ 0., 4., 0., 0.],
258-
[ 0., 0., 5., 0.],
259-
[ 0., 0., 0., 1.]]), 4)
256+
(array([[3., 0., 0., 0.],
257+
[0., 4., 0., 0.],
258+
[0., 0., 5., 0.],
259+
[0., 0., 0., 1.]]), 4)
260260

261261
The qform affine
262262
================
@@ -273,10 +273,10 @@ You can get and set the qform affine using the equivalent methods to those for
273273
the sform: ``get_qform()``, ``set_qform()``.
274274

275275
>>> n1_header.get_qform(coded=True)
276-
(array([[ -2. , 0. , 0. , 117.86],
277-
[ -0. , 1.97, -0.36, -35.72],
278-
[ 0. , 0.32, 2.17, -7.25],
279-
[ 0. , 0. , 0. , 1. ]]), 1)
276+
(array([[ -2. , 0. , 0. , 117.86],
277+
[ -0. , 1.97, -0.36, -35.72],
278+
[ 0. , 0.32, 2.17, -7.25],
279+
[ 0. , 0. , 0. , 1. ]]), 1)
280280

281281
The qform also has a corresponding ``qform_code`` with the same interpretation
282282
as the `sform_code`.
@@ -295,10 +295,10 @@ Again like SPM, we prefer to assume LAS+ voxel orientation by default.
295295
You can always get the fall-back affine with ``get_base_affine()``:
296296

297297
>>> n1_header.get_base_affine()
298-
array([[ -2. , 0. , 0. , 127. ],
299-
[ 0. , 2. , 0. , -95. ],
300-
[ 0. , 0. , 2.2, -25.3],
301-
[ 0. , 0. , 0. , 1. ]])
298+
array([[ -2. , 0. , 0. , 127. ],
299+
[ 0. , 2. , 0. , -95. ],
300+
[ 0. , 0. , 2.2, -25.3],
301+
[ 0. , 0. , 0. , 1. ]])
302302

303303
.. _choosing-image-affine:
304304

@@ -329,10 +329,10 @@ The sform and qform codes will be initialised to 2 (aligned) and 0 (unknown)
329329
respectively:
330330

331331
>>> img.get_sform(coded=True) # doctest: +NORMALIZE_WHITESPACE
332-
(array([[ 2., 0., 0., 0.],
333-
[ 0., 2., 0., 0.],
334-
[ 0., 0., 2., 0.],
335-
[ 0., 0., 0., 1.]]), 2)
332+
(array([[2., 0., 0., 0.],
333+
[0., 2., 0., 0.],
334+
[0., 0., 2., 0.],
335+
[0., 0., 0., 1.]]), 2)
336336
>>> img.get_qform(coded=True)
337337
(None, 0)
338338

@@ -434,21 +434,21 @@ image is written. We can do this by setting the fields directly, or with
434434
>>> array_header.get_slope_inter()
435435
(2.0, 10.0)
436436
>>> array_header['scl_slope']
437-
array(2.0, dtype=float32)
437+
array(2., dtype=float32)
438438
>>> array_header['scl_inter']
439-
array(10.0, dtype=float32)
439+
array(10., dtype=float32)
440440

441441
Setting the scale factors in the header has no effect on the image data before
442442
we save and load again:
443443

444-
>>> array_img.get_data()
445-
array([[[ 0, 1, 2, 3],
446-
[ 4, 5, 6, 7],
447-
[ 8, 9, 10, 11]],
444+
>>> array_img.get_fdata()
445+
array([[[ 0., 1., 2., 3.],
446+
[ 4., 5., 6., 7.],
447+
[ 8., 9., 10., 11.]],
448448
<BLANKLINE>
449-
[[12, 13, 14, 15],
450-
[16, 17, 18, 19],
451-
[20, 21, 22, 23]]], dtype=int16)
449+
[[12., 13., 14., 15.],
450+
[16., 17., 18., 19.],
451+
[20., 21., 22., 23.]]])
452452

453453
Now we save the image and load it again:
454454

@@ -457,14 +457,14 @@ Now we save the image and load it again:
457457

458458
The data array has the scaling applied:
459459

460-
>>> scaled_img.get_data()
461-
...([[[ 10., 12., 14., 16.],
462-
[ 18., 20., 22., 24.],
463-
[ 26., 28., 30., 32.]],
460+
>>> scaled_img.get_fdata()
461+
array([[[10., 12., 14., 16.],
462+
[18., 20., 22., 24.],
463+
[26., 28., 30., 32.]],
464464
<BLANKLINE>
465-
[[ 34., 36., 38., 40.],
466-
[ 42., 44., 46., 48.],
467-
[ 50., 52., 54., 56.]]])
465+
[[34., 36., 38., 40.],
466+
[42., 44., 46., 48.],
467+
[50., 52., 54., 56.]]])
468468

469469
The header for the loaded image has had the scaling reset to undefined, to
470470
mark the fact that the scaling has been "consumed" by the load:

0 commit comments

Comments
 (0)