Making an equidistant latlon grid from a non equidistant latlon grid
5 views (last 30 days)
Show older comments
I have the following type of ascii dataset: A 3 vector array with gridded latlon data with size [3,62880] in which the first column represents longitude values, the second column latitude values and the third height values. This consists of a full latlon grid made onedimensional. The latitude and longitude gridsizes are 240 and 262 respectively. (So this data can be easily put into a grid for plotting purposes). But (coming from a UTM conversion) the lat and lon values are not equidistant (and unevenly spaced) and I want to get an equidistant grid. So far I have tried to it like this:
x = data(1,:); %longitude
y = data(2,:); %latitude
z = data(3,:); %height
xmin = min(x); ymin = min(y);
xmax = max(x); ymax = max(y);
nlat = 240;
mlon = 262;
xv = linspace(xmin, xmax, mlon);
yv = linspace(ymin, ymax, nlat);
[X,Y] = meshgrid(xv,yv);
[X,Y,Z] = griddata(x,y,z,X,Y);
ID = isnan(Z);
Z(ID) = -9999;
Is this the correct way to do it? I obtain quite a bunch of missing values (which I set to -9999 for further processing) with trying different interpolation (should I use something else than griddata and meshgrid?) methods, and I want to minimize that as much as possible. Besides, I feel like some of the data is lost with this method. Could somebody recommend me the best way to convert a non equidistant latlon grid to a equidistant grid with correctly interpolated height values?
I hope I have provided enough information for you to help me, if not, ask me to provide more. I feel I might be doing something wrong with the conversion from the 1D vectors to the 2D grid as well (but find it hard to write down how it is originally put into the current array) but I doubt it has something to with the missing values.
Thanks in advance!
(for people known with NCL this is the way I usually read this data (which might explain the format)):
lon2d = onedetond(x,(/nlat,mlon/)) lat2d = onedtond(y, (/nlat,mlon/)) z2d = onedtond(z,(/nlat,mlon/))
1 Comment
Walter Roberson
on 23 Jan 2012
Dang, no wonder I could never locate these kinds of questions to refer to them: I kept reading the term as "lation" instead of "latlon". Time for new glasses, I think!
Accepted Answer
Bjorn Gustavsson
on 24 Jan 2012
Look at the matlab function: griddata, (there is nowadays a similar function with a new name that eludes me at the moment.) or John D'Errico's gridfit function: http://www.mathworks.se/matlabcentral/fileexchange/8998-surface-fitting-using-gridfit, that provides some smoothing as well, while griddata does a triangulation-interpolation.
HTH,
More Answers (2)
Walter Roberson
on 24 Jan 2012
MATLAB File Exchange, John D'Errico's inpaint_nans
2 Comments
Walter Roberson
on 24 Jan 2012
It depends what you want to do with the missing values. inpaint_nans would be for the case where you want the values to be interpolated to fill in the holes, taking in to account that multiple adjacent values might be missing; John's routine takes in to account curvatures of the area around, whereas most other routines that try to fill in for nans just use linear interpolation.
See Also
Categories
Find more on Surface and Mesh Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!