Newer
Older
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
function corTsgMethod1(hMainFig, dateMin, dateMax)
%
% Correct the TSG salinity time series with the Water sample.
% Use the median value of TIME_WINDOWS water sample to compute the
% correction. see the documentation
%
% Input
% hMainFig ..... Handle to the main GUI
% dateMin ...... the correction is applied between dateMin and date Max
% dateMax ...... the correction is applied between dateMin and date Max
%
% Output
%
% TO DO
% corTsgMethod1.m
% 1) Test if there are NaN values in 'sample':
% We could get some problem with the computation of the median and std
% 2) Initialisation de la structure 'cor'
% 3) Test for anormal sample-tsg difference - Suppress bad points
% 4) Test on the validation code. do we apply the correction whatever the
% is the code ?
% 5) Return an Error code ?
% Get application data
% --------------------
tsg = getappdata( hMainFig, 'tsg_data');
sample = getappdata( hMainFig, 'sample');
% Shorten the variable name
% -------------------------
TIME_WINDOWS = tsg.cst.COR_TIME_WINDOWS;
% The correction is computed between dateMin and dateMax
% ------------------------------------------------------
dt = find(sample.DAYD >= dateMin & sample.DAYD <= dateMax);
% TO DO : Initialisation de la structure 'cor'
% --------------------------------------------
% --------------------------------------------
for i = 1 : length(dt)
% Find the sample within TIME_WINDOWS
% ------------------------------------
ind = find( sample.DAYD(dt) >= sample.DAYD(dt(i)) - TIME_WINDOWS/2 &...
sample.DAYD(dt) <= sample.DAYD(dt(i)) + TIME_WINDOWS/2);
% Compute the median difference and error within TIME_WINDOWS
% -----------------------------------------------------------
if ~isempty(ind)
cor.DAYD(i) = sample.DAYD(i);
cor.DIFF(i) = median(sample.SSPS_DIF(ind));
cor.ERROR(i) = std(sample.SSPS_DIF(ind))/sqrt(length(ind));
cor.NVALUE(i) = length(ind);
end
end
% The error is maximum if the median is computed with less than 4 samples
% -----------------------------------------------------------------------
cor.ERROR( find(cor.NVALUE < 4) ) = 1;
% The correction is applied between dateMin and dateMax
% We attribute to dateMin the first correction computed
% and to dateMax the last one
%
% Find the tsg date in the interval dateMin-dateMax
% -------------------------------------------------
dtTsg = find(tsg.DAYD >= dateMin & tsg.DAYD <= dateMax);
if cor.DAYD(1) ~= dateMin
cor.DAYD = [tsg.DAYD(dtTsg(1)) cor.DAYD];
cor.DIFF = [cor.DIFF(1) cor.DIFF];
cor.ERROR = [cor.ERROR(1) cor.ERROR];
cor.NVALUE = [cor.NVALUE(1) cor.NVALUE];
end
if cor.DAYD(end) ~= dateMax
cor.DAYD = [cor.DAYD tsg.DAYD(dtTsg(end))];
cor.DIFF = [cor.DIFF cor.DIFF(end)];
cor.ERROR = [cor.ERROR cor.ERROR(end)];
cor.NVALUE = [cor.NVALUE cor.NVALUE(end)];
end
% The correction is applied to the TSG between dateMin and dateMax using
% a linear interpolation
% ----------------------------------------------------------------------
tsg.SSPS_ADJUSTED(dtTsg) = tsg.SSPS(dtTsg) + ...
interp1(cor.DAYD, cor.DIFF, tsg.DAYD(dtTsg));
tsg.SSPS_ADJUSTED_ERROR(dtTsg) = ...
interp1(cor.DAYD, cor.ERROR, tsg.DAYD(dtTsg));
% Update tsg application data
% ---------------------------
setappdata( hMainFig, 'tsg_data', tsg);