Example #1
0
def make_data_field():
    nsubj = 1
    dimx = 60
    dimy = 60
    pos = 3*np.array([[ 6,  7],
                      [10, 10],
                      [15, 10]])
    ampli = np.array([5, 7, 6])
    sjitter = 6.0
    dataset = simul.make_surrogate_array(nbsubj=nsubj, dimx=dimx,
                                         dimy=dimy, 
                                         pos=pos, ampli=ampli, width=10.0)

    # step 2 : prepare all the information for the parcellation
    nbparcel = 10
    ref_dim = (dimx,dimy)
    xy = np.array(np.where(dataset[0])).T
    nvox = np.size(xy,0)
    xyz = np.hstack((xy,np.zeros((nvox,1))))
	
    ldata = np.reshape(dataset,(dimx*dimy,1))
    anat_coord = xy
    mu = 10.
    nn = 18
    feature = np.hstack((ldata/np.std(ldata),
                         mu*anat_coord/np.std(anat_coord)))
    g = fg.WeightedGraph(nvox)
    g.from_3d_grid(xyz.astype(np.int),nn)
    g = ff.Field(nvox,g.edges,g.weights,feature)
    return g
Example #2
0
def test_bsa_methods():
    # generate the data
    nbsubj=10
    dimx=60
    dimy=60
    pos = 2*np.array([[ 6,  7],
                      [10, 10],
                      [15, 10]])
    # make a dataset with a nothing feature
    null_ampli = np.array([0, 0, 0])
    null_dataset = simul.make_surrogate_array(nbsubj=nbsubj,
                                              dimx=dimx,
                                              dimy=dimy, 
                                              pos=pos,
                                              ampli=null_ampli,
                                              width=5.0,
                                              seed=1)
    null_betas = np.reshape(null_dataset, (nbsubj, dimx, dimy))
    # make a dataset with a something feature
    pos_ampli = np.array([5, 7, 6])
    pos_dataset = simul.make_surrogate_array(nbsubj=nbsubj,
                                              dimx=dimx,
                                              dimy=dimy, 
                                              pos=pos,
                                              ampli=pos_ampli,
                                              width=5.0,
                                              seed=2)
    pos_betas = np.reshape(pos_dataset, (nbsubj, dimx, dimy))
    # set various parameters
    theta = float(st.t.isf(0.01, 100))
    dmax = 5./1.5
    half_subjs = nbsubj/2
    thq = 0.9
    smin = 5
    # tuple of tuples with each tuple being
    # (name_of_method, ths_value, data_set, test_function)
    algs_tests = (('simple', half_subjs, null_betas, lambda AF, BF: AF == None),
                  ('dev', half_subjs, null_betas, lambda AF, BF: AF == None),
                  ('ipmi', half_subjs, null_betas, lambda AF, BF: AF == None),
                  ('simple', 1, pos_betas, lambda AF, BF: AF.k>1),
                  ('dev', 1, pos_betas, lambda AF, BF: AF.k>1),
                  ('ipmi', 1, pos_betas, lambda AF, BF: AF.k>1),
                  )
    for name, ths, betas, test_func in algs_tests:
        # run the algo
        AF, BF = make_bsa_2d(betas, theta, dmax, ths, thq, smin, method = name)
        yield assert_true, test_func(AF, BF)
Example #3
0
def make_dataset(ampli_factor=1.0, nsubj=10):
    """
    Generate a standard multi-subject as a set of multi-subject 2D maps
    if null, no activation is added
    """
    nsubj = 10
    dimx = 60
    dimy = 60
    pos = 2*np.array([[ 6,  7], [10, 10], [15, 10]])
    ampli = ampli_factor*np.array([5, 6, 7])
    dataset = simul.make_surrogate_array(nbsubj=nsubj, dimx=dimx, dimy=dimy, 
                                         pos=pos, ampli=ampli, width=5.0, seed=1)
    return dataset
Example #4
0
def make_surrogate_data():
    """ 
    """
    dimx = 40
    dimy = 40
    pos   = np.array([[ 2, 10],
                      [10,  4],
                      [20, 30],
                      [30, 20]])
    ampli = np.array([5,5,5,5])
    data = make_surrogate_array(nbsubj=1, pos=pos, dimx=40, noise_level=0,
                                dimy=40, ampli=ampli, spatial_jitter=0,
                                signal_jitter=0).squeeze()
    return data
