Skip to content
Snippets Groups Projects
Commit 3d45e06f authored by Yves Gouriou's avatar Yves Gouriou
Browse files

2007-11-27 Y.Gouriou fonction de correction D. Mathias

parent 617aadfe
No related branches found
No related tags found
No related merge requests found
function [correction] = dev_corMethod1( sample, TIME_WINDOWS )
function [tsg] = ...
dev_corMethod1(tsg, sample, dateMin, dateMax, TIME_WINDOWS)
%
% TO DO
% 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'
%
% *************************************************************************
% The correction is computed between dateMin and dateMax
% ------------------------------------------------------
dt = find(sample.TIME >= dateMin & sample.TIME <= dateMax);
% Calcul des valeurs medianes de correction: achaque point de
% comparaison, on attribue la mediane des corrections dans une fenetre de
% 10 jours. Puis on interpole entre chaque mediane pour avoir la correction
% a appliquer en chaque point de donnee TSG
% TO DO : Initialisation de la structure 'cor'
% --------------------------------------------
% Fenetre de temps = 10 jours pour le calcul des valeurs medianes de
% correction
% ------------------------------------------------------------------
COR_mediane = [0 0];
erreur_mediane = [0 0];
for i = 1:length(sample)
% --------------------------------------------
for i = 1 : length(dt)
is = find( sample.TIME > sample.TIME(i) - TIME_WINDOWS/2 & ...
sample.TIME < sample.TIME(i) + TIME_WINDOWS/2);
% Find the sample witihin TIME_WINDOWS
% ------------------------------------
ind = find( sample.TIME(dt) >= sample.TIME(dt(i)) - TIME_WINDOWS/2 &...
sample.TIME(dt) <= sample.TIME(dt(i)) + TIME_WINDOWS/2);
if ~isempty(is)
COR_mediane = [COR_mediane;...
[ sample.TIME(i) median(sample.PSAL_DIF(is))]];
erreur_mediane = [erreur_mediane;...
[std(sample.PSAL_DIF(is))/sqrt(length(is)) length(is)]];
% Compute the median difference and error witihn TIME_WINDOWS
% -----------------------------------------------------------
if ~isempty(j)
cor.TIME(i) = sample.TIME(i);
cor.DIFF(i) = median(sample.PSAL_DIF(ind));
cor.ERROR(i) = std(sample.PSAL_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;
COR_mediane = COR_mediane(2:length(COR_mediane),:);
erreur_mediane = erreur_mediane(2:length(erreur_mediane),:);
erreur_mediane( find(erreur_mediane(:,2) < 4), 1) = 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.TIME >= dateMin & tsg.TIME <= dateMax);
% Complete les series de correction PAS TRES BON
if COR_mediane(1,1) ~= tsg.TIME(1)
COR_mediane = [[tsg.TIME(1) COR_mediane(1,2)];COR_mediane];
if cor.TIME(1) ~= dateMin
cor.TIME = [tsg.TIME(dtTsg(1)) cor.TIME];
cor.DIFF = [cor.DIFF(1) cor.DIFF];
cor.ERROR = [cor.ERROR(1) cor.ERROR];
cor.NVALUE = [cor.NVALUE(1) cor.NVALUE];
end
% Pas très bon : La correction ne doit pas être appliquée + de 10 jours
% avant ou après le dernier echantillon
% --------------------------------------------------------------------
if COR_mediane(length(COR_mediane),1) ~= tsg.TIME(end)
COR_mediane = [COR_mediane; ...
[tsg.TIME(end) ...
COR_mediane(length(COR_mediane),2)]];
if cor.TIME(end) ~= dateMax
cor.TIME = [cor.TIME tsg.TIME(dtTsg(end))];
cor.DIFF = [cor.DIFF cor.DIFF(end)];
cor.ERROR = [cor.ERROR cor.ERROR(end)];
cor.NVALUE = [cor.NVALUE cor.NVALUE(end)];
end
COR = interp1(COR_mediane(:,1), COR_mediane(:,2), tsg.TIME);
% The correction is applied to the TSG between dateMin and dateMax using
% a linear interpolation
% ----------------------------------------------------------------------
tsg.PSAL_ADJ(dtTsg) = tsg.PSAL(dtTsg) + ...
interp1(cor.TIME, cor.DIFF, tsg.TIME(dtTsg));
tsg.PSAL_ERR(dtTsg) = interp1(cor.TIME, cor.ERROR, tsg.TIME(dtTsg));
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment