forked from mguerrap/5Beam-Turbulence-Methods
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Signature_QC.m
130 lines (86 loc) · 3.61 KB
/
Signature_QC.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
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
% Signature Low Correlation and Low Amp QC
clc
clear all
close all
% Define Min correlation and min amplitude
% Choose thresholds according to your data-set
% Nortek recommends using 50% of the maximum correlation of your data
mincor=50;
minamp=30;
% Number of bins
Nbin=20;
% Ensembles to QC
Ens1=10;
EnsN=43;
NEns=EnsN-Ens1+1;
% File path: where are the bin files
fpath = ['/Users/Maru/Documents/PhD_UW/5BeamCodes/BinDataSignature'];
prefix='SignatureData_Bin';
% Save path: where to save the QC data
savepath=['/Users/Maru/Documents/PhD_UW/5BeamCodes/BinDataSignature'];
% Raw Data
for bin=1:Nbin
bin
fname = [prefix int2str(bin) '.mat'];
load([ fpath '/' fname ])
% Only for good ensembles: 10 to 43
for fi=Ens1:EnsN
b1=SigData.vbeam1(:,fi);
b2=SigData.vbeam2(:,fi);
b3=SigData.vbeam3(:,fi);
b4=SigData.vbeam4(:,fi);
b5=SigData.vbeam5(:,fi);
NBurst=length(b1);
c1=SigData.Corbeam1(:,fi);
c2=SigData.Corbeam2(:,fi);
c3=SigData.Corbeam3(:,fi);
c4=SigData.Corbeam4(:,fi);
c5=SigData.Corbeam5(:,fi);
a1=SigData.Ampbeam1(:,fi);
a2=SigData.Ampbeam2(:,fi);
a3=SigData.Ampbeam3(:,fi);
a4=SigData.Ampbeam4(:,fi);
a5=SigData.Ampbeam5(:,fi);
bad = find( c1 < mincor | c2 < mincor | c3 < mincor | c4 < mincor | c5 < mincor |...
a1 < minamp | a2 < minamp | a3 < minamp | a4 < minamp | a5 < minamp);
%bad = find(isnan(burstu)==1);
all_data=find(c1); %get indices of all data
good_data=find(ismember(all_data,bad)==0); %finds the indices that are not in bad, i.e. the good ones
largobad(bin,fi)=length(bad);
largogood(bin,fi)=length(good_data);
if length(bad) < 0.3 * length(b1)
%burstu(bad) = nanmean(burstu); burstv(bad) = nanmean(burstv); burstw(bad) = nanmean(burstw);
SigData.vbeam1(bad,fi)= nanmean(b1(good_data));
SigData.vbeam2(bad,fi)= nanmean(b2(good_data));
SigData.vbeam3(bad,fi)= nanmean(b3(good_data));
SigData.vbeam4(bad,fi)= nanmean(b4(good_data));
SigData.vbeam5(bad,fi)= nanmean(b5(good_data));
SigData.u_x(bad,fi)=nanmean(SigData.u_x((good_data),fi));
SigData.v_y(bad,fi)=nanmean(SigData.v_y((good_data),fi));
SigData.w_z(bad,fi)=nanmean(SigData.w_z((good_data),fi));
SigData.u_east(bad,fi)=nanmean(SigData.u_east((good_data),fi));
SigData.v_north(bad,fi)=nanmean(SigData.v_north((good_data),fi));
SigData.w_up(bad,fi)=nanmean(SigData.w_up((good_data),fi));
% Replace NaN data with an interpolation
else
%burstu = NaN(size(burstu)); burstv = NaN(size(burstv)); burstw = NaN(size(burstw));
SigData.vbeam1(bad,fi)= NaN(size(b1));
SigData.vbeam2(bad,fi)= NaN(size(b1));
SigData.vbeam3(bad,fi)= NaN(size(b1));
SigData.vbeam4(bad,fi)= NaN(size(b1));
SigData.vbeam5(bad,fi)= NaN(size(b1));
SigData.u_x(bad,fi)=NaN(size(b1));
SigData.v_y(bad,fi)=NaN(size(b1));
SigData.w_z(bad,fi)=NaN(size(b1));
SigData.u_east(bad,fi)=NaN(size(b1));
SigData.v_north(bad,fi)=NaN(size(b1));
SigData.w_up(bad,fi)=NaN(size(b1));
end
end
save([savepath '/' 'SignatureData_QC_Bin' int2str(bin) '.mat'], 'SigData')
clear bad
end
%% Bad data percentage
BadTotal=sum(sum(largobad));
DataTotal=Nbin*NBurst*NEns;
PercentBad=BadTotal/DataTotal*100;