MATLAB T-S Diagram

Author: The Eighth Galaxy – Xiang Xianjun

Email: [email protected]

MATLAB T-S Diagram

Data Source:

www.argo.org.cn

MATLAB T-S Diagram

File Import

close all
clear
clc
%% File Import
file_S = "E:\data\woa18_decav_s02_04.nc";   % Salinity
file_T = "E:\data\woa18_decav_t02_04.nc";   % Temperature
% Information View
ncdisp(file_S);  % Salinity
ncdisp(file_T);  % Temperature
% Variable Extraction
lon = ncread(file_S, 'lon');    % Longitude
latitude = ncread(file_S, 'lat');    % Latitude
depth = ncread(file_S, 'depth');  % Depth
salinity = ncread(file_S, 's_an');   % Salinity
temperature = ncread(file_T, 't_an');  % Temperature

MATLAB T-S Diagram

Data Processing

%% Data Processing
% ------ 60°1250'E ------
lon1 = find(lon==60.1250);  lat1 = find(latitude( latitude>=1 && latitude<=124 ) );
% Dimensionality Reduction
S1= squeeze( salinity( lon1,lat1,:) );   T1 = squeeze( temperature( lon1, lat1, :) );  % Average and reduce dimensionality
S1 = squeeze(nanmean( S1(93:220,:),2 ));
T1 = squeeze(nanmean( T1(93:220,:),2 ));
% ------ 110°1250'E ------
lon2 = find(lon==110.1250);  lat2 = find(latitude( latitude>=1 && latitude<=124 ) );
% Dimensionality Reduction
S2= squeeze( salinity( lon2,lat2,:) );   T2 = squeeze( temperature( lon2, lat2, :) );  % Average and reduce dimensionality
S2 = squeeze(nanmean( S2(93:220,:), 2 ));
T2 = squeeze(nanmean( T2(93:220,:), 2 ));
% ------ 160°1250'E ------
lon3 = find(lon==160.1250);  lat3 = find(latitude( latitude>=1 && latitude<=124 ) );
% Dimensionality Reduction
S3= squeeze( salinity( lon3,lat3,:) );   T3 = squeeze( temperature( lon3, lat3, :) );  % Average and reduce dimensionality
S3 = squeeze(nanmean( S3(93:220,:), 2 ));
T3 = squeeze(nanmean( T3(93:220,:), 2 ));

MATLAB T-S Diagram

Image Plotting

%% Image Plotting
figure('Position', [300, 300, 600, 450]);
scatter(S1,T1,30,'red','filled');  % 60°1250'E
hold on
scatter(S2,T2,30,'blue','diamond','filled'); % 110°1250'E
hold on
scatter(S3,T3,30,'black','^','filled');  % 160°1250'E
hold on
% ------ Isopycnal Contour Plot ------
% Observe value range from scatter plot
sal = 33.6 : 0.1 : 35.2;   temp = -2 : 2 : 14;  [sal, temp] = meshgrid(sal, temp); % Grid

% Density Calculation
dens = sw_dens(sal, temp, 10);     % Density calculation
[C, h] = contour(sal, temp, dens,8, 'LineWidth',0.4,'linecolor','black');
clabel(C,h);  % Add contour labels
% Legend
lg = legend("60°1250'E", "110°1250'E", "160°1250'E");
lg.Box = "on";
lg.Color = 'white';
lg.EdgeColor = 'none';
lg.FontSize = 12;
lg.Location = 'southeast';
lg.FontName = 'Times New Roman';
% Axes
ax = gca;
ax.Box = "on";
ax.TickDir = "out";
ax.TickLength = [0.005 0.005];
ax.LineWidth = 0.85;
ax.FontSize = 11;
ax.FontSmoothing = "on";
ax.FontName = 'Times New Roman';
ax.YAxisLocation = 'left';
ax.XAxisLocation = 'bottom';
grid on
ax.GridLineWidth = 0.5;
% Labels
xlabel('\fontname{Times New Roman}Salinity / ‰','FontSize',14,'FontWeight','bold');
ylabel('\fontname{Times New Roman}Temperature / ℃','FontSize',14,'FontWeight','bold');

%% Image Saving
print('E:\picture\Meridional T-S Diagram.jpg', '-djpeg', '-r1000');

END

Leave a Comment