# Module eyekit.io

Functions for reading and writing data.

## Functions

 def read(file_path) 

Read in a JSON file. FixationSequence and TextBlock objects are automatically decoded and instantiated.

 def write(data, file_path, compress=False) 

Write arbitrary data to a JSON file. If compress is True, the file is written in the most compact way; if False, the file will be more human readable. FixationSequence and TextBlock objects are automatically encoded.

 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 the placement_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 and contains the fixations along with any other extracted variables. 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', start_header='start', end_header='end', trial_header=None) 

Import data from a CSV file. By default, the importer expects the CSV file to contain the column headers, x, y, start, and end, but this can be customized by setting the relevant arguments to whatever column headers your CSV file contains. 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 and contains the fixations along with the trial identifier (if specified). For example:

[
{
"trial_id" : 1,
"fixations" : FixationSequence[...]
},
{
"trial_id" : 2,
"fixations" : FixationSequence[...]
}
]