Drawing Tidal Ellipses on an m_map in MATLAB
조회 수: 6 (최근 30일)
이전 댓글 표시
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
Angelo Yeo
2024년 11월 21일
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.
채택된 답변
Angelo Yeo
2024년 11월 29일
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);
% 주요 조석 성분 설정
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
Angelo Yeo
2024년 11월 29일
Please accept the answer if you think it was helpful so that others can recognize easily.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Oceanography and Hydrology에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!