Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

[solved] Pupil size obtention

edited March 2015 in PyGaze


I want to obtain the pupil size of my subject, and to do this I have made the following modifications to, in the flushData(self) function :

  • addition of 'L.PupilSize' and 'R.PupilSize' in self.datafile.write('\t'.join(['TimeStamp',
  • addition of g.LeftPupil ande g.RightPupil in self.datafile.write('%.1f\t%.4f\t%.4f\t%d\t%.4f\t%.4f\t%d\t%d\t%d'%(

The function now looks like :


        # time of the first event
        timeStampStart = self.gazeData[0].Timestamp

        # loop through all data points
        for g in self.gazeData:

            # write timestamp and gaze position for both eyes to the datafile
                                g.LeftGazePoint2D.x*self.disp.dispsize[0] if g.LeftValidity!=4 else -1.0,
                                g.LeftGazePoint2D.y*self.disp.dispsize[1] if g.LeftValidity!=4 else -1.0,
                                g.RightGazePoint2D.x*self.disp.dispsize[0] if g.RightValidity!=4 else -1.0,
                                g.RightGazePoint2D.y*self.disp.dispsize[1] if g.RightValidity!=4 else -1.0,

My problem is that in the output file colums of R.PupilSize and L.PupilSize I have only '3' or '4' when the sample is valid, -1 if not.
What is my mistake ? Why don't I obtain a pupil size ?

Thanks for any help !


  • edited 6:21PM

    I finally found the error...

    t%d was just not the good way to treat the value as a decimal, I replace it by t%.4f and it works fine.

    '3' and '4' were just the whole part of the pupil size.

    Sorry for the useless question.

  • edited 6:21PM


    Indeed, %d is for integers, and will effectively round floats down.

    Btw, if you feel that this a wortwhile addition to PyGaze that other people might benefit from as well, you could consider sending Edwin a pull request with the changes through GitHub. The repository is here:


  • edited 6:21PM

    This is brilliant, thanks for adding this clearly important feature I neglected!

  • Hi @Edwin , I was wondering if this feature is included in the latest version of PyGaze. I also found it'd be very helpful to record pupillary data. I believe that in my current version, pupil size is included for the eye tribe tracker output but not for tobii ouput.


  • edited September 2018

    Hi @hanzh,

    Yes, it should be possible! What Tobii back-end are you using? Are you using tobii or tobii-legacy in the latest version of PyGaze, or perhaps using an older version that only has tobii (which is the current tobii-legacy)?

    Edit: I just checked, and the functionality above was never pull-requested into the tobii-legacy back-end. It should be supported by the tobii back-end, I believe, which is based on the new Tobii Pro SDK. If you're using the Tobii legacy back-end, I would be very happy to implement the pupil size solution mentioned above.


  • Hi @Edwin,

    I am using an older version of PyGaze where we only have the tobii backend because we run a Tobii T60. I think it's time for me to update the package, but it would be really nice to add pupillary measures to it!


Sign In or Register to comment.