Skip to content

Commit

Permalink
Merge pull request #679 from aodn/fix_676
Browse files Browse the repository at this point in the history
fixup for 676, fixes 676
  • Loading branch information
lbesnard authored Aug 6, 2020
2 parents ed6c9b9 + 2acf9d5 commit 50a01b3
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 33 deletions.
44 changes: 17 additions & 27 deletions AutomaticQC/imosTimeSeriesSpikeQC.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,17 @@

if (is_profile || time_missing), return, end

has_burst_duration = (isfield(sample_data.meta, 'instrument_burst_duration') &&~isempty(sample_data.meta.instrument_burst_duration)) || (isfield(sample_data, 'instrument_burst_duration') &&~isempty(sample_data.instrument_burst_duration));
has_burst_interval = (isfield(sample_data.meta, 'instrument_burst_interval') &&~isempty(sample_data.meta.instrument_burst_interval)) || (isfield(sample_data, 'instrument_burst_interval') &&~isempty(sample_data.instrument_burst_interval));

has_burst_duration = false;
has_burst_interval = false;
try
has_burst_duration = sample_data.meta.instrument_burst_duration;
has_burst_interval = sample_data.meta.instrument_burst_interval;
catch
try
has_burst_duration = sample_data.instrument_burst_duration;
has_burst_interval = sample_data.meta.instrument_burst_interval;
end
end
has_burst = has_burst_duration || has_burst_interval;

if has_burst
Expand All @@ -71,8 +79,8 @@

if auto
user_interaction = struct();
spike_methods = load_classifiers(opts_file, has_burst);
method = readProperty(opts_file, 'auto_method');
spike_methods = loadSpikeClassifiers(opts_file, has_burst);
method = readProperty('auto_function',opts_file);

for k = 1:length(ts_variables)
user_interaction.(ts_variables{k}) = spike_methods(method);
Expand Down Expand Up @@ -129,7 +137,6 @@
% Construct the SpikeQC log strings for each variable
% and each parameters used.
%
nspikes = length(user_input.spikes);
fun_name = func2str(user_input.fun);
nargs = length(user_input.args);
arg_string = cell(1, nargs);
Expand Down Expand Up @@ -160,12 +167,11 @@
c = 1;

for k = 1:length(ts_dims)
not_empty = ~isempty(ts_dims{k});
no_empty_dims = ~isempty(ts_dims{k});
not_depth = ~strcmpi(varnames{k}, 'DEPTH');
var = getVar(sample_data.variables,varnames{k});
is_vector = var && isvector(var);

if not_empty && not_depth && is_vector
is_vector = var && isvector(sample_data.variables{var}.data);
if no_empty_dims && not_depth && is_vector
ts_variables{c} = varnames{k};
c = c + 1;
end
Expand All @@ -185,7 +191,7 @@
% sample_data - the toolbox data struct.
% ts_variables - the time-series variables to process.
% has_burst - if the data is in burst-mode.
%
%
% Outputs:
%
% postqc - A data structure that is a copycat of sample_data but with clean timeSeries variables only.
Expand Down Expand Up @@ -260,19 +266,3 @@
end

end

function [valid_burst_range, max_burst_len] = cut_burst_range(burst_index_ranges, l, r)
%function [valid_burst_range, max_burst_len] = cut_burst_range(burst_index_ranges, l, r)
% find the valid burst range and the maximum burst length
%
find_burst_ind = @(ind, x)(any(x == ind));
find_l = @(x)(find_burst_ind(l, x));
find_r = @(x)(find_burst_ind(r, x));
first_valid_burst = find(cellfun(find_l, burst_index_ranges));
last_valid_burst = find(cellfun(find_r, burst_index_ranges));

valid_burst_range = burst_index_ranges(first_valid_burst:last_valid_burst);

compute_burst_len = @(x)(max(x) - min(x));
max_burst_len = max(cellfun(compute_burst_len, valid_burst_range));
end
8 changes: 5 additions & 3 deletions AutomaticQC/imosTimeSeriesSpikeQC.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
%If auto is on, use the default options from named method
auto_function = hampel
auto_function = Hampel

%Hampel

hampel_function = imosSpikeClassifierHampel
%window of data at each side
Expand All @@ -9,7 +11,7 @@ hampel_madfactor = 5
%clipping_mad
hampel_lower_mad_limit = 0.0

%SavGol Filter with OTSU Threshold - despiking2
%OTSU-Savgol/despiking1

otsu_savgol_function = imosSpikeClassifierNonBurstSavGolOTSU
%odd window filtering size
Expand All @@ -21,7 +23,7 @@ otsu_savgol_nbins = 100
%scale to reduce the otsu threshold
otsu_savgol_oscale = 1

%OTSU Threhsold - despiking1
%OTSU-Thresholding/despiking2

otsu_threshold_function = imosSpikeClassifierOTSU
%number of histogram bins in otsu thresholding
Expand Down
6 changes: 3 additions & 3 deletions AutomaticQC/imosTimeSeriesSpikeQCBurst.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
%If auto is on, use the default options from named method
auto_function = burst_hampel
auto_function = Hampel-Burst

% burst Hampel filter
% Hampel-Burst
burst_hampel_function = imosSpikeClassifierBurstHampel
% boolean use windows as bursts instead of samples
burst_hampel_use_burst_window = 0
Expand All @@ -15,7 +15,7 @@ burst_hampel_lower_mad_limit = 0
%detect all not only repeated
burst_hampel_repeated_only = 0

%Running Statistics
%Running-Statistics/imosBurstQC
burst_runningstats_function = imosSpikeClassifierBurstRunningStats

% the scale statistic function
Expand Down
34 changes: 34 additions & 0 deletions test/UI/test_imosTimeSeriesSpikeQC.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
classdef test_imosTimeSeriesSpikeQC < matlab.unittest.TestCase

methods (Test)
function test_no_ndvars_processed(~)
sample_data = create_sample_data([100,1],{'2dvar','3dvar','TEMP','PITCH','ROLL'});
dummy = sample_data.variables{1}.data;
sample_data.variables{1}.data = repmat(dummy,1,6);
sample_data.variables{1}.dimensions = 2;
sample_data.variables{2}.data = repmat(dummy,1,6,12);
sample_data.variables{2}.dimensions = 3;
z = imosTimeSeriesSpikeQC(sample_data,true);
procvars = fieldnames(z);
assert(~inCell(procvars,'2dvar'));
assert(~inCell(procvars,'3dvar'));
end

end
end

function sample_data = create_sample_data(asize,varnames)
sample_data = struct();
sample_data.variables = cell(1, 1);
sample_data.dimensions = cell(1, 1);
dummy = randn(asize);

for k = 1:length(varnames)
sample_data.variables{k} = struct();
sample_data.variables{k}.name = varnames{k};
sample_data.variables{k}.data = dummy;
sample_data.variables{k}.flags = zeros(asize);
sample_data.variables{k}.dimensions = 1;
end
sample_data.dimensions{1} = struct('name','TIME','data',linspace(0,length(dummy),1),'flags',zeros(asize));
end

0 comments on commit 50a01b3

Please sign in to comment.