Home > data-import > gaze > import_possci_eye_files.m

import_possci_eye_files

PURPOSE ^

Imports the Positive Science text files and creates

SYNOPSIS ^

function import_possci_eye_files(sid, agents, frames)

DESCRIPTION ^

 Imports the Positive Science text files and creates
 cont2_eye_xy, cont_eye_x, and cont_eye_y variables.

 sid = subject id

 agents = a cell array of agent types. Ex.  agents = {'child', 'parent'}.
 Note: The number of agents needs to be the same as the number of rows for
 the frames argument.

 frames = an array of [start_frame end_frame] that defines the start and
 end frame cut from the original video for the listed agents.  Each row
 corresponds to the index of the agents cell array.  Note: This needs to
 have the same number of rows as there are agents.

 Eye Files have 7 lines of header and 12 columns:
        1                2            3              4           5    6
 recordFrameCount movieFrameCount frames/sec QTtime(h:m:s.msec) porX porY 
    7      8      9           10          11        12
 pupilX pupilY cornealRefX cornealRefY diameterW diameterH
 
 We only pull out the recordFrameCount, porX, and porY columns.

 Notes:  We assume that the frame rate is 29.97 fps, that the first
 frame that we extract is frame 0 in the cam##_frames_p folder, and that
 that frame corresponds to time = 30.0 seconds.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function import_possci_eye_files(sid, agents, frames)
0002 % Imports the Positive Science text files and creates
0003 % cont2_eye_xy, cont_eye_x, and cont_eye_y variables.
0004 %
0005 % sid = subject id
0006 %
0007 % agents = a cell array of agent types. Ex.  agents = {'child', 'parent'}.
0008 % Note: The number of agents needs to be the same as the number of rows for
0009 % the frames argument.
0010 %
0011 % frames = an array of [start_frame end_frame] that defines the start and
0012 % end frame cut from the original video for the listed agents.  Each row
0013 % corresponds to the index of the agents cell array.  Note: This needs to
0014 % have the same number of rows as there are agents.
0015 %
0016 % Eye Files have 7 lines of header and 12 columns:
0017 %        1                2            3              4           5    6
0018 % recordFrameCount movieFrameCount frames/sec QTtime(h:m:s.msec) porX porY
0019 %    7      8      9           10          11        12
0020 % pupilX pupilY cornealRefX cornealRefY diameterW diameterH
0021 %
0022 % We only pull out the recordFrameCount, porX, and porY columns.
0023 %
0024 % Notes:  We assume that the frame rate is 29.97 fps, that the first
0025 % frame that we extract is frame 0 in the cam##_frames_p folder, and that
0026 % that frame corresponds to time = 30.0 seconds.
0027 
0028 
0029 % Check that there are the same number of agents as there are frames.
0030 num_agents = length(agents);
0031 num_chunks = size(frames, 1);
0032 
0033 if num_agents ~= num_chunks    
0034     error('The number of agents does not match the number of frame chunks.')
0035 end
0036 
0037 % 29.97 Frame rate assumption and starting time for frame 0 is 30.0 seconds.
0038 rate = 1/29.97;
0039 trial_start_time = 30;
0040 
0041 
0042 % Get the subject directory information.
0043 sub_dir = get_subject_dir(sid);
0044 sub_info = get_subject_info(sid);
0045 sub_number = sprintf('__%d_%d', sub_info(3), sub_info(4));
0046 
0047 % Go through each agent and their corresponding frames.
0048 for i = 1:num_agents
0049     
0050     agent = agents{i};
0051     chunk_frames = frames(i,:);
0052     num_frames = frames(i,2) - frames(i,1)+1;
0053 
0054     % Get the text file name.
0055     eye_file_path = sprintf('%s/extra_p/%s_%s_eye.txt', sub_dir, sub_number, agent);
0056 
0057     % Read the text file.
0058     fid = fopen(eye_file_path);
0059     eye_data = textscan(fid, '%d %d %f %s %f %f %f %f %f %f %f %f', 'Headerlines',7);
0060     fclose(fid);
0061 
0062     % Get the raw x and y coordinates.
0063     eye_xy_raw = [eye_data{1} eye_data{5} eye_data{6}];
0064 
0065     % Grab just the frames specified.
0066     eye_xy = double(eye_xy_raw(frames(i,1):frames(i,2), :));
0067     
0068     % Generate the new times.
0069     end_time = rate*num_frames + trial_start_time - rate;
0070     new_times = [30:rate:end_time]';
0071     eye_xy(:,1) = new_times(:);
0072 
0073     cont2_eye_x = eye_xy(:,1:2); 
0074     cont2_eye_y = [eye_xy(:,1) eye_xy(:,3)]; 
0075     
0076     % Save xy, x, and y cont vars
0077     record_variable(sid, sprintf('cont2_eye_xy_%s', agent), eye_xy);
0078     record_variable(sid, sprintf('cont_eye_x_%s', agent), cont2_eye_x);
0079     record_variable(sid, sprintf('cont_eye_y_%s', agent), cont2_eye_y);
0080 
0081 end
0082 
0083 
0084 
0085 
0086 
0087

Generated on Wed 24-May-2017 00:00:56 by m2html © 2005