1
1
function [sts , outchannel ] = pspm_pupil_pp (fn , options )
2
2
% ● 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.
8
10
% Pupil preprocessing is performed in three main steps:
9
11
% 1. In the first step, the "valid" samples are determined. Samples that
10
12
% are not valid are not used in the second step. Determining valid
153
155
[sts_load , data ,infos , pos_of_channel(1 )] = pspm_load_channel(alldata , options .channel , ' pupil' );
154
156
if sts_load ~= 1 , return , end
155
157
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
+
156
166
if action_combine
157
167
[sts_load , data_combine , infos , pos_of_channel(2 )] = pspm_load_channel(alldata , options .channel_combine , ' pupil' );
158
168
if sts_load ~= 1
159
169
return
160
170
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
+
161
181
[sts1 , eye1 ] = pspm_find_eye(data .header .chantype );
162
182
[sts2 , eye2 ] = pspm_find_eye(data_combine .header .chantype );
163
183
if (sts1 < 1 || sts2 < 1 ), return , end
225
245
[sts , out_id ] = pspm_write_channel(fn , smooth_signal , options .channel_action , o );
226
246
outchannel = out_id .channel ;
227
247
248
+ if con_flag == 1 , warning(' At least one channel was converted to "mm". See details above.' ) ; end
249
+
228
250
%% 7 run second pass if required
229
251
if ~flag_valid_combine
230
252
[sts , out_id ] = pspm_pupil_pp(fn , newoptions );
359
381
end
360
382
end
361
383
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
0 commit comments