forked from gwynox/cardiacModel2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoscillatorLib.py~
More file actions
157 lines (85 loc) · 4.52 KB
/
Copy pathoscillatorLib.py~
File metadata and controls
157 lines (85 loc) · 4.52 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import numpy as np
import pbd
import matplotlib.pyplot as plt
import numpy.random.normal
class oscillator(object):
def __init__(self, dt, title, maxTime):
self.dt = dt
self.title = title
# Preprocessing:
self.genTime(maxTime)
######################################################
def genTime(self, maxTime):
self.t = np.arange(0, maxTime, self.dt)
######################################################
def genIndices(self, events):
ix = np.zeros(np.size(events))
for i in range(0, np.size(events)):
ix[i] = int(np.argmin(np.abs(events[i] - self.t)))
return ix.astype(int)
######################################################
def phaseGen(self,ix,t):
phase = np.zeros(t.shape)
ixDiff = np.diff(ix,n=1,axis=0)
for ii in range(0,ix.shape[0]-1):
#phase[ix[ii,0],0] = 0
for jj in range(0,int(ixDiff[ii])+1):
phase[int(ix[ii])+jj] = float(jj)/float(ixDiff[ii])
return phase #, ixDiff
##############################################################
##############################################################
##############################################################
class cardiac(measurement):
def __init__(self, dt, maxTime, staticRate=0.8, leakRate = 0.1, randomStd=0.1, peakEpsilon=1, actionPotentialLength=0.25, contractionDelaycouplingWindow=0.05, peakForce=1, c0 = 0, sensitivityWindow=1, peakCouplingRate=0.2, sensitivityMean = 0.2, sensitivityStd = 0.1):
self.cellEvents = []
# k_constant computed such that, all other factors aside, we accumulate staticRate of our accumulation
# variable every unit time
self.k_constant = staticRate*dt
# For radnom component: We want the random step to be a zero mean normal distribution
# with a standard deviation after a unit time equivalent to randomStd
# Considering Gaussian random walks, where each time step has standard deviation
# k_random_std, after n timesteps, we have a normal distribution with standard
# deviation sqrt(n)*k_random_std
self.k_random_std = random_Std * np.sqrt(dt)
# c_leak, the leak rate per timestep, is computed such that after n timesteps in a unit time
# we get a reduction in integrating variable by 1-leakRate:
self.k_leak = leakRate**(dt)
self.k_coup = dt * peakCouplingRate / peakEpsilon
super().__init__(dt, title, maxTime)
self.c = np.zeros_like(self.t)
self.c[0] = c0
if sensitivityWindow == 1:
self.sensitivity = lambda c: np.exp(-(c-sensitivityMean)**2/(2*sensitivityStd**2))
######################################################
def stepTime(self, i, epsilon):
self.c[i] = (1 - self.c_leak)*self.c[i-1] + self.k_constant + numpy.random.normal(0, k_random_std) + self.sensitivity(self.c[i-1]) * epsilon * self.k_coup
if self.c[i] > 1:
self.c[i] = 0
#################################################################
#################################################################
#################################################################
class substrate(measurement):
def __init__(self, dt, maxTime):
super().__init__(cellEvents, cellFreq, cellNaturalFreq, dt, startTime, title, maxTime)
######################################################
def relativePhase(self, subTheta, subIx):
if subTheta.size > self.cellTheta.size:
subTheta = subTheta[0:self.cellTheta.size]
elif subTheta.size < self.cellTheta.size:
self.cellTheta = self.cellTheta[0:subTheta.size]
dTheta = np.mod(self.cellTheta - subTheta, 1)
minIndex = int(np.max([np.min(self.cellIx), np.min(subIx)]))
maxIndex = int(np.min([np.max(self.cellIx), np.max(subIx)]))
dTheta2 = dTheta[minIndex:maxIndex]
t2 = self.t[minIndex:maxIndex]
return t2, dTheta2
def relativePhase(self, subTheta, subIx):
if subTheta.size > self.cellTheta.size:
subTheta = subTheta[0:self.cellTheta.size]
elif subTheta.size < self.cellTheta.size:
self.cellTheta = self.cellTheta[0:subTheta.size]
dTheta = np.mod(self.cellTheta - subTheta, 1)
minIndex = int(np.max([np.min(self.cellIx), np.min(subIx)]))
maxIndex = int(np.min([np.max(self.cellIx), np.max(subIx)]))
dTheta2 = dTheta[minIndex:maxIndex]
t2 = self.t[minIndex:maxIndex]