-
Notifications
You must be signed in to change notification settings - Fork 2
/
process_svc_3Coutput.m
121 lines (88 loc) · 3.24 KB
/
process_svc_3Coutput.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
function [svc_final] = process_svc_3Coutput(input_struct,input_path,station_ids)
% %%%%%%%%%%%%%%%%%%%%%% %
% process_svc_3Coutput.m %
% %%%%%%%%%%%%%%%%%%%%%% %
%
% Inputs:
% -------
% input_struct : structure containing svc data with
% scans sorted correctly and outliers identified
% (default = svc_final [output from
% process_svc_rrs.m])
% input_path : location of files generated with 3C (in Python)
% station_ids : Station name/ID for colocated data, aligned with
% the input structure
%
% Outputs:
% --------
% svc_final : structure array from process_svc_rrs, updated
% with Rrs values calculated using 3C and QA/QC
% metrics
%
% -------------------------------------------------------------------------
% Set inputs to default values if not defined
% -------------------------------------------
if exist('input_struct','var')==0
disp('Input structure required to run function');
return
end
if exist('input_path','var')==0
disp('No path provided for 3C input files');
return
end
% Number of stations
if exist('station_ids','var')==0
cnt = 0;
for ii = 1:length(input_struct)
cnt = cnt + 1;
station_ids{ii} = strcat(['St',num2str(cnt)]);
end
end
% Get 3C output file names from input directory
% ---------------------------------------------
contents = dir(input_path);
files = string([]);
for ii = 1:length(contents)
if ~strcmp(contents(ii).name(1),'.') % removes "hidden" contents
files = [files; string(contents(ii).name)];
end
end
% Get station ids from file names (everything before the last underscore)
% -----------------------------------------------------------------------
file_ids = string([]);
for ii = 1:size(files,1)
file_char = char(files(ii));
uidx = strfind(file_char,'_');
file_ids(ii) = string(file_char(1:max(uidx)-1));
end
file_ids = file_ids';
files = string(files);
clear contents uidx;
% Initiate output structure & append data within 3C output files
% --------------------------------------------------------------
fn = fieldnames(input_struct);
for ii=1:length(input_struct)
svc_final(ii).station_id = station_ids(ii);
for jj = 1:length(fn)
svc_final(ii).(fn{jj}) = input_struct(ii).(fn{jj});
end
idx = find(strcmp(file_ids,svc_final(ii).station_id));
for jj = 1:length(idx)
dat=importdata(fullfile(input_path,files{idx(jj)}),',');
svc_final(ii).rrs_wave_3C(:,jj)=dat.data(:,1);
svc_final(ii).rrs_3C(:,jj)=dat.data(:,5);
end
end
% Calculate Quality Water Index Polynomial (QWIP) score (Dierssen et al.,
% 2022) and Wei QA score (Wei et al., 2016) for 3C spectra in final output
% structure
% ------------------------------------------------------------------------
for ii = 1:length(svc_final)
[qwip_3c,~] = qwip_score(svc_final(ii).rrs_3C,svc_final(ii).rrs_wave_3C);
svc_final(ii).qwip_score_3C = qwip_3c;
for jj = 1:size(svc_final(ii).rrs_3C,2)
[~,~,~,wei_3c] = QAscores(svc_final(ii).rrs_3C(:,jj)',svc_final(ii).rrs_wave_3C(:,jj)');
svc_final(ii).wei_score_3C(jj) = wei_3c;
end
end
end