Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@willpatera
Last active September 18, 2018 18:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save willpatera/6bfff3ed05904741bfec to your computer and use it in GitHub Desktop.
Save willpatera/6bfff3ed05904741bfec to your computer and use it in GitHub Desktop.
Read `pupil_data` pickle file and export as `.csv` file
# coding=utf-8
import pickle
import numpy as np
import sys
# open the pickled file
# replace with your path to pupil_data
if sys.version_info >= (3, 0):
pupil_data = pickle.load(open("/Users/wrp/recordings/2016_01_28/001/pupil_data","rb"),encoding='latin1')
else:
pupil_data = pickle.load(open("/Users/wrp/recordings/2016_01_28/001/pupil_data","rb"))
# pupil_data will be unpickled as a dictionary with three main keys
#'pupil_positions', 'gaze_positions', 'notifications'
# here we are interested in pupil_positions
pupil_positions = pupil_data['pupil_positions']
# uncomment the below line to see what keys are in a pupil_positions list item
# pupil_positions[0].keys()
# to export pupil diameter in millimeters to a .csv file with timestamps frame numbers and timestamps
# as correlated columns you can do the following:
header = ['timestamp','diameter','confidence','diameter_3D','modelConfidence']
header_str = ','.join(header)
filtered_pupil_positions = []
for i in pupil_positions:
filtered_pupil_positions.append([i[v] for v in header])
np.savetxt("/Users/wrp/Desktop/pupil_data.csv",filtered_pupil_positions,delimiter=",",header=header_str,comments="")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment