-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_opt_L.m
58 lines (38 loc) · 1.25 KB
/
find_opt_L.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
function L_opt = find_opt_L(SF,rf_lonlat)
L_test = 0.5:0.5:100;
D = [];
D2 = [];
STDs = [];
% Reduce spatial resolution
sires= [500 500];
% in case z is already small (smaller than 500x500)
if size(SF.z,1)<= 500
sires(1)= size(SF.z,1);
end
if size(SF.z,2)<= 500
sires(2) = size(SF.z,2);
end
lat2 = imresize(SF.lat,sires);
lon2 = imresize(SF.lon,sires);
z2 = imresize(SF.z, sires);
% Find values of reduction factor/ water levels in rfgrid
P = [];
xy = [lon2(:) lat2(:)];
for ii = 1: size(rf_lonlat,1)
[~,P(ii,1)] = min(abs(distance(rf_lonlat(ii,2),rf_lonlat(ii,1),xy(:,2),xy(:,1))));
end
for c = 1: length(L_test)
L = L_test(c);
rfgrid = red_fac_grid_FOL(lon2,lat2,z2,rf_lonlat,L);
% differences between the optimal interpolation grid and the values at
% the scalar positions
D{c,1} = rfgrid(P) - rf_lonlat(:,3);
D2(c,1) = mean(D{c,1});
STDs(c,1) = std(std(rfgrid));
end
% normalization
STDs_n = (STDs - min(STDs))./(max(STDs) - min(STDs));
D2_n = (D2 - min(D2))./(max(D2) - min(D2));
% criteria for the optimal value of the interpolation length (L)
[~,L_opt] = max(STDs_n./D2_n);
L_opt = L_test(L_opt);