Skip to content

Commit

Permalink
fix 504
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominik Bach committed Aug 18, 2023
1 parent 3cd3a6b commit ec800a5
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions src/pspm_dcm.m
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
% ├────.filter: Filter settings.
% │ Modality specific default.
% ├───.channel: Channel number.
% │ Default: first SCR channel
% │ Default: last SCR channel
% ├──────.norm: Normalise data.
% │ i.e. Data are normalised during inversion but results
% │ transformed back into raw data units.
Expand Down Expand Up @@ -204,7 +204,7 @@
% 2.3 get further input or set defaults --
% check data channel --
if ~isfield(model, 'channel')
model.channel = 'scr'; % this returns the first SCR channel
model.channel = 'scr'; % this returns the last SCR channel
elseif ~isnumeric(model.channel) && ~strcmp(model.channel,'scr')
warning('ID:invalid_input', 'Channel number must be numeric.'); return;
end
Expand Down Expand Up @@ -343,19 +343,20 @@
return;
end

% use the last data channel, consistent with sf and glm
y{iSn} = data{iSn}{end}.data;
sr{iSn} = data{iSn}{end}.header.sr;
model.filter.sr = sr{iSn};


% load and check existing missing data (if defined)
if ~isempty(model.missing{iSn})
[~, missing{iSn}] = pspm_get_timing('missing', ...
model.missing{iSn}, 'seconds');
else
missing{iSn} = [];
end
y{iSn} = data{iSn}{end}.data;
% to use the last channel in data channels
% this is consistent to sf and glm
sr{iSn} = data{iSn}{end}.header.sr;
model.filter.sr = sr{iSn};


% try to find missing epochs according to subsession threshold
n_data = size(y{iSn},1);
if isempty(missing{iSn})
Expand Down Expand Up @@ -384,16 +385,10 @@
% put missing epochs together
miss_epochs = [nan_ep_start(:), nan_ep_stop(:)];

% classify if epoch should be considered
% true for duration > substhresh and for missing epochs
ignore_epochs = diff(miss_epochs, 1, 2)/sr{iSn} > ...
model.substhresh;

else
% use missing epochs as specified by file
miss_epochs = pspm_time2index(missing{iSn}, sr{iSn});
ignore_epochs = diff(missing{iSn}, 1, 2) > model.substhresh;


% and set data to NaN to enable later detection of `short` missing
% epochs
for k = 1:size(miss_epochs, 1)
Expand All @@ -402,6 +397,9 @@
end
end

% epoch should be ignored if duration > threshold
ignore_epochs = diff(miss_epochs, 1, 2)/sr{iSn} > model.substhresh;

if any(ignore_epochs)
i_e = find(ignore_epochs);

Expand Down Expand Up @@ -444,8 +442,7 @@
ones(n_miss,1)];
else
subsessions(end+1,1:4) = [iSn, ...
[1, numel(y{iSn})]/sr{iSn}, 0];

[0, numel(y{iSn})]/sr{iSn}, 0];

end
end
Expand Down Expand Up @@ -556,8 +553,8 @@

% assign trials to subsessions
trls = num2cell([sn_trlstart{iSn}, sn_trlstop{iSn}],2);
subs = cellfun(@(x) find(x(1) > subsessions(:,2) & ...
x(2) < (subsessions(:,3)) ...
subs = cellfun(@(x) find(x(1) >= subsessions(:,2) & ...
x(2) <= (subsessions(:,3)) ...
& subsessions(:, 1) == iSn), trls, 'UniformOutput', 0);

emp_subs = cellfun(@isempty, subs);
Expand Down

0 comments on commit ec800a5

Please sign in to comment.