How would you upscale gridded data?

2 views (last 30 days)
andrew joros
andrew joros on 5 Apr 2012
Hi
I have a 2-d 12km dataset that I would like to convert to 32km gridded resolution. Just wondering how you would approach this? I have written a for loop seen here: http://pastebin.com/6iq97HyR, but it takes way too long to complete(~1.5 weeks)
Thanks
for lo = 20:91
for la = 1:101
tmplat = latsmall(lo,la);
tmplon = lonsmall(lo,la);
f = find(min((latNLDAS(:)-tmplat).^2+(lonNLDAS(:)-tmplon).^2)==((latNLDAS(:)-tmplat).^2+(lonNLDAS(:)-tmplon).^2));
y = floor(f/224)+1;
y = y(1);
x = mod(f,224);
x = x(1);
for yr = 1:15
tic;
for mo = 1:5
fprintf(' lo %d la %d yr %d mo %d \n',lo,la,yr+1994,mo);
for dy=1:31
pptNL(yr,lo,la,mo,dy)= nan;
if (mo == 2 || 5) && (dy==31)
continue;
else
date = [num2str(mo+4) '/' num2str(dy) '/' num2str(1994+yr)];
if (x-2<=0) || (y-2<=0) || (x-2>224) || (y-2>464) ||...,
(x-1<=0) || (y-1<=0) || (x-1>224) || (y-1>464) ||...,
(x-0<=0) || (y-0<=0) || (x-0>224) || (y-0>464) ||...,
(x+1<=0) || (y+1<=0) || (x+1>224) || (y+1>464) ||...,
(x+2<=0) || (y+2<=0) || (x+2>224) || (y+2>464)
continue
else
pptNL(yr,lo,la,mo,dy)= nanmean...,
([PRECIP(x-2,y+2,datevec2doy(datevec(date)))...,
PRECIP(x-2,y+1,datevec2doy(datevec(date)))...,
PRECIP(x-2,y+0,datevec2doy(datevec(date)))...,
PRECIP(x-2,y-1,datevec2doy(datevec(date)))...,
PRECIP(x-2,y-2,datevec2doy(datevec(date)))...,
PRECIP(x-1,y+2,datevec2doy(datevec(date)))...,
PRECIP(x-1,y+1,datevec2doy(datevec(date)))...,
PRECIP(x-1,y+0,datevec2doy(datevec(date)))...,
PRECIP(x-1,y-1,datevec2doy(datevec(date)))...,
PRECIP(x-1,y-2,datevec2doy(datevec(date)))...,
PRECIP(x,y+2,datevec2doy(datevec(date)))...,
PRECIP(x,y+1,datevec2doy(datevec(date)))...,
PRECIP(x,y,datevec2doy(datevec(date)))...,
PRECIP(x,y-1,datevec2doy(datevec(date)))...,
PRECIP(x,y-2,datevec2doy(datevec(date)))...,
PRECIP(x+1,y+2,datevec2doy(datevec(date)))...,
PRECIP(x+1,y+1,datevec2doy(datevec(date)))...,
PRECIP(x+1,y+0,datevec2doy(datevec(date)))...,
PRECIP(x+1,y-1,datevec2doy(datevec(date)))...,
PRECIP(x+1,y-2,datevec2doy(datevec(date)))...,
PRECIP(x+2,y+2,datevec2doy(datevec(date)))...,
PRECIP(x+2,y+1,datevec2doy(datevec(date)))...,
PRECIP(x+2,y+0,datevec2doy(datevec(date)))...,
PRECIP(x+2,y-1,datevec2doy(datevec(date)))...,
PRECIP(x+2,y-2,datevec2doy(datevec(date)))...,
]);
end
end
end
end
end
end
end
  1 Comment
Oleg Komarov
Oleg Komarov on 5 Apr 2012
I added the code, next time please consider formatting it into the post as I did.
Have you tried running the profile on a small data set to identify the bottlenecks?
Preallocating pptNL would help drastically.
Also, as is, contributors cannot help you because you didn't supply some sample inputs to run your code with.
http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer
What is latsmall and lonsmall? (function or variable?)

Sign in to comment.

Answers (0)

Categories

Find more on Data Type Conversion 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!