Approach to computing statistics on a latitude/longitude grid

67 views (last 30 days)
I'm looking for suggestions on the best approach to computing statistics on a latitude/longitude grid in MATLAB.
I have a non-gridded dataset with global wind observations (wind magnitude in knots) based on latitude and longitude over 30 years. I want to average that data on some latitude/longitude grid (say 1°x1° grid) then create a density-like plot of those average wind values on a map.
I'm trying to find the most efficient approach to doing this analysis in MATLAB. Thanks.

Answers (3)

Image Analyst
Image Analyst on 20 Oct 2025 at 2:31
I'd probably convert the (lat, lon, speed) into a double matrix (image). Then I'd sum up all the matrices to get the overall average. See attached scatteredInterpolant demo.

Star Strider
Star Strider on 20 Oct 2025 at 3:14
It would probably be best to use Mapping Toolbox functions for this, since on a world map, the latitude and longitude distances would be different at different locations.
It has several interpolation functions, geointerp may be closest to what you want to do, and mapinterp could also be useful. There are also others. (I do not have the Mapping Toolbox, so I have little experience with it.)
Calculating spatial statistics could be a challenge.
There are contour functions (specifically contour3m) that could help to depict those values.
  11 Comments
Star Strider
Star Strider on 21 Oct 2025 at 18:26
I'm not certain that I completely understand.
If your data are in the same locations and simply gathered at different dates and times, and all you want are the statistics on those specific locations (that don't change), then using the mean function (and related functions) will work. There would be no specific need to interpolate them.
Since I doubt that any of the data are ever negative and are all probably greater than zero, they would most likely be lognormally distributed. If so, use the lognormal distribution functions to estimate their means and variances or standard deviations. You can get estimates of the parameters in the original data units from:
lognparms = @(mu,sigma) [exp(mu + sigma^2/2); exp(2*mu + sigma^2) * (exp(sigma^2)-1); exp(mu); exp(mu-sigma.^2)]; % [mean; var; median; mode]
using the returned by the lognormal distribution fitting functions.
.
Cedric Wannaz
Cedric Wannaz on 21 Oct 2025 at 18:41
Edited: Cedric Wannaz on 21 Oct 2025 at 18:45
"With respect to wind magnitude, I assume that also includes direction. It would likely be best to decompose the wind magnitude and direction to individual east-west and north-south components before doing any statistics on them."
Aside from issues related to continuity, this comment from Star Strider is especially important if your are planning on using the summarized data for computing atmospheric mixing/transport/etc. (e.g., in a Eulerian model). Imagine a trivial world where winds go east to west half the time and west to east the other half. Averaging your data in this situation would lead to a wind velocity of 0 (or close), that is no mixing and no transport. In this context, it is often preferable to decompose wind speed+directions or velocities into components u+, u-, v+, v-, before averaging (otherwise we underestimate mixing/transport).

Sign in to comment.


William Rose
William Rose ungefär 11 timmar ago
Edited: William Rose ungefär en timme ago
[Edit: I am replacing the script with a revised version that corrects a mistake in the previous version. The error was in the calculation of X and Y components of velocity for the quiver plot. Wind directions in this simulated data file, and as recorded by data buoys, are compass headings. When computing x and y components of wind vectors, do x=-r* cosd(theta) and y=-r*sind(theta), where theta=90-compass heading. In the earlier version, I did x=-r*cosd(compass heading), etc. (The minus signs are because wind is "out of", or from, the specified direction.)]
I've been trying to submit an answer but I keep getting an error. I will try with text, and without the figures I had intended to attach. I will attach data files and script separately.
------------
Here is a file with 180K simulated observations of wind direction and speed at random latitudes and longitudes.
I was unable to upload the full file of wind observations because it exceeds 5 MB, even when zipped. Therefore I saved the top and bottom halves of the array separately, and attached them. Do the following to reconstruct the full file:
load('windObs3a');
load('windObs3b');
windObs3=[windObs3a;windObs3b];
save('windObs3',windObs3');
Then you will be able to run the attached script, which loads data from file windObs3.mat.
The latitudes are distributed in proportion to the area (circumference) at each latitude, up to some random flucuations. If you didn't do that, you'd get much more dense sampling at the poles.
Find the mean of direction by taking the cosine and sine of each direction, then find the mean values of the cosines and sines, then using atan2d() to find the mean direction:
meanX=mean(cosd(wdir));
meanY=mean(sind(wdir));
meanwDir=atan2d(meanY,meanX);
This approach prevents the problems that otherwise occur for values near the 0 to 360 boundary. (You don't want the mean direction of 359 and 1 to be 180; you want it to be 0...)
Use logical indexing to find the means for each latitude range and for each latitude, longitude block. For example,
LatEdges=-90:3:90; % edges of 3-degree latitude bands
LatMid=(LatEdges(1:end-1)+LatEdges(2:end))/2; % middle of each band (used for plotting)
M1=length(LatMid);
LongEdges=0:3:360; % edges of 3-degree longitude bands
LongMid=(LongEdges(1:end-1)+LongEdges(2:end))/2; % middle of each band (used for plotting)
M2=length(LongMid);
% ...
% Compute mean speed in each latitude,longitude block
meanWspd2=zeros(M1,M2);
for i=1:M1
for j=1:M2
meanWspd2(i,j)=mean(wspd(Lat>=LatEdges(i) & Lat<LatEdges(i+1) & ...
Long>=LongEdges(j) & Long<LongEdges(j+1)));
end
end
The attached script makes 5 figures.
Figure 1 shows the number of observations in each band of latitude and longitude. It shows that the number of samples at each latitude is approximately proportional to cos(Lat), and the number at each longitude is approximately the same at all longitudes. This is what we expect, if the sampling is random with the same likelihood over the whole globe.
Figure 2 shows the mean wind speed and mean wind direction as functions of latitude. The winds vary across the tropics (defined here at 0 to +-30), mid-latitudes (+-30 to 60), and polar regions (+-60 to 90). The mean wind speed is near 0 at the equator, the poles, and the boundaries between topics, mid-latitudes, and polar regions. The mean wind speed is ~10 knots in the mid-tropics, ~15 in the mid-mid-latitudes, and ~10 in the mid-polar regions. The prevailing wind direction is S at S pole, SE at Lat=-75, E at Lat=-60, W at Lat=-59, NW at Lat=-45, N at Lat=-30, S at Lat=-29, SE at Lat=-15, and E at the equator. In the northern hemisphere the directions are reflected in the N versus S direction, so wdir=NE at Lat=+15, SW at Lat=+45, NE at Lat=+75, and N at N pole.
Figure 3 shows the histogram of wind speed around latitudes +15, +45, and +75.
Figure 4 shows the histogram of wind direction around latitudes +15, +45, and +75. The plots shows that the most likely direction is NE at Lat=+15, SW at Lat=+45, and NE at Lat=+75, and it shows that the direction varies significantly.
Figure 5 shows mean wind speed as a function of latitude and longitude, using 6x6 degree blocks. There are some blocks near the poles where there are no samples. This is an equirectangular projection of the Earth's surface.
Combine mean wind speed and direction data to get the x and y components of wind velocity.
meanWindX=-cosd(meanWdir2).*meanWspd2;
meanWindY=-sind(meanWdir2).*meanWspd2;
Plot the data with quiver():
quiver(LongMid,LatMid,meanWindX,meanWindY)
Good luck with your research.
  1 Comment
William Rose
William Rose 37 minuter ago
If you run the script attached to the answer I offered, you should get 6 figures. They correspond to the figures I refer to in my answer as Figures 1-5, plus quiver plot.

Sign in to comment.

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!