figure(1)
clf
contourf(datenum(ww.Datetime),ww.Depth,ww.pH_free)
cb = colorbar;
cb.Label.String = '^oC';
% cb.Limits = [7 18];
% hold on
% contour(datenum(ww.Datetime),ww2.Depth,ww2.Sigma0')
datetick
title(datestr(ww.Datetime(1),'dd-mmm-yyyy'))
% legend('Temperature','Sigma')
%%
figure
clf
pcolor(ww.Datenum,ww.Depth,ww.pH_free)
colormap hot(20)
cb = colorbar;
cb.Label.String = {['pH free'],['k0 = -1.4214']};
shading("flat")
% cb.Limits = [7 18];
% hold on
% contour(datenum(ww.Datetime),ww2.Depth,ww2.Sigma0')
datetick
title('Thoon WW pH free, Original')
subtitle([datestr(ww.Datetime(1),'dd-mmm-yyyy'), ' to ', datestr(ww.Datetime(end),'dd-mmm-yyyy')])
% legend('Temperature','Sigma')
%%
figure
clf
pcolor(ww.Datenum,ww.Depth,ww.pH_free_adj)
colormap hot(20)
cb = colorbar;
cb.Label.String = {['pH free'],['k0 = ', num2str(ww.k0_adj)]};
shading("flat")
% cb.Limits = [7 18];
% hold on
% contour(datenum(ww.Datetime),ww2.Depth,ww2.Sigma0')
datetick
title('Thoon WW pH free, adjusted')
subtitle([datestr(ww.Datetime(1),'dd-mmm-yyyy'), ' to ', datestr(ww.Datetime(end),'dd-mmm-yyyy')])
% legend('Temperature','Sigma')
%%
figure
clf
contourf(ww.Datenum,ww.Depth,ww.pH_tot_adj,10,"LineWidth",.1)
colormap('hot')
cb = colorbar;
cb.Label.String = '^oC';
% cb.Limits = [7 18];
% hold on
% contour(datenum(ww.Datetime),ww2.Depth,ww2.Sigma0')
datetick
title(datestr(ww.Datetime(1),'dd-mmm-yyyy'))
% legend('Temperature','Sigma')
%%

maxsigma = max(ww.Sigma0,[],"all");

[ixs, iys] = find(ww.Sigma0 == maxsigma); % Metric for the deepest water

mintemp = min(ww.Temperature,[],"all");

[ixt, iyt] = find(ww.Temperature == mintemp); % Metric for the deepest water

%%
cla
clf
scatter(ww.Datetime,ww.pH_canyonB(30,:)-ww.pH_free_adj(30,:))
hold on
scatter(ww.Datetime,ww.pH_canyonB(30,:)-ww.pH_free(30,:))
xlabel('pH measured')
ylabel('residual')
legend('ph adjusted - canyonB','pH measured - canyonB')

%%
wwf.rho = density(wwf.Practical_Salinity,wwf.Temperature) - 1000;
figure
clf
contourf(wwf.dn,wwf.depth,wwf.rho);
% shading("flat")
% set(gca, 'YDir', 'reverse')
cb = colorbar;
cb.Label.String = 'density';
% cb.Limits = [7 18];
% hold on
% [M, c] = contour(wwf.dn,wwf.depth,wwf.rho,12);
datetick
title([datestr(wwf.dn(1),'dd-mmm-yyyy'), ' - ', datestr(wwf.dn(end),'dd-mmm-yyyy')])

%%
ii = wwf.rho > 26.5;
% anyii = any(ii);

k02plot = wwf.k0_timeseries(ii);
k02plot = k02plot(755:end);
plot(k02plot)
grid on
title('all k0, chronologically, measured at rho > 26.5 kg/m^3')

%%
[~, idx_max] = max(wwf.rho);
k0atmaxrho = wwf.k0_timeseries(sub2ind(size(wwf.k0_timeseries), idx_max, 1:size(wwf.k0_timeseries, 2)));
plot(wwf.dn(60:end),k0atmaxrho(:,60:end))
% datetick
grid on
title('k0 at max rho')
%%
[c, M] = contourf(ww.Datenum,ww.Depth,ww.rho,25);
%%
% scatter
figure
clf
tiledlayout(2,1)
nexttile
k0 = nanmean(wwf.k0_timeseries(1:20,:));
pres = nanmean(wwf.Pressure(1:20,:));
scatter(pres,k0)
ylabel('k0')
xlabel('pressure')
grid on

nexttile
temp = nanmean(wwf.Temperature(1:20,:));
scatter(temp,k0)
ylabel('k0')
xlabel('temp')
grid on
%%
clf
plot(1:2082,wwf.k0_timeseries(20,:))