-
Notifications
You must be signed in to change notification settings - Fork 1
/
unperturbed.py~
266 lines (174 loc) · 7.21 KB
/
unperturbed.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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
import numpy as np
import pdb
import matplotlib.pyplot as plt
import oscillatorLib as ol
import experimentLib
import matplotlib
import matplotlib.patches as patches
from matplotlib.ticker import FormatStrFormatter
######################################
######################################
###### SIMULATION PARAMETERS ######
######################################
######################################
#####################################
### SYSTEM PARAMETERS:
dt = 0.0001
maxTime = 45
#####################################
### CELL PARAMETERS:
staticRate = 1/1.78 # Computed as 1/((1/.429) - 0.55), where .429 is the frequency of cells from 20160516
leakRate = 0#0.2
# Note: std of unstretched contractile events was 0.055 (averaged over three trials)
# random Std was chosen to generate a similar value:
randomStd = .0245
peakEpsilon = 1
epsilon_floor = 0.8 # Provides nonlinearity...
actionPotentialLength = 0.5 # measured from contractions on 20160516
contractionDelay = 0.005 # pretty random i suppose
peakForce = 1
peakCouplingRate = 10
c0 = 0
sensitivityWinType = 1
sensitivityMean = 0.6
sensitivityStd = 0.1
cellTitle = "cardiacOscillator_1"
####################################
### SUBSTRATE PARAMETERS:
funcType = 'sinusoidal'
minStrain = 0
maxStrain = 1
phi0 = 1.5*np.pi
omega0 = 2*np.pi / (actionPotentialLength + 1/staticRate) # Note, this is natural contractile rate of cell
omega1 = 1.14 * omega0
####################################
####################################
####################################
sensitivityWinParam = {'sensitivityWinType' : sensitivityWinType, 'sensitivityMean' : sensitivityMean, 'sensitivityStd' : sensitivityStd}
strainFunctionParameters = {'funcType' : funcType, 'minStrain' : minStrain, 'maxStrain' : maxStrain, 'phi0' : phi0}
cell = ol.cardiac(dt, maxTime, staticRate, leakRate, randomStd, peakEpsilon, epsilon_floor, actionPotentialLength, contractionDelay, peakForce, c0, peakCouplingRate, sensitivityWinParam, cellTitle)
sub1 = ol.substrate(dt, maxTime, strainFunctionParameters, omega1)
uncoupled0 = ol.ap(cell, 0)
print("step")
#coupled1 = ol.ap(cell, sub1.epsilon)
#print("step")
#####################################
#####################################
#####################################
if 0:
plt.plot(uncoupled0.t, uncoupled0.c, coupled3.t, coupled3.c)
plt.show()
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
######## POSTPROCESS DATA USING EXPERIMENTAL LIBS #########
##############################################################
##############################################################
##############################################################
##############################################################
##############################################################
experimentTitle = '20160516_model1'
maxStrain = .13
cellNaturalFreq = 1/np.mean(np.diff(uncoupled0.ix))
#######################################
# Optional: Use nominal substrate frequency (no phase data!)
useAvailableSubstrateEvents = 1 # Set to unity to use *data* for substrate, as opposed to measured frequency
cellEvents = [uncoupled0.ix]#, coupled1.ix]
subEvents = [[]]#, sub1.ix]
title = ['uncoup0']#, 'coup1']
voltage = np.zeros(len(cellEvents))
startTime = np.arange(len(cellEvents))
nominalSubFreq = np.zeros(len(cellEvents))
reactionTime = 0
subEventTimeShift = np.zeros(len(cellEvents))
params = {'cellEvents':cellEvents, 'subEvents':subEvents, 'voltage':voltage, 'startTime':startTime, 'dt':dt, 'useAvailableSubstrateEvents':useAvailableSubstrateEvents, 'nominalSubFreq':nominalSubFreq, 'reactionTime':reactionTime, 'subEventTimeShift':subEventTimeShift, 'maxStrain':maxStrain, 'cellNaturalFreq':cellNaturalFreq, 'title':title, 'experimentTitle':experimentTitle}
s1 = experimentLib.experiment(params)
u0 = s1.genUnstretchedMeasurement(0)
#m1 = s1.genStretchedMeasurement(1)
if 0:
ol.animateCoupledUncoupled(sub3.epsilon, coupled3.c, uncoupled0.c, DF=500)
#sub1.epsilon
print("cellFreq(u0) =", u0.cellFreq)
print()
#print("subFreq(m3) =", m1.subFreq)
#print("cellFreq(m3) =", m1.cellFreq)
#print()
print("u0 std", np.std(np.diff(u0.cellEvents)))
print("u0 mean", np.mean(np.diff(u0.cellEvents)))
#print("m3 std", np.std(np.diff(m3.cellEvents)))
#print("m3 mean", np.mean(np.diff(m3.cellEvents)))
#plt.plot(m1.t2, m1.dTheta, m2.t2, m2.dTheta, m3.t2, m3.dTheta, m4.t2, m4.dTheta, m5.t2, m5.dTheta)
#plt.show()
###########################################################
if 0:
####################################################
# Plot histograms of substrate phase:
measurementList = [m3, m4, m5, m6, m7, m8]
nRows = 2
nColumns = 3
figsize = (14,6)
top=0.93
bottom=0.12
left=0.07
right=0.92
hspace=0.32 # vertical spacing between rows
wspace=0.22
hist_maxProbability = 1
s1.plotSubstratePhaseHistograms(measurementList, nRows, nColumns, figsize, top, bottom, left, right, hspace, wspace, hist_maxProbability)
####################################################
# Plot histogram of stretched taus:
measurementList = [m3, m4, m5, m6, m7, m8]
nRows = 2
nColumns = 3
figsize = (14,6)
top=0.93
bottom=0.12
left=0.07
right=0.92
hspace=0.32 # vertical spacing between rows
wspace=0.22
hist_maxProbability = 1.1
nBins = 16
s1.stretchedTauHistogram(measurementList, nRows, nColumns, figsize, top, bottom, left, right, hspace, wspace, hist_maxProbability, nBins)
#####################################################
# Plot histogram of unstretched taus:
unstretchedList = [u0, u1, u2]
nRows = 1
nColumns = 3
figsize = (14, 3)
top = 0.87
bottom = 0.19
left=0.1
right=0.92
hspace=0.32
wspace=0.22
nBins = 16
hist_maxProbability = 1.1
if 0:
# Vertical array!
nRows = 3
nColumns = 1
figsize = (4,10)
top = .96
bottom = 0.12
left = 0.2
right = 0.9
s1.unstretchedTauHistogram(unstretchedList, nRows, nColumns, figsize, top, bottom, left, right, hspace, wspace, hist_maxProbability, nBins)
########################################################
# Frequency plot:
figsize = (4.5,4.5)
top = 0.95
left = 0.18
right = 0.95
bottom = 0.1
s1.plotFrequencyErrorbars(figsize, top, bottom, left, right, hspace, wspace)
#########################################################
# Plot relative phase:
m3.plotRelativePhase(figsize, top=0.9, bottom=0.11, left=0.15, right=0.95)
m4.plotRelativePhase(figsize, top=0.9, bottom=0.11, left=0.15, right=0.95)
m5.plotRelativePhase(figsize, top=0.9, bottom=0.11, left=0.15, right=0.95)
m6.plotRelativePhase(figsize, top=0.9, bottom=0.11, left=0.15, right=0.95)
m7.plotRelativePhase(figsize, top=0.9, bottom=0.11, left=0.15, right=0.95)
m8.plotRelativePhase(figsize, top=0.9, bottom=0.11, left=0.15, right=0.95)