Eyelink data is sometimes int16 when extracted in matlab

Hi Chris,

I have a strange observation that I cannot figure out. I’m analyzing .mwk2 files using the matlab sdk. When I extract eye position and pupil size data, they are in int16 data type in 6 out of 38 sessions. The data appear to be accurate (e.g. eyeX appears to actually be the horizontal eye position), but they are rounded to the nearest integer. All sessions were collected using more or less the same MWorks protocol and the real-time eye tracking was working correctly during all sessions (I constantly monitor the eye window and would have noticed if they were only integer valued). Below is my code snippet for getting the eye data in matlab:

f = mworks.MWKFile(fName) ;
    f.selectEvents([eyeXCD ; eyeYCD ; pupilSizeCD])
    
    i = 1 ;
    while true
        temp = f.nextEvent;
    
        if isempty(temp)
            break
        else            
            eventsEye(i) = temp ;
        end
        i = i+1 ;
        
    end


    [~,inds] = sort([eventsEye.time_us]); % Sort events according to when they occurred
    eventsEye = eventsEye(inds);
    eCodes = [eventsEye.event_code]';
    eCodeData = {eventsEye.data}';
    eTimes = [eventsEye.time_us]';
    
    
    EyeInd = find(eCodes == eyeYCD) ;
    eyeY = (cat(2, eCodeData{EyeInd}));

Any thoughts on what could be going on?

Thanks,
Gabe

Hi Gabe,

This doesn’t make any sense. MWorks’ EyeLink interface reports all eye sample data as floating-point values, so that’s how they should be stored in the event file. And even if they were stored in the event file as integers, they would be read into MATLAB as int64’s, not int16’s.

Would it be possible for you to share your data file with me (e.g. via Dropbox)? Also, what version of MATLAB are you using?

Thanks,
Chris

Hi Chris,

Apologies, it is indeed int64. I am using Matlab 2022a. Below is a dropbox link to an example session where I am seeing this. The relevant mWorks variables are ‘eye_x’ and ‘eye_y’. To reiterate, almost all of the other sessions look as expected.

Gabe

Hi Gabe,

Thanks for sharing the event file.

Looking at eye_x and eye_y, I see only six events (3 for each variable) where the data is not a floating-point value. These events are the earliest for each variable, and all have value 0, so I assume they represent each variable’s initial value.

I checked the file three ways: via the sqlite3 command-line tool, and with MWorks’ Python and MATLAB interfaces. All three methods yielded the same result. In MATLAB, I used the following function:

function checkType()
    f = mworks.MWKFile('20231207_g.mwk2');
    f.selectEvents([f.ReverseCodec('eye_x'), f.ReverseCodec('eye_y')])
    while true
        event = f.nextEvent;
        if isempty(event)
            break
        end
        if ~isa(event.data, 'double')
            fprintf('%d %d %s\n', event.event_code, event.time_us, ...
                    string(event.data))
        end
    end    
    f.close
end

It produced this output, in MATLAB R2024b and R2022a:

>> checkType
23 7958955626670 0
23 7958955628948 0
23 7958957339705 0
24 7958955626670 0
24 7958955628949 0
24 7958957339706 0

Can you try my checkType function and see if you get the same result? If you do, then the values must be getting converted to int64 some time after they’re read from the event file.

Cheers,
Chris