Beispiel #1
0
def main(argv):
    """Compute the tdcs."""
    # create a dir for leadfields and tmp
    if not op.exists("tmp"):
        import os
        os.mkdir('tmp')
    if not op.exists("leadfields"):
        import os
        os.mkdir('leadfields')

    filename = 'leadfields/HDTDCS_' + argv + '.vtp'
    filename_HMi = op.join('tmp', argv + '_HMi.mat')

    if recompute:
        model = load_headmodel(argv)
        if recompute_HMi or not op.exists(filename_HMi):
            hm = om.HeadMat(model['geometry'])
            hm.invert()
            hm.save(filename_HMi)
        else:
            print("Loading %s" % filename_HMi)
            hm = om.SymMatrix(filename_HMi)

        sm = om.EITSourceMat(model['geometry'], model['tdcssources'])
        # set here the input currents (actually a current density [I/L])
        activation = om.fromarray(
            np.array([[-4., 1.], [1., -4.], [1., 1.], [1., 1.], [1., 1.]]))
        # each column must have a zero mean
        # now apply the currents and get the result
        X = hm * (sm * activation)
        # concatenate X with input currents (to see the what was injected)
        Xt = np.append(om.asarray(X),
                       np.zeros((model['geometry'].size() - X.nlin(),
                                 X.ncol())),
                       0)
        currents = om.asarray(activation)
        for s in range(model['tdcssources'].getNumberOfSensors()):
            # get the triangles supporting this sensor
            tris = model['tdcssources'].getInjectionTriangles(s)
            for it in tris:
                Xt[it.getindex(), :] = (currents[s, :] *
                                        model['tdcssources'].getWeights()(s))

        X = om.fromarray(Xt)
        model['geometry'].write_vtp(filename, X)

    display_vtp(filename)
Beispiel #2
0
#print m1.ncol()

m2 = om.Matrix()
m2.load(ssm_file)
#m2.setvalue(2,3,-0.2) # m2(2,3)=-0.2
#print m2(2,3)
#print m2(0, 0)
#print m2.nlin()
#print m2.ncol()

###############################################################################
# Numpy interface

# For a Vector
v = hm(1, 10, 1, 1).getcol(0)
vec = om.asarray(v)
m = om.fromarray(vec)
assert ((v - m.getcol(0)).norm() < 1e-15)

# For a Matrix
mat = om.asarray(m2)
assert ((m2 - om.fromarray(mat)).frobenius_norm() < 1e-15)
#print mat.shape
#print mat.sum()
#mat[0:2, 1:3] = 0
#print mat[0:5, 0:5]

#remove useless files
os.remove(hm_file)
os.remove(ssm_file)
Beispiel #3
0
m2 = om.Matrix()
m2.load(ssm_file)
#m2.setvalue(2,3,-0.2) # m2(2,3)=-0.2
#print m2(2,3)
#print m2(0, 0)
#print m2.nlin()
#print m2.ncol()

###############################################################################
# Numpy interface

# For a Vector
v=hm(1,10,1,1).getcol(0)
vec = om.asarray(v)
m=om.fromarray(vec)
assert((v-m.getcol(0)).norm() < 1e-15)

# For a Matrix
mat = om.asarray(m2)
assert((m2-om.fromarray(mat)).frobenius_norm() < 1e-15)
#print mat.shape
#print mat.sum()
#mat[0:2, 1:3] = 0
#print mat[0:5, 0:5]


#remove useless files
os.remove(hm_file)
os.remove(ssm_file)