From bf51ffb50ed727a21a2b4392148251e08dfe49d4 Mon Sep 17 00:00:00 2001 From: Dominik Bach Date: Sun, 13 Aug 2023 16:50:26 +0200 Subject: [PATCH] bugfixes --- src/pspm_interp1.m | 9 ++++----- src/pspm_sf.m | 40 +++++++++++++++++++++++++--------------- src/pspm_sf_dcm.m | 9 +++++---- 3 files changed, 34 insertions(+), 24 deletions(-) diff --git a/src/pspm_interp1.m b/src/pspm_interp1.m index 86b1e5aae..9e9154844 100644 --- a/src/pspm_interp1.m +++ b/src/pspm_interp1.m @@ -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 diff --git a/src/pspm_sf.m b/src/pspm_sf.m index beb3cec24..3cf6e4f42 100644 --- a/src/pspm_sf.m +++ b/src/pspm_sf.m @@ -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 @@ -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) @@ -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, :)); @@ -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 diff --git a/src/pspm_sf_dcm.m b/src/pspm_sf_dcm.m index 2df113ac7..1d27f2076 100644 --- a/src/pspm_sf_dcm.m +++ b/src/pspm_sf_dcm.m @@ -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);