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, filter_variables={}, extract_variables=[])
-
Import an ASC file produced from an EyeLink device. By default, this will import all trials in the ASC file, where a trial is defined as all fixations (EFIX lines) that occur within a START–END block. Optionally, the importer can try to filter only those trials that match certain user-defined variables. For example, if the filter_variables argument is set to:
{"trial_type":"test", "passage_id":["A", "B", "C"]}
the importer will only extract trials where "trial_type" is set to "test" and "passage_id" is set to either "A", "B", or "C". Variables are somewhat loosely defined as some string that occurs in a MSG line; anything that follows this string is its value. For example, if a trial in your ASC file contained these messages:
MSG 4244101 !V TRIAL_VAR trial_type test MSG 4244101 !V TRIAL_VAR passage_id A
then this trial would be extracted. The extract_variables argument can be used to extract further variables without any filtering. This could be used, for example, to extract trial or stimulus IDs that were written to the data stream as messages. If unsure, you should first inspect your ASC file to see what messages you wrote to the data stream.
The importer will return something like this:
{ "imported_from" : "my_asc_file.asc", "trials" : [ { "trial_type" : "test", "passage_id" : "A", "fixations" : FixationSequence[...] }, { "trial_type" : "test", "passage_id" : "B", "fixations" : FixationSequence[...] } ] }