max value inside a circular region in grided data
1 次查看(过去 30 天)
显示 更早的评论
Hi and thanks in advance.
I have a set of grided wind data (lat, lon, windspeed) that I am processing. Data is grided every 0.11deg between (0-60Deg South and 50-190Deg E) and I want to find the max wind inside a circle of say 30km. How can I do this?
0 个评论
采纳的回答
Voss
2024-8-16
% assuming sample data
lat = -60:0;
lon = 90:160;
wind = randi(10, numel(lat), numel(lon));
% forcing max wind of 100m/s at (lat, lon) = (-25, 115)
[~,latIdx] = min(abs(lat--25));
[~,lonIdx] = min(abs(lon-115));
wind(latIdx, lonIdx) = 100;
% visualize data
figure
imagesc(lon,lat,wind)
axis xy
colorbar
% define the center of circle
center_lat = -30;
center_lon = 120;
R = 6371; % radius of the earth in km
% Haversine formula to calculate distances
dlat = lat - center_lat;
dlon = lon - center_lon;
a = sind(dlat.'/2).^2 + cosd(center_lat) .* cosd(lat.') .* sind(dlon/2).^2;
c = 2 * atan2(sqrt(a), sqrt(1-a));
distances = R * c;
figure
imagesc(lon,lat,distances)
line(lon(lonIdx),lat(latIdx),'Marker','x','Color','r')
axis xy
colorbar
% find points within 3000 km radius
radius_km = 3000;
within_radius = distances <= radius_km;
% get the maximum wind speed within the radius
[max_wind_speed,max_idx] = max(wind(within_radius));
tmp = distances(within_radius);
fprintf('maximum wind speed = %.2f\nat a distance of = %.2f\n', max_wind_speed, tmp(max_idx));
更多回答(1 个)
akshatsood
2024-8-15
编辑:akshatsood
2024-8-15
I understand that you want to determine the maximum value within a circular region in gridded data. To find the maximum wind speed within a 30km radius for your gridded wind data, you can follow these steps:
Load and Prepare Your Data: Ensure your data is loaded into MATLAB. I am assuming that you have three arrays taking reference from the question: lat, lon and windspeed.
Convert Degrees to Radians: convert your latitude and longitude from degrees to radians using "deg2rad" function.
Calculate Distances: Use the Haversine formula to calculate the distance between your points and the center point of your circle. For more information on Haversone formulae, please refer to the following resource
Find Maximum Wind Speed: Identify points within the 30km radius and find maximum value amongst these..
% load your data
% define the center of your circle
center_lat = -30;
center_lon = 100;
% convert degrees to radians
lat_rad = deg2rad(lat);
lon_rad = deg2rad(lon);
center_lat_rad = deg2rad(center_lat);
center_lon_rad = deg2rad(center_lon);
R = 6371; % radius of the earth in km
% Haversine formula to calculate distances
dlat = lat_rad - center_lat_rad;
dlon = lon_rad - center_lon_rad;
a = sin(dlat/2).^2 + cos(center_lat_rad) .* cos(lat_rad) .* sin(dlon/2).^2;
c = 2 * atan2(sqrt(a), sqrt(1-a));
distances = R * c;
% find points within 30km radius
radius_km = 30;
within_radius = distances <= radius_km;
% get the maximum wind speed within the radius
max_wind_speed = max(windspeed(within_radius));
fprintf('The maximum wind speed within a 30km radius is %.2f\n', max_wind_speed);
I hope this helps.
4 个评论
akshatsood
2024-8-16
Dear @Sarvesh
Thank you for the response
I beleive the issue you're experiencing seems to be related to the indexing and calculation of distances within the grid. When you extend the longitude range, the grid size changes, affecting how distances are calculated and which points fall within the specified radius.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Mapping Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!