|
226 | 226 | file_paths{1,1} = eye_data_cell{1}.source.file ; |
227 | 227 | end |
228 | 228 |
|
229 | | - % Check if the first data has the StartTime field |
230 | | - if isfield(data{1}.header, 'StartTime') |
231 | | - % Check if all StartTimes are the same |
232 | | - start_times = cellfun(@(x) x.header.StartTime, data, 'UniformOutput', false); |
233 | | - if ~isequal(start_times{:}) ; warning('Not all data have the same StartTime. Please check the input data.'); end |
234 | | - else |
235 | | - % If there is no StartTime field start time will set to 0 |
236 | | - for i = 1:length(data); data{i}.header.StartTime = 0; end |
237 | | - end |
| 229 | +%% --- Add the eye data to the channels --- |
| 230 | +num_eyes = length(eye_data_cell); |
| 231 | +switch num_eyes |
| 232 | + case 0; warning('No eye data available.'); |
| 233 | + case 1 |
| 234 | + eyeSide = lower(eye_data_cell{1}.RecordedEye); |
| 235 | + warning('Only %s eye data available.', eyeSide); |
| 236 | + |
| 237 | + if strcmp(eyeSide, 'right') |
| 238 | + pupil_r = eye_data_cell{1}.Columns{:,'pupil_size'}; |
| 239 | + gaze_x_r = eye_data_cell{1}.Columns{:,'x_coordinate'}; |
| 240 | + gaze_y_r = eye_data_cell{1}.Columns{:,'y_coordinate'}; |
| 241 | + |
| 242 | + data{1}.data = pupil_r; |
| 243 | + data{1}.header.chantype = 'pupil_r'; |
| 244 | + data{2}.data = gaze_x_r; |
| 245 | + data{2}.header.chantype = 'gaze_x_r'; |
| 246 | + data{3}.data = gaze_y_r; |
| 247 | + data{3}.header.chantype = 'gaze_y_r'; |
| 248 | + |
| 249 | + elseif strcmp(eyeSide, 'left') |
| 250 | + pupil_l = eye_data_cell{1}.Columns{:,'pupil_size'}; |
| 251 | + gaze_x_l = eye_data_cell{1}.Columns{:,'x_coordinate'}; |
| 252 | + gaze_y_l = eye_data_cell{1}.Columns{:,'y_coordinate'}; |
| 253 | + |
| 254 | + data{1}.data = pupil_l; |
| 255 | + data{1}.header.chantype = 'pupil_l'; |
| 256 | + data{2}.data = gaze_x_l; |
| 257 | + data{2}.header.chantype = 'gaze_x_l'; |
| 258 | + data{3}.data = gaze_y_l; |
| 259 | + data{3}.header.chantype = 'gaze_y_l'; |
| 260 | + |
| 261 | + else |
| 262 | + warning('Unknown RecordedEye eye_data_cell.'); |
| 263 | + return |
| 264 | + end |
| 265 | + case 2 |
| 266 | + eyes = lower({eye_data_cell{1}.RecordedEye, eye_data_cell{2}.RecordedEye}); |
| 267 | + if strcmp(eyes{1}, eyes{2}) |
| 268 | + warning('Both recorded eyes are %s.', eyes{1}); |
| 269 | + % Maybe choose the better eye? -> it chooses the better depends |
| 270 | + % on l or eye |
| 271 | + else |
| 272 | + % Correctly assign each cell to the corresponding eye. |
| 273 | + idxRight = find(strcmp(eyes, 'right'), 1); |
| 274 | + idxLeft = find(strcmp(eyes, 'left'), 1); |
| 275 | + |
| 276 | + if isempty(idxRight) || isempty(idxLeft); warning('...');end % ??? |
| 277 | + |
| 278 | + pupil_r = eye_data_cell{idxRight}.Columns{:,'pupil_size'}; |
| 279 | + gaze_x_r = eye_data_cell{idxRight}.Columns{:,'x_coordinate'}; |
| 280 | + gaze_y_r = eye_data_cell{idxRight}.Columns{:,'y_coordinate'}; |
| 281 | + |
| 282 | + pupil_l = eye_data_cell{idxLeft}.Columns{:,'pupil_size'}; |
| 283 | + gaze_x_l = eye_data_cell{idxLeft}.Columns{:,'x_coordinate'}; |
| 284 | + gaze_y_l = eye_data_cell{idxLeft}.Columns{:,'y_coordinate'}; |
| 285 | + |
| 286 | + % right eye channels |
| 287 | + data{1}.header.chantype = 'pupil_r'; |
| 288 | + data{1}.data = pupil_r; |
| 289 | + |
| 290 | + data{2}.header.chantype = 'gaze_x_r'; |
| 291 | + data{2}.data = gaze_x_r; |
| 292 | + data{3}.header.chantype = 'gaze_y_r'; |
| 293 | + data{3}.data = gaze_y_r; |
| 294 | + |
| 295 | + % left eye channels |
| 296 | + data{4}.header.chantype = 'pupil_l'; |
| 297 | + data{4}.data = pupil_l; |
| 298 | + data{5}.header.chantype = 'gaze_x_l'; |
| 299 | + data{5}.data = gaze_x_l; |
| 300 | + data{6}.header.chantype = 'gaze_y_l'; |
| 301 | + data{6}.data = gaze_y_l; |
| 302 | + |
| 303 | + end |
| 304 | + |
| 305 | + otherwise; error('Unexpected number of eye data cells.'); |
| 306 | + |
| 307 | + |
| 308 | +end |
| 309 | + |
| 310 | +data = data'; |
| 311 | + |
| 312 | +%% Add header data for pupil and gaze data |
| 313 | + |
| 314 | +% For one eye |
| 315 | +if num_eyes == 1; idxRight = 1; idxLeft = 1; end |
| 316 | + |
| 317 | +for i = 1:length(data) |
| 318 | + % pupil |
| 319 | + if strcmp(data{i}.header.chantype(1:end-1) , 'pupil_') |
| 320 | + if strcmp(data{i}.header.chantype(end:end) , 'r') |
| 321 | + data{i}.header.Description = eye_data_cell{idxRight}.pupil_size.Description; |
| 322 | + data{i}.header.units = eye_data_cell{idxRight}.pupil_size.Units; |
| 323 | + data{i}.header.sr = eye_data_cell{idxRight}.SamplingFrequency; |
| 324 | + |
| 325 | + elseif strcmp(data{i}.header.chantype(end:end) , 'l') |
| 326 | + data{i}.header.Description = eye_data_cell{idxLeft}.pupil_size.Description; |
| 327 | + data{i}.header.units = eye_data_cell{idxLeft}.pupil_size.Units; |
| 328 | + data{i}.header.sr = eye_data_cell{idxLeft}.SamplingFrequency; |
| 329 | + |
| 330 | + else |
| 331 | + warning('No valid pupil channel found.'); |
| 332 | + end |
| 333 | + % gaze |
| 334 | + elseif strcmp(data{i}.header.chantype(1:end-4) , 'gaze') |
| 335 | + if strcmp(data{i}.header.chantype(6) , 'x') |
| 336 | + if strcmp(data{i}.header.chantype(8) , 'r') |
| 337 | + % gaze_x_r |
| 338 | + if any(strcmp(fieldnames(eye_data_cell{idxRight}),'SampleCoordinateUnits')) |
| 339 | + data{i}.header.units = eye_data_cell{idxRight}.SampleCoordinateUnits; % "pixel" |
| 340 | + elseif any(strcmp(fieldnames(eye_data_cell{idxRight}),'x_coordinate')) |
| 341 | + data{i}.header.units = eye_data_cell{idxRight}.x_coordinate.Units; |
| 342 | + else |
| 343 | + warning('ID:missing_units', 'Units could not be determined for gaze_x_r channel.'); |
| 344 | + end |
| 345 | + |
| 346 | + data{i}.header.sr = eye_data_cell{idxRight}.SamplingFrequency; |
| 347 | + data{i}.header.range = [eye_data_cell{idxRight}.GazeRange.xmin, eye_data_cell{idxRight}.GazeRange.xmax] ; % e.g. [0 1151] |
| 348 | + elseif strcmp(data{i}.header.chantype(8) , 'l') |
| 349 | + % gaze_x_l |
| 350 | + if any(strcmp(fieldnames(eye_data_cell{idxLeft}),'SampleCoordinateUnits')) |
| 351 | + data{i}.header.units = eye_data_cell{idxLeft}.SampleCoordinateUnits; % "pixel" |
| 352 | + elseif any(strcmp(fieldnames(eye_data_cell{idxLeft}),'x_coordinate')) |
| 353 | + data{i}.header.units = eye_data_cell{idxLeft}.x_coordinate.Units; |
| 354 | + else |
| 355 | + warning('ID:missing_units', 'Units could not be determined for gaze_x_l channel.'); |
| 356 | + end |
| 357 | + |
| 358 | + data{i}.header.sr = eye_data_cell{idxLeft}.SamplingFrequency; |
| 359 | + data{i}.header.range = [eye_data_cell{idxLeft}.GazeRange.xmin, eye_data_cell{idxLeft}.GazeRange.xmax] ; % e.g. [0 1151] |
| 360 | + else |
| 361 | + warning('Something went worng with gaze x channels') |
| 362 | + end |
| 363 | + |
| 364 | + elseif strcmp(data{i}.header.chantype(6) , 'y') |
| 365 | + if strcmp(data{i}.header.chantype(8) , 'r') |
| 366 | + % gaze_y_r |
| 367 | + if any(strcmp(fieldnames(eye_data_cell{idxRight}),'SampleCoordinateUnits')) |
| 368 | + data{i}.header.units = eye_data_cell{idxRight}.SampleCoordinateUnits; % "pixel" |
| 369 | + elseif any(strcmp(fieldnames(eye_data_cell{idxRight}),'y_coordinate')) |
| 370 | + data{i}.header.units = eye_data_cell{idxRight}.y_coordinate.Units; |
| 371 | + else |
| 372 | + warning('ID:missing_units', 'Units could not be determined for gaze_y_r channel.'); |
| 373 | + end |
| 374 | + data{i}.header.sr = eye_data_cell{idxRight}.SamplingFrequency; |
| 375 | + data{i}.header.range = [eye_data_cell{idxRight}.GazeRange.ymin, eye_data_cell{idxRight}.GazeRange.ymax] ; % e.g. [0 1151] |
| 376 | + |
| 377 | + elseif strcmp(data{i}.header.chantype(8) , 'l') |
| 378 | + % gaze_y_l |
| 379 | + if any(strcmp(fieldnames(eye_data_cell{idxLeft}),'SampleCoordinateUnits')) |
| 380 | + data{i}.header.units = eye_data_cell{idxLeft}.SampleCoordinateUnits; % "pixel" |
| 381 | + elseif any(strcmp(fieldnames(eye_data_cell{idxLeft}),'y_coordinate')) |
| 382 | + data{i}.header.units = eye_data_cell{idxLeft}.y_coordinate.Units; % should i add a check that x and y are the same units? |
| 383 | + else |
| 384 | + warning('ID:missing_units', 'Units could not be determined for gaze_y_l channel.'); |
| 385 | + end |
| 386 | + |
| 387 | + data{i}.header.sr = eye_data_cell{idxLeft}.SamplingFrequency; |
| 388 | + data{i}.header.range = [eye_data_cell{idxLeft}.GazeRange.ymin, eye_data_cell{idxLeft}.GazeRange.ymax] ; % e.g. [0 1151] |
| 389 | + |
| 390 | + else |
| 391 | + warning('Something went worng with gaze y channels') |
| 392 | + end |
| 393 | + end |
| 394 | + end |
| 395 | +end |
| 396 | + |
| 397 | +%% --- Build the eye infos.source ---- |
| 398 | + |
| 399 | +% --- infos.source --- |
| 400 | +infos.source = struct(); |
| 401 | +infos.source.chan = {} ;% {'Column 02'} {'Column 01'}? |
| 402 | +infos.source.chan_stats = cell(length(data), 1); % nan_stats |
| 403 | + |
| 404 | +% Calculating the nan ratio |
| 405 | +for i = 1:length(data) |
| 406 | + n_data = size(data{i}.data, 1); |
| 407 | + n_inv = sum(isnan(data{i}.data)); |
| 408 | + infos.source.chan_stats{i,1} = struct(); |
| 409 | + infos.source.chan_stats{i,1}.nan_ratio = n_inv / n_data; |
| 410 | +end |
| 411 | + |
| 412 | +if ~isequal(eye_data_cell{idxRight}.GazeRange, eye_data_cell{idxLeft}.GazeRange) |
| 413 | + warning("GazeRange is not equal"); |
| 414 | +end |
| 415 | + |
| 416 | +infos.source.gaze_coords = eye_data_cell{idxRight}.GazeRange; |
| 417 | + |
| 418 | +if any(strcmp(fieldnames(eye_data_cell{idxRight}),'PupilFitMethod')) |
| 419 | + infos.source.elcl_proc = lower(eye_data_cell{idxRight}.PupilFitMethod); % or should it be called PupilFitMethod? lowercase! |
| 420 | +elseif any(strcmp(fieldnames(eye_data_cell{idxRight}),'ElclProc')) |
| 421 | + infos.source.elcl_proc = lower(eye_data_cell{idxRight}.ElclProc); % like in the Calinet dataset |
| 422 | +end |
| 423 | + |
| 424 | +% eyesObserved and best_eye |
| 425 | +if num_eyes == 2 |
| 426 | + infos.source.eyesObserved = 'lr'; |
| 427 | +elseif num_eyes == 1 |
| 428 | + infos.source.eyesObserved = data{1}.header.chantype(end); |
| 429 | +end |
| 430 | + |
| 431 | +infos.source.best_eye = eye_with_smaller_nan_ratio(data, infos.source.eyesObserved); |
| 432 | +infos.source.type = 'BIDS (json/tsv)' ; |
| 433 | + |
| 434 | + |
| 435 | +if num_eyes == 2 |
| 436 | + % physio_infos.source.file = [eye_data_cell{1}.source.file, eye_data_cell{2}.source.file] ; % {1},{2} gives the right order |
| 437 | + file_paths{1,1} = eye_data_cell{1}.source.file; |
| 438 | + file_paths{2,1} = eye_data_cell{2}.source.file; |
| 439 | +else |
| 440 | + file_paths{1,1} = eye_data_cell{1}.source.file ; |
| 441 | +end |
| 442 | + |
| 443 | + |
| 444 | + |
| 445 | +% Check if the first data has the StartTime field |
| 446 | +if isfield(data{1}.header, 'StartTime') |
| 447 | + % Check if all StartTimes are the same |
| 448 | + start_times = cellfun(@(x) x.header.StartTime, data, 'UniformOutput', false); |
| 449 | + if ~isequal(start_times{:}) ; warning('Not all data have the same StartTime. Please check the input data.'); end |
| 450 | +else |
| 451 | + % If there is no StartTime field start time will set to 0 |
| 452 | + for i = 1:length(data); data{i}.header.StartTime = 0; end |
| 453 | +end |
238 | 454 |
|
239 | 455 | else |
240 | 456 | warning('No data for physio eye data was imported.'); |
|
0 commit comments