Skip to content

Commit 427db2c

Browse files
committed
Merge branch 'patch-1'
* patch-1: Test visualization example Update doc/labs/viz.rst Cast coordinates to int
2 parents 2c1cf76 + 6482f49 commit 427db2c

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

doc/labs/viz.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ An example
3636
mni_sform_inv = np.linalg.inv(mni_sform)
3737
# Color an asymmetric rectangle around Broca area:
3838
x, y, z = -52, 10, 22
39-
x_map, y_map, z_map = coord_transform(x, y, z, mni_sform_inv)
39+
x_map, y_map, z_map = [int(coord) for coord in coord_transform(x, y, z, mni_sform_inv)]
4040
map = np.zeros((182, 218, 182))
4141
map[x_map-30:x_map+30, y_map-3:y_map+3, z_map-10:z_map+10] = 1
4242

nipy/labs/tests/test_viz.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
""" Tests for visualization
2+
"""
3+
4+
import numpy as np
5+
6+
from nipy.labs.viz import plot_map, mni_sform, coord_transform
7+
8+
9+
def test_example():
10+
# Example from tutorial.
11+
# First, create a fake activation map: a 3D image in MNI space with
12+
# a large rectangle of activation around Broca Area
13+
mni_sform_inv = np.linalg.inv(mni_sform)
14+
# Color an asymmetric rectangle around Broca area:
15+
x, y, z = -52, 10, 22
16+
x_map, y_map, z_map = [int(coord) for coord in coord_transform(x, y, z,
17+
mni_sform_inv)]
18+
map = np.zeros((182, 218, 182))
19+
map[x_map-30:x_map+30, y_map-3:y_map+3, z_map-10:z_map+10] = 1
20+
21+
# We use a masked array to add transparency to the parts that we are
22+
# not interested in:
23+
thresholded_map = np.ma.masked_less(map, 0.5)
24+
25+
# And now, visualize it:
26+
plot_map(thresholded_map, mni_sform, cut_coords=(x, y, z), vmin=0.5)

0 commit comments

Comments
 (0)