Skip to content

Commit

Permalink
fix(Parser): handle non binmapped oceancontour NetCDFs and add OceanC…
Browse files Browse the repository at this point in the history
…ontour unittests
  • Loading branch information
lbesnard committed Dec 14, 2022
1 parent 45e84a9 commit cd9c771
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 7 deletions.
18 changes: 11 additions & 7 deletions Parser/OceanContour/OceanContour.m
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ function warning_failed(failed_items, filename)
%
% %read from netcdf
% file = [toolboxRootPath 'data/testfiles/netcdf/Nortek/OceanContour/Signature/s500_enu_avg.nc'];
% [sample_data] = readOceanContour(file);
% [sample_data] = OceanContour.readOceanContourFile(file);
% assert(strcmpi(sample_data{1}.meta.instrument_model,'Signature500'))
% assert(isequal(sample_data{1}.meta.instrument_avg_interval,60))
% assert(isequal(sample_data{1}.meta.instrument_sample_interval,600))
Expand All @@ -458,7 +458,7 @@ function warning_failed(failed_items, filename)
%
% % read from matfile
% file = [toolboxRootPath 'data/testfiles/mat/Nortek/OceanContour/Signature/s500_enu_avg.mat'];
% [sample_data] = readOceanContour(file);
% [sample_data] = OceanContour.readOceanContourFile(file);
% assert(strcmpi(sample_data{1}.meta.instrument_model,'Signature500'))
% assert(isequal(sample_data{1}.meta.instrument_avg_interval,60))
% assert(isequal(sample_data{1}.meta.instrument_sample_interval,600))
Expand Down Expand Up @@ -548,12 +548,16 @@ function warning_failed(failed_items, filename)

meta.magDec = get_att('magDec');
custom_magnetic_declination = logical(meta.magDec);
meta.binMapping = get_att('binMapping');
binmapped = logical(meta.binMapping);
try
meta.binMapping = get_att('binMapping');
binmapped = logical(meta.binMapping);
catch
binmapped = false;
end

%Now that we know some preliminary info, we can load the variable
% name mappings and the list of variables to import.



var_mapping = OceanContour.get_varmap(ftype, group_name, nBeams, custom_magnetic_declination,binmapped);
import_mapping = OceanContour.get_importmap(nBeams, custom_magnetic_declination);

Expand All @@ -568,7 +572,7 @@ function warning_failed(failed_items, filename)
meta.dim_meta = data_metadata.(group_name).Dimensions;
meta.var_meta = data_metadata.(group_name).Variables;
gid = dataset_groups(k);
get_var = @(x)(nc_get_var(gid, var_mapping.(x)));
get_var = @(x)(nc_get_var(gid, var_mapping.(x)));
else
fname = getindex(dataset_groups, k);
get_var = @(x)(transpose(matdata.(fname).(var_mapping.(x))));
Expand Down
47 changes: 47 additions & 0 deletions test/Parser/GenericParser/testOceanContour.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
classdef testOceanContour < matlab.unittest.TestCase

% Test Reading Nortek Signature files output by OceanContour software
% with the OceanContour
% function.
%
% author: laurent.besnard@utas.edu.au
%
% TODO: understand why fillValues for s500 and s1000 are different by a
% factor 10


properties (TestParameter)
mode = {'timeSeries'};
oceancontour_sig500_file = files2namestruct(rdir([toolboxRootPath 'data/testfiles/netcdf/Nortek/OceanContour/Signature/sig500']));
oceancontour_sig1000_file = files2namestruct(rdir([toolboxRootPath 'data/testfiles/netcdf/Nortek/OceanContour/Signature/sig1000']));
end

methods (Test)

function testOceanContourSig500(~, oceancontour_sig500_file)
data = OceanContour.readOceanContourFile(oceancontour_sig500_file);
assert(strcmp(data{1}.meta.instrument_model,'Signature500'));
assert(strcmp(data{1}.meta.instrument_make,'Nortek'));
assert(strcmp(data{1}.meta.coordinate_system,'ENU'));
assert(data{1}.meta.beam_angle==25);
assert(round(mean(data{1,1}.variables{1,5}.data)) == 19) % TEMP var check

tolerance = 0.001;
assert(abs(min(data{1,1}.variables{1,16}.data(:,1)) - -32.7680) < tolerance); % UCUR var check. fillvalue seems to be -32.7680
end

function testOceanContourSig1000(~, oceancontour_sig1000_file)
data = OceanContour.readOceanContourFile(oceancontour_sig1000_file);
assert(strcmp(data{1}.meta.instrument_model,'Signature1000'));
assert(strcmp(data{1}.meta.instrument_make,'Nortek'));
assert(strcmp(data{1}.meta.coordinate_system,'ENU'));
assert(data{1}.meta.beam_angle==25);
assert(round(mean(data{1,1}.variables{1,5}.data)) == 20) % temperature var check

tolerance = 0.001;
assert(abs(min(data{1,1}.variables{1,16}.data(:,1)) - -3.27680) < tolerance); % UCUR var check. fillvalue seems to be -3.27680
end
end

end

0 comments on commit cd9c771

Please sign in to comment.