Example #5
0
def test_parcel_multi_subj():
    """
    """
    # step 1:  generate some synthetic data
    nsubj = 10
    dimx = 60
    dimy = 60
    pos = 3*np.array([[ 6,  7],
                      [10, 10],
                      [15, 10]])
    ampli = np.array([5, 7, 6])
    sjitter = 6.0
    dataset = simul.make_surrogate_array(nbsubj=nsubj, dimx=dimx,
                                         dimy=dimy, 
                                         pos=pos, ampli=ampli, width=10.0)

    # step 2 : prepare all the information for the parcellation
    nbparcel = 10
    ref_dim = (dimx,dimy)
    xy = np.array(np.where(dataset[0])).T
    nvox = np.size(xy,0)
    xyz = np.hstack((xy,np.zeros((nvox,1))))
	
    ldata = np.reshape(dataset,(nsubj,dimx*dimy,1))
    anat_coord = xy
    mask = np.ones((nvox,nsubj)).astype('bool')
    Pa = fp.Parcellation(nbparcel,xyz,mask-1)

    # step 3 : run the algorithm
    Pa =  hp.hparcel(Pa, ldata, anat_coord, mu = 10.0)
    	
    # step 4:  look at the results
    Label =  np.array([np.reshape(Pa.label[:,s],(dimx,dimy))
                       for s in range(nsubj)])
    control = True
    for s in range(nsubj):
        control *= (np.unique(Label)==np.arange(nbparcel)).all()
    assert(control)

################################################################################
# Main script 
################################################################################

# generate the data
nsubj = 10
dimx = 60
dimy = 60
pos = 2*np.array([[ 6,  7],
                  [10, 10],
                  [15, 10]])
ampli = np.array([5, 7, 6])
sjitter = 1.0
dataset = simul.make_surrogate_array(nbsubj=nsubj, dimx=dimx, dimy=dimy, 
                                     pos=pos, ampli=ampli, width=5.0)
betas = np.reshape(dataset, (nsubj, dimx, dimy))

# set various parameters
theta = float(st.t.isf(0.01, 100))
dmax = 5./1.5
ths = 1#nsubj/2
thq = 0.9
verbose = 1
smin = 5
method = 'simple'#'dev'#'ipmi'#'sbf'

# run the algo
AF, BF = make_bsa_2d(betas, theta, dmax, ths, thq, smin, method, verbose=verbose)
mp.show()
import matplotlib
import matplotlib.pylab as mp

import nipy.neurospin.graph.field as ff
import nipy.neurospin.utils.simul_2d_multisubject_fmri_dataset as simul
################################################################################
# data simulation
dimx=60
dimy=60
pos = 2*np.array([[ 6,  7],
                  [10, 10],
                  [15, 10]])
ampli = np.array([3, 4, 4])

nbvox = dimx*dimy
x = simul.make_surrogate_array(nbsubj=1, dimx=dimx, dimy=dimy,
                               pos=pos, ampli=ampli, width=10.0)

x = np.reshape(x, (dimx, dimy, 1))
beta = np.reshape(x, (nbvox, 1))

xyz = np.array(np.where(x))
nbvox = np.size(xyz,1)
th = 2.36

# compute the field structure and perform the watershed
Fbeta = ff.Field(nbvox)
Fbeta.from_3d_grid(xyz.T.astype('i'), 18)
Fbeta.set_field(beta)
idx, depth, major, label = Fbeta.custom_watershed(0,th)

#compute the region-based signal average
Example #8
0
import numpy as np
import pylab as pl

from nipy.neurospin.utils.simul_2d_multisubject_fmri_dataset import \
     make_surrogate_array

pos = np.array([[10, 10],
                [14, 20],
                [23, 18]])
ampli = np.array([4, 5, 2])

# First generate some noiseless data
noiseless_data = make_surrogate_array(nbsubj=1, noise_level=0, spatial_jitter=0,
                                signal_jitter=0, pos=pos, ampli=ampli)

pl.figure(figsize=(10, 3))
pl.subplot(1, 4, 1)
pl.imshow(noiseless_data[0])
pl.title('Noise-less data')

# Second, generate some group data, with default noise parameters
group_data = make_surrogate_array(nbsubj=3, pos=pos, ampli=ampli)

pl.subplot(1, 4, 2)
pl.imshow(group_data[0])
pl.title('Subject 1')
pl.subplot(1, 4, 3)
pl.title('Subject 2')
pl.imshow(group_data[1])
pl.subplot(1, 4, 4)
pl.title('Subject 3')