Skip to content

Commit

Permalink
Merge branch 'Finalising-version-5.1.0' of https://github.com/bachlab…
Browse files Browse the repository at this point in the history
…/PsPM into Finalising-version-5.1.0
  • Loading branch information
teddychao committed Jun 17, 2021
2 parents d67983f + 4db75b7 commit aca1e22
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 17 deletions.
21 changes: 13 additions & 8 deletions src/pspm_cfg/pspm_cfg_glm_sps.m
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
function [glm_sps] = pspm_cfg_glm_sps
% GLM SPS
% This function applies to the glm model for the modality ScanPath Speed (sps) only

% $Id: pspm_cfg_glm_hp_fc.m 404 2017-01-06 14:02:02Z tmoser $
% $Id: pspm_cfg_glm_sps.m 404 2017-01-06 14:02:02Z tmoser $
% $Rev: 404 $

% Updated by Teddy (WCHN)

% Initialise
global settings
if isempty(settings), pspm_init; end;
if isempty(settings)
pspm_init;
end

% set variables

Expand Down Expand Up @@ -77,20 +82,20 @@
chan_def_left = cfg_const;
chan_def_left.name = 'Last left eye';
chan_def_left.tag = 'chan_def_left';
chan_def_left.val = {'pupil_l'};
chan_def_left.help = {'Use last left eye channel.'};
chan_def_left.val = {'sps_l'};
chan_def_left.help = {'Use the last sps channel from left eye.'};

chan_def_right = cfg_const;
chan_def_right.name = 'Last right eye';
chan_def_right.tag = 'chan_def_right';
chan_def_right.val = {'pupil_r'};
chan_def_right.help = {'Use last right eye channel.'};
chan_def_right.val = {'sps_r'};
chan_def_right.help = {'Use the last sps channel from right eye.'};

best_eye = cfg_const;
best_eye.name = 'Best eye';
best_eye.tag = 'best_eye';
best_eye.val = {'pupil'};
best_eye.help = {['Use eye with the fewest NaN values.']};
best_eye.val = {'sps'};
best_eye.help = {'Use the sps data from the eye with fewest NaN values.'};

chan_def = cfg_choice;
chan_def.name = 'Default';
Expand Down
17 changes: 10 additions & 7 deletions src/pspm_cfg/pspm_cfg_run_glm_sps.m
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
function out = pspm_cfg_run_glm_sps(job)
% Executes pspm_glm
% This function executes pspm_glm for the modality ScanPath Speed (sps) only

% $Id: pspm_cfg_run_glm_hp_fc.m 386 2016-11-29 10:30:55Z tmoser $
% $Rev: 386 $

% Updated 16-06-21 Teddy (WCHN)

global settings
if isempty(settings), pspm_init; end;
if isempty(settings)
pspm_init;
end

% set modality
% set for only the modality sps
modality = 'sps';
modelspec = 'sps';

Expand Down Expand Up @@ -38,11 +42,11 @@
model.modelspec = modelspec;

if isfield(job.chan.chan_def, 'chan_def_left')
model.channel = 'pupil_l';
model.channel = 'sps_l';
elseif isfield(job.chan.chan_def, 'chan_def_right')
model.channel = 'pupil_r';
model.channel = 'sps_r';
else
model.channel = 'pupil';
model.channel = 'sps';
end

out = pspm_glm(model, options);
Expand All @@ -55,4 +59,3 @@
end;

end

9 changes: 7 additions & 2 deletions src/pspm_glm.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@
% otherwise.
%
% optional fields
% model.modelspec: 'scr' (default); specify the model to be used. See
% pspm_init, defaults.glm() which modelspecs are possible
% model.modelspec: 'scr' (default); specify the model to be used.
% See pspm_init, defaults.glm() which modelspecs are possible
% with glm.
% model.modality: specify the modality to be processed.
% When model.modality is set to be sps, the model.channel
% should be set among sps_l, sps_r, or defaultly sps.
% model.bf: basis function/basis set; modality specific default
% with subfields .fhandle (function handle or string) and
% .args (arguments, first argument sampling interval will
Expand All @@ -46,6 +49,8 @@
% precedence order described in its documentation. In a nutshell,
% it prefers preprocessed channels and channels from the best eye
% to other pupil channels.
% SPECIAL: for the modality "sps", the model.channel
% accepts only "sps_l", "sps_r", or "sps".
% DEFAULT: last channel of the specified modality
% (for PSR this is 'pupil')
% model.norm: normalise data; default 0
Expand Down
57 changes: 57 additions & 0 deletions src/pspm_load_data.m
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@
if ischar(chan) && ~strcmp(chan, 'none')
if strcmpi(chan, 'pupil') && isfield(infos.source, 'best_eye')
flag = get_chans_to_load_for_pupil(data, flag, infos.source.best_eye);
elseif strcmpi(chan, 'sps') && isfield(infos.source, 'best_eye')
flag = get_chans_to_load_for_sps(data, flag, infos.source.best_eye);
else
for k = 1:numel(data)
if (any(strcmpi(chan, {'event', 'events'})) && strcmpi(data{k}.header.units, 'events')) || ...
Expand Down Expand Up @@ -315,3 +317,58 @@
flag = besteye_channels;
end
end


function flag = get_chans_to_load_for_sps(data, flag, best_eye)
% 16-06-21 This is a tempory patch for loading sps data, copied from
% pupil data
% It needs to be updated for testing the compatibility with sps
% Set flag variable according to the precedence order:
%
% 1. Combined channels (by definition also preprocessed)
% 2. Preprocessed channels corresponding to best eye
% 3. Preprocessed channels
% 4. Best eye pupil channels
%
% The earliest possible option is taken and then the function returns.
best_eye = lower(best_eye);
chantype_list = cellfun(@(x) x.header.chantype, data, 'uni', false);
sps_channels = cell2mat(cellfun(...
@(chantype) strncmp(chantype, 'sps',numel('sps')),...
chantype_list,...
'uni',...
false...
));
preprocessed_channels = cell2mat(cellfun(...
@(chantype) strcmp(chantype(end-2:end), '_pp'),...
chantype_list,...
'uni',...
false...
));
combined_channels = cell2mat(cellfun(...
@(chantype) contains(chantype, '_lr_') && strcmp(chantype(end-2:end), '_pp'),...
chantype_list,...
'uni',...
false...
));
besteye_channels = cell2mat(cellfun(...
@(chantype) strcmp(chantype(end-1:end), ['_' best_eye]) || contains(chantype, ['_' best_eye '_']),...
chantype_list,...
'uni',...
false...
));
preprocessed_channels = preprocessed_channels & sps_channels;
combined_channels = combined_channels & sps_channels;
besteye_channels = besteye_channels & sps_channels;

if any(combined_channels)
flag = combined_channels;
elseif any(preprocessed_channels)
flag = preprocessed_channels & besteye_channels;
if ~any(flag)
flag = preprocessed_channels;
end
else
flag = besteye_channels;
end
end

0 comments on commit aca1e22

Please sign in to comment.