Drawing Tidal Ellipses on an m_map in MATLAB

32 views (last 30 days)
I want to draw tidal ellipses on an m_map, but the figure is not displaying correctly. Please help me.
% 사용자 지정 위도 및 경도 (덕적도)
latitude = 37 + 13/60 + 35/3600; % N 37° 13' 35"
longitude = 126 + 9/60 + 24/3600; % E 126° 09' 24"
% 데이터 파일 로드
fnm = 'cmems_mod_glo_phy_my_0.083deg_P1D-m_1731894708544.nc';
lon = ncread(fnm, 'longitude');
lat = ncread(fnm, 'latitude');
time = ncread(fnm, 'time');
dateT = datetime(1970, 01, 01, 00, 00, 00) + seconds(time);
u = ncread(fnm, 'uo');
v = ncread(fnm, 'vo');
% 지정된 위치에 가장 가까운 격자 점 찾기
[~, lat_idx] = min(abs(lat - latitude));
[~, lon_idx] = min(abs(lon - longitude));
% 해당 지점의 유속 데이터 추출
u_series = squeeze(u(lon_idx, lat_idx, :));
v_series = squeeze(v(lon_idx, lat_idx, :));
% 조석 성분 분석 (t_tide)
[NAME, FREQ, TIDECON, ~] = t_tide(u_series + 1i * v_series, ...
'interval', 1, 'start time', datenum(dateT(1)), 'latitude', latitude);
% 주요 조석 성분 설정
major_constituents = {'M2', 'S2', 'K1', 'O1'};
colors = {'r', 'g', 'b', 'k'}; % 각각 빨강, 초록, 파랑, 검정
NAME = strtrim(string(NAME)); % 조석 성분 이름 정리
% 지도 설정 (m_map)
figure;
m_proj('mercator', 'lon', [120 128], 'lat', [33 40]); % 범위 설정 (한반도)
m_gshhs_l('patch', [0.8 0.8 0.8]); % 육지 표시
m_grid('box', 'fancy', 'tickdir', 'out'); % 격자 추가
hold on;
% 주요 조석 성분별로 타원 그리기
for i = 1:length(major_constituents)
% 해당 조석 성분의 인덱스 찾기
idx = find(strcmp(NAME, major_constituents{i}));
if ~isempty(idx)
% 타원 매개변수 추출
major_axis = TIDECON(idx, 1); % 장축 반경 (확대)
minor_axis = TIDECON(idx, 3); % 단축 반경 (확대)
inclination = TIDECON(idx, 5) * pi / 180; % 경사각 (라디안)
x0 = longitude; % 타원의 중심 경도
y0 = latitude; % 타원의 중심 위도
% 타원 그리기
ellipsedraw(major_axis, minor_axis, x0, y0, inclination, colors{i});
end
end
% 제목 및 기타 설정
title('Tidal Ellipses for Major Constituents');
hold off;
  2 Comments
Angelo Yeo
Angelo Yeo on 21 Nov 2024
Can you share your data and all other necessary functions? It is a good idea to let others reproduce your issue if you want to get helped.
은진
은진 on 22 Nov 2024 at 7:13
I would like to share my data, but I can't due to the file size limit.

Sign in to comment.

Accepted Answer

