Skip to content

Commit 983eaff

Browse files
committed
Merge branch 'rename-fixes' into main-master
* rename-fixes: better figures for Bayesian structural analysis example debugged and improved the examples some cleaning in mask a nd statistical mapping (+pep8) renames and moved emp_null cleaning and renaming of the emp_null module moved utils.fast_distance to algorithms.routines removed a bad dependency fixed tiny bugs added a word of caution on clustering updated nibabel.gifti io updated the example in clustering comparison moved the clusting stuff from labs to algorithms moved algorithmic examples to algo subdir corrected mask-related bugs
2 parents 706536c + cc86fdf commit 983eaff

Some content is hidden

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

50 files changed

+349
-382
lines changed

doc/labs/plots/enn_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
x = np.c_[np.random.normal(size=1e4),
55
np.random.normal(scale=4, size=1e4)]
66

7-
from nipy.labs.utils.emp_null import ENN
8-
enn = ENN(x)
7+
from nipy.algorithms.statistics.empirical_pvalue import NormalEmpiricalNull
8+
enn = NormalEmpiricalNull(x)
99
enn.threshold(verbose=True)
1010

examples/labs/bayesian_gaussian_mixtures.py renamed to examples/algorithms/bayesian_gaussian_mixtures.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
import numpy.random as nr
1717
import pylab as pl
1818

19-
import nipy.labs.clustering.bgmm as bgmm
20-
from nipy.labs.clustering.gmm import plot2D
19+
import nipy.algorithms.clustering.bgmm as bgmm
20+
from nipy.algorithms.clustering.gmm import plot2D
2121

2222

2323
dim = 2

examples/labs/clustering_comparisons.py renamed to examples/algorithms/clustering_comparisons.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,18 @@
1010

1111
import numpy as np
1212
import numpy.random as nr
13-
import nipy.labs.graph.field as ff
14-
13+
from nipy.labs.graph.field import Field
14+
from scipy.ndimage import gaussian_filter
1515

1616
dx = 50
1717
dy = 50
1818
dz = 1
1919
nbseeds = 10
20-
F = ff.Field(dx * dy * dz)
20+
data = gaussian_filter( np.random.randn(dx, dy), 2)
21+
F = Field(dx * dy * dz)
2122
xyz = np.reshape(np.indices((dx, dy, dz)), (3, dx * dy * dz)).T.astype(np.int)
2223
F.from_3d_grid(xyz, 18)
23-
data = nr.randn(dx * dy * dz, 1)
24-
F.set_weights(F.get_weights() / 18)
2524
F.set_field(data)
26-
F.diffusion(5)
27-
data = F.get_field()
2825

2926
seeds = np.argsort(nr.rand(F.V))[:nbseeds]
3027
seeds, label, J0 = F.geodesic_kmeans(seeds)

examples/labs/gaussian_mixture_models.py renamed to examples/algorithms/gaussian_mixture_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import numpy as np
1313

14-
import nipy.labs.clustering.gmm as gmm
14+
import nipy.algorithms.clustering.gmm as gmm
1515

1616

1717
dim = 2

examples/labs/ward_clustering.py renamed to examples/algorithms/ward_clustering.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import matplotlib.pylab as mp
1212

1313
from nipy.labs import graph
14-
from nipy.labs.clustering.hierarchical_clustering import ward
14+
from nipy.algorithms.clustering.hierarchical_clustering import ward
1515

1616
# n = number of points, k = number of nearest neighbours
1717
n = 100
@@ -27,17 +27,17 @@
2727
threshold = .5 * n
2828
u = tree.partition(threshold)
2929

30-
mp.figure()
31-
mp.subplot(1, 2, 1)
30+
mp.figure(figsize=(12, 6))
31+
mp.subplot(1, 3, 1)
3232
for i in range(u.max()+1):
3333
mp.plot(X[u == i, 0], X[u == i, 1], 'o', color=(rand(), rand(), rand()))
3434

3535
mp.axis('tight')
3636
mp.axis('off')
37-
mp.title('clustering into clusters of inertia<%f' % threshold)
37+
mp.title('clustering into clusters \n of inertia < %g' % threshold)
3838

3939
u = tree.split(k)
40-
mp.subplot(1, 2, 2)
40+
mp.subplot(1, 3, 2)
4141
for e in range(G.E):
4242
mp.plot([X[G.edges[e, 0], 0], X[G.edges[e, 1], 0]],
4343
[X[G.edges[e, 0], 1], X[G.edges[e, 1], 1]], 'k')
@@ -61,7 +61,9 @@
6161
valid[tree.parents[v]]=1
6262
nv = np.sum(valid)
6363

64-
ax = tree.plot()
64+
ax = mp.subplot(1, 3, 3)
65+
ax = tree.plot(ax)
66+
ax.set_title('Dendrogram')
6567
ax.set_visible(True)
6668
mp.show()
6769

