-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocessAssessmentData.py
163 lines (124 loc) · 9.51 KB
/
processAssessmentData.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env python3
# coding: utf-8
# In[1]:
import sys
sys.path.append("pyFiles/")
# sys.path.append("../")
import os
import pandas as pd
import numpy as np
import logging
import pickle
import json
import matplotlib.pyplot as plt
import evaluateSegAlgo as ev
import loadData as ld
fmt = '%(levelname)s_%(name)s-%(funcName)s(): - %(message)s'
logging.basicConfig(level=logging.INFO, format=fmt)
logger = logging.getLogger(__name__)
def calibAssessment(sessionDictIn,saveDir = 'figout/', confidenceThresh = False, title="", show_filtered_out=False, override_to_2d=False):
#if override_to_2d:
# ball_catching = False
# if ('processedExp' in sessionDictIn) and (('ballPos','x') in sessionDictIn):
# ball_catching = True
#else:
# # !!!!! This doesn't use the binocular model -- it averages up the monocular models!
# sessionDictIn = ev.calcCyclopean(sessionDictIn, 'processedCalib')
# try:
# sessionDictIn = ev.calcCyclopean(sessionDictIn, 'processedExp')
# ball_catching = True
# except KeyError:
# ball_catching = False
# sessionDictIn = ev.calcCyclopean(sessionDictIn, 'processedSequence')
sessionDictIn = ev.calcCyclopean(sessionDictIn, 'processedCalib')
try:
sessionDictIn = ev.calcCyclopean(sessionDictIn, 'processedExp')
ball_catching = True
except KeyError:
ball_catching = False
sessionDictIn = ev.calcCyclopean(sessionDictIn, 'processedSequence')
#print(sessionDictIn['processedCalib']['targetPos'])
#print()
#print(sessionDictIn['processedCalib']['targeLocalPos'])
#print(sessionDictIn['processedSequence'].keys())
#print('x:',sessionDictIn['processedSequence']['screen-pos', 'x'])
#print('y:',sessionDictIn['processedSequence']['screen-pos', 'y'])
#print('z:',sessionDictIn['processedSequence']['screen-pos', 'z'])
#exit()
sessionDictIn = ev.calcSphericalCoordinates(sessionDictIn,'targetPos','targetWorldSpherical', sessionDictKey = 'processedCalib')
if ball_catching:
sessionDictIn = ev.calcSphericalCoordinates(sessionDictIn,'ballPos','targetWorldSpherical', sessionDictKey = 'processedExp')
sessionDictIn = ev.calcSphericalCoordinates(sessionDictIn,'targeLocalPos','targetLocalSpherical', sessionDictKey = 'processedCalib')
if ball_catching:
sessionDictIn = ev.calcSphericalCoordinates(sessionDictIn,'ballPos','targetLocalSpherical', sessionDictKey = 'processedExp') # Should be something like ballLocalPos
sessionDictIn = ev.calcSphericalCoordinates(sessionDictIn, 'screen-pos', 'targetLocalSpherical', sessionDictKey = 'processedSequence')
#print(sessionDictIn['processedCalib']['targeLocalPos'])
#print(sessionDictIn['processedSequence'].keys())
#print(sessionDictIn['processedSequence'].loc[0]['screen-pos', 'x'], sessionDictIn['processedSequence'].loc[0]['screen-pos', 'y'], sessionDictIn['processedSequence'].loc[0]['screen-pos', 'z'])
#print("to")
#print(sessionDictIn['processedSequence'].loc[0]['targetLocalSpherical', 'az'], sessionDictIn['processedSequence'].loc[0]['targetLocalSpherical', 'el'])
#print(sessionDictIn['processedSequence'].loc[350]['targetLocalSpherical', 'az'], sessionDictIn['processedSequence'].loc[350]['targetLocalSpherical', 'el'])
#print("vs")
#print(sessionDictIn['processedCalib'].loc[0]['targetLocalSpherical', 'az'], sessionDictIn['processedCalib'].loc[0]['targetLocalSpherical', 'el'])
#exit()
sessionDictIn = ev.calcSphericalCoordinates(sessionDictIn,'gaze-normal0','gaze0Spherical', sessionDictKey = 'processedCalib',flipY=True,override_to_2d=('0' if override_to_2d else None))
if ball_catching:
sessionDictIn = ev.calcSphericalCoordinates(sessionDictIn,'gaze-normal0','gaze0Spherical', sessionDictKey = 'processedExp',flipY=True,override_to_2d=('0' if override_to_2d else None))
sessionDictIn = ev.calcSphericalCoordinates(sessionDictIn,'gaze-normal0','gaze0Spherical', sessionDictKey = 'processedSequence',flipY=True,override_to_2d=('0' if override_to_2d else None))
sessionDictIn = ev.calcSphericalCoordinates(sessionDictIn,'gaze-normal1','gaze1Spherical', sessionDictKey = 'processedCalib',flipY=True,override_to_2d=('1' if override_to_2d else None))
if ball_catching:
sessionDictIn = ev.calcSphericalCoordinates(sessionDictIn,'gaze-normal1','gaze1Spherical', sessionDictKey = 'processedExp',flipY=True,override_to_2d=('1' if override_to_2d else None))
sessionDictIn = ev.calcSphericalCoordinates(sessionDictIn,'gaze-normal1','gaze1Spherical', sessionDictKey = 'processedSequence',flipY=True,override_to_2d=('1' if override_to_2d else None))
sessionDictIn = ev.calcSphericalCoordinates(sessionDictIn,'gaze-normal2','gaze2Spherical', sessionDictKey = 'processedCalib',flipY=True,override_to_2d=('' if override_to_2d else None))
if ball_catching:
sessionDictIn = ev.calcSphericalCoordinates(sessionDictIn,'gaze-normal2','gaze2Spherical', sessionDictKey = 'processedExp',flipY=True,override_to_2d=('' if override_to_2d else None))
sessionDictIn = ev.calcSphericalCoordinates(sessionDictIn,'gaze-normal2','gaze2Spherical', sessionDictKey = 'processedSequence',flipY=True,override_to_2d=('' if override_to_2d else None))
sessionDictIn = ev.calcTrialLevelCalibInfo(sessionDictIn, ball_catching=ball_catching)
sessionDictIn = ev.calcGazeToTargetFixError(sessionDictIn,'gaze0Spherical','targetLocalSpherical','fixError_eye0', sessionDictKey='processedCalib')
#sessionDictIn = ev.calcGazeToTargetFixError(sessionDictIn,'gaze0Spherical','targetLocalSpherical','fixError_eye0', sessionDictKey='processedExp')
sessionDictIn = ev.calcGazeToTargetFixError(sessionDictIn,'gaze1Spherical','targetLocalSpherical','fixError_eye1', sessionDictKey='processedCalib')
#sessionDictIn = ev.calcGazeToTargetFixError(sessionDictIn,'gaze1Spherical','targetLocalSpherical','fixError_eye1', sessionDictKey='processedExp')
sessionDictIn = ev.calcGazeToTargetFixError(sessionDictIn,'gaze2Spherical','targetLocalSpherical','fixError_eye2', sessionDictKey='processedCalib')
#sessionDictIn = ev.calcGazeToTargetFixError(sessionDictIn,'gaze2Spherical','targetLocalSpherical','fixError_eye2', sessionDictKey='processedExp')
sessionDictIn = ev.calcGazeToCalibFixError(sessionDictIn,'gaze0Spherical','targetLocalSpherical','fixError_eye0', sessionDictKey='processedSequence')
sessionDictIn = ev.calcGazeToCalibFixError(sessionDictIn,'gaze1Spherical','targetLocalSpherical','fixError_eye1', sessionDictKey='processedSequence')
sessionDictIn = ev.calcGazeToCalibFixError(sessionDictIn,'gaze2Spherical','targetLocalSpherical','fixError_eye2', sessionDictKey='processedSequence')
# sessionDictIn['trialInfo']['fixTargetSpherical','az'] = sessionDictIn['trialInfo']['fixTargetSpherical','az'].round(2)
# sessionDictIn['trialInfo']['fixTargetSpherical','el'] = sessionDictIn['trialInfo']['fixTargetSpherical','el'].round(2)
sessionDictIn = ev.calcAverageGazeDirPerTrial(sessionDictIn, ball_catching=ball_catching)
sessionDictIn = ev.calcAverageGazeDirPerCalibTrial(sessionDictIn)
sessionDictIn = ev.calcCalibrationSequenceStatistics(sessionDictIn, confidenceThresh)
sessionDictIn = ev.calcFixationStatistics(sessionDictIn, confidenceThresh)
ev.plotCalibrationSequence(sessionDictIn, saveDir, confidenceThresh=confidenceThresh, title=title, show_filtered_out=show_filtered_out)
try:
ev.plotFixAssessment(sessionDictIn, saveDir, confidenceThresh=confidenceThresh, title=title, show_filtered_out=show_filtered_out)
except Exception as e:
print(sessionDictIn.keys())
ev.plotIndividualFix(sessionDictIn, saveDir=saveDir, confidenceThresh=confidenceThresh, title=title)
return sessionDictIn
def processAllData(confidenceThresh=False,doNotLoad = True, saveDir = 'figOut/', targets=[], show_filtered_out=False, load_realtime_ref_data=None, override_to_2d=False):
allSessionData = []
dataFolderList = []
[dataFolderList.append(name) for name in os.listdir("Data/") if ((name[0] is not '.' and (name[0:9] == "_Pipeline")))]
for subNum, subString in enumerate(dataFolderList):
# For each export from pupil labs
#pupilLabsExportFolderList = ld.findPupilLabsExports(subString)
folderDict = ld.getSubjectSubFolders(subNum)
for expNum, exportFolderString in enumerate(folderDict['pupilExportsFolderList']):
if len(targets) == 0 or exportFolderString in targets:
#sessionDict = ld.unpackSession(subNum, exportFolderString, doNotLoad=doNotLoad)
sessionDict = ld.unpackSession(subNum, load_realtime_ref_data, doNotLoad=doNotLoad, specificExport=exportFolderString)
# saveDir = 'figOut/{0}_{1}/{0}_{1}'.format(subString, exportFolderString)
currSaveDir = saveDir+subString+"/"
try:
os.stat(currSaveDir)
except:
os.makedirs(currSaveDir, exist_ok=True)
sessionDict = calibAssessment(sessionDict, saveDir=currSaveDir, confidenceThresh=confidenceThresh, title=subString, show_filtered_out=show_filtered_out, override_to_2d=override_to_2d)
allSessionData.append(sessionDict)
return allSessionData
if __name__ == "__main__":
allSessionData = processAllData(doNotLoad=False,confidenceThresh=0.00)
with open('allSessionData.pickle', 'wb') as handle:
pickle.dump(allSessionData, handle, protocol=pickle.HIGHEST_PROTOCOL)
# makeFixAssessmentFig(0, 40,40,saveDir = 'figOut/', figWidthHeight = 30 )