Skip to main content

Eyetracking data tools based on pandas

Project description

cili

Cili is meant to reduce the overhead of basic eyetracking data processing. While it sets the stage for more advanced work by providing data in the form of pandas DataFrames, manipulating the contents of those DataFrames works like manipulating any other pandas DataFrame, so that’s where cili stops - we leave it to the user to learn to work with pandas. If you’re going to be dealing with eyetracking data in python, you’ll be glad you did.

At the moment, we support EyeLink data only. We’d be happy to support other manufacturers, but don’t have the data on hand to do so. If you have the data, and would like us to support something in particular, please drop us a message at https://github.com/beOn/cili/issues, or add it yourself and submit a pull request.

Please note that this is an alpha release.

Installation

Before installing cili, you’ll need to install numpy. The rest of the dependencies should install when you install cili, but numpy is special. Then you can install cili using pip or easy_install:

pip install numpy
pip install cili

Or grab the latest development version from https://github.com/beOn/cili, and install using setup.py.

Examples

Smoothing Data

If you look closely at EyeLink data, you’ll probably notice a little high frequency noise. This can be a little problematic in several circumstances. To deal with it, cili provides a butterworth filter function with default settings based on previously published pupillometry studies. You can modify the order and cutoff frequency of the filter if you like, but the basic usage looks like this:

samps = butterworth_series(samps, fields=["pup_l"])

FMI, check out the documentation on butterworth_series.

Events from a List of Dicts

Sometimes you are interested in events recorded using something other than EyeLink software. For those crazy times, if you can turn that data into a list of dicts, each containing a name, onset and duration, then it’s pretty easy to create a cili Events object. Assuming you already have your list of dicts, and that it’s called list_o_dicts, then all you do is:

from cili.models import Events
events = Events.from_list_of_dicts(list_o_dicts)

Extracting Event-based Ranges

To my mind, this is where things start to get interesting. In many eye tracking and pupillometry studies, the goal is to examine a collection of sample ranges surrounding certain events. So cili provides a method for extracting sample ranges based on event timing, returning a DataFrame with a MultiIndex (event #, sample #).

Suppose you were interested in the 10 seconds following every event in some Events object, called “events,” and you have a 1kHz Samples object, samps. To extract this range for every event in events, you would:

from cili.extract import extract_event_ranges
ranges = extract_event_ranges(samps, events, end_offset=10000)

Often, pupillometric sample ranges will be transformed into a % deviation from baseline measure, where the baseline is an average of some small range immediately preceding the range of interest. Continuing the example above, let’s extract baseline measures for each of the events, then divide the ranges of interest by the baselines for the field “pup_r”:

baselines = extract_event_ranges(samps, events, start_offset=-100, end_offset=-1).mean(level=0)
ranges.pup_r = (ranges.pup_r / baselines.pup_r - 1).values

Not so painful! For more info on range extraction, check out the documentation on extract_event_ranges. To work with the returned data effectively, You’ll probably also want to take a minute to learn about pandas MultiIndex objects.

Borrowing Event Attributes

If your events each have a field, let’s say “subject”, and you’d like to insert each event’s value for that field into every row of the corrisponding range under a column of the same name, you can “borrow” event attributes using borrow_attributes, like so:

ranges = extract_event_ranges(samps, events, end_offset=10000, borrow_attributes=["subject"])

Saving and Loading

If you keep reading and writing large .txt files, you’ll die young. Or at least having spent too much of your time waiting for .txt files to be read or written. So cili uses hdf5 to speed things up. To use this, you’ll need to install h5py and its dependencies, as documented at http://docs.h5py.org/en/latest/build.html.

Once that’s done, saving and loading Samples and Events objects is pretty easy. It works the same way in both cases, so we’ll just work with samples below:

from cili.models import Samples
samps.save("some_filename.hdf")
samps_2 = Samples.load_saved("some_filename.hdf")

Exporting to .txt

If you have to export samples or extracted ranges to a .txt file, fine. Ok. We understand.

Luckily, pandas datasets already include a function for writing csv files, any several other formats as well (check their documentation for the complete list: http://pandas.pydata.org/pandas-docs/stable/io.html). For example, to create a tab delimited .txt file:

samps.to_csv("some_filename.txt", sep="\t")

To create a Zamboni delimited .txt file, just set sep to “Zamboni”.

Checking For Signal Dropout

Sometimes, for one reason or another, eyetracking sessions can go pretty poorly. Usually, this means that there’s a high level of signal dropout due to blinks, or the tracker losing track of the eye. One way to check for this is to see what percentage of the timeline’s pupil value(s) were recorded as 0. Cili’s util.py offers a convenient way to check the dropout rate for all of the .asc files in a directory, like so:

util.py --dropout -d /path/to/dir/containing/ascf_iles/

Reporting Bugs, Requesting Features

Submit all bug reports and feature requests using the github ticketing system: https://github.com/beOn/cili/issues

Please make an effort to provide high quality bug reports. If we get one that just says, “sample range extraction is broken,” we’ll probably trash it without a second look, because the submitter is probably the kind of person who saps energy from everything they touch.

A good bug report should include three things:

  1. Steps to reproduce the bug

  2. Expected result

  3. Actual result

The goal is to give the developers the ability to recreate the bug before their own eyes. If you can give us that, we’ll take a very close look.

Why Cili?

Because, like the mighty ciliary muscles, it brings your eye data into focus.

TODO: Thanks, credit to CCP Lab

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cili-0.5.3.tar.gz (15.7 kB view details)

Uploaded Source

Built Distributions

cili-0.5.3-py2.7.egg (32.5 kB view details)

Uploaded Source

cili-0.5.3-py2-none-any.whl (22.0 kB view details)

Uploaded Python 2

File details

Details for the file cili-0.5.3.tar.gz.

File metadata

  • Download URL: cili-0.5.3.tar.gz
  • Upload date:
  • Size: 15.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for cili-0.5.3.tar.gz
Algorithm Hash digest
SHA256 0c5d0a7e809416ecd1efee47f1a62416cfc8b57a0e96f127f6be51136a4550d5
MD5 a7145f63c2bc4a0baf4eb3d8b7c0e58d
BLAKE2b-256 5bc3c256867b66e996c973df1217b823356b85b0e8ecdd0d0f9f31f7e3a596b1

See more details on using hashes here.

File details

Details for the file cili-0.5.3-py2.7.egg.

File metadata

  • Download URL: cili-0.5.3-py2.7.egg
  • Upload date:
  • Size: 32.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for cili-0.5.3-py2.7.egg
Algorithm Hash digest
SHA256 1e8e101aeb7ed35ce595ff87f26c40f19be5eb8ef5613b21e82821143b545c1f
MD5 d2c44c351978aae8667c00e0d819831a
BLAKE2b-256 403c763cb72d8c6492b0a55863397bc18de1edeeae6bf345b4a7593a33de674d

See more details on using hashes here.

File details

Details for the file cili-0.5.3-py2-none-any.whl.

File metadata

File hashes

Hashes for cili-0.5.3-py2-none-any.whl
Algorithm Hash digest
SHA256 b92fecb865fe5da0d0fd10cab7f29068459392d712c5b721f7b9297a8369e9a3
MD5 4f055d96ea9c3bdbf1a30c7162fd10ef
BLAKE2b-256 cf8b95a72358093f73c247f4b62724295a99eb8a385fd95aa24de2467b29251c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page