examples/labs/bayesian_structural_analysis.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,31 +88,36 @@ def make_bsa_2d(betas, theta=3., dmax=5., ths=0, thq=0.5, smin=0,
8888
AF.show()
8989

9090
group_map.shape = ref_dim
91-
mp.figure()
92-
mp.subplot(1, 3, 1)
91+
mp.figure(figsize=(8, 3))
92+
ax = mp.subplot(1, 3, 1)
9393
mp.imshow(group_map, interpolation='nearest', vmin=-1, vmax=lmax)
94-
mp.title('Blob separation map')
95-
mp.colorbar()
94+
mp.title('Blob separation map', fontsize=10)
95+
mp.axis('off')
96+
plop = mp.colorbar(shrink=.8)
9697

9798
if AF != None:
9899
group_map = AF.map_label(coord, 0.95, dmax)
99100
group_map.shape = ref_dim
100101

101102
mp.subplot(1, 3, 2)
102103
mp.imshow(group_map, interpolation='nearest', vmin=-1, vmax=lmax)
103-
mp.title('group-level position 95% \n confidence regions')
104-
mp.colorbar()
104+
mp.title('group-level position 95% \n confidence regions', fontsize=10)
105+
mp.axis('off')
106+
mp.colorbar(shrink=.8)
105107

106108
mp.subplot(1, 3, 3)
107109
likelihood.shape = ref_dim
108110
mp.imshow(likelihood, interpolation='nearest')
109-
mp.title('Spatial density under h1')
110-
mp.colorbar()
111+
mp.title('Spatial density under h1', fontsize=10)
112+
mp.axis('off')
113+
mp.colorbar(shrink=.8)
111114

112115

113-
mp.figure()
116+
fig_output = mp.figure(figsize=(8, 3.5))
117+
fig_output.text(.5, .9, "Individual landmark regions", ha="center")
114118
for s in range(nsubj):
115-
mp.subplot(nsubj / 5, 5, s + 1)
119+
ax = mp.subplot(nsubj / 5, 5, s + 1)
120+
#ax.set_position([.02, .02, .96, .96])
116121
lw = - np.ones(ref_dim)
117122
if BF[s] is not None:
118123
nls = BF[s].get_roi_feature('label')
@@ -123,9 +128,11 @@ def make_bsa_2d(betas, theta=3., dmax=5., ths=0, thq=0.5, smin=0,
123128
mp.imshow(lw, interpolation='nearest', vmin=-1, vmax=lmax)
124129
mp.axis('off')
125130

126-
mp.figure()
131+
fig_input = mp.figure(figsize=(8, 3.5))
132+
fig_input.text(.5,.9, "Input activation maps", ha='center')
127133
for s in range(nsubj):
128-
mp.subplot(nsubj / 5, 5, s + 1)
134+
ax = mp.subplot(nsubj / 5, 5, s + 1)
135+
#ax.set_position([.02, .02, .96, .96])
129136
mp.imshow(betas[s], interpolation='nearest', vmin=betas.min(),
130137
vmax=betas.max())
131138
mp.axis('off')

examples/labs/demo_dmtx.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,15 @@
4747
fir_delays=range(1, 6))
4848

4949
# plot the results
50-
fig = mp.figure()
50+
fig = mp.figure(figsize=(10, 6))
5151
ax = mp.subplot(1, 3, 1)
5252
X1.show(ax=ax)
53-
ax.set_title('example of event-related design matrix')
53+
ax.set_title('Event-related design matrix', fontsize=12)
5454
ax = mp.subplot(1, 3, 2)
5555
X2.show(ax=ax)
56-
ax.set_title('example of block design matrix')
56+
ax.set_title('Block design matrix', fontsize=12)
5757
ax = mp.subplot(1, 3, 3)
5858
X3.show(ax=ax)
59-
ax.set_title('example of FIR design matrix')
59+
ax.set_title('FIR design matrix', fontsize=12)
6060
mp.subplots_adjust(top=0.9, bottom=0.25)
61-
fig.set_size_inches((12, 6))
6261
mp.show()

examples/labs/histogram_fits.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import numpy as np
1818

1919
import nipy.labs.utils.simul_multisubject_fmri_dataset as simul
20-
import nipy.labs.utils.emp_null as en
20+
import nipy.algorithms.statistics.empirical_pvalue as en
2121

2222
###############################################################################
2323
# simulate the data
@@ -82,7 +82,7 @@
8282
###############################################################################
8383
# Fit the null mode of Beta with an empirical normal null
8484

85-
efdr = en.ENN(Beta)
85+
efdr = en.NormalEmpiricalNull(Beta)
8686
emp_null_fdr = efdr.fdr(Beta)
8787
emp_null_fdr = emp_null_fdr.reshape((dimx, dimy))
8888

examples/labs/multi_subject_parcellation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@
4141
for s in range(nsubj)])
4242

4343
import matplotlib.pylab as mp
44-
mp.figure()
44+
mp.figure(figsize=(8, 4))
4545
mp.title('Input data')
4646
for s in range(nsubj):
4747
mp.subplot(2, 5, s + 1)
4848
mp.imshow(dataset[s], interpolation='nearest')
4949
mp.axis('off')
5050

51-
mp.figure()
51+
mp.figure(figsize=(8, 4))
5252
mp.title('Resulting parcels')
5353
for s in range(nsubj):
5454
mp.subplot(2, 5, s+1)

examples/labs/need_data/bayesian_structural_analysis.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@
4040
subj_id = ['%04d' %i for i in range(12)]
4141
theta = float(stats.t.isf(0.01, 100))
4242
dmax = 4.
43-
ths = 0 #2# or nbsubj/4
43+
ths = 0
4444
thq = 0.95
4545
verbose = 1
4646
smin = 5
4747
swd = tempfile.mkdtemp()
48-
method = 'simple'
48+
method = 'quick'
4949
print 'method used:', method
5050

5151
# call the function

0 commit comments

Comments
 (0)