MATLAB Typhoon Path Visualization

MATLAB Typhoon Path Visualization

MATLAB Typhoon Path Visualization

Author: Li Zhi

Email:[email protected]

MATLAB Typhoon Path Visualization

1

File Import and Parameter Settings

%% Parameter Settings
track_file = 'G:\lizhi_4090\D\lizhi\yu\CH2024BST-2411.txt';
output_file = 'typhoon_track_final.png';
shp_file = 'G:\lizhi_4090\D\lizhi\yu\中国标准行政区划数据GS(2024)0650号\中国标准行政区划数据GS(2024)0650号\shp格式\中国_省.shp';
map_limits = [100, 150, 10, 40]; % Longitude 100-150E, Latitude 10-40N

2

Professional Color Scheme

%% Professional Color Scheme (China Meteorological Administration Standard)
typhoon_colors = [
    0.7, 0.7, 0.7;   % 0 - Weaker than Tropical Depression
    0.1, 0.8, 0.1;   % 1 - Tropical Depression (TD)
    0.2, 0.6, 1.0;   % 2 - Tropical Storm (TS)
    1.0, 0.8, 0.0;   % 3 - Severe Tropical Storm (STS)
    1.0, 0.4, 0.0;   % 4 - Typhoon (TY)
    1.0, 0.0, 0.0;   % 5 - Severe Typhoon (STY)
    0.6, 0.0, 0.0;   % 6 - Super Typhoon (SuperTY)
    0.4, 0.4, 0.4;   % 9 - Degenerate
];

3

Data Processing

%% Data Reading and Parsing
fid = fopen(track_file, 'r');
header = textscan(fid, '%5c %4d %3d %4d %4d %1d %1d %20c %8c', 1);
n_points = header{3};
data = textscan(fid, '%10s %1d %3d %4d %4d %3d %3d', n_points);
fclose(fid);
% Data Conversion
time_str = data{1};
raw_intensity = data{2};
lat = double(data{3}) / 10;   % Convert to degrees
lon = double(data{4}) / 10;
pres = data{5};
wnd = data{6};
dt = datetime(time_str, 'InputFormat', 'yyyyMMddHH');
% Intensity Validation
valid_intensity = [0, 1, 2, 3, 4, 5, 6, 9];
intensity = arrayfun(@(x) validate_intensity(x, valid_intensity), raw_intensity);

4

Image Plotting

%% Map Initialization
figure('Position', [100, 100, 1400, 1000], 'Color', 'w')
ax = axesm('MapProjection', 'mercator',...
          'MapLatLimit', map_limits(3:4),...
          'MapLonLimit', map_limits(1:2),...
          'Frame', 'on',...
          'Grid', 'on',...
          'MLabelLocation', 2,...
          'PLabelLocation', 2,...
          'FontSize', 10);
proj = gcm;
tightmap
%% Draw Geographic Boundaries
province_shp = shaperead(shp_file, 'UseGeoCoords', true);
geoshow(province_shp, 'EdgeColor', [0.4, 0.4, 0.4], 'LineWidth', 0.6)
hold on
%% Draw Typhoon Path (Black Solid Line)
plotm(lat, lon, 'k-', 'LineWidth', 2.5)

5

Add Direction Arrows

%% Add Direction Arrows (Every 3 Points)
arrow_interval = 3;
for i = 1:arrow_interval:length(lon)-1
    [x1, y1] = projfwd(proj, lat(i), lon(i));
    [x2, y2] = projfwd(proj, lat(i+1), lon(i+1));
    quiver(x1, y1, x2-x1, y2-y1, 0,...
        'Color', 'k',...
        'LineWidth', 2,...
        'MaxHeadSize', 0.8,...
        'AutoScale', 'off')
end

6

Draw Intensity Marking System

%% Draw Intensity Marking System
marker_base = 0.08;
text_offset = 1.2; % Degree Unit Offset
for i = 1:length(lon)
    % Get Color Index
    color_idx = get_color_index(intensity(i));
    % Calculate Marker Size (Lower Pressure, Larger Size)
    sz = marker_base * (1020 - pres(i)) * 0.5;
    % Draw Marker
    plotm(lat(i), lon(i), 'o',...
        'MarkerSize', sz,...
        'MarkerEdgeColor', typhoon_colors(color_idx, :),...
        'MarkerFaceColor', typhoon_colors(color_idx, :),...
        'LineWidth', 1.8)
    % Time Label (Every 12 Hours)
    if mod(hour(dt(i)), 12) == 0
        textm(lat(i) + text_offset * 0.2, lon(i) + text_offset,...
            datestr(dt(i), 'mm/dd HH'),...
            'FontSize', 5,...
            'BackgroundColor', [1, 1, 0.8],...
            'Margin', 0.5)
    end
end

7

Legend

%% Legend
% Create All Legend Handles
legend_labels = {'TD', 'TS', 'STS', 'TY', 'STY', 'SuperTY', 'Degenerate'};
legend_handles = gobjects(length(legend_labels), 1);
% Generate Legend Markers
for i = 1:length(legend_labels)
    color_idx = i + 1; % Color Scheme Index Corresponding to 2-8
    legend_handles(i) = plotm(nan, nan, 'o',...
        'MarkerSize', 12,...
        'MarkerFaceColor', typhoon_colors(color_idx, :),...
        'MarkerEdgeColor', typhoon_colors(color_idx, :),...
        'LineWidth', 1.5,...
        'Visible', 'on'); % Ensure Visible
end
% Draw Main Legend (Including All Levels)
lg = legend(legend_handles, legend_labels,...
    'Location', 'southoutside',...
    'Orientation', 'horizontal',...
    'Box', 'off',...
    'FontSize', 11,...
    'NumColumns', 4);
% Adjust Legend Position
lg.Position = [0.55, 0.72, 0.5, 0.05];
% Add Legend Title
annotation('textbox',...
    [0.4, 0.18, 0.2, 0.05],...
    'String', 'Typhoon Intensity Levels',...
    'EdgeColor', 'none',...
    'FontSize', 12,...
    'FontWeight', 'bold',...
    'HorizontalAlignment', 'center');

8

Image Output

%% Output Image
print(gcf, output_file, '-dpng', '-r1200')

9

Helper Functions

%% Helper Functions
function idx = get_color_index(inten)
    if inten == 9
        idx = 8;
    else
        idx = inten + 1;
    end
end
function out = validate_intensity(val, valid_values)
    if ismember(val, valid_values)
        out = val;
    else
        warning('Found abnormal intensity value: %d, reset to 0', val)
        out = 0;
    end
end

MATLAB Typhoon Path Visualization

END

Leave a Comment