-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresample_lucy_v1.m
73 lines (67 loc) · 1.45 KB
/
resample_lucy_v1.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
function [out] = resample_lucy_v1(a,res,gridname)
% This function to change pixel resolution
%30 arc seconds = 0.00833333333
% size of the matrix s
a(a==0)=NaN;
s=round(res/0.00833333333);
m=1;
n=s;
out=zeros( );
if strcmp(gridname,'countries')
for i=1:size(a,1)/s;
o=1;
p=s;
for j=1:size(a,2)/s;
x=a(m:n,o:p);
if sum(sum(isnan(x)))<=((s*s)*(2/3))
k1=mode(x(:));
else
k1=NaN;
end
out(i,j)=k1;
o=o+s;
p=p+s;
end
clear x
m=m+s;
n=n+s;
end
elseif strcmp(gridname,'urban')
for i=1:size(a,1)/s;
o=1;
p=s;
for j=1:size(a,2)/s;
x=a(m:n,o:p);
if sum(sum(isnan(x)))<=((s*s)*(2/3))
k1=mode(x(:));
else
k1=NaN;
end
out(i,j)=k1;
o=o+s;
p=p+s;
end
clear x
m=m+s;
n=n+s;
end
elseif strcmp(gridname,'population')
for i=1:size(a,1)/s;
o=1;
p=s;
for j=1:size(a,2)/s;
x=a(m:n,o:p);
if sum(sum(isnan(x)))<=((s*s)*(2/3))
k1=nanmean(x(:));
else
k1=NaN;
end
out(i,j)=k1;
o=o+s;
p=p+s;
end
clear x
m=m+s;
n=n+s;
end
end