/
condVelocity.py
executable file
·61 lines (49 loc) · 1.79 KB
/
condVelocity.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python
from numpy import *
#from scipy.io import write_array
#from scipy.io import read_array
from sctools import read_array_pts
def condVelocity(ptsFile, actFile, output=True):
"""
Function to calculate the conduction velocity in a cable slab
Input: ptsFile - description of the nodes
actFile - file with activation time of the nodes
Example:
0 1 2 3 4 5 6 7 8
A B
Bernardo Martins Rocha, 2008
"""
xyz = read_array_pts(ptsFile)
#act = read_array(actFile) # deprecated under new SciPy/Numpy
act = loadtxt(actFile)
actTeste = act
distA = max(xyz[:,0]/4)
distB = 3*max(xyz[:,0]/4)
# node A
tmp = abs(xyz[:,0] - distA)
tmpID = where(tmp == tmp.min()) # where return tuple
aux = tmpID[0][0] + 1
nodeA = xyz[aux]
actTI = where(act[:,0] == aux) # activation time index
if size(actTI) == 0:
if output: print " NodeA was not activated. CV is unknown!"
return nan
else:
actTI = actTI[0][0] # from tuple to scalar
actTA = act[actTI , 1] # activation time for node A
# node B
tmp = abs(xyz[:,0] - distB)
tmpID = where(tmp == tmp.min()) # where return tuple
aux = tmpID[0][0] + 1
nodeB = xyz[aux]
actTI = where(act[:,0] == aux) # activation time index
if size(actTI) == 0:
if output: print " NodeB was not activated. CV is unknown!"
return nan
else:
actTI = actTI[0][0] # from tuple to scalar
actTB = act[actTI , 1] # activation time for node B
distAB = sqrt(sum(pow(nodeB - nodeA,2)))
condve = distAB / (actTB - actTA)
if output: print " CV = %.3f m/s" % (condve/1000)
return (condve/1000)