Home > tests > utilities > test_get_POLCOMS_tsobc.m

test_get_POLCOMS_tsobc

PURPOSE ^

Unit test for get_POLCOMS_tsobc.

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 Unit test for get_POLCOMS_tsobc.

 DESCRIPTION:
   Currently checks against a reference data set for the following:
       - number of nodes in the output
       - number of sigma layers in the output
       - number of time steps in the output
       - range of values in the node arrays

 It uses a simplified POLCOMS NetCDF file from January, 2001 as the base
 input. The mesh object (Mobj) contains the required input for
 get_POLCOMS_tsobc as well as a set of 'known good' results
 (Mobj.temperature, Mobj.salt and Mobj.ts_times) for comparison against
 the new result.

 Author(s):
   Pierre Cazenave (Plymouth Marine Laboratory)

 Revision history:
   2013-05-17 First version.
   2016-06-02 Updated to actually compare the interpolated data rather
   than just the grid information.

==========================================================================

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % Unit test for get_POLCOMS_tsobc.
0002 %
0003 % DESCRIPTION:
0004 %   Currently checks against a reference data set for the following:
0005 %       - number of nodes in the output
0006 %       - number of sigma layers in the output
0007 %       - number of time steps in the output
0008 %       - range of values in the node arrays
0009 %
0010 % It uses a simplified POLCOMS NetCDF file from January, 2001 as the base
0011 % input. The mesh object (Mobj) contains the required input for
0012 % get_POLCOMS_tsobc as well as a set of 'known good' results
0013 % (Mobj.temperature, Mobj.salt and Mobj.ts_times) for comparison against
0014 % the new result.
0015 %
0016 % Author(s):
0017 %   Pierre Cazenave (Plymouth Marine Laboratory)
0018 %
0019 % Revision history:
0020 %   2013-05-17 First version.
0021 %   2016-06-02 Updated to actually compare the interpolated data rather
0022 %   than just the grid information.
0023 %
0024 %==========================================================================
0025 
0026 matlabrc
0027 close all
0028 clc
0029 
0030 % Set up our test environment.
0031 [base, subname] = fileparts(mfilename('fullpath'));
0032 addpath(fullfile(base, '../../fvcom_prepro'))
0033 
0034 load(fullfile(base, '../data/get_POLCOMS_tsobc_data.mat'));
0035 
0036 % Perform the interpolation using the new routine.
0037 obc_ts = {fullfile(base, '../data/Daily.PolcomsErsem.2001.01.nc')};
0038 Mobj_new = get_POLCOMS_tsobc(Mobj, obc_ts);
0039 
0040 % Add the necessary information for the checks.
0041 t = delaunayTriangulation(Mobj_new.lon, Mobj_new.lat);
0042 Mobj_new.tri = t.ConnectivityList;
0043 clear t
0044 Mobj.nVerts = length(Mobj.lon);
0045 Mobj.nElems = size(Mobj.tri, 1);
0046 Mobj_new.nVerts = length(Mobj_new.lon);
0047 Mobj_new.nElems = size(Mobj_new.tri, 1);
0048 
0049 % Check we have the temperature, salinity and time fields in the new mesh
0050 % object.
0051 fnames = fieldnames(Mobj_new);
0052 
0053 for ff = 1:length(fnames)
0054     switch fnames{ff}
0055         case {'temperature', 'salt', 'ts_times'}
0056             assert(isfield(Mobj_new, fnames{ff}), 'Missing field %s', fnames{ff})
0057     end
0058 end
0059 
0060 % Clear out fields which don't exist in both Mobj and Mobj_new.
0061 fnames = intersect(fnames, fieldnames(Mobj));
0062 
0063 %%
0064 
0065 results = struct();
0066 
0067 for ff = 1:length(fnames)
0068 
0069     results.(fnames{ff}) = struct();
0070 
0071     switch fnames{ff}
0072         case {'siglayz', 'lon', 'lat', 'obc_nodes', 'nObcNodes', 'ts_times'}
0073 
0074             results.(fnames{ff}).vectorValues = 'FAIL';
0075 
0076             results.(fnames{ff}).check = ...
0077                 Mobj.(fnames{ff}) - Mobj_new.(fnames{ff});
0078             checkDiff = max(results.(fnames{ff}).check) - ...
0079                 min(results.(fnames{ff}).check);
0080             if checkDiff == 0
0081                 results.(fnames{ff}).vectorValues = 'PASS';
0082             end
0083 
0084         otherwise
0085 
0086             %--------------------------------------------------------------
0087             % Set the pass/fail flags for the tests. Assume fail and only
0088             % change if proven otherwise.
0089             %--------------------------------------------------------------
0090             results.(fnames{ff}).nodeNumber = 'FAIL';
0091             results.(fnames{ff}).elementNumber = 'FAIL';
0092             results.(fnames{ff}).numNodeTimes = 'FAIL';
0093             results.(fnames{ff}).nodeValues = 'FAIL';
0094 
0095             %--------------------------------------------------------------
0096             % Check we have the same number of points and time steps in the
0097             % new interpolation as in the original.
0098             %--------------------------------------------------------------
0099 
0100             % Get number of new nodes, times and elements
0101             results.(fnames{ff}).nVerts = Mobj_new.nVerts;
0102             results.(fnames{ff}).nElems = Mobj_new.nElems;
0103             results.(fnames{ff}).nTimes = length(Mobj_new.ts_times);
0104             results.(fnames{ff}).orignTimes = length(Mobj.ts_times);
0105 
0106             % Compare old and new nodes, elements and times.
0107             if results.(fnames{ff}).nVerts == Mobj.nVerts
0108                 results.(fnames{ff}).nodeNumber = 'PASS';
0109             end
0110             if results.(fnames{ff}).nTimes == length(Mobj.ts_times)
0111                 results.(fnames{ff}).numNodeTimes = 'PASS';
0112             end
0113             if results.(fnames{ff}).nElems == Mobj.nElems
0114                 results.(fnames{ff}).elementNumber = 'PASS';
0115             end
0116 
0117             %--------------------------------------------------------------
0118             % Check the values in the node arrays match the reference
0119             % values.
0120             %--------------------------------------------------------------
0121             results.(fnames{ff}).nodeDiff = ...
0122                 Mobj.(fnames{ff}) - ...
0123                 Mobj_new.(fnames{ff});
0124 
0125             results.(fnames{ff}).nodeRange = ...
0126                 max(results.(fnames{ff}).nodeDiff(:));
0127 
0128             if results.(fnames{ff}).nodeRange == 0
0129                 results.(fnames{ff}).nodeValues = 'PASS';
0130             end
0131     end
0132 end
0133 
0134 %%
0135 %--------------------------------------------------------------------------
0136 % Print a summary of the testing
0137 %--------------------------------------------------------------------------
0138 totalTests = 0;
0139 totalPasses = 0;
0140 
0141 for ff = 1:length(fnames)
0142     resultnames = fieldnames(results.(fnames{ff}));
0143     numRes = length(resultnames);
0144 
0145     for fi = 1:numRes
0146 
0147         % Skip if the field is not a string (we're only interested in
0148         % pass/fail really.
0149         if ~ischar(results.(fnames{ff}).(resultnames{fi}))
0150             continue
0151         else
0152             % Increment the number of tests performed.
0153             totalTests = totalTests + 1;
0154         end
0155 
0156         % Get the total number of PASSed tests.
0157         if strcmp(results.(fnames{ff}).(resultnames{fi}), 'PASS')
0158             totalPasses = totalPasses + 1;
0159         end
0160 
0161         S = results.(fnames{ff}).(resultnames{fi});
0162 
0163         switch resultnames{fi}
0164             case 'vectorValues'
0165                 fprintf('%s %s values test\n', S, fnames{ff})
0166                 if strcmp(S, 'FAIL')
0167                     fprintf('\tmin/max of %s range: %f, %f\n', ...
0168                         fnames{ff}, ...
0169                         min(results.(fnames{ff}).check), ...
0170                         max(results.(fnames{ff}).check))
0171                 end
0172 
0173             case 'nodeNumber'
0174                 fprintf('%s %s node number test\n', S, fnames{ff})
0175                 if strcmp(S, 'FAIL')
0176                     fprintf('\toriginal/new number of %s nodes: %d, %d\n', ...
0177                         fnames{ff}, ...
0178                         Mobj.nVerts, ...
0179                         results.(fnames{ff}).nVerts)
0180                 end
0181 
0182             case 'elementNumber'
0183                 fprintf('%s %s element number test\n', S, fnames{ff})
0184                 if strcmp(S, 'FAIL')
0185                     fprintf('\toriginal/new number of %s elements: %d, %d\n', ...
0186                         fnames{ff}, ...
0187                         Mobj.nElems, ...
0188                         results.(fnames{ff}).nElems)
0189                 end
0190 
0191             case 'numNodeTimes'
0192                 fprintf('%s %s node time steps test\n', S, fnames{ff})
0193                 if strcmp(S, 'FAIL')
0194                     fprintf('\toriginal/new number of %s node times: %d, %d\n', ...
0195                         fnames{ff}, ...
0196                         results.(fnames{ff}).orignTimes, ...
0197                         results.(fnames{ff}).nTimes)
0198                 end
0199 
0200             case 'numElementTimes'
0201                 fprintf('%s %s element time steps test\n', S, fnames{ff})
0202                 if strcmp(S, 'FAIL')
0203                     fprintf('\toriginal/new number of %s element times: %d, %d\n', ...
0204                         fnames{ff}, ...
0205                         results.(fnames{ff}).origElementTimes, ...
0206                         results.(fnames{ff}).nElementTimes)
0207                 end
0208 
0209             case 'nodeValues'
0210                 fprintf('%s %s node values test\n', S, fnames{ff})
0211                 if strcmp(S, 'FAIL')
0212                     fprintf('\trange of %s node values: %d\n', ...
0213                         fnames{ff}, ...
0214                         results.(fnames{ff}).nodeRange)
0215                 end
0216 
0217             case 'elementValues'
0218                 fprintf('%s %s element values test\n', S, fnames{ff})
0219                 if strcmp(S, 'FAIL')
0220                     fprintf('\trange of %s element values: %d\n', ...
0221                         fnames{ff}, ...
0222                         results.(fnames{ff}).elemRange)
0223                 end
0224         end
0225     end
0226 end
0227 
0228 fprintf('\n------------------SUMMARY------------------\n')
0229 fprintf('           %d of %d tests passed', totalPasses, totalTests)
0230 fprintf('\n-------------------------------------------\n')

Generated on Wed 20-Feb-2019 16:06:01 by m2html © 2005