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

Modification du module de correction. Le code

VALUE_CAHNGED n'es tplus attribué pour une correction
parent eb33ea18
No related branches found
No related tags found
No related merge requests found
No preview for this file type
......@@ -22,20 +22,24 @@ PROBABLY_GOOD = get(tsg.qc.hash, 'PROBABLY_GOOD', 'code');
PROBABLY_BAD = get(tsg.qc.hash, 'PROBABLY_BAD', 'code');
VALUE_CHANGED = get(tsg.qc.hash, 'VALUE_CHANGED', 'code');
% intialisation
% -------------
if isempty( tsg.([PARA '_ADJUSTED']) )
tsg.([PARA '_ADJUSTED']) = tsg.(PARA);
tsg.([PARA '_ADJUSTED_QC']) = tsg.([PARA '_QC']);
end
% If only calibration have been applied ERROR is empty
% ---------------------------------------------------
if isempty( tsg.([PARA '_ADJUSTED_ERROR']) )
tsg.([PARA '_ADJUSTED_ERROR']) = NaN* ones(size(tsg.(PARA)));
end
if dateMax > dateMin
% intialisation
% -------------
if isempty( tsg.([PARA '_ADJUSTED']) )
msgbox( ['Variable ' PARA '_ADJUSTED should be initialise in updateTsgStruct'],...
'Function ''corTsgLinear''',...
'warn', 'modal');
end
% Find samples within TIME_WINDOWS with Good and probably Good QC
% Find samples within TIME_WINDOWS with Good, probably Good, , probably bad QC
% ---------------------------------------------------------------
ind = find( tsg.DAYD_SPL >= dateMin & tsg.DAYD_SPL <= dateMax &...
tsg.([PARA '_SPL_QC']) <= PROBABLY_GOOD);
tsg.([PARA '_SPL_QC']) <= PROBABLY_BAD);
if ~isempty(ind)
......@@ -56,20 +60,21 @@ if dateMax > dateMin
[p, S, mu] = polyfit( X, Y, 1);
% The correction is applied to the TSG between dateMin and dateMax using
% a linear interpolation only on measurements with GOOD and
% PROBABLY_GOOD QC
% a linear interpolation only on measurements better than
% PROBABLY_BAD QC
% ----------------------------------------------------------------------
dtTsg = find( tsg.DAYD >= dateMin & tsg.DAYD <= dateMax &...
tsg.([PARA '_QC']) <= PROBABLY_GOOD);
tsg.([PARA '_QC']) <= PROBABLY_BAD);
[tsg.([PARA '_ADJUSTED'])(dtTsg), tsg.([PARA '_ADJUSTED_ERROR'])(dtTsg)] =...
polyval( p, tsg.DAYD(dtTsg), S, mu);
tsg.([PARA '_ADJUSTED'])(dtTsg) = ...
tsg.(PARA)(dtTsg) + tsg.([PARA '_ADJUSTED'])(dtTsg);
% VALUE_CHANGED code
% ------------------
tsg.([PARA '_ADJUSTED_QC'])(dtTsg) = VALUE_CHANGED;
% Line commented - We do not used anymore the VALUE_CHANGED code for
% the ADJUSTED variable
% ------------------------------------------------------------------
% tsg.([PARA '_ADJUSTED_QC'])(dtTsg) = VALUE_CHANGED;
end
end
end
......
......@@ -35,23 +35,28 @@ TIME_WINDOWS = tsg.cst.COR_TIME_WINDOWS;
% Get PROBABLY_GOOD, PROBABLY_BAD and VALUE_CHANGED codes
% -------------------------------------------------------
PROBABLY_GOOD = get(tsg.qc.hash, 'PROBABLY_GOOD', 'code');
PROBABLY_BAD = get(tsg.qc.hash, 'PROBABLY_BAD', 'code');
PROBABLY_BAD = get(tsg.qc.hash, 'PROBABLY_BAD', 'code');
BAD = get(tsg.qc.hash, 'BAD', 'code');
VALUE_CHANGED = get(tsg.qc.hash, 'VALUE_CHANGED', 'code');
% intialisation
% -------------
if isempty( tsg.([PARA '_ADJUSTED']) )
tsg.([PARA '_ADJUSTED']) = tsg.(PARA);
tsg.([PARA '_ADJUSTED_QC']) = tsg.([PARA '_QC']);
end
% If only calibration have been applied ERROR is empty
% ---------------------------------------------------
if isempty( tsg.([PARA '_ADJUSTED_ERROR']) )
tsg.([PARA '_ADJUSTED_ERROR']) = NaN* ones(size(tsg.(PARA)));
end
% Create a structure with an NaN
% No other solution, as I can't add a structure to an empty one
% -------------------------------------------------------------
cor = struct('DAYD', NaN, 'DIFF', NaN, 'ERROR', NaN, 'NVALUE', NaN);
if dateMax > dateMin
% intialisation
% -------------
if isempty( tsg.([PARA '_ADJUSTED']) )
msgbox( ['Variable ' PARA '_ADJUSTED should be initialise in updateTsgStruct'],...
'Function ''corTsgMedian''',...
'warn', 'modal');
end
% Find the indices of samples within the time limits.
% --------------------------------------------------
......@@ -61,11 +66,11 @@ if dateMax > dateMin
for i = 1:length(indSample)
% Find samples within TIME_WINDOWS with Good and probably Good QC
% Find samples within TIME_WINDOWS with Good, probably Good, probably Bad QC
% ---------------------------------------------------------------
ind = find( tsg.DAYD_SPL >= (tsg.DAYD_SPL(indSample(i)) - TIME_WINDOWS/2) &...
tsg.DAYD_SPL <= (tsg.DAYD_SPL(indSample(i)) + TIME_WINDOWS/2) &...
tsg.([PARA '_SPL_QC']) <= PROBABLY_GOOD);
tsg.([PARA '_SPL_QC']) <= PROBABLY_BAD);
if ~isempty(ind)
......@@ -100,7 +105,7 @@ if dateMax > dateMin
% ------------------------------------------------------
ind4 = find( A < meanA-3*stdA | A > meanA+3*stdA);
if ~isempty( ind4 )
tsg.([PARA '_SPL_QC'])(ind(ind2(ind4))) = PROBABLY_BAD;
tsg.([PARA '_SPL_QC'])(ind(ind2(ind4))) = BAD;
end
end
end
......@@ -148,16 +153,17 @@ if dateMax > dateMin
% PROBABLY_GOOD QC
% ----------------------------------------------------------------------
dtTsg = find( tsg.DAYD >= dateMin & tsg.DAYD <= dateMax &...
tsg.([PARA '_QC']) <= PROBABLY_GOOD);
tsg.([PARA '_QC']) <= PROBABLY_BAD);
tsg.([PARA '_ADJUSTED'])(dtTsg) = tsg.(PARA)(dtTsg) + ...
interp1(cor.DAYD, cor.DIFF, tsg.DAYD(dtTsg));
tsg.([PARA '_ADJUSTED_ERROR'])(dtTsg) = ...
interp1(cor.DAYD, cor.ERROR, tsg.DAYD(dtTsg));
% VALUE_CHANGED code
% ------------------
tsg.([PARA '_ADJUSTED_QC'])(dtTsg) = VALUE_CHANGED;
% Line commented - We do not used anymore the VALUE_CHANGED code for
% the ADJUSTED variable
% ------------------------------------------------------------------
% tsg.([PARA '_ADJUSTED_QC'])(dtTsg) = VALUE_CHANGED;
end
......
......@@ -39,18 +39,10 @@ if ~isempty( tsg.([PARA '_SPL']) )
end
end
% Select the record with VALUE_CHANGED code
% -----------------------------------------
iVC = find( tsg.([PARA '_ADJUSTED_QC']) == VALUE_CHANGED );
% Select only records corrected but not calibrated.
% Records corrected and calibrated have the same QC code.
% Select the records CORRECTED
% Records corrected have an error value
% ------------------------------------------------------
iERR = [];
if iVC ~= 0
iERR = find( isnan( tsg.([PARA '_ADJUSTED_ERROR'])(iVC) ) == 0 );
end
% -------------------------------------------
iERR = find( isnan(tsg.([PARA '_ADJUSTED_ERROR'])) == 0);
% Plot the difference tsg.SSPS_ADJUSTED-tsg.SSPS on axe 1
% but only for records that were corrected using Water Sample
......@@ -58,8 +50,8 @@ end
% -----------------------------------------------------------
if iERR ~= 0
plot_Tsg( hMainFig, hPlotAxes, 1,...
tsg.DAYD(iVC(iERR)),...
tsg.([PARA '_ADJUSTED'])(iVC(iERR))-tsg.(PARA)(iVC(iERR)),...
tsg.DAYD(iERR),...
tsg.([PARA '_ADJUSTED'])(iERR)-tsg.(PARA)(iERR),...
[], [PARA '_ADJUSTED'],'b','none','.',1);
end
......@@ -98,11 +90,11 @@ plot_Tsg( hMainFig, hPlotAxes, 3, tsg.DAYD, tsg.(PARA),...
% Plot TSG_ADJUSTED + ERROR on axe 3
% -----------------------------------
if iERR ~= 0
plot_Tsg( hMainFig, hPlotAxes, 3, tsg.DAYD(iVC(iERR)),...
tsg.([PARA '_ADJUSTED'])(iVC(iERR)) + tsg.([PARA '_ADJUSTED_ERROR'])(iVC(iERR)),...
plot_Tsg( hMainFig, hPlotAxes, 3, tsg.DAYD(iERR),...
tsg.([PARA '_ADJUSTED'])(iERR) + tsg.([PARA '_ADJUSTED_ERROR'])(iERR),...
[], [PARA '_ADJUSTED'],'g','none','*',2);
plot_Tsg( hMainFig, hPlotAxes, 3, tsg.DAYD(iVC(iERR)),...
tsg.([PARA '_ADJUSTED'])(iVC(iERR)) - tsg.([PARA '_ADJUSTED_ERROR'])(iVC(iERR)),...
plot_Tsg( hMainFig, hPlotAxes, 3, tsg.DAYD(iERR),...
tsg.([PARA '_ADJUSTED'])(iERR) - tsg.([PARA '_ADJUSTED_ERROR'])(iERR),...
[], [PARA '_ADJUSTED'],'g','none','*',2);
end
......
function updateAdjustedVariable( hMainFig )
%
% Update adjusted SSPS, SSJT, and SSTP arrays once calibration has been
% applied to these variable.
% Update adjusted SSPS, SSJT, and SSTP arrays with calibrated
% variables if they exist
%
% The TRICK :
% The programe test the variable ADJUSTED_ERROR as only records corrected
......@@ -33,37 +33,56 @@ for i = 1 :3
% -----------------------
if ~isempty( tsg.(para5) )
% in case of the ADJUSTED_ERROR is not initialised
% ------------------------------------------------
if isempty( tsg.(para4) )
tsg.(para4) = NaN * ones(size(tsg.DAYD));
end
% Get Adjusted records that were not corrected using Water samples
% Only records corrected get error values
% ----------------------------------------------------------------
ind = find( isnan(tsg.(para4) ) == 1);
if ~isempty(tsg.(para1))
tsg.(para2)(ind) = tsg.(para1)(ind);
% If no correction have been made and CAL parameter exists, the
% ADJUSTED variable is set to CAL
% -------------------------------------------------------------
if isempty( tsg.(para4) ) && ~isempty( tsg.(para1) )
% I do not want that calibration get a VALUE_CHANGED code
%tsg.(para3)(ind) = VALUE_CHANGED;
tsg.(para2) = tsg.(para1);
tsg.(para3) = tsg.(para6);
elseif isempty( tsg.(para4) ) && isempty( tsg.(para1) )
else
% No Correction and no Calibrated records : ADJUSTED variable is
% empty
% --------------------------------------------------------------
tsg.(para2) = [];
tsg.(para3) = [];
elseif ~isempty( tsg.(para4) ) % If ERROR not empty
% If the calibration has been canceled the ADJUSTED value is set to
% the raw value
% -----------------------------------------------------------------
tsg.(para2)(ind) = tsg.(para5)(ind);
tsg.(para3)(ind) = tsg.(para6)(ind);
% The QC code are set to the QC code of the raw variable
% ------------------------------------------------------
tsg.(para3) = tsg.(para6);
% Get Adjusted records that were not corrected using Water samples
% Only records corrected get error values
% ----------------------------------------------------------------
ind = find( isnan(tsg.(para4) ) == 1);
% If the parameter has been calibrated
% ------------------------------------
if ~isempty( tsg.(para1) )
% Adjusted records not corrected are set to the calibrated value
% --------------------------------------------------------------
if ~isempty( ind )
tsg.(para2)(ind) = tsg.(para1)(ind);
end
else
% Adjusted records not corrected are set to the raw value
% -------------------------------------------------------
if ~isempty( ind )
tsg.(para2)(ind) = tsg.(para5)(ind);
end
end
end
end
end
% Save tsg application data
% Save tsg application data
% --------------------------
setappdata( hMainFig, 'tsg_data', tsg );
......
......@@ -43,28 +43,32 @@ if isempty(tsg.SPDC)
tsg.SPDC = [tsg.SPDC';0];
end
% Initialise ADJUSTED variables if empty
% --------------------------------------
% Varaibles must exists
% ---------------------
for i = 1: nPARA
para1 = PARA(i,:);
para2 = [PARA(i,:) '_QC'];
para3 = [PARA(i,:) '_ADJUSTED'];
para4 = [PARA(i,:) '_ADJUSTED_QC'];
para5 = [PARA(i,:) '_ADJUSTED_ERROR'];
if isempty( tsg.(para3) ) && ~isempty( tsg.(para1) )
tsg.(para3) = tsg.(para1);
tsg.(para4) = tsg.(para2);
tsg.(para5) = NaN * ones( size( tsg.(para1) ));
elseif isempty( tsg.(para1) )
if isempty( tsg.(para1) )
msgbox(['You must initialise the tsg.' PARA(i) ' variable'],...
'function ''updateTsgStruct''', ....
'warn', 'modal');
'function ''updateTsgStruct''', ....
'warn', 'modal');
end
end
% Empty variables filled with NaN
% -------------------------------
names = fieldnames( tsg );
for i = 1: length(names)
para = char( names(i) );
if ~isstruct( tsg.(para) ) && ~isempty( tsg.(para) )
A = tsg.(para);
ind = find( isnan( A ) == 0 );
if isempty( ind )
tsg.(para) = [];
end
end
end
% Initialise 'variables_LINCOEF'
% -------------------------------
......
......@@ -1425,10 +1425,6 @@ errTsg = readTsgDataTsg( hMainFig, fullFileName);
% Get tsg application data
% ------------------------
tsg = getappdata( hMainFig, 'tsg_data' );
% pour test
% tsg.SSTP = [];
% setappdata( hMainFig, 'tsg_data', tsg );
% Draw the 3 plots of the validation figure
% -----------------------------------------
......@@ -1545,6 +1541,9 @@ errTsg = readTsgDataTsg( hMainFig, fullFileName);
% ------------------------
tsg = getappdata( hMainFig, 'tsg_data' );
% Emptied the CAL variables
% -------------------------
tsg.CNDC_CAL = [];
tsg.SSPS_CAL = [];
tsg.SSJT_CAL = [];
tsg.SSTP_CAL = [];
......@@ -1553,8 +1552,8 @@ errTsg = readTsgDataTsg( hMainFig, fullFileName);
% --------------------------
setappdata( hMainFig, 'tsg_data', tsg );
% Update the Adjusted variables (SSPS - SSJT) with calibrated records
% -------------------------------------------------------------------
% Update the Adjusted variables
% -----------------------------
updateAdjustedVariable( hMainFig );
% Refresh plot #1
......@@ -2343,11 +2342,10 @@ errTsg = readTsgDataTsg( hMainFig, fullFileName);
% --------------------------------------------------
PARA = tsg.preference.parameter;
% To cancel the correction set the ERROR to NaN then
% To cancel the correction set the ERROR to [] then
% call updateAdjustedVariable.
% --------------------------------------------------
tsg.([PARA '_ADJUSTED_ERROR']) = ...
NaN * ones( size(tsg.([PARA '_ADJUSTED_ERROR'])));
tsg.([PARA '_ADJUSTED_ERROR']) = [];
% Save tsg data
% -------------
......
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