Interpolation problem between two 2D global datasets

2 次查看(过去 30 天)
Hello,
I have two matrices I would like to compare.
First Matrix:
Serna (360x720)
lat (360x1)
lon (720x1)
Second Matrix:
first_model (288x192)
lat_model (192x1)
lon_model (288x1)
I would like to interpolate first_model to the dimensions of Serna. However, when I use this code:
[X, Y] = meshgrid(lat_model, lon_model); %first_model coordinates
[Xq, Yq] = meshgrid(lat, lon); %Serna coordinates
Serna_approx = interp2(X, Y, first_model', Xq, Yq);
I get the error that it is not monotonically increasing. However, when I interpolate Serna to the dimensions of first_model (to lower resolution), it works perfectly fine. I don't know what I'm doing wrong.
I have attached the data
Any help is appreciated.
Thanks!
Melissa

采纳的回答

Stephen23
Stephen23 2015-5-15
编辑:Stephen23 2015-5-15
There is a major discontinuity in the middle of the longitude data, that makes interpolation impossible. Lets find it:
>> median(diff(lat_model))
ans =
0.9424
>> all(0<diff(lat_model)) % this is monotonic, so no problem
ans =
1
>> median(diff(lon_model))
ans =
1.2500
>> all(0>diff(lon_model)) % not monotonic!
ans =
0
>> tmp = diff(lon_model);
>> find(tmp<0) % lets find where...
ans =
145
>> lon_model(140:150) % and the data looks like this:
ans =
173.7500
175.0000
176.2500
177.5000
178.7500
180.0000
-178.7500
-177.5000
-176.2500
-175.0000
-173.7500
Wow... it jumps from +180 to -178.75, in the middle of a monotonic increasing sequence.
How to deal with this is up to you, and depends on what the data represents. If these are degrees you may be able to convert them to the positive equivalents:
idx = lon_model<0;
lon_model(idx) = 360 + lon_model(idx);
You should also remove that transpose from first_model, which will cause another error. This code works without error:
load data
idx = lon_model<0;
lon_model(idx) = 360 + lon_model(idx);
[X, Y] = meshgrid(lat_model, lon_model); %first_model coordinates
[Xq, Yq] = meshgrid(lat, lon); %Serna coordinates
Serna_approx = interp2(X, Y, first_model, Xq, Yq);
although this is not proof that it does what want it too
  2 个评论
Melissa
Melissa 2015-5-15
When I use this code, it only gives me the interpolated data for longitudes 0+
The reason why the longitude vector is not monotonically increasing is because I wrapped it to 180.
Originally, the lon_model spanned 0 to 360 while the lon (Serna) spanned -180 to 180. Therefore, I can't seem to keep both of them monotonically increasing while still on the same degrees coordinate system
Walter Roberson
Walter Roberson 2015-5-15
You need to unwrap the one that crosses 0, like I indicated before:
degrad = pi./180;
unwrappedBlong = unwrap(Blong .* degrad) ./ degrad;
For example, [177 178 180 -178 -177] unwraps to [177 178 180 182 183].
You can circshift the matrix if you need to move the negative values to after the positive values.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by