Skip to content

Commit

Permalink
Merge pull request #426 from matthew-brett/gmm-plot-2d-fix
Browse files Browse the repository at this point in the history
MRG: fix more numpy 1.12 indexing errors

More indexing errors found by running the examples.
  • Loading branch information
matthew-brett committed Feb 7, 2017
2 parents f135947 + 1815fe9 commit 32ffcd6
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions examples/algorithms/ward_clustering.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
from __future__ import print_function # Python 2/3 compatibility
from __future__ import print_function, division # Python 2/3 compatibility
__doc__ = """
Demo ward clustering on a graph: various ways of forming clusters and dendrogram
Expand All @@ -28,7 +28,7 @@
verbose = False

X = randn(n, 2)
X[:np.ceil(n / 3)] += 3
X[:int(np.ceil(n / 3))] += 3
G = knn(X, 5)
tree = ward(G, X, verbose)

Expand Down Expand Up @@ -57,7 +57,7 @@

nl = np.sum(tree.isleaf())
validleaves = np.zeros(n)
validleaves[:np.ceil(n / 4)] = 1
validleaves[:int(np.ceil(n / 4))] = 1
valid = np.zeros(tree.V, 'bool')
valid[tree.isleaf()] = validleaves.astype('bool')
nv = np.sum(validleaves)
Expand Down
6 changes: 3 additions & 3 deletions examples/labs/permutation_test_fakedata.py
Expand Up @@ -35,11 +35,11 @@ def make_data(n=10, mask_shape=(10, 10, 10), axis=0, r=3, signal=5):
P = PT.permutation_test_onesample(data, XYZ)

# clusters definition (height threshold, max diameter)
c = [(P.random_Tvalues[P.ndraws * (0.95)], None)]
c = [(P.random_Tvalues[int(P.ndraws * (0.95))], None)]

# regions definition (label vector)
r = np.ones(data.shape[1], int)
r[data.shape[1]/2.:] *= 10
r[int(data.shape[1] / 2.):] *= 10
voxel_results, cluster_results, region_results = \
P.calibrate(nperms=100, clusters=c, regions=[r])

Expand All @@ -57,7 +57,7 @@ def make_data(n=10, mask_shape=(10, 10, 10), axis=0, r=3, signal=5):

# rfx calibration
P = PT.permutation_test_twosample(data1, data2, XYZ)
c = [(P.random_Tvalues[P.ndraws * (0.95)], None)]
c = [(P.random_Tvalues[int(P.ndraws * (0.95))], None)]
voxel_results, cluster_results, region_results = P.calibrate(nperms=100,
clusters=c)

Expand Down
2 changes: 1 addition & 1 deletion nipy/algorithms/clustering/gmm.py
Expand Up @@ -206,7 +206,7 @@ def plot2D(x, my_gmm, z=None, with_dots=True, log_scale=False, mpaxes=None,
ax = mpaxes

gdx = gd1.n_bins[0]
Pdens = np.reshape(L, (gdx, np.size(L) / gdx))
Pdens = np.reshape(L, (gdx, -1))
extent = [xm, xs, ym, ys]
if log_scale:
plt.imshow(np.log(Pdens.T), alpha=2.0, origin='lower',
Expand Down
2 changes: 1 addition & 1 deletion nipy/algorithms/clustering/hierarchical_clustering.py
Expand Up @@ -146,7 +146,7 @@ def plot(self, ax=None):
rank = np.arange(self.V)
temp[:n] = np.argsort(aux[:n])
for i in range(n):
rank[temp[i]] = i
rank[int(temp[i])] = i

# 2. derive the abscissa in the dendrogram
idx = np.zeros(self.V)
Expand Down
2 changes: 1 addition & 1 deletion nipy/info.py
Expand Up @@ -191,7 +191,7 @@
%s
Check the instructions in the ``doc/users/install_data.rst`` file in the nipy
source tree, or online at http://nipy.org/nipy/stable/users/install_data.html
source tree, or online at http://nipy.org/nipy/users/install_data.html
If you have the package, have you set the path to the package correctly?"""

Expand Down
4 changes: 2 additions & 2 deletions nipy/labs/group/permutation_test.py
Expand Up @@ -546,11 +546,11 @@ def height_threshold(self, pval):
"""
tvals = self.random_Tvalues
ndraws = tvals.size
idx = np.ceil(ndraws*(1-pval))
idx = int(np.ceil(ndraws * (1 - pval)))
if idx >= ndraws:
return np.inf
candidate = tvals[idx]
if tvals[max(0, idx-1)]<candidate:
if tvals[max(0, idx-1)] < candidate:
return candidate
idx = np.searchsorted(tvals, candidate, 'right')
if idx >= ndraws:
Expand Down
6 changes: 3 additions & 3 deletions nipy/labs/statistical_mapping.py
Expand Up @@ -127,10 +127,10 @@ def cluster_stats(zimg, mask, height_th, height_control='fpr',

# Voxel-level corrected p-values
p = None
if nulls['zmax'] == 'bonferroni':
p = bonferroni(pval, nvoxels)
elif isinstance(nulls['zmax'], np.ndarray):
if isinstance(nulls['zmax'], np.ndarray):
p = simulated_pvalue(zscore, nulls['zmax'])
elif nulls['zmax'] == 'bonferroni':
p = bonferroni(pval, nvoxels)
c['fwer_pvalue'] = p

# Cluster-level p-values (corrected)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -88,7 +88,7 @@ def data_install_msgs():
from nibabel.data import datasource_or_bomber
except ImportError:
log.warn('Cannot check for optional data packages: see: '
'http://nipy.org/nipy/stable/users/install_data.html')
'http://nipy.org/nipy/users/install_data.html')
return
DATA_PKGS = INFO_VARS['DATA_PKGS']
templates = datasource_or_bomber(DATA_PKGS['nipy-templates'])
Expand Down

0 comments on commit 32ffcd6

Please sign in to comment.