Skip to content

Commit 9a0c10b

Browse files
authored
Merge pull request #836 from bachlab/822_pspm_pupil_pp_unit_check
822 pspm pupil pp unit check
2 parents 8c02d50 + 6023f44 commit 9a0c10b

File tree

2 files changed

+59
-9
lines changed

2 files changed

+59
-9
lines changed

src/pspm_pupil_pp.m

+55-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
function [sts, outchannel] = pspm_pupil_pp (fn, options)
22
% ● Description
3-
% pspm_pupil_pp preprocesses pupil diameter signals given in any unit of
4-
% measurement, with a possibility of combining left/right pupil.
5-
% It performs the steps described in [1]. This function uses
6-
% a modified version of [2]. The modified version with a list of changes
7-
% from the original is shipped with PsPM under pupil-size directory.
3+
% pspm_pupil_pp preprocesses pupil diameter signals provided in
4+
% millimeters (mm), with the option to combine left and right pupil data.
5+
% If the measurement unit is not 'mm' but one of the supported units
6+
% ('cm', 'dm', 'm', 'km', 'in', 'inches'), it will be automatically
7+
% converted to mm. It performs the steps described in [1]. This function
8+
% uses a modified version of [2]. The modified version with a list of
9+
% changes from the original is shipped with PsPM under pupil-size directory.
810
% Pupil preprocessing is performed in three main steps:
911
% 1. In the first step, the "valid" samples are determined. Samples that
1012
% are not valid are not used in the second step. Determining valid
@@ -153,11 +155,29 @@
153155
[sts_load, data,infos, pos_of_channel(1)] = pspm_load_channel(alldata, options.channel, 'pupil');
154156
if sts_load ~= 1, return, end
155157

158+
% Check for invalid pupil data units in options.channel
159+
con_flag = 0;
160+
[stc1,data] = pspm_check_units(data);
161+
if stc1 < 1
162+
warning('ID:invalid_unit', 'Unsupported pupil data unit: "%s" in "options.channel".', data.header.units);
163+
return;
164+
elseif stc1 == 2, con_flag = 1 ; end
165+
156166
if action_combine
157167
[sts_load, data_combine, infos, pos_of_channel(2)] = pspm_load_channel(alldata, options.channel_combine, 'pupil');
158168
if sts_load ~= 1
159169
return
160170
end
171+
% Check for invalid pupil data units in options.channel
172+
[stc2,data_combine] = pspm_check_units(data_combine);
173+
if stc2 < 1
174+
warning('ID:invalid_unit', 'Unsupported pupil data unit: "%s" in "options.channel".', data.header.units);
175+
return
176+
elseif stc2 == 2, con_flag = 1 ; end
177+
178+
179+
180+
161181
[sts1, eye1] = pspm_find_eye(data.header.chantype);
162182
[sts2, eye2] = pspm_find_eye(data_combine.header.chantype);
163183
if (sts1 < 1 || sts2 < 1), return, end
@@ -225,6 +245,8 @@
225245
[sts, out_id] = pspm_write_channel(fn, smooth_signal, options.channel_action, o);
226246
outchannel = out_id.channel;
227247

248+
if con_flag == 1 , warning('At least one channel was converted to "mm". See details above.'); end
249+
228250
%% 7 run second pass if required
229251
if ~flag_valid_combine
230252
[sts, out_id] = pspm_pupil_pp(fn, newoptions);
@@ -359,3 +381,31 @@
359381
end
360382
end
361383
end
384+
385+
function [sts,data] = pspm_check_units(data)
386+
% sts will return 1 when units are "mm" and 2 when the data was converted
387+
% and -1 in all other cases
388+
sts = -1;
389+
convertable_units = { 'cm', 'dm', 'm', 'km', 'in', 'inches'};
390+
391+
if ~strcmp(data.header.units,'mm')
392+
if ~ismember(data.header.units, convertable_units)
393+
return;
394+
else
395+
% convert to 'mm'
396+
[stc, converted] = pspm_convert_unit(data.data, data.header.units,'mm');
397+
if stc == 1
398+
% [~ , eye, new_chantype] = pspm_find_eye(data.header.chantype); % maybe?
399+
warning(' "%s" channel data was converted from "%s" to "mm".', data.header.chantype, data.header.units);
400+
data.data = converted;
401+
data.header.units = 'mm';
402+
sts = 2;
403+
return;
404+
else
405+
return;
406+
end
407+
end
408+
409+
end
410+
sts = 1;
411+
return

src/pspm_pupil_pp_options.m

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
%
1616
% │ // Allowable values criteria
1717
%
18-
% ├─PupilDiameter_Min: Minimum allowable pupil size. Pupil values less than
19-
% │ this value will be marked as invalid. (Default: 1.5)
20-
% ├─PupilDiameter_Max: Maximum allowable pupil size. Pupil values greater than
21-
% │ thin value will be marked as invalid. (Default: 9.0)
18+
% ├─PupilDiameter_Min: Minimum allowable pupil size in mm. Pupil values less than
19+
% │ this value will be marked as invalid. (Default: 1.5 mm)
20+
% ├─PupilDiameter_Max: Maximum allowable pupil size in mm. Pupil values greater than
21+
% │ thin value will be marked as invalid. (Default: 9.0 mm)
2222
%
2323
% │ // Isolated sample filter criteria
2424
% │ // 'Sample-islands' are clusters of samples that are temporally separated

0 commit comments

Comments
 (0)