Module eyekit.io
Functions for reading and writing data.
Functions
def read(file_path)
-
Read in a JSON file.
FixationSequence
andTextBlock
objects are automatically decoded and instantiated. def write(data, file_path, compress=False)
-
Write arbitrary data to a JSON file. If
compress
isTrue
, the file is written in the most compact way; ifFalse
, the file will be larger but more human-readable.FixationSequence
andTextBlock
objects are automatically serialized. def import_asc(file_path, variables=[], placement_of_variables='after_end')
-
Import data from an ASC file produced from an SR Research EyeLink device (you will first need to use SR Research's Edf2asc tool to convert your original EDF files to ASC). The importer will extract all trials from the ASC file, where a trial is defined as a sequence of fixations (EFIX lines) that occur inside a START–END block. Optionally, the importer can extract user-defined variables from the ASC file and associate them with the appropriate trial. For example, if your ASC file contains messages like this:
MSG 4244101 !V TRIAL_VAR trial_type practice MSG 4244101 !V TRIAL_VAR passage_id 1
then you could extract the variables
"trial_type"
and"passage_id"
. A variable is some string that is followed by a space; anything that follows this space is the variable's value. By default, the importer looks for variables that follow the END tag. However, if your variables are placed before the START tag, then set theplacement_of_variables
argument to"before_start"
. If unsure, you should first inspect your ASC file to see what messages you wrote to the data stream and where they are placed. The importer will return a list of dictionaries, where each dictionary represents a single trial, for example:[ { "trial_type" : "practice", "passage_id" : "1", "fixations" : FixationSequence[...] }, { "trial_type" : "test", "passage_id" : "2", "fixations" : FixationSequence[...] } ]
def import_csv(file_path, x_header='x', y_header='y', duration_header='duration', trial_header=None)
-
Import data from a CSV file (requires Pandas to be installed). By default, the importer expects the CSV file to contain the column headers,
x
,y
, andduration
, but this can be customized by setting the relevant arguments. Each row of the CSV file is expected to represent a single fixation. If your CSV file contains data from multiple trials, you should also specify the column header of a trial identifier, so that the data can be segmented into trials. The importer will return a list of dictionaries, where each dictionary represents a single trial, for example:[ { "trial_id" : 1, "fixations" : FixationSequence[...] }, { "trial_id" : 2, "fixations" : FixationSequence[...] } ]