Package: saccademodel
A least-squares optimal offline method to find saccadic reaction time and saccade duration from tracked gaze points.You have tracked the gaze points of the following event sequence:A person looks at point (A). An image appears at (B).The person reacts to the image and starts to move their gaze toward (B). Thesaccadestarts.The gaze arrives to (B). The saccade ends.The person looks at point (B).Now you want to determine:The time between events 1 and 2, called thesaccadic reaction timeorSRT.The time between events 2 and 3, called thesaccade durationorSD.Thesaccademodelalgorithm computes the times for you by fitting an ideal gaze path to the data. The ideal gaze path has the following structure. From t=0 to t=saccade_start the ideal gaze is exactly at point (A). From t=saccade_start to t=saccade_end the ideal gaze moves from (A) to (B) with constant velocity. From t=saccade_end to t=n the gaze remains at (B). The algorithm finds such timessaccade_startandsaccade_endthatminimize the mean squared errorbetween the ideal gaze path and the given tracked gaze points. In other words, the algorithm splits the data to three segments: source fixation, saccade, and target fixation.As thegreatest advantage, when compared to velocity-based saccade recognition methods, data does not need to be filtered beforehand because the squared error approach does that by itself. Even though filtering would yield smaller total squared error, it does not affect the estimates ofsaccade_startandsaccade_end. However, if the noise in the data is nonstationary, some special noise filtering methods might be needed.As thegreatest disadvantage, thesaccademodelalgorithm is suitable only for offline analysis and therefore cannot be used in realtime setups.1. InstallWithpip:$ pip install saccademodel2. UsageThe data structurepointlistis used thoroughly. It is a list of points, where each point is a list [x, y].The usage is simple:>>> import saccademodel
>>> rawdata = [
    [130.012, 404.231],
    [129.234, 403.478],
    [None, None],
    [133.983, 450.044],
    ...
]
>>> results = saccademodel.fit(rawdata)
>>> print(results)
{
    'source_points': [[344.682, 200.115], ...],
    'saccade_points': [[324.233, 202.393], ...],
    'target_points': [[556.423, 112.607], ...],
    'mean_squared_error': 0.000166802
}Note that the lengths of the returned lists can be used to determine saccadic reaction time and duration. For example, given the points from the appearance of stimulus, the saccadic reaction time is captured in the length ofsource_pointsand the saccade duration insaccade_points. If the frame rate is known, you can convert the lengths to seconds by:>>> framerate = 300.0  # samples per second
>>> saccadic_reaction_time = len(results.source_points) / framerate
>>> saccade_duration = len(results.saccade_points) / framerate3. API3.1. saccademodel.fit(gazepointlist)Parameter:gazepointlist: a list of [x, y] points i.e. a list of lists.Return dict with following keys:source_points: the points before the saccadesaccade_points: the points in the saccadetarget_points: the points after the saccade.mean_squared_error: the average squared error from the model for a point.3.2. saccademodel.versionThe current version string:>>> saccademodel.version
'1.2.3'4. For developers4.1. VirtualenvUse virtualenv:$ virtualenv -p python3.5 saccademodel-py
$ cd saccademodel-py
$ source bin/activate
...
$ deactivate4.2. Jupyter NotebookUsage:$ cd explore
$ jupyter notebookInstall requirements:$ pip install --editable .[notebook]4.3. TestingFollowinstructions to install pyenvand then either run quick tests:$ python3.5 setup.py testor comprehensive tests for multiple Python versions intox.ini:$ pyenv local 2.6.9 2.7.10 3.1.5 3.2.6 3.3.6 3.4.3 3.5.0
$ eval "$(pyenv init -)"
$ pyenv rehash
$ toxInstall new pyenv environments by:$ pyenv install 3.4.5Validate README.rst athttp://rst.ninjs.org/4.4. Publishing to PyPIFollowpython packaging instructions:Create an unpacked sdist:$ python setup.py sdistCreate a universal wheel:$ python setup.py bdist_wheel--universalGo toPyPI and register the project by filling the package formby uploadingsaccademodel.egg-info/PKG_INFOfile.Upload the package with twine:Sign the dist:$ gpg--detach-sign-adist/saccademodel-1.2.3*Upload:twine uploaddist/saccademodel-1.2.3*(will ask your PyPI password)Package published!Updating the package takes same steps except the 3rd.5. VersioningSemantic Versioning 2.0.06. LicenseMIT License