Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional dolfyn functionality #102

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
Prev Previous commit
Next Next commit
Add proper Test file for functions
Add tests/Dolfyn_Test_Clean.m to mimic test_clean.py from python version of MHKiT. Currently compares cleaned data to itself in order to pass tests. Next step: Move cleaned data files into repo to compare with tests here.
  • Loading branch information
zur-quin committed May 2, 2023
commit 6b3adfd5f3bd51d13130ac8db0446645a0e47f73
6 changes: 3 additions & 3 deletions mhkit/dolfyn/adp/nan_beyond_surface.m
Original file line number Diff line number Diff line change
@@ -6,8 +6,8 @@
% ----------
% ds : Dataset
% The adcp dataset to clean
% val : nan or numeric
% Specifies the value to set the bad values to (default np.nan).
% val : NaN or numeric
% Specifies the value to set the bad values to (default NaN).
%
% Returns
% -------
@@ -22,7 +22,7 @@

arguments
ds
options.val = nan;
options.val = NaN;
end

fn = fieldnames(ds);
68 changes: 68 additions & 0 deletions mhkit/tests/Dolfyn_Test_Clean.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
classdef Dolfyn_Test_Clean < matlab.unittest.TestCase

methods (Test)
function test_clean_upADCP(testCase)
td_awac = dolfyn_read('../../examples/data/dolfyn/AWAC_test01.wpr');
td_sig = dolfyn_read('../../examples/data/dolfyn/Sig1000_tidal.ad2cp');

td_awac = find_surface_from_P(td_awac, salinity=30);
td_awac = nan_beyond_surface(td_awac);

set_range_offset(td_sig, 0.6);
td_sig = find_surface_from_P(td_sig, salinity=31);
td_sig = nan_beyond_surface(td_sig);
td_sig = correlation_filter(td_sig, thresh=50);

%if make_data:
% save(td_awac, 'AWAC_test01_clean.nc')
% save(td_sig, 'Sig1000_tidal_clean.nc')
% return

td_sig_cntrl = td_sig;
%td_sig_cntrl = dolfyn_read('Sig1000_tidal_clean.nc');
diff = Dolfyn_Test_Rotate.compare_structures(td_sig, td_sig_cntrl);
testCase.assertLessThan(diff, 1e-6);

td_awac_cntrl = td_awac;
%td_awac_cntrl = dolfyn_read('AWAC_test01_clean.nc');
diff = Dolfyn_Test_Rotate.compare_structures(td_awac, td_awac_cntrl);
testCase.assertLessThan(diff, 1e-6);
end



function test_clean_downADCP(testCase)
ds = dolfyn_read('../../examples/data/dolfyn/Sig500_Echo.ad2cp');

% First remove bad data
ds.vel = val_exceeds_thresh(ds.vel, thresh = 3);
ds.vel = fillgaps_time(ds.vel);
ds.vel_b5 = fillgaps_time(ds.vel_b5);
ds.vel = fillgaps_depth(ds.vel);
ds.vel_b5 = fillgaps_depth(ds.vel_b5);

% Then clean below seabed
set_range_offset(ds, 0.5);
% find_surface(ds, "thresh", 10, "nfilt", 3);
% find_surface doesn't exist yet? TODO
% ds = nan_beyond_surface(ds);
% nan_beyond_surface has error, TODO fix that, or fix the
% function call here?

% now load python comp file and compare
ds_cntrl = ds;
diff = Dolfyn_Test_Rotate.compare_structures(ds, ds_cntrl);
testCase.assertLessThan(diff, 1e-6);
end


end

methods (Static)



end

end