1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
import numpy as np
import nipy.neurospin.statistical_mapping as sm
from nipy.io.imageformats import Nifti1Image as Image
from nipy.utils import example_data
def remake_images():
# Get group data
group_data = example_data.get_filename('neurospin','language_babies','offset_002.npz')
f = np.load(group_data)
data, vardata, xyz = f['mat'], f['var'], f['xyz']
dX = xyz[0,:].max() + 1
dY = xyz[1,:].max() + 1
dZ = xyz[2,:].max() + 1
aux = np.zeros([dX,dY,dZ])
data_images = []
vardata_images = []
mask_images = []
for i in range(data.shape[0]):
aux[list(xyz)] = data[i,:]
data_images.append(Image(aux.copy(), np.eye(4)))
aux[list(xyz)] = vardata[i,:]
vardata_images.append(Image(aux.copy(), np.eye(4)))
aux[list(xyz)] = 1
mask_images.append(Image(aux.copy(), np.eye(4)))
return data_images, vardata_images, mask_images
data_images, vardata_images, mask_images = remake_images()
#zimg, mask = sm.onesample_test(data_images, None, mask_images, 'student')
zimg, mask, nulls = sm.onesample_test(data_images, None, mask_images, 'wilcoxon',
permutations=1024, cluster_forming_th=0.01)
clusters, info = sm.cluster_stats(zimg, mask, 0.01, nulls=nulls)
"""
# Save results
np.savez('group_result.npz', clusters=clusters, info=info)
"""
"""
# Load results
f = np.load('group_result.npz')
clusters = f['clusters']
info = f['info']
"""
|