-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_simulation.m
More file actions
338 lines (317 loc) · 10.7 KB
/
plot_simulation.m
File metadata and controls
338 lines (317 loc) · 10.7 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
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
function plot_simulation(T,X,params, Kin_opts, labels, tf, MealInfo)
close all
exp_start = params{1}.tchange + 60 + 6*60;
tf = tf - exp_start;
times1 = (T{1}-exp_start)/1;
times2 = (T{2}-exp_start)/1;
varnames = set_params().varnames;
% color options
c1= [0.9290, 0.6940, 0.1250];%yellow
c2 = [0.3010, 0.7450, 0.9330]; %blue
c3 = [0.4940, 0.1840, 0.5560];%purple
% which plots?
plt_PhiKin = 0;
plt_con = 1;
plt_amt = 1;
plt_Mgut = 1;
plt_flux = 0;
plt_effects = 0;
plt_kidney = 0;
plt_ALD = 0;
plt_MEAL_exp = 0;
plt_KCL_exp = 1;
plt_MealKCL_exp = 0;
% fontsizes
fonts.title = 15;
fonts.xlabel = 15;
fonts.ylabel = 15;
fonts.legend = 15;
marker_size = 15;
%% plot Phi_Kin
if plt_PhiKin
PhiKin_vals1 = zeros(size(T{1}));
for ii = 1:length(T{1})
[PhiKin_vals1(ii), ~] = get_PhiKin(T{1}(ii), 0, params{1}, Kin_opts{1}, MealInfo{1});
end % for ii
PhiKin_vals2 = zeros(size(T{2}));
for ii = 1:length(T{2})
[PhiKin_vals2(ii), ~] = get_PhiKin(T{2}(ii), 0, params{2}, Kin_opts{2}, MealInfo{2});
end %for ii
figure(99)
plot(times1, PhiKin_vals1, 'linewidth', 2, 'color', c1)
hold on
plot(times2, PhiKin_vals2, 'linewidth', 2, 'color', c2, 'linestyle', '-.')
xlabel('time (mins)', 'fontsize', fonts.xlabel)
ylabel('$\Phi_{Kin}$ (mEq/min)', 'interpreter', 'latex', 'fontsize', fonts.ylabel)
title('$K^+$ intake ($\Phi_{Kin}$)', 'interpreter', 'latex', 'fontsize', fonts.title)
legend(labels{1}, labels{2}, 'fontsize', fonts.legend)
xlim([-exp_start, tf])
hold off
end
%% Mgut
if plt_Mgut
figure(37)
plot(times1, X{1}(:,1), 'linewidth', 2, 'color', c1)
hold on
plot(times2, X{2}(:,1), 'linewidth', 2, 'color', c2, 'linestyle', '-.')
xlabel('time (mins)', 'fontsize', fonts.xlabel)
ylabel('M_{Kgut}', 'fontsize', fonts.ylabel)
legend(labels{1}, labels{2}, 'fontsize', fonts.legend)
hold off
end %if
%% amounts
if plt_amt
figure(1)
plot_these = {1,2,...
3, 4 ,...
'totalECF','totalbodyK'};
for ii = 1:6
s = subplot(3,2, ii);
if strcmp(plot_these{ii}, 'totalECF')
vals1 = X{1}(:, 2) + X{1}(:, 3);
vals2 = X{2}(:, 2) + X{2}(:,3);
elseif strcmp(plot_these{ii}, 'totalbodyK') % not including gut %Sophia: Gut is included if the 1st column of X is added
vals1 = X{1}(:, 2) + X{1}(:,3) + X{1}(:,4) + X{1}(:, 5) + X{1}(:, 6);% + X{1}(:,1);
vals2 = X{2}(:,2) + X{2}(:,3) + X{2}(:,4) + X{2}(:, 5) + X{2}(:,6);
else
vals1 = X{1}(:, plot_these{ii});
vals2 = X{2}(:, plot_these{ii});
end
plot(s, times1, vals1, 'linewidth', 2, 'color', c1)
hold on
plot(s, times2, vals2, 'linewidth', 2, 'color', c2, 'linestyle', '-.')
xlabel('time (mins)', 'fontsize', fonts.xlabel)
if ismember(ii, [1,2,3,4])
ylabel('mEq', 'fontsize', fonts.ylabel)
else
ylabel('mEq', 'fontsize', fonts.ylabel)
%ylabel('mEq/L', 'fontsize', fonts.ylabel)
end
if strcmp(plot_these{ii}, 'totalECF')
title('Total ECF K', 'fontsize', fonts.title)
elseif strcmp(plot_these{ii}, 'totalbodyK')
title('Total body K', 'fontsize', fonts.title)
else
title(varnames{plot_these{ii}}, 'fontsize', fonts.title)
end
xlim([-exp_start, tf])
hold off
end
legend(labels{1}, labels{2}, 'fontsize', fonts.legend)
end
%% concentrations
if plt_con
plot_these = {5,6,7,8};
figure(10)
for ii = 1:4
s = subplot(2,2, ii);
vals1 = X{1}(:,plot_these{ii});
vals2 = X{2}(:,plot_these{ii});
plot(s, times1, vals1, 'linewidth', 2, 'color', c1)
hold on
plot(s, times2, vals2, 'linewidth', 2, 'color', c2, 'linestyle', '-.')
xlabel('time (mins)', 'fontsize', fonts.xlabel)
%ylabel('mEq/min', 'fontsize', fonts.ylabel)
ylabel('mEq/L', 'fontsize', fonts.ylabel)
title(varnames{plot_these{ii}}, 'fontsize', fonts.title)
xlim([-exp_start,tf])
% if plot_these{ii} == 10
% ylim([145, 155])
% if plot_these{ii} == 11
% ylim([135, 145])
% elseif plot_these{ii} == 12
% ylim([115, 125])
% elseif ismember(plot_these{ii}, [7,8, 9])
% ylim([4, 5.0])
end
hold off
end
legend(labels{1}, labels{2}, 'fontsize', fonts.legend)
%% fluxes
if plt_flux
figure(2)
plot_these = {9, 13, 14, 15};
for ii = 1:4
s = subplot(2,2,ii);
vals1 = X{1}(:,plot_these{ii});
vals2 = X{2}(:,plot_these{ii});
plot(s, times1, vals1, 'linewidth', 2, 'color', c1)
hold on
plot(s, times2, vals2, 'linewidth', 2, 'color', c2, 'linestyle', '-.')
xlabel('time (mins)', 'fontsize', fonts.xlabel)
ylabel('mEq/min', 'fontsize', fonts.ylabel)
title(varnames{plot_these{ii}}, 'fontsize', fonts.title)
xlim([-exp_start, tf])
hold off
end
legend(labels{1}, labels{2}, 'fontsize', fonts.legend)
end
%% effects
if plt_effects
figure(3)
plot_these = {10, 11, 12, 20, 21, 25, 33};
for ii = 1:7
s = subplot(3,3,ii);
vals1 = X{1}(:,plot_these{ii});
vals2 = X{2}(:,plot_these{ii});
plot(s, times1, vals1, 'linewidth', 2, 'color', c1)
hold on
plot(s, times2, vals2, 'linewidth', 2, 'color', c2, 'linestyle', '-.')
xlabel('time (mins)', 'fontsize', fonts.xlabel)
title(varnames{plot_these{ii}}, 'fontsize', fonts.title)
xlim([-exp_start, tf])
hold off
end
legend(labels{1}, labels{2}, 'fontsize', fonts.legend)
end
%% kidney
if plt_kidney
figure(4)
plot_these = {16, 17, 18, 19, 23, 24, 28, 'CDKtrans', 29};
for ii = 1:9
s = subplot(3,3, ii);
if strcmp(plot_these{ii}, 'CDKtrans')
vals1 = X{1}(:, 27) - X{1}(:, 24); % reab - sec, positive means net reab
vals2 = X{2}(:, 27) - X{2}(:, 24);
else
vals1 = X{1}(:,plot_these{ii});
vals2 = X{2}(:,plot_these{ii});
end
plot(s, times1, vals1, 'linewidth', 2, 'color', c1)
hold on
plot(s, times2, vals2, 'linewidth', 2, 'color', c2, 'linestyle', '-.')
xlabel('time (mins)', 'fontsize', fonts.xlabel)
ylabel('mEq/min', 'fontsize', fonts.ylabel)
if strcmp(plot_these{ii}, 'CDKtrans')
title('Net CD K transport', 'fontsize', fonts.title)
else
title(varnames{plot_these{ii}}, 'fontsize', fonts.title)
end
xlim([-exp_start, tf])
hold off
end
legend(labels{1}, labels{2}, 'fontsize', fonts.legend)
end
%% ALD
if plt_ALD
figure(5)
plot_these = {29, 32, 20, 12};
for ii = 1:4
s = subplot(2,2,ii);
vals1 = X{1}(:,plot_these{ii});
vals2 = X{2}(:,plot_these{ii});
plot(s, times1, vals1, 'linewidth', 2, 'color', c1)
hold on
plot(s, times2, vals2, 'linewidth', 2, 'color', c2, 'linestyle', '-.')
xlabel('time (mins)', 'fontsize', fonts.xlabel)
title(varnames{plot_these{ii}}, 'fontsize', fonts.title)
xlim([-exp_start, tf])
hold off
end
legend(labels{1}, labels{2}, 'fontsize', fonts.legend)
end
%% compare to data from the MEAL experiment
if plt_MEAL_exp
data = load('./Data/PrestonData.mat');
% plot serum [K+]
figure(20)
vals1 = X{1}(:,5);
vals2 = X{2}(:,5);
data_times = data.time_serum;
data_vals = data.Meal_serum_scaled;
plot(times1,vals1, 'linewidth', 2, 'color', c1)
hold on
plot(times2, vals2, 'linewidth', 2, 'color', c2, 'linestyle', '-.')
plot(data_times, data_vals, '.', 'markersize', marker_size, 'color', 'k')
xlabel('time (mins)')
ylabel('mEq/L')
title('Plasma concentration for Meal experiment')
legend(labels{1}, labels{2}, 'Preston data (Meal only)')
hold off
% plot uK
figure(21)
vals1 = X{1}(:,28);
vals2 = X{2}(:,28);
data_times = data.time_UK;
data_vals = data.Meal_UK_scaled;
plot(times1, vals1, 'linewidth', 2, 'color', c1)
hold on
plot(times2, vals2, 'linewidth', 2, 'color', c2, 'linestyle', '-.')
plot(data_times, data_vals, '.', 'markersize', marker_size, 'color', 'k')
xlabel('time (mins)')
ylabel('mEq/min')
title('Urine K excretion for Meal experiment')
legend(labels{1}, labels{2}, 'Preston data (Meal only)')
hold off
end
%% compare simulation to the KCL only experiment
if plt_KCL_exp
data = load('./Data/PrestonData.mat');
% plot serum K
figure(20)
vals1 = X{1}(:,5);
vals2 = X{2}(:,5);
data_times = data.time_serum;
data_vals = data.KCL_serum_scaled;
plot(times1,vals1, 'linewidth', 2, 'color', c1)
hold on
plot(times2, vals2, 'linewidth', 2, 'color', c2, 'linestyle', '-.')
plot(data_times, data_vals, '.', 'markersize', marker_size, 'color', 'k')
xlabel('time (mins)')
ylabel('mEq/L')
%xlim([-10, 400])
title('Plasma concentration for KCL experiment')
legend(labels{1}, labels{2}, 'Preston data (KCL only)')
hold off
% plot uK
figure(21)
vals1 = X{1}(:,28);
vals2 = X{2}(:,28);
data_times = data.time_UK;
data_vals = data.KCL_UK_scaled;
plot(times1, vals1, 'linewidth', 2, 'color', c1)
hold on
plot(times2, vals2, 'linewidth', 2, 'color', c2, 'linestyle', '-.')
plot(data_times, data_vals, '.', 'markersize', marker_size, 'color', 'k')
xlabel('time (mins)')
ylabel('mEq/min')
%xlim([-10, 400])
title('Urine K excretion for KCL experiment')
legend(labels{1}, labels{2}, 'Preston data (KCL only)')
hold off
end
%% Plot Meal + KCL experiment
if plt_MealKCL_exp
data = load('./Data/PrestonData.mat');
% plot serum K
figure(20)
vals1 = X{1}(:,5);
vals2 = X{2}(:,5);
data_times = data.time_serum;
data_vals = data.MealKCL_serum_scaled;
plot(times1,vals1, 'linewidth', 2, 'color', c1)
hold on
plot(times2, vals2, 'linewidth', 2, 'color', c2, 'linestyle', '-.')
plot(data_times, data_vals, '.', 'markersize', marker_size, 'color', 'k')
xlabel('time (mins)')
ylabel('mEq/L')
title('Plasma concentration for Meal+ KCL experiment')
legend(labels{1}, labels{2}, 'Preston data (Meal + KCL)')
hold off
% plot uK
figure(21)
vals1 = X{1}(:,28);
vals2 = X{2}(:,28);
data_times = data.time_UK;
data_vals = data.MealKCL_UK_scaled;
plot(times1, vals1, 'linewidth', 2, 'color', c1)
hold on
plot(times2, vals2, 'linewidth', 2, 'color', c2, 'linestyle', '-.')
plot(data_times, data_vals, '.', 'markersize', marker_size, 'color', 'k')
xlabel('time (mins)')
ylabel('mEq/min')
title('Urine K excretion for Meal + KCL experiment')
legend(labels{1}, labels{2}, 'Preston data (Meal + KCL)')
hold off
end
end %plot_simulation