-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot_boxmodel.m
369 lines (306 loc) · 12.1 KB
/
plot_boxmodel.m
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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
%% Plotting function for boxmodel output
%
% Optional input argument (varargin) can be one of two strings:
% - 'time': returns a plot of DOC and biomass over time
% - 'boxes': returns a plot of DOC and biomass color-coded in the seven
% ocean boxes
function [cx, cy] = plot_boxmodel(t, y, PE, PO, PD, varargin)
% calendar year
ty = t/(365);
% get box coordinates
if PE.nb == 7
% smallest box is square, respectively set width of all boxes
W = repmat(sqrt(min(PO.A)), 1, 7); % width of all boxes [m]
% calculate length of all boxes from their width
L = PO.A./W; % length of all boxes [m]
H = PO.H; % height of all boxes [m]
assert(all(W.*L - PO.A==0), 'wrong width or length')
% Try 2: NADW
V_NADW = PO.V(6);
h = (H(3)+H(5))-H(2);
hx = (V_NADW-L(2)*W(2)*h-L(4)*W(4)*h)/((L(2)+L(3)+L(4))*W(2));
NADW_bottom = 1000+hx; % NADW bottom depth
% AABW
V_AABW = PO.V(7);
hy = (V_AABW-L(1)*W(1)*(750+hx))/(L(1)*W(1)+(L(2)+L(3)+L(4))*W(2));
AABW_bottom = 1000+hx+hy;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Set up coordinates of boxes
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% starting at lower left corner, in clockwise direction.
%(replicate last point if < 8 coordinates so all vectors are same size)
AAx = [0 0 L(1) L(1) L(1) L(1) L(1) L(1)];
AAy = [H(1) 0 0 H(1) H(1) H(1) H(1) H(1)];
SAx = [L(1) L(1) L(1)+L(2) L(1)+L(2) L(1)+L(2) L(1)+L(2) L(1)+L(2)...
L(1)+L(2)];
SAy = [H(2) 0 0 H(2) H(2) H(2) H(2) H(2)];
LLx = [L(1)+L(2) L(1)+L(2) sum(L(1:3)) sum(L(1:3)) sum(L(1:3)) ...
sum(L(1:3)) sum(L(1:3)) sum(L(1:3))];
LLy = [H(3) 0 0 H(3) H(3) H(3) H(3) H(3)];
NAx = [sum(L(1:3)) sum(L(1:3)) sum(L(1:4)) sum(L(1:4)) sum(L(1:4)) ...
sum(L(1:4)) sum(L(1:4)) sum(L(1:4))];
NAy = [H(4) 0 0 H(4) H(4) H(4) H(4) H(4)];
TCx = [L(1)+L(2) L(1)+L(2) sum(L(1:3)) sum(L(1:3)) sum(L(1:3)) ...
sum(L(1:3)) sum(L(1:3)) sum(L(1:3))];
TCy = [H(3)+H(5) H(3) H(3) H(3)+H(5) H(3)+H(5) H(3)+H(5) H(3)+H(5)...
H(3)+H(5)];
NADWx = [L(1) L(1) L(1)+L(2) L(1)+L(2) sum(L(1:3)) sum(L(1:3))...
sum(L(1:4)) sum(L(1:4))];
NADWy = [NADW_bottom H(2) H(2) H(3)+H(5) H(3)+H(5) H(4) H(4) NADW_bottom];
AABWx = [0 0 L(1) L(1) sum(L(1:4)) sum(L(1:4)) sum(L(1:4)) sum(L(1:4))];
AABWy = [AABW_bottom H(1) H(1) NADW_bottom NADW_bottom AABW_bottom...
AABW_bottom AABW_bottom];
cx = [AAx; SAx; LLx; NAx; TCx; NADWx; AABWx]';
cy = [AAy; SAy; LLy; NAy; TCy; NADWy; AABWy]';
elseif PE.nb == 2
nb = PE.nb;
W = sqrt(min(PO.A)); % width of all boxes [m]
L = PO.A./W; % length of all boxes [m]
H = PO.H; % height of all boxes [m]
AAx = [0 0 L(1) L(1)];
AAy = [H(1) 0 0 H(1)];
TCx = [0 0 L(1) L(1)];
TCy = [H(2) H(1) H(1) H(2)];
cx = [AAx; TCx]';
cy = [AAy; TCy]';
elseif PE.nb == 1
nb = PE.nb;
W = sqrt(min(PO.A)); % width of all boxes [m]
L = PO.A./W; % length of all boxes [m]
H = PO.H; % height of all boxes [m]
cx = [0 0 L(1) L(1)];
cy = [H(1) 0 0 H(1)];
end
%% Plot development of all variables over time
if any(strcmp(varargin, 'time'))
lw = 1;
% change default colors
co = PD.cols;
set(groot, 'defaultAxesColorOrder', co, 'defaultAxesLineStyleOrder','-|--|:')
figure('color', 'white', 'position', [444,425,515,412])
subplot(3,2,1)
plot(ty(ty<PD.yspin), y(ty<PD.yspin, PE.Jdom), 'linewidth', lw)
ylabel(sprintf('DOC\n[mmol/m³]')), axis([0 inf 0 inf])
title('spin-up phase')
subplot(3,2,2)
plot(ty(ty>=PD.yspin), y(ty>=PD.yspin, PE.Jdom), 'linewidth', lw)
axis tight
title('model run')
subplot(3,2,3)
plot(ty(ty<PD.yspin), y(ty<PD.yspin, PE.Jbac), 'linewidth', lw)
ylabel(sprintf('Bacteria\n[mmol/m³]')), axis([0 inf 0 inf])
subplot(3,2,4)
plot(ty(ty>=PD.yspin), y(ty>=PD.yspin, PE.Jbac), 'linewidth', lw)
axis tight
l = legend(PD.BoxAbbr);
l.Position = [0.77896,0.09,0.1257,0.1175];
set(findall(gcf, '-property', 'fontsize'), 'fontsize', 10)
end
%% Plot over short time interval (last x years)
if any(strcmp(varargin, 'shorttime'))
ind = find(strcmp(varargin, 'shorttime'));
if isnumeric(varargin{ind+1})
tsp = varargin{ind+1};
else
tsp = 10; % plot last 10 years
end
t = t/365;
lw = [1.3 1.3 1.3 1.3 1.5 1.7 2.1 2.5];
lstyles = {'-', '-', '-', '-', '-', '-', '-'};
idx = max(t)-tsp; % last tsp years of simulation
figure('color', 'white', 'position', [368,497,1140,208])
for i = 1:PE.nb
subplot(1,3,1)
hold on
plot(t(t>=idx), y(t>=idx, PE.Jdom(i)), 'linewidth', lw(i),...
'color', PD.cols(i,:), 'linestyle', lstyles{i})
axis tight
xlabel('Time [y]'), ylabel('DOC [mmolC/m³]')
ax1 = gca;
subplot(1,3,2)
hold on
plot(t(t>=idx), y(t>=idx, PE.Jbac(i)), 'linewidth', lw(i),...
'color', PD.cols(i,:), 'linestyle', lstyles{i})
axis tight
xlabel('Time [y]'), ylabel('Biomass [mmolC/m³]')
ax2 = gca;
end
ax1.YLim(1) = min(min(y(t>=idx, PE.Jdom)));
ax2.YLim(1) = 0 ;
ax1.Position(4) = ax1.Position(4)*0.8;
ax2.Position(4) = ax2.Position(4)*0.8;
l = legend('AA', 'SA', 'LL', 'NA', 'TC', 'NADW', 'AABW');
set(findall(gcf, '-property', 'fontsize'), 'fontsize', 10)
l.Position = [0.652,0.226,0.09574,0.69761];
ax1.Position(2) = ax1.Position(2)+0.12;
ax2.Position(2) = ax2.Position(2)+0.12;
a = annotation('textbox', [0.112, 1, 0, 0], 'string', 'A', 'Fontsize', 10, 'Fontweight', 'bold');
a.Position(2) = a.Position(2)+0.01;
annotation('textbox', [0.395, 1, 0, 0], 'string', 'B', 'Fontsize', 10, 'Fontweight', 'bold')
end
%% Plot left column time and right column spatial end distribution
if any(strcmp(varargin, 'time_and_boxes'))
lw = 1.5;
% change default colors
co = PD.cols;
set(groot, 'defaultAxesColorOrder', co, 'defaultAxesLineStyleOrder','-|--|:')
figure('color', 'white', 'position', [304,284,660,148])
subplot(3,2,1)
plot(ty, y(:, PE.Jdom), 'linewidth', lw)
ylabel(sprintf('DOC\n[mmol/m³]')), axis([0 inf 0 inf])
title('Model run over time')
subplot(3,2,3)
plot(ty, y(:, PE.Jbac), 'linewidth', lw)
ylabel(sprintf('Bacteria\n[mmol/m³]')), axis([0 inf 0 inf])
% Plot with colorscale, at end of model run
DOM_conc = y(end, PE.Jdom);
Bac_conc = y(end, PE.Jbac);
subplot(3,2,2)
set(gca, 'YDir', 'reverse', 'Color', 'white')
patch(cx, cy, DOM_conc)
ylabel('Depth [m]'), axis tight
c = colorbar; ylabel(c, 'DOC [mmol/m³] ')
colormap(parula(100))
legend('off')
ax = gca;
ax.XTick = ax.XLim;
ax.XTickLabel = {'South', 'North'};
ax.YTick = [0, 1000, 2000, 3000];
title('End distribution')
subplot(3,2,4)
set(gca, 'YDir', 'reverse', 'Color', 'white')
patch(cx, cy, Bac_conc)
ylabel('Depth [m]'), axis tight
c = colorbar; ylabel(c, 'Biomass [mmol/m³] ')
colormap(parula(100))
legend('off')
ax = gca;
ax.XTick = ax.XLim;
ax.XTickLabel = {'South', 'North'};
ax.YTick = [0, 1000, 2000, 3000];
set(findall(gcf, '-property', 'fontsize'), 'fontsize', 10)
end
%% Plot spatial distribution in boxes
% Assuming that box surface areas are rectangles, such that the smallest
% box is square
% Height of box 6 and 7 are mean heights
if any(strcmp(varargin, 'boxes'))
% Plot with colorscale, at end of model run
DOM_conc = y(end, PE.Jdom);
Bac_conc = y(end, PE.Jbac);
if any(strcmp(varargin, 'DOC_only'))
figure('color', 'white', 'position', [304,284,660,148])
s = subplot(1,2,2);
set(s, 'YDir', 'reverse', 'Color', 'white')
patch(cx, cy, DOM_conc)
% xlabel('Horizontal extent [m]')
ylabel('Depth [m]'), axis tight
c = colorbar; ylabel(c, 'DOC [mmol/m³] ')
colormap(parula(100))
% title('DOC after spin-up phase')
legend('off')
ax = gca;
ax.XTick = ax.XLim;
ax.XTickLabel = {'South', 'North'};
ax.YTick = [0, 1000, 2000, 3000];
set(findall(gcf, '-property', 'fontsize'), 'fontsize', 11.5)
elseif any(strcmp(varargin, 'subplots'))
% find subplot data
ind = find(strcmp(varargin, 'subplots'));
values = varargin{ind+1};
for i = 1:size(values,1)
s = subplot(2,ceil(size(values,1)/2),i);
set(s, 'YDir', 'reverse', 'Color', 'white')
patch(cx, cy, values(i,:))
colormap(parula(100))
caxis([min(min(values)) max(max(values))])
axis tight
ax = gca;
ax.XTick = ax.XLim;
ax.XTickLabel = {'S', 'N'};
if i == 1 || i == ceil(size(values,1)/2)+1
ax.YTick = [0, 1000, 2000, 3000];
ylabel('Depth [m]')
elseif i == size(values,1)
ax.YTick = [];
c = colorbar;
c.Position = c.Position + [0.09 0 0 0];
ylabel(c, sprintf('DOC\n[mmol/m³]'))
else
ax.YTick = [];
end
end
set(findall(gcf, '-property', 'fontsize'), 'fontsize', 11.5)
elseif any(strcmp(varargin, 'all'))
figure('color', 'white', 'position', [309,285,1066,159])
subplot(1,3,1, 'YDir', 'reverse')
patch(cx, cy, DOM_conc)
ylabel('Depth [m]'), axis tight
c = colorbar; ylabel(c, sprintf('DOC\n[mmol/m³] '))
if length(c.Ticks) == 6
c.Ticks([1,3,5]) = [];
elseif length(c.Ticks) == 5
c.Ticks([2,4]) =[];
end
colormap(parula(100))
% title('DOC after spin-up phase')
ax = gca;
ax.XTick = ax.XLim;
ax.XTickLabel = {'South', 'North'};
ax.YTick = [0, 1000, 2000, 3000];
subplot(1,3,2, 'YDir', 'reverse')
patch(cx, cy, Bac_conc)
%xlabel('Horizontal extent [m]')
axis tight
c = colorbar; ylabel(c, sprintf('Bacterial biomass\n[mmol/m³]'))
colormap(parula(100))
% title('Bacteria after spin-up phase')
ax = gca;
ax.XTick = ax.XLim;
ax.XTickLabel = {'South', 'North'};
ax.YTick = [];
if length(c.Ticks) == 6
c.Ticks([1,3,5]) = [];
elseif length(c.Ticks) == 5
c.Ticks([2,4]) =[];
end
set(findall(gcf, '-property', 'fontsize'), 'fontsize', 11.5)
else
figure('color', 'white', 'position', [304,284,660,148])
subplot(1,2,1, 'YDir', 'reverse')
patch(cx, cy, DOM_conc)
%xlabel('Horizontal extent [m]')
ylabel('Depth [m]'), axis tight
c = colorbar; ylabel(c, sprintf('DOC\n[mmolC/m³]'))
colormap(parula(100))
caxis([22 65])
c.Ticks = 30:10:70;
% title('DOC after spin-up phase')
ax = gca;
ax.XTick = ax.XLim;
ax.XTickLabel = {'South', 'North'};
ax.YTick = [0, 1000, 2000, 3000];
subplot(1,2,2, 'YDir', 'reverse')
patch(cx, cy, Bac_conc)
% xlabel('Horizontal extent [m]')
axis tight
c = colorbar; ylabel(c, sprintf('Bacterial biomass\n[mmolC/m³]'))
c.Ticks = (0:0.5:2);
colormap(parula(100))
% title('Bacteria after spin-up phase')
caxis([0 2])
ax = gca;
ax.XTick = ax.XLim;
ax.XTickLabel = {'South', 'North'};
ax.YTick = [];
annotation('textbox', [0.06, 0.99, 0, 0], 'string', 'A', 'Fontsize', 11, 'Fontweight', 'bold')
annotation('textbox', [0.52, 0.99, 0, 0], 'string', 'B', 'Fontsize', 11, 'Fontweight', 'bold')
set(findall(gcf, '-property', 'fontsize'), 'fontsize', 11.5)
end
% Ratio deep to surface
rsd1 = mean(DOM_conc(PO.Idp))/mean(DOM_conc(PO.Isfc));
rsd2 = mean(DOM_conc(PO.Idp))/mean(DOM_conc(PO.Isfc));
fprintf('\nmean DOC deep/surface = %1.2f (without TC = %1.2f)', rsd1, rsd2)
set(findall(gcf, '-property', 'fontsize'), 'fontsize', 11.5)
end
end