Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve eyelink #702

Merged
merged 7 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
61 changes: 26 additions & 35 deletions src/Import/eyelink/import_eyelink.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@
% - ymin: y coordinate of top left corner of screen in pixels.
% - xmax: x coordinate of bottom right corner of screen in pixels.
% - ymax: y coordinate of bottom right corner of screen in pixels.
% markers: Array of the same size as data columns. An entry is 1 if there is
% marker at that time.
% markerinfos: Structure with the following fields:
% markers: Sample number of any detected marker
% markerinfo: Structure with the following fields:
% - name: Cell array of marker name.
% - value: Index of the marker name to an array containing
% unique marker names.
Expand Down Expand Up @@ -52,7 +51,7 @@

% write outputs
% -------------
markers_sess = create_marker_val_fields(markers_sess);
markers_sess = create_marker_val_fields(markers_sess); % create marker values from unique names
for sn = 1:numel(dataraw)
data{sn}.raw = dataraw{sn};
data{sn}.channels = data{sn}.raw(:, chan_info{sn}.col_idx);
Expand All @@ -71,29 +70,25 @@
data{sn}.gaze_coords.ymax = chan_info{sn}.ymax;
data{sn}.elcl_proc = chan_info{sn}.elcl_proc;

data{sn}.markers = markers_sess{sn}.markers;
data{sn}.markerinfos.name = markers_sess{sn}.names;
data{sn}.markerinfos.value = markers_sess{sn}.vals;
data{sn}.markers = markers_sess{sn}.times;
data{sn}.markerinfo.name = markers_sess{sn}.names;
data{sn}.markerinfo.value = markers_sess{sn}.vals;
end
data{end + 1} = combine_markers(markers_sess);

session_end_times = calc_session_end_times(messages);
for i = 1:numel(data) - 1
[data{i}.markers, data{i}.markerinfos] = remove_markers_beyond_end(...
data{i}.markers, data{i}.markerinfos, markers_sess{i}.times, session_end_times{i});
[data{i}.markers, data{i}.markerinfo] = remove_markers_beyond_end(...
data{i}.markers, data{i}.markerinfo, session_end_times{i}, data{1}.raw(1,1));
end
[data{end}.markers, data{end}.markerinfo] = remove_markers_beyond_end(...
data{end}.markers, data{end}.markerinfo, session_end_times{end}, data{1}.raw(1,1));
end

function [markers_out, markerinfos_out] = remove_markers_beyond_end(markers, markerinfos, markertimes, sess_end_time)
mask = markertimes <= sess_end_time;

marker_indices = find(markers);
markers_out = markers;
if any(~mask)
markers_out(marker_indices(end)) = 0;
end

markerinfos_out = markerinfos;
function [markers_out, markerinfos_out] = remove_markers_beyond_end(markers, markerinfo, sess_end_time, first_sess_start)
mask = (markers <= sess_end_time) & (markers > first_sess_start);
markers_out = markers(mask);
markerinfos_out = markerinfo;
markerinfos_out.name = markerinfos_out.name(mask);
markerinfos_out.value = markerinfos_out.value(mask);
end
Expand Down Expand Up @@ -267,7 +262,10 @@
eblink_indices = find(strncmp(messages, 'EBLINK', numel('EBLINK')));
ssacc_indices = find(strncmp(messages, 'SSACC', numel('SSACC')));
esacc_indices = find(strncmp(messages, 'ESACC', numel('ESACC')));
msg_indices = strncmp(messages, 'MSG', numel('MSG'));
% MSG refers to ethernet input using python eyelink library, and INPUT to
% parallel/serial port input
msg_indices = strncmp(messages, 'MSG', numel('MSG')) | ...
strncmp(messages, 'INPUT', numel('INPUT'));
for name = {'RECCFG', 'ELCLCFG', 'GAZE_COORDS', 'THRESHOLDS', 'ELCL_', 'PUPIL_DATA_TYPE', '!MODE'}
msg_indices = msg_indices & ~contains(messages, name);
end
Expand Down Expand Up @@ -303,21 +301,14 @@
end

% construct markers
markers.markers = false(size(dataraw, 1), 1);
markers.times = [];
markers.names = {};
for idx = msg_indices
msgline = messages{idx};
parts = split(msgline);
time = str2num(parts{2});
if ismember(time,markers.times)
warning('ID:markers_with_same_timestamp',['PsPM found markers with same timestamps.',...
'Only the first one will be imported.'])
elseif time <= session_end_time
markers.markers(bsearch(timecol, time)) = true;
markers.times(end + 1, 1) = time;
markers.names{end + 1, 1} = cell2mat(join(parts(3:end), ' '));
end
markers.times(end + 1, 1) = time;
markers.names{end + 1, 1} = cell2mat(join(parts(3:end), ' '));
end

% set data columns
Expand Down Expand Up @@ -433,7 +424,7 @@
extra = setdiff(beg_indices, end_indices);
for idx = extra
parts = split(messages{idx});
which_eye = parts{2}
which_eye = parts{2};
beg_time = str2num(parts{3});
end_time = session_end_time;

Expand Down Expand Up @@ -461,11 +452,11 @@
for i = 1:numel(markers_sess)
all_marker_names = [all_marker_names; markers_sess{i}.names];
end
all_markers_struct.times = [];
all_markers_struct.vals = [];
all_markers_struct.names = all_marker_names;
all_markers_struct.markers = [];
all_markers_struct.markerinfo.value = [];
all_markers_struct.markerinfo.name = all_marker_names;
for i = 1:numel(markers_sess)
all_markers_struct.times = [all_markers_struct.times; markers_sess{i}.times];
all_markers_struct.vals = [all_markers_struct.vals; markers_sess{i}.vals];
all_markers_struct.markers = [all_markers_struct.markers; markers_sess{i}.times];
all_markers_struct.markerinfo.value = [all_markers_struct.markerinfo.value; markers_sess{i}.vals];
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@
%
% - all elements in right data columns (except blink/saccade) that correspond to right
% blink or saccade rows are set to NaN
if nargin == 3
%__________________________________________________________________________
%
% (C) 2019 Eshref Yozdemir

if nargin == 3
fn_is_left = @(x) strcmp(x(end-1:end), '_l');
end

Expand Down
35 changes: 0 additions & 35 deletions src/backroom/blink_saccade_filtering.m

This file was deleted.

110 changes: 0 additions & 110 deletions src/pspm_blink_saccade_filt.m

This file was deleted.