-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcurAscTotalQCtests_v11.m
123 lines (97 loc) · 3.7 KB
/
curAscTotalQCtests_v11.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
%% curAscTotalQCtests_v11.m
% This function performs the QC tests on total velocity data. The tests are
% the ones defined for the European common data and metadata model. This
% function is suited for the conversion of native .cur_asc WERA files in to
% netCDF files compliant to the European common data and metadata model.
% In particular, the following tests are performed:
% - Velocity threshold
% - GDOP threshold
% - Variance threshold
% - Temporal Derivative
% - Data Density threshold
% - Balance of contributing radials from different sites
% INPUT:
% mat_tot: structure containing total file in Codar format
% Total_QC_params: structure containing parameters for total QC tests
% OUTPUT:
% overall: overall quality flag (good data value is assigned
% if and only if all QC tests are passed
% varThr: Variance threshold quality flags
% GDOPThr: GDOP threshold quality flags
% dataDens: Data Density quality flags
% velThr: Velocity threshold quality flags
% Author: Lorenzo Corgnati
% Date: June 6, 2019
% E-mail: [email protected]
%%
function [overall, varThr, GDOPThr, dataDens, velThr] = curAscTotalQCtests_v11(mat_tot, Total_QC_params)
disp(['[' datestr(now) '] - - ' 'curAscTotalQCtests_v11.m started.']);
TQC_err = 0;
%% Prepare QC flag variables
try
overall = netcdf.getConstant('NC_FILL_BYTE').*int8(ones(size(mat_tot.U_grid)));
varThr = netcdf.getConstant('NC_FILL_BYTE').*int8(ones(size(mat_tot.U_grid)));
GDOPThr = netcdf.getConstant('NC_FILL_BYTE').*int8(ones(size(mat_tot.U_grid)));
dataDens = netcdf.getConstant('NC_FILL_BYTE').*int8(ones(size(mat_tot.U_grid)));
velThr = netcdf.getConstant('NC_FILL_BYTE').*int8(ones(size(mat_tot.U_grid)));
catch err
disp(['[' datestr(now) '] - - ERROR in ' mfilename ' -> ' err.message]);
TQC_err = 1;
end
%%
%% Prepare variables for QC tests
try
% Variance Threshold QC test
variance = ((mat_tot.U_grid.^2).*(mat_tot.U_acc).^2) + ((mat_tot.V_grid.^2).*(mat_tot.V_acc).^2);
% Velocity Threshold QC test
totVel = sqrt(((mat_tot.U_grid).^2) + ((mat_tot.V_grid).^2));
catch err
disp(['[' datestr(now) '] - - ERROR in ' mfilename ' -> ' err.message]);
TQC_err = 1;
end
%%
%% Populate QC variables
try
% Velocity Threshold quality flags
velThr(totVel>Total_QC_params.VelThr) = 4;
velThr(totVel<=Total_QC_params.VelThr) = 1;
% GDOP Threshold quality flags
if(sum(sum(isnan(mat_tot.GDOP)))<numel(mat_tot.GDOP))
GDOPThr(mat_tot.GDOP>Total_QC_params.GDOPThr) = 4;
GDOPThr(mat_tot.GDOP<=Total_QC_params.GDOPThr) = 1;
else
GDOPThr(~isnan(totVel)) = 0;
end
% Data Density Threshold quality flag
dataDens(~isnan(totVel)) = 1;
% Variance Threshold quality flags
varThr(variance>Total_QC_params.VarThr) = 4;
varThr(variance<=Total_QC_params.VarThr) = 1;
catch err
disp(['[' datestr(now) '] - - ERROR in ' mfilename ' -> ' err.message]);
TQC_err = 1;
end
%%
%% Populate the overall quality variable
% Current data file
try
for ii=1:size(overall,1)
for jj = 1:size(overall,2)
if(~isnan(mat_tot.U_grid(ii,jj)))
if((varThr(ii,jj) == 1) && (velThr(ii,jj) == 1) && (GDOPThr(ii,jj) == 1) && (dataDens(ii,jj) == 1))
overall(ii,jj) = 1;
else
overall(ii,jj) = 4;
end
end
end
end
catch err
disp(['[' datestr(now) '] - - ERROR in ' mfilename ' -> ' err.message]);
TQC_err = 1;
end
%%
if(TQC_err==0)
disp(['[' datestr(now) '] - - ' 'curAscTotalQCtests_v11.m successfully ecexuted.']);
end
return