Example #1
0
 # filling cvArray
 cvArray = zeros((arrSize,3))
 for i in xrange(arrSize):
     cvArray[i][0] = resArray[i]
     
 # main loop
 i = 1
 for dir in dirList:
     os.chdir(dir)
     print " >> %s " % dir
     j = 0
     if arrSize == 1:
         sim    = "t%04dum" % resArray[arrIndex]
         simPts = sim + "/" + sim + "_i.pts"
         simAct = sim + "/" + "activation-thresh.dat"
         cv = condVelocity(simPts, simAct)
         cvArray[0][i] = cv
     else:
         for res in resArray:
             sim    = "t%04dum" % res
             simPts = sim + "/" + sim + "_i.pts"
             simAct = sim + "/" + "activation-thresh.dat"
             
             if (os.path.isfile(simPts) != True):
                 print " error calculateCV: file %s not found" + simPts
                 exit(-1)
             
             if (os.path.isfile(simAct) != True):
                 print " error calculateCV: file %s not found" + simAct
                 exit(-1)
             
Example #2
0
def find_CV(avg_dx, vel, gil, gel, beta, model, sv_init, plugs, carpBinary, mesherBinary, carp_ver):
    """
    Input: avg_dx  - mesh resolution as a scalar or list
                           (list - Not implemented yet)
           gil     - intracellular conductivity along the cable
           gel     - extracellular conductivity along the cable
           vel     - desired conduction velocity
           beta    - surface-to-volume ratio
           model   - which ionic model to use
           sv_init - file holding initial state vector
           plugs   - which plugins are used to augment the model
    Output:
           cv_measured in a 1cm long cable with avg_dx of resolution and using
           the value of g_bulk as conductivity
    """
    resList = []   # list of resolutions
    cvList  = []   # list of conduction velocities measured
    
    if isinstance(avg_dx,list):
        resList = avg_dx
    elif isinstance(avg_dx,int) or isinstance(avg_dx,float):
        resList.append(avg_dx)    

    # temporary files setttings
    if os.name == 'posix':
	temp_dir  = os.environ.get("HOME")
        temp_dir += '/tmp'
    else:
        temp_dir = ''

    # settings
    xsize = 1.0 # cm
    mesh_temp = "mesh4exp"
    mesh_name = "%s/mesh4exp"     % (temp_dir)
    mesh_file = "%s/expMesh.par"  % (temp_dir)
    carp_file = "%s/expParam.par" % (temp_dir)
    out_dir   = "%s/OUTPUT_DIR"   % (temp_dir)

    for res in resList:
        yzsize = float(res/10000.)   # convert to cm
        tend   = float(xsize/vel*10.) * 2 # cm*10/(mm/ms) +100%

        # create mesh and cable 
        msh = MeshFile(mesh_name, size0=xsize, size1=yzsize,
                       size2=yzsize, element=1, resolution=res)
        msh.write_to_file(mesh_file)

        cab = CableTest(model, sv_init, plugs, gil, gel, beta, tend, carp_ver)
        cab.write_to_file(carp_ver, carp_file)

        # run MESHER
        cmd = '%s +F %s' % (mesherBinary, mesh_file)
        if DEBUG: print 'running %s' % cmd
        run_command_line(cmd)        

        # run CARP
        cmd = '%s +F %s -meshname %s -simID %s'  % (carpBinary,
                                  carp_file, mesh_name, out_dir)
        if DEBUG: print 'running %s' % cmd
        run_command_line(cmd)

        # calculate CV
        sim_pts = "%s/%s_i.pts" % (out_dir, mesh_temp)
        sim_act = "%s/activation-thresh" % (out_dir)
        condvel = condVelocity(sim_pts, sim_act, output=False)
        cvList.append(condvel)

        # clean temp files
        if os.path.isdir(out_dir):
            shutil.rmtree(out_dir)
        if os.path.isfile(carp_file):
            os.remove(carp_file)
    
    if len(resList) == 1: return cvList[0]
    return cvList