在MATLAB上执行普通克里金法

时间:2019-04-21 18:56:50

标签: matlab grid interpolation kriging

我正在尝试使用以下链接中的函数在MATLAB中对数据执行普通克里金法! https://www.mathworks.com/matlabcentral/fileexchange/29025-ordinary-kriging

这似乎很简单,但是我在使它工作时遇到了一些问题。当前,使用我将提供的代码,我得到了错误:

Error using griddedInterpolant
The grid vectors do not define a grid of points that match the given values.

Error in interp2/makegriddedinterp (line 214)
            F = griddedInterpolant(varargin{:});

Error in interp2 (line 127)
        F = makegriddedinterp({X, Y}, V, method,extrap);

Error in untitled (line 18)
    z = interp2(X,Y,Z,x,y); 

我尝试为lat和lon划分网格,但是我不知道这是否必要,当我完成这些任务时,我遇到了内存问题,达到了内存极限,即使这确实可以正常工作,但速度太慢而无法实现,因为这些阵列的分辨率约为88000x88000。

以下是我的代码:

lat = ncread('/projectnb/atmchem/ahsouri/MCIP/GRIDCRO2D_1km_HGB_2013249', 'LAT'); % degrees
no2 = ncread('/projectnb/atmchem/ahsouri/CCTM/CCTM_US1k.CONC.1km_HGB.2013249', 'NO2'); % ppm
lon = ncread('/projectnb/atmchem/ahsouri/MCIP/GRIDCRO2D_1km_HGB_2013249', 'LON'); % degrees 
no2_snip = [no2(1,1,1,12), no2(100,100,1,12), no2(260,260,1,12)];
lat_snip = [lat(1,1),lat(100,100),lat(260,260)];
lon_snip = [lon(1,1), lon(100,100),lon(260,260)];

% create random field with autocorrelation
x = lat;
y = lon;
no2_surf = no2(:,:,1,12);
Z = no2_surf;

% sample the field
n = 500;
X = lat_snip;
Y = lon_snip;
z = interp2(X,Y,Z,x,y);

% plot the random field
subplot(2,2,1)
imagesc(X(1,:),Y(:,1),Z); axis image; axis xy
hold on
plot(x,y,'.k')
title('random field with sampling locations')

% calculate the sample variogram
v = variogram([x y],z,'plotit',false,'maxdist',100);
% and fit a spherical variogram
subplot(2,2,2)
[dum,dum,dum,vstruct] = variogramfit(v.distance,v.val,[],[],[],'model','stable');
title('variogram')

% now use the sampled locations in a kriging
[Zhat,Zvar] = kriging(vstruct,x,y,z,X,Y);
subplot(2,2,3)
imagesc(X(1,:),Y(:,1),Zhat); axis image; axis xy
title('kriging predictions')
subplot(2,2,4)
contour(X,Y,Zvar); axis image
title('kriging variance')

lat是336x264 lon是336x264 no2(:,:,1,12)是336x264

lat snip,lon snip和no2 snip的长度均为3个变量,并分别在我要从其插入的点上指定lat,lon和no2的值

我希望从整个图中指定的三个点进行插值。任何帮助将不胜感激!

0 个答案:

没有答案