Efficient Method for Multiple Gridded Interpolation

2 ビュー (過去 30 日間)
FeAde
FeAde 2020 年 11 月 28 日
回答済み: Sindar 2020 年 11 月 30 日
I have scattered points of rain guage stations with random missing values. I also have NDVI values at these stations (complete records). The data is from January -Decemeber, 2016.
I want to interpolate both variables indepedently at daily time scale excluding any NaN stations for BOTH variables (i.e. exclude Nan from rainfall and corresponding NDVI). They will be saved as a Geotiff. This is my code for a single grid.
I want to do this in a loop with NaN excluded at each time step.
%%% load data
load data_now.dat
[lon,lat] = ndgrid(lon,lat);
lonobs = data_now(:,1);
latobs = data_now(:,2);
J= data_now(:,3);
G=data_now(:,4)
% lon and lat are read from a netcdf file
lon = ncread('important_gh.nc','lon');
lat = ncread('important_gh.nc','lat');
%Interpolate
Rainq = griddata(latobs,lonobs,J,lat,lon);
NDVIq = griddata(latobs,lonobs,G,lat,lon);
Thanks

回答 (1 件)

Sindar
Sindar 2020 年 11 月 30 日
I don't know how fast it will be, but I think this'll work
% lon and lat are read from a netcdf file
lon = ncread('important_gh.nc','lon');
lat = ncread('important_gh.nc','lat');
[lon,lat] = ndgrid(dl.lon,dl.lat);
data_files = ...
for ind=1:length(data_files)
% load into a variable
data_now = load(data_files{ind});
lonobs = data_now(:,1);
latobs = data_now(:,2);
J= data_now(:,3);
G= data_now(:,4);
% find valid locations
idx = (~isnan(J)) & (~isnan(G));
%Interpolate, dropping nan locations
Rainq = griddata(latobs(idx),lonobs(idx),J(idx),lat,lon);
NDVIq = griddata(latobs(idx),lonobs(idx),G(idx),lat,lon);
% save
end

カテゴリ

Help Center および File ExchangeNetCDF についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by