Skip to content

Commit

Permalink
Merge pull request #65 from bachlab/bugfix/get-events-extended-bugfix
Browse files Browse the repository at this point in the history
Extend get_events bugfix according to the previously implemented tests
  • Loading branch information
eozd authored Nov 4, 2019
2 parents 0fe29f5 + de74a36 commit 7219417
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/pspm_get_events.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@
data = data';
end

possible_values = unique(data);
min_values_indices = data == min(possible_values);
max_values_indices = data == max(possible_values);
data_orig = data;
data = (data + min(possible_values)) / (max(possible_values) - min(possible_values));
data(min_values_indices) = 0;
data(max_values_indices) = 1;
% add more data in order to prevent deleting values with diff
data = [0; 0; 0; data; 0; 0; NaN;];
% store information about finite and infinite in vector
Expand Down Expand Up @@ -97,9 +104,9 @@
if ~isfield(import, 'markerinfo') && ~isempty(import.data)

% determine baseline
v = unique(data(~isnan(data)));
v = unique(data_orig(~isnan(data_orig)));
for i=1:numel(v)
v(i,2) = numel(find(data == v(i,1)));
v(i,2) = numel(find(data_orig == v(i,1)));
end

% ascending sorting: most frequent value is at the end of this
Expand All @@ -108,7 +115,7 @@
baseline = v(end, 1);

% we are interested in the delta -> remove "baseline offset"
values = data(round(mPos)) - baseline;
values = data_orig(round(mPos) - 3) - baseline;
import.markerinfo.value = values;

% prepare values to convert them into strings
Expand Down
5 changes: 3 additions & 2 deletions test/pspm_get_events_test.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
% unittest class for the pspm_get_events function
%__________________________________________________________________________
% SCRalyze TestEnvironment
% (C) 2013 Linus Rüttimann (University of Zurich)
% (C) 2013 Linus R�ttimann (University of Zurich)

methods
function check = checkFlankChange(this, positions, data)
Expand Down Expand Up @@ -70,7 +70,8 @@ function continuous(this)
[sts, rimport] = pspm_get_events(import);
this.verifyEqual(sts, 1);
this.verifyTrue(length(rimport.data) == length(rimport.markerinfo.value));
this.verifyTrue(length(rimport.data) == length(d));
%if we invert the signal, number of markers denoted by high signals is one more!
this.verifyTrue(length(rimport.data) == length(d) + 1);
import.data = -1 * import.data;

import.flank = 'ascending';
Expand Down

0 comments on commit 7219417

Please sign in to comment.