Angelo Yeo
Angelo Yeo on 29 Nov 2024 at 6:41
I made some slight changes of your code and made it run in the MATLAB Answers environment. I used the drawEllipse function created by @William Rose for ellipse plotting from one of your previous questions (link).
Note that the original dataset is from Copernicus (link) and deals with ocean current not tidal current. I consulted someone around me who is researching tidal currents, and he mentioned that tidal currents are sub-concept to ocean currents. However, due to the nature of the Copernicus dataset, which provides global satellite data, the resolution may be too low to be suitable for analyzing tidal characteristics at specific locations (in this case, Deokjeokdo). If you are looking to analyze tidal characteristics at specific locations within the country (in this case, South Korea), it might be better to utilize observational data from location-specific stations provided by Korea Hydrographic and Oceanographic Agency. (link).
unzip("t_tide_v1_5.zip");
% 사용자 지정 위도 및 경도 (덕적도)
latitude = 37 + 13/60 + 35/3600; % N 37° 13' 35"
longitude = 126 + 9/60 + 24/3600; % E 126° 09' 24"
% 데이터 파일 로드
% fnm = 'cmems_mod_glo_phy_my_0.083deg_P1D-m_1731894708544.nc';
% finfo = ncinfo(fnm)
% lon = ncread(fnm, 'longitude');
% lat = ncread(fnm, 'latitude');
% time = ncread(fnm, 'time');
% u = ncread(fnm, 'uo');
% v = ncread(fnm, 'vo');
load("oceanCurrentDataset.mat") % only using the essential data
dateT = datetime(1970, 01, 01, 00, 00, 00) + seconds(time);
% 지정된 위치에 가장 가까운 격자 점 찾기
[~, lat_idx] = min(abs(lat - latitude));
[~, lon_idx] = min(abs(lon - longitude));
% 해당 지점의 유속 데이터 추출
% u_series = squeeze(u(lon_idx, lat_idx, :));
% v_series = squeeze(v(lon_idx, lat_idx, :));
% 조석 성분 분석 (t_tide)
[NAME, FREQ, TIDECON, ~] = t_tide(u_series + 1i * v_series, ...
'interval', 1, 'start time', datenum(dateT(1)), 'latitude', latitude);
number of standard constituents used: 35 Points used: 2007 of 2008 percent of X var residual after lsqfit/var original: 79.63 % percent of Y var residual after lsqfit/var original: 68.41 % Greenwich phase computed with nodal corrections applied to amplitude and phase relative to center time Using nonlinear bootstrapped error estimates Generating prediction with nodal corrections, SNR is 2.000000 percent of X var residual after synthesis/var original: 83.96 % percent of Y var residual after synthesis/var original: 73.36 % ----------------------------------- date: 29-Nov-2024 nobs = 2008, ngood = 2007, record length (days) = 83.67 start time: 01-Jan-2016 rayleigh criterion = 1.0 Greenwich phase computed with nodal corrections applied to amplitude \n and phase relative to center time x0= 0.00247, x trend= 0 var(x)= 0.0034369 var(xp)= 0.0005363 var(xres)= 0.0028857 percent var predicted/var original= 15.6 % y0= -0.00903, x trend= 0 var(y)= 0.0073277 var(yp)= 0.0019106 var(yres)= 0.0053755 percent var predicted/var original= 26.1 % ellipse parameters with 95%% CI estimates tide freq major emaj minor emin inc einc pha epha snr MM 0.0015122 0.011 0.014 -0.000 0.01 127.74 96.97 256.32 104.17 0.68 *MSF 0.0028219 0.066 0.020 0.007 0.02 116.79 14.35 7.80 16.83 11 ALP1 0.0343966 0.007 0.008 0.001 0.01 127.12 75.62 251.22 90.03 0.77 2Q1 0.0357064 0.008 0.008 0.000 0.01 118.74 64.86 256.57 76.79 0.97 Q1 0.0372185 0.007 0.008 -0.003 0.01 126.27 74.12 95.42 95.64 0.82 O1 0.0387307 0.004 0.007 0.001 0.01 156.03 116.35 197.71 160.44 0.24 NO1 0.0402686 0.010 0.008 -0.000 0.01 101.89 39.95 186.81 49.61 1.5 *K1 0.0417807 0.015 0.009 -0.001 0.01 122.93 33.54 100.36 39.60 2.5 J1 0.0432929 0.008 0.008 -0.001 0.01 127.52 68.92 116.68 62.48 1 OO1 0.0448308 0.008 0.010 -0.001 0.01 123.83 81.44 127.67 110.83 0.61 UPS1 0.0463430 0.013 0.013 -0.003 0.01 113.89 53.97 318.94 81.77 1 EPS2 0.0761773 0.002 0.004 -0.001 0.00 37.07 124.59 327.74 157.17 0.18 MU2 0.0776895 0.002 0.004 0.000 0.00 42.53 123.21 44.47 135.94 0.31 N2 0.0789992 0.004 0.004 -0.002 0.00 154.60 93.93 265.25 104.17 0.85 *M2 0.0805114 0.012 0.005 -0.000 0.01 132.40 28.07 243.66 29.15 5 L2 0.0820236 0.006 0.006 -0.000 0.01 143.30 63.04 267.14 64.59 1.2 S2 0.0833333 0.001 0.004 0.000 0.00 20.72 115.08 184.30 188.47 0.077 ETA2 0.0850736 0.010 0.008 -0.000 0.01 88.54 65.10 96.75 59.67 1.5 MO3 0.1192421 0.006 0.007 0.002 0.01 117.59 72.62 70.67 97.33 0.82 M3 0.1207671 0.007 0.006 -0.003 0.00 121.48 53.73 35.38 64.43 1.5 MK3 0.1222921 0.004 0.005 -0.002 0.00 139.68 96.17 223.67 108.49 0.71 SK3 0.1251141 0.009 0.007 -0.001 0.01 107.23 43.68 16.08 58.70 1.4 MN4 0.1595106 0.005 0.004 0.002 0.00 121.21 69.83 53.80 73.05 1.4 M4 0.1610228 0.004 0.005 0.001 0.00 100.42 66.43 27.73 90.60 0.83 SN4 0.1623326 0.007 0.005 0.001 0.00 128.36 43.47 301.88 44.34 1.9 MS4 0.1638447 0.005 0.004 0.001 0.00 122.15 73.95 212.32 79.26 1.1 S4 0.1666667 0.006 0.005 0.002 0.00 118.89 65.27 269.25 78.07 1.1 2MK5 0.2028035 0.005 0.005 0.001 0.01 144.05 69.22 326.80 76.59 1 2SK5 0.2084474 0.006 0.006 -0.001 0.01 88.05 59.21 345.88 79.44 1 *2MN6 0.2400221 0.006 0.004 -0.001 0.00 114.42 37.67 50.48 45.31 2 M6 0.2415342 0.004 0.004 -0.000 0.00 110.23 48.61 14.15 61.02 1.3 2MS6 0.2443561 0.002 0.004 0.001 0.00 108.82 82.96 255.82 116.75 0.37 2SM6 0.2471781 0.003 0.003 0.000 0.00 128.85 79.97 355.41 90.52 0.94 3MK7 0.2833149 0.002 0.003 0.000 0.00 109.26 76.80 13.06 121.27 0.47 M8 0.3220456 0.002 0.002 0.001 0.00 111.42 65.61 213.81 84.10 1.1 total var= 0.010765 pred var= 0.0024469 percent total var predicted/var original= 22.7 %
% 주요 조석 성분 설정
major_constituents = {'M2', 'S2', 'K1', 'O1'};
colors = {'r', 'g', 'b', 'k'}; % 각각 빨강, 초록, 파랑, 검정
NAME = strtrim(string(NAME)); % 조석 성분 이름 정리
% 지도 설정 (m_map)
% figure;
% m_proj('mercator', 'lon', [120 128], 'lat', [33 40]); % 범위 설정 (한반도)
% m_gshhs_l('patch', [0.8 0.8 0.8]); % 육지 표시
% m_grid('box', 'fancy', 'tickdir', 'out'); % 격자 추가
% hold on;
% 주요 조석 성분별로 타원 그리기
for i = 1:length(major_constituents)
% 해당 조석 성분의 인덱스 찾기
idx = find(strcmp(NAME, major_constituents{i}));
if ~isempty(idx)
% 타원 매개변수 추출
major_axis = TIDECON(idx, 1); % 장축 반경 (확대)
minor_axis = TIDECON(idx, 3); % 단축 반경 (확대)
inclination = TIDECON(idx, 5) * pi / 180; % 경사각 (라디안)
x0 = longitude; % 타원의 중심 경도
y0 = latitude; % 타원의 중심 위도
% 타원 그리기
drawEllipse(major_axis, minor_axis, x0, y0, inclination, colors{i});
hold on;
end
end
% 제목 및 기타 설정
title('Tidal Ellipses for Major Constituents');
hold off;
  2 Comments
Angelo Yeo
Angelo Yeo on 29 Nov 2024 at 8:18
Please accept the answer if you think it was helpful so that others can recognize easily.

Sign in to comment.

More Answers (0)

Categories

Find more on Oceanography and Hydrology in Help Center and File Exchange

Products


Release

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!