-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCAFEPlot.m
More file actions
142 lines (137 loc) · 4.3 KB
/
CAFEPlot.m
File metadata and controls
142 lines (137 loc) · 4.3 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
function [h] = CAFEPlot(file1,file2,const,type,color)
% Compute the cumulative area fraction difference between two fort.53's for
% either harmonic amplitudes or harmonic phases (by changing the "type").
% CAFE plots originate from Hagen et al. 2001.
% kjr, und, chl 2018
x1 = ncread(file1,'x');
y1 = ncread(file1,'y') ;
t1 = double(ncread(file1,'element')');
p1 = [x1,y1] ;
switch type
case('amp')
disp('For amplitude');
temp = ncread(file1,'amp');
a1 = temp(const,:)'; clearvars temp;
case('amppe')
disp('For amplitude with percent error');
temp = ncread(file1,'amp');
a1 = temp(const,:)'; clearvars temp;
case('phs')
disp('For phase');
temp = ncread(file1,'phs');
a1 = temp(const,:)'; clearvars temp;
end
x2 = ncread(file2,'x');
y2 = ncread(file2,'y') ;
t2 = double(ncread(file2,'element')');
p2 = [x2,y2] ;
switch type
case('amp')
temp = ncread(file2,'amp');
a2 = temp(const,:)'; clearvars temp;
F = scatteredInterpolant(x2,y2,a2);
clearvars a2;
a2 = F(x1,y1);
case('amppe')
temp = ncread(file2,'amp');
a2 = temp(const,:)'; clearvars temp;
F = scatteredInterpolant(x2,y2,a2);
clearvars a2;
a2 = F(x1,y1);
case('phs')
temp = ncread(file2,'amp');
a2 = temp(const,:)'; clearvars temp;
temp = ncread(file2,'phs');
phs2 = temp(const,:)'; clearvars temp;
% convert to complex
c_2 = a2.*exp(1i*deg2rad(phs2));
% interpolate onto 1
F = scatteredInterpolant(x2,y2,c_2);
a2 = F(x1,y1);
% convert back to phase
a2 = rad2deg(angle(a2));
a2(a2 < 0) = a2(a2 < 0) + 360;
end
pmid1 = (p1(t1(:,1),:)+p1(t1(:,2),:)+p1(t1(:,3),:))/+3; % compute centroids
pmid2 = (p2(t2(:,1),:)+p2(t2(:,2),:)+p2(t2(:,3),:))/+3; % compute centroids
% calculate areas of triangles
for i = 1 : length(t1)
x1 = p1(t1(i,1),1);
x2 = p1(t1(i,2),1);
x3 = p1(t1(i,3),1);
y1 = p1(t1(i,1),2);
y2 = p1(t1(i,2),2);
y3 = p1(t1(i,3),2);
area1(i) = 1/2*abs((x2-x1)*(y3-y1)-(x3-x1)*(y2-y1));
aa1(i,1) = sum(a1(t1(i,:)))/3; % <-average solution on element
aa2(i,1) = sum(a2(t1(i,:)))/3; % <-average solution on element
end
%
switch type
case('amp')
bins = -0.10:0.01:0.10;
bincenters = bins(1:end-1)+(diff(bins)/2);
error = aa2 - aa1 ;
case('amppe')
bins = -5:1:5;
bincenters = bins(1:end-1)+(diff(bins)/2);
error = 100.*((aa2 - aa1)./aa1);
case('phs')
bins = -10:1:10;
bincenters = bins(1:end-1)+(diff(bins)/2);
error = aa2 - aa1 ;
end
% % DEBUG
% figure;
% fastscatter(pmid1(:,1),pmid1(:,2),error);
% cmocean('balance',9); colorbar;
% figure;
% % END DEBUG
binmap = discretize(error,bins);
for i = 1 : length(bins)-1
ix=find(binmap==i);
NumInBin=length(find(binmap==i));
areaOfErr(i)=NumInBin*sum(area1(ix));
end
valid = ~isnan(binmap);
totalArea = sum(area1(valid))*sum(valid);
% cumulative area fraction
hold on;h= plot(bincenters,100.*(areaOfErr./totalArea),'color',color,'linewi',2);
switch type
case('amp')
% decorations
hold on; plot(linspace(-0.1,0.1,100),linspace(1,1,100),'k-','linewi',2);
xlim([-0.1 0.1]);
ylim([0.001 100]);
YTick=[0.01; 0.1; 1; 10; 100];
yticks(YTick);
xlabel('Elevation Difference (m)');
ylabel('Cumulative Area (%)');
set(gca, 'YScale', 'log');
set(gca,'FontSize',16);
grid minor;
case('amppe')
% decorations
hold on; plot(linspace(-5,5,100),linspace(1,1,100),'k-','linewi',2);
xlim([-5 5]);
ylim([0.001 100]);
YTick=[0.01; 0.1; 1; 10; 100];
yticks(YTick);
xlabel('Relative Elevation Difference (%)');
ylabel('Cumulative Area (%)');
set(gca, 'YScale', 'log');
set(gca,'FontSize',16);
grid minor;
case('phs')
% decorations
hold on; plot(linspace(-10,10,100),linspace(1,1,100),'k-','linewi',2);
xlim([-10 10]);
ylim([0.001 100]);
YTick=[0.01; 0.1; 1; 10; 100];
yticks(YTick);
xlabel('Elevation Phase Difference (deg)');
ylabel('Cumulative Area (%)');
set(gca, 'YScale', 'log');
set(gca,'FontSize',16);
grid minor;
end