Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Bach committed Aug 13, 2023
1 parent d83eefc commit bf51ffb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 24 deletions.
9 changes: 4 additions & 5 deletions src/pspm_interp1.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@
end
X_body = X(index_non_nan_full(1):index_non_nan_full(end));
% processing body
index = 1:length(X_body);
index_nan = index(isnan(X_body) | index_missing(index_non_nan_full(1):index_non_nan_full(end))) ;
index_non_nan = 1 - index_nan;
if ~isempty(index_nan)
X_body_interp = interp1(index_non_nan,X_body(index_non_nan),index_nan);
index_nan = zeros(size(X_body));
index_nan(isnan(X_body) | index_missing(index_non_nan_full(1):index_non_nan_full(end))) = 1;
if any(index_nan)
X_body_interp = interp1(find(~index_nan),X_body(~index_nan), (1:numel(X_body))');
else
X_body_interp = X_body;
end
Expand Down
40 changes: 25 additions & 15 deletions src/pspm_sf.m
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@
% 3.5 Get missing epochs --
if ~isempty(model.missing{iFile})
[~, missing{iFile}] = pspm_get_timing('missing', model.missing{iFile}, 'seconds');
model.missing_data = zeros(size(y{2}));
missing_index = pspm_time2index(missing{iFile}, sr(datatype(k)));
model.missing_data((missing_index(:,1)+1):(missing_index(:,2)+1)) = 1;
else
missing{iFile} = [];
end
Expand All @@ -247,9 +250,9 @@
return;
end
end
% use first marker channel
events{iFile} = ndata{1}.data(:);
end
% use first marker channel
events{iFile} = data{1}.data(:);


for iEpoch = 1:size(epochs{iFile}, 1)
Expand All @@ -263,17 +266,23 @@
case 'samples'
win = round(epochs{iFile}(iEpoch, :) * sr(datatype(k)) / sr(1));
case 'markers'
win = round(events(epochs{iFile}(iEpoch, :)) * sr(datatype(k)));
win = round(events{iFile}(epochs{iFile}(iEpoch, :)) * sr(datatype(k)));
case 'whole'
win = [1 numel(y{datatype(k)})];
end
if any(win > numel(y{datatype(k)}) + 1) || any(win < 0)
warning('\nEpoch %2.0f outside of file %s ...', iEpoch, model.modelfile{iFile});
inv_flag = 0;
else
inv_flag = 1;
% correct issues with using 'round'
win(1) = max(win(1), 1);
win(2) = min(win(2), numel(y{datatype(k)}));
end
if diff(win) < 4
warning('\nEpoch %2.0f contains insufficient data ...', iEpoch);
inv_flag = 0;
end
% 3.6.1 collect information --
sf.model{k}(iEpoch).modeltype = method{k};
sf.model{k}(iEpoch).boundaries = squeeze(epochs{iFile}(iEpoch, :));
Expand All @@ -283,23 +292,24 @@
%
escr = y{datatype(k)}(win(1):win(end));
sf.model{k}(iEpoch).data = escr;
if any(missing{iFile})
model.missing_data = zeros(size(escr));
missing_index = pspm_time2index(missing, sr(datatype(k)));
model.missing_data((missing_index{iFile}(:,1)+1):(missing_index{iFile}(:,2)+1)) = 1;
end

% 3.6.2 do the analysis and collect results --
if any(missing{iFile})
model_analysis = struct('scr', escr, 'sr', sr(datatype(k)), 'missing_data', model.missing_data);
if ~isempty(model.missing{iFile})
model_analysis = struct('scr', escr, 'sr', sr(datatype(k)), 'missing_data', model.missing_data(win(1):win(end)));
else
model_analysis = struct('scr', escr, 'sr', sr(datatype(k)));
end
invrs = fhandle{k}(model_analysis, options);
if any(strcmpi(method{k}, {'dcm', 'mp'}))
sf.model{k}(iEpoch).inv = invrs;
if inv_flag ~= 0
invrs = fhandle{k}(model_analysis, options);
sf.model{k}(iEpoch).inv = invrs;
else
sf.model{k}(iEpoch).inv = [];
end
if inv_flag == 0
sf.stats(iEpoch, k) = NaN;
elseif any(strcmpi(method{k}, {'dcm', 'mp'}))
sf.stats(iEpoch, k) = invrs.f;
else
sf.model{k}(iEpoch).stats = invrs;
else
sf.stats(iEpoch, k) = invrs;
end
end
Expand Down
9 changes: 5 additions & 4 deletions src/pspm_sf_dcm.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,13 @@
flag_missing_too_long = 0;
if any(diff(miss_epoch, 1, 2)/model.sr > 0)
if any(diff(miss_epoch, 1, 2)/model.sr > options.missingthresh)
warning_message = ['Imported data includes too long miss epoches (over ',...
num2str(options.missingthresh), 's), thus estimation has been skipped.'];
warning_message = ['Epoch includes missing data of more than ',...
num2str(options.missingthresh), ' s, thus estimation has been skipped. ', ...
'Please adjust options.missingthresh to proceed if you wish.'];
flag_missing_too_long = 1;
else
warning_message = ['Imported data includes miss epoches (over ',...
num2str(options.missingthresh), 's), but the trial has been allowed. ',...
warning_message = ['Epoch includes missing data of less than ',...
num2str(options.missingthresh), ' s, hence estimation is proceeding. ', ...
'Please adjust options.missingthresh to skip if you wish.'];
end
warning('ID:missing_data', warning_message);
Expand Down

0 comments on commit bf51ffb

Please sign in to comment.