-
Notifications
You must be signed in to change notification settings - Fork 0
/
paramKhil.m
363 lines (296 loc) · 10.7 KB
/
paramKhil.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
clc; clear; close all;
set(groot,'defaultAxesXGrid','on');
set(groot,'defaultAxesYGrid','on');
set(groot, 'defaultFigureUnits', 'centimeters', 'defaultFigurePosition', [5 5 40 15]);
set(0,'defaultAxesFontSize',18);
% Add subfolders to path
addpath(genpath(pwd));
load('Matfiles/epsHil.mat','pgridIC3','pgridM1','rhoIC3','rhoM1','sixDayEpsHM_IC3','sixDayEpsHM_M1','timegridIC3','timegridM1');
load('N_is.mat','N2_IC3','N2_M1','zmid_IC3','zmid_M1','time');
mooring = ["IC3","M1"];
%% Diffusivity
Rf = 1/6;
K_IC3 = Rf.*sixDayEpsHM_IC3./N2_IC3;
K_M1 = Rf.*sixDayEpsHM_M1./N2_M1;
% Histogram of diffusivity
ax1 = figure;
histogram(log(K_IC3));
xlabel('$K_{\rho,hil} [m^2 s^{-1}]$','Interpreter','latex');
ylabel('No. of observations');
title('Diffusivity (before binning)');
exportgraphics(ax1,'figures/main/HIL/' + mooring(1) + '_D_hist.png');
%% Correct Diffusivity:
K_IC3c = K_IC3;
K_M1c = K_M1;
% % Leave out correction just for now
% for i=1:length(K_IC3(:,1))
% for j=1:length(K_IC3(1,:))
% if K_IC3(i,j) >= 1e-2
% K_IC3c(i,j) = NaN;
% end
% end
% end
%
% for i=1:length(K_M1(:,1))
% for j=1:length(K_M1(1,:))
% if K_M1(i,j) >= 1e-2
% K_M1c(i,j) = NaN;
% end
% end
% end
%% Diffusivity: IC3 (not binned)
K_IC3c(1:16,1:8277) = nan;
ax2 = figure;
contourf(timegridIC3,pgridIC3,log10(K_IC3c),-2.4:-0.1:-6,'LineColor','none');
datetick('x','yyyy mmm','keeplimits');
ylabel('Depth [m]');
colormap(flipud(cbrewer2('Spectral')));
c = colorbar;
c.Label.String = 'log_{10}(K_{\rho,hil}) [log m^2 s^{-1}]';
ylim([-1525 -100]);
title('IC3: Diffusivity $K_{\rho,hil}$','Interpreter','latex');
exportgraphics(ax2,'figures/main/HIL/' + mooring(1) + '_Kp.png');
%% Diffusivity: M1 (not binned)
ax3 = figure;
contourf(timegridM1,pgridM1,log10(K_M1c),-2.4:-0.1:-6,'LineColor','none');
datetick('x','yyyy mmm','keeplimits');
ylabel('Depth [m]');
colormap(flipud(cbrewer2('Spectral')));
c = colorbar;
c.Label.String = 'log_{10}(K_{\rho,hil}) [log m^2 s^{-1}]';
ylim([-1625 -100]);
title('M1: Diffusivity $K_{\rho,hil}$','Interpreter','latex');
exportgraphics(ax3,'figures/main/HIL/' + mooring(2) + '_Kp.png');
%% Kurtosis for Kp at IC3 and M1
% Extremely high kurtosis. Unlikely (?) to be accurate.
% Is it even appropriate to find kurtosis of a derived value such as this?
kurt_K_IC3 = nan(1,41); kurt_K_M1 = nan(1,42);
for i = 1:41
kurt_K_IC3(i) = kurtosis(K_IC3c(i,:));
end
for i = 1:42
kurt_K_M1(i) = kurtosis(K_M1c(i,:));
end
ax4 = figure;
sgtitle('Kurtosis of $K_{\rho,hil}(z,t)$','Interpreter','latex',fontsize=18);
subplot(1,2,1)
plot(kurt_K_IC3,zmid_IC3(:,1),'DisplayName','K_{\rho,hil}(z,t)');
hold on
xline(3,':','DisplayName','Kurtosis = 3');
hold off
legend('Location','best');
% xlabel('Kurtosis($K_{\rho,hil}(z,t)$)','Interpreter','latex');
ylabel('Depth [m]');
title('IC3');
subplot(1,2,2)
plot(kurt_K_M1,zmid_M1(:,1),'DisplayName','K_{\rho,hil}(z,t)');
hold on
xline(3,':','DisplayName','Kurtosis = 3');
hold off
legend('Location','best');
% xlabel('Kurtosis($K_{\rho,hil}(z,t)$)','Interpreter','latex');
ylabel('Depth [m]');
title('M1');
exportgraphics(ax4,'figures/main/HIL/0_kurtK.png');
%% Calculate Flux(z,t) for IC3 and M1
% Initialise differences dz and dThetadz
dz_IC3 = cat(1,10*ones(5,1),25*ones(6,1),50*ones(30,1));
dz_M1 = cat(1,10*ones(5,1),25*ones(6,1),50*ones(31,1));
dThetadz_IC3 = nan(41,52873);
dThetadz_M1 = nan(42,52873);
% Use original non-stabilised values for CT
CT_M1 = load('SA_CT_interpolated.mat').CT_M1_i;
CT_IC3 = load('SA_CT_interpolated.mat').CT_IC3_i;
% Heat capacity of seawater
cp0 = 3992;
for j=1:length(time)
for i=1:length(dz_M1)
dThetadz_M1(i,j) = (CT_M1(i+1,j) - CT_M1(i,j))/(dz_M1(i));
end
for i=1:length(dz_IC3)
dThetadz_IC3(i,j) = (CT_IC3(i+1,j) - CT_IC3(i,j))/(dz_IC3(i));
end
end
clear CT_IC3 CT_M1;
% dThetadz_IC3(isinf(dThetadz_IC3)) = 0;
% dThetadz_M1(isinf(dThetadz_M1)) = 0;
flux_IC3 = cp0.*rhoIC3.*K_IC3c.*dThetadz_IC3;
flux_M1 = cp0.*rhoM1.*K_M1c.*dThetadz_M1;
%% Conservative Temperature (z,t)
CTmid_M1 = load('SA_CT_interpolated.mat').CTmid_M1_i;
CTmid_IC3 = load('SA_CT_interpolated.mat').CTmid_IC3_i;
% clim('manual');
ax5 = figure;
contourf(timegridIC3,pgridIC3,CTmid_IC3,linspace(3,12,25),'LineColor','none');
datetick('x','yyyy mmm','keeplimits');
c = colorbar;
c.Label.String = '\Theta [K]';
colormap(flipud(cbrewer2('RdBu')));
ylim([-1525 0]); clim([3 12]);
title('IC3: Conservative Temperature');
exportgraphics(ax5,'Figures/Main/Param/CT_IC3.png');
ax6 = figure;
contourf(timegridM1,pgridM1,CTmid_M1,linspace(3,12,25),'LineColor','none');
datetick('x','yyyy mmm','keeplimits');
c = colorbar;
c.Label.String = '\Theta [K]';
colormap(flipud(cbrewer2('RdBu')));
ylim([-1625 0]); clim([3 12]);
title('M1: Conservative Temperature');
exportgraphics(ax6,'Figures/Main/Param/CT_M1.png');
clear CTmid_IC3 CTmid_M1;
%% CT Gradient (z,t)
dThetadz_IC3(1:16,1:8600) = nan;
ax7 = figure;
contourf(timegridIC3,pgridIC3,dThetadz_IC3,linspace(-0.0189,0.0033,100),'LineColor','none');
datetick('x','yyyy mmm','keeplimits');
c = colorbar;
c.Label.String = 'd\Theta/dz [Cm^{-1}]';
colormap(flipud(cbrewer2('RdBu')));
ylim([-1525 0]);
title('IC3: temperature gradient');
exportgraphics(ax7,'Figures/Main/Param/dThetadz_IC3.png');
ax8 = figure;
contourf(timegridM1,pgridM1,dThetadz_M1,linspace(-0.1162,0.0153,100),'LineColor','none');
datetick('x','yyyy mmm','keeplimits');
c = colorbar;
c.Label.String = 'd\Theta/dz [Cm^{-1}]';
colormap(flipud(cbrewer2('RdBu')));
ylim([-1625 0]);
title('M1: temperature gradient');
exportgraphics(ax8,'Figures/Main/Param/dThetadz_M1.png');
%% Absolute Salinity (z,t)
load('SA_CT_interpolated.mat','SA_IC3_i','SAmid_IC3_i','SA_M1_i','SAmid_M1_i');
ax9 = figure;
contourf(timegridIC3,pgridIC3,SAmid_IC3_i,linspace(34.3,35.5,25),'LineColor','none');
datetick('x','yyyy mmm','keeplimits');
c = colorbar;
c.Label.String = 'S_A [g kg^{-1}]';
colormap(flipud(cbrewer2('YlGnBu')));
ylim([-1525 0]); clim([34.3 35.5]);
title('IC3: Absolute Salinity');
exportgraphics(ax9,'Figures/Main/Param/SA_IC3.png');
ax10 = figure;
contourf(timegridM1,pgridM1,SAmid_M1_i,linspace(34.3,35.5,25),'LineColor','none');
datetick('x','yyyy mmm','keeplimits');
c = colorbar;
c.Label.String = 'S_A [g kg^{-1}]';
colormap(flipud(cbrewer2('YlGnBu')));
ylim([-1625 0]); clim([34.3 35.5]);
title('M1: Absolute Salinity');
exportgraphics(ax10,'Figures/Main/Param/SA_M1.png');
clear SAmid_IC3_i SAmid_M1_i;
%% Absolute Salinity Gradient (z,t)
dSAdz_IC3 = nan(41,52873); dSAdz_M1 = nan(42,52873);
for j=1:length(time)
for i=1:length(dz_M1)
dSAdz_M1(i,j) = (SA_M1_i(i+1,j) - SA_M1_i(i,j))/(dz_M1(i));
end
for i=1:length(dz_IC3)
dSAdz_IC3(i,j) = (SA_IC3_i(i+1,j) - SA_IC3_i(i,j))/(dz_IC3(i));
end
end
clear i j;
dSAdz_IC3(1:16,1:8600) = nan;
ax11 = figure;
contourf(timegridIC3,pgridIC3,1000*dSAdz_IC3,'LineColor','none');
datetick('x','yyyy mmm','keeplimits');
c = colorbar;
c.Label.String = '\Delta S_A [mg kg^{-1}]';
colormap(flipud(cbrewer2('RdBu')));
ylim([-1525 0]);
title('IC3: \Delta S_A');
exportgraphics(ax11,'Figures/Main/Param/deltaSA_IC3.png');
ax12 = figure;
contourf(timegridM1,pgridM1,1000*dSAdz_M1,linspace(-7.6,9.1,25),'LineColor','none');
datetick('x','yyyy mmm','keeplimits');
c = colorbar;
c.Label.String = '\Delta S_A [mg kg^{-1}]';
colormap(flipud(cbrewer2('RdBu')));
ylim([-1625 0]);
title('M1: \Delta S_A');
exportgraphics(ax12,'Figures/Main/Param/deltaSA_M1.png');
clear SA_IC3_i SA_M1_i;
%% Density
ax13 = figure;
contourf(timegridIC3,pgridIC3,rhoIC3,linspace(1.0268e3,1.0349e3,20),'LineColor','none');
datetick('x','yyyy mmm','keeplimits');
c = colorbar;
c.Label.String = '\rho [kg m^{-3}]';
colormap(cbrewer2('Purples'));
ylim([-1525 0]);
title('IC3: Density');
exportgraphics(ax13,'Figures/Main/Param/rho_IC3.png');
ax14 = figure;
contourf(timegridM1,pgridM1,rhoM1,linspace(1.0268e3,1.0349e3,20),'LineColor','none');
datetick('x','yyyy mmm','keeplimits');
c = colorbar;
c.Label.String = '\rho [kg m^{-3}]';
colormap(cbrewer2('Purples'));
ylim([-1625 0]);
title('M1: In-situ density');
exportgraphics(ax14,'Figures/Main/Param/rho_M1.png');
%% Flux, no bin (IC3)
% set(groot, 'defaultFigureUnits', 'centimeters', 'defaultFigurePosition', [5 5 35 20]);
%
% figure
% test = [-200 -50 -10:0.1:10 50 200];
% ax7b = figure;
% contourf(timegridIC3,pgridIC3,flux_IC3,test,'LineColor','none');
% datetick('x','yy mmm','keeplimits','keepticks');
% ylabel('Depth [m]');
% % cmocean('tempo');
% colormap(flipud(cbrewer2('RdBu')));
% c = colorbar;
% c.Label.String = 'Flux [W m^{-2}]';
% % title('IC3: Diffusivity');
% exportgraphics(ax7b,'figures/main/HIL/' + mooring(1) + '_Flux.png');
%% Optimise flux binning
edges_IC3 = [-200 -20 -1 -0.8 -0.5 -0.2 -0.1 0 0.1 0.2 0.5 0.8 1 20 200];
edges_M1 = edges_IC3;
NCbar = length(edges_IC3)-1;
% Bin flux values, then clear originals
fluxB_IC3 = discretize(flux_IC3,edges_IC3);
fluxB_M1 = discretize(flux_M1,edges_M1);
clear flux_IC3 flux_M1;
% % Check binning
% figure;
% histogram(fluxB_IC3);
% title('IC3: Flux (after binning)');
%
% ax16 = figure;
% histogram(fluxB_M1);
% title('M1: Flux (after binning)');
%% IC3: Flux(z,t)
ax15 = figure;
contourf(timegridIC3,pgridIC3,fluxB_IC3,'LineStyle','none');
datetick('x','yyyy mmm','keeplimits');
cmap = colormap(cbrewer2('RdBu',NCbar));
c = colorbar;
c.Ticks = 1:(1-1/NCbar):length(edges_IC3);
c.TickLabels = {num2str(edges_IC3(1)), num2str(edges_IC3(2)), num2str(edges_IC3(3)), num2str(edges_IC3(4)), ...
num2str(edges_IC3(5)), num2str(edges_IC3(6)), num2str(edges_IC3(7)), num2str(edges_IC3(8)), num2str(edges_IC3(9)), ...
num2str(edges_IC3(10)), num2str(edges_IC3(11)), num2str(edges_IC3(12)), num2str(edges_IC3(13)), num2str(edges_IC3(14)), num2str(edges_IC3(15))};
c.Label.String = 'Flux [W m^{-2}]';
ylabel('Depth [m]');
% ylim([-inf -100]);
ylim([-1525 -100]);
title('IC3: flux');
exportgraphics(ax15,'figures/main/HIL/' + mooring(1) + '_FluxBinned.png');
%% M1: Flux(z,t)
ax16 = figure;
contourf(timegridM1,pgridM1,fluxB_M1,'LineStyle','none');
datetick('x','yyyy mmm','keeplimits');
cmap = colormap(cbrewer2('RdBu',NCbar));
c = colorbar;
c.Ticks = 1:(1-1/NCbar):length(edges_M1);
c.TickLabels = {num2str(edges_M1(1)), num2str(edges_M1(2)), num2str(edges_M1(3)), num2str(edges_M1(4)), ...
num2str(edges_M1(5)), num2str(edges_M1(6)), num2str(edges_M1(7)), num2str(edges_M1(8)), num2str(edges_M1(9)), ...
num2str(edges_M1(10)), num2str(edges_M1(11)), num2str(edges_M1(12)), num2str(edges_M1(13)), num2str(edges_M1(14)), num2str(edges_M1(15))};
c.Label.String = 'Flux [W m^{-2}]';
ylabel('Depth [m]');
% ylim([-inf -100]);
ylim([-1625 -100]);
title('M1: Flux');
exportgraphics(ax16,'figures/main/HIL/' + mooring(2) + '_FluxBinned.png');
clear ax1 ax2 ax3 ax4 ax5 ax6 ax7 ax8 ax9 ax10 ax11 ax12 ax13 ax14 ax15 ax16 c cmap;