Example #1
0
def test_bsa_methods():
    # generate the data
    nbsubj=10
    dimx=60
    dimy=60
    pos = np.array([[12,  14],
                    [20, 20],
                    [40, 50]])
    # make a dataset with a nothing feature
    null_ampli = np.array([0, 0, 0])
    null_dataset = simul.surrogate_2d_dataset(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.surrogate_2d_dataset(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.k == 0),
        ('ipmi', half_subjs, null_betas, lambda AF, BF: AF.k == 0),
        ('simple', 1, pos_betas, lambda AF, BF: AF.k>1),
        ('ipmi', 1, pos_betas, lambda AF, BF: AF.k>1),
        ('sbf', 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)
        if test_func(AF, BF)==False:
            stop
        assert(test_func(AF, BF))
Example #2
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.surrogate_2d_dataset(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 #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.surrogate_2d_dataset(nbsubj=nsubj, dimx=dimx, dimy=dimy, 
                                         pos=pos, ampli=ampli, width=5.0, 
                                         seed=1)
    return dataset
def make_surrogate_data():
    """ Return a single deterministic 3D image 
    """
    dimx = 40
    dimy = 40
    pos   = np.array([[ 2, 10],
                      [10,  4],
                      [20, 30],
                      [30, 20]])
    ampli = np.array([5,5,5,5])
    data = surrogate_2d_dataset(nbsubj=1, pos=pos, dimx=40, noise_level=0,
                                dimy=40, ampli=ampli, spatial_jitter=0,
                                signal_jitter=0).squeeze()
    data = np.reshape(data,(dimx,dimy,1))
    return Nifti1Image(data, np.eye(4))
def test_surrogate_array():
    """ Check that with no noise, the surrogate activation correspond to
        the ones that we specify. 2D version
    """
    # We can't use random positions, as the positions have to be
    # far-enough not to overlap.
    pos   = np.array([[ 2, 10],
                      [10,  4],
                      [80, 30],
                      [40, 60],
                      [90, 70]])
    ampli = np.random.random(5)
    data = surrogate_2d_dataset(nbsubj=1, noise_level=0, spatial_jitter=0,
                                signal_jitter=0, pos=pos, dimx=100,
                                dimy=100, ampli=ampli).squeeze()
    x, y = pos.T
    np.testing.assert_array_equal(data[x, y], ampli)
Example #6
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.surrogate_2d_dataset(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)
import nipy.neurospin.utils.simul_multisubject_fmri_dataset as simul
from nipy.neurospin.utils.reproducibility_measures import \
     voxel_reproducibility, cluster_reproducibility, map_reproducibility,\
     peak_reproducibility


################################################################################
# Generate the data 
nsubj = 105
dimx = 60
dimy = 60
pos = np.array([[ 12,  14],
                [20, 20],
                [30, 20]])
ampli = np.array([2.5, 3.5, 3])
dataset = simul.surrogate_2d_dataset(nbsubj=nsubj, dimx=dimx, dimy=dimy, 
                                     pos=pos, ampli=ampli, width=5.0)
betas = np.reshape(dataset, (nsubj, dimx, dimy))

# set the variance at 1 everywhere
func = np.reshape(betas,(nsubj, dimx*dimy)).T
var = np.ones((dimx*dimy, nsubj))

from nipy.io.imageformats import Nifti1Image 
mask = Nifti1Image(np.ones((dimx, dimy, 1)),np.eye(4))

################################################################################
# Run reproducibility analysis 

ngroups = 10
thresholds = np.arange(.5, 6., .5)
sigma = 2.0
Example #8
0

import numpy as np

import nipy.neurospin.spatial_models.hroi as hroi
import nipy.neurospin.utils.simul_multisubject_fmri_dataset as simul
from nipy.neurospin.spatial_models.discrete_domain import domain_from_array

##############################################################################
# simulate the data
dimx = 60
dimy = 60
pos = np.array([[12, 14], [20, 20], [30, 20]])
ampli = np.array([3,4,4])

dataset = simul.surrogate_2d_dataset(nbsubj=1, dimx=dimx, dimy=dimy, pos=pos,
                                     ampli=ampli, width=10.0).squeeze()

# create a domain descriptor associated with this
domain = domain_from_array(dataset**2>0)

nroi = hroi.HROI_as_discrete_domain_blobs(domain, dataset.ravel(),
                                          threshold=2.0, smin=3)

n1 = nroi.copy()
n2 = nroi.reduce_to_leaves()

td = n1.make_forest().depth_from_leaves()
root = np.argmax(td)
lv = n1.make_forest().rooted_subtree(root)
u = nroi.make_graph().cc()
Example #9
0
# 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 pylab as pl

from nipy.neurospin.utils.simul_multisubject_fmri_dataset import \
     surrogate_2d_dataset

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

# First generate some noiseless data
noiseless_data = surrogate_2d_dataset(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 = surrogate_2d_dataset(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])