-
Notifications
You must be signed in to change notification settings - Fork 1
/
plotRecordingOverviewPerAnimal.py
93 lines (73 loc) · 4.16 KB
/
plotRecordingOverviewPerAnimal.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
from oauth2client import tools
tools.argparser.add_argument("-m","--mouse", help="specify name of the mouse", required=False)
tools.argparser.add_argument("-d","--date", help="specify name of the mouse", required=False)
tools.argparser.add_argument("-r","--recs", help="specify index of the specify recording on that day", required=False)
args = tools.argparser.parse_args()
import tools.extractSaveData as extractSaveData
import tools.dataAnalysis as dataAnalysis
import tools.createVisualizations as createVisualizations
import pdb, pickle, os
###########################################
#mouseD = '190101_f15' # id of the mouse to analyze
mouseD = '210214_m15'
expDateD = 'all910' # specific date e.g. '180214', 'some' for manual selection or 'all'
recordingsD ='all910' # 'all or 'some'
readDataAgain = True
wheelCircumsphere = 80.65 # in cm
###########################################
if args.mouse == None:
mouse = mouseD
else:
mouse = args.mouse
if args.date == None:
try:
expDate = expDateD
except :
expDate = 'all'
else:
expDate = args.date
if args.recs == None:
try:
recordings = recordingsD
except :
recordings = 'all'
else:
recordings = args.recs
eSD = extractSaveData.extractSaveData(mouse)
(foldersRecordings,dataFolder) = eSD.getRecordingsList(expDate=expDate,recordings=recordings) # get recordings for specific mouse and date
cV = createVisualizations.createVisualizations(eSD.figureLocation,mouse)
if os.path.isfile(eSD.analysisLocation + '/allDataPerSession.p') and not readDataAgain:
pass
allDataPerSession = pickle.load( open( eSD.analysisLocation + '/allDataPerSession.p', 'rb' ) )
else:
allDataPerSession = []
for f in range(len(foldersRecordings)):
tracks = []
frames = []
caImaging = []
for r in range(len(foldersRecordings[f][2])): # loop over all trials
# check for rotary encoder
(rotaryExistence, rotFileHandle) = eSD.checkIfDeviceWasRecorded(foldersRecordings[f][0],foldersRecordings[f][1],foldersRecordings[f][2][r],'RotaryEncoder')
if rotaryExistence: #angularSpeed,linearSpeed,wTimes,startTime,monitor
(angluarSpeed,linearSpeed,sTimes,timeStamp,monitor,angleTimes) = eSD.getWalkingActivity([foldersRecordings[f][0],foldersRecordings[f][2][r],'walking_activity'])
tracks.append([angluarSpeed,linearSpeed,sTimes,timeStamp,monitor,angleTimes,foldersRecordings[f][0],foldersRecordings[f][1],foldersRecordings[f][2][r]])
# check for video recording during trial
(camExistence, camFileHandle) = eSD.checkIfDeviceWasRecorded(foldersRecordings[f][0], foldersRecordings[f][1], foldersRecordings[f][2][r], 'CameraGigEBehavior')
if camExistence:
(idxTimePoints, startEndExposureTime, startEndExposurepIdx, videoIdx, frameSummary, startTime) = eSD.readBehaviorVideoTimeData([foldersRecordings[f][0], foldersRecordings[f][2][r], 'behaviorVideo'])
firstLastRecordedFrame = eSD.getBehaviorVideoFrames([foldersRecordings[f][0], foldersRecordings[f][2][r],'behaviorVideoFirstLastFrames'])
#pdb.set_trace()
frames.append([firstLastRecordedFrame, startEndExposureTime, startTime])
# check for ca-imaging data during entire session
(caImgExistence, tiffList,recLocation) = eSD.checkIfDeviceWasRecorded(foldersRecordings[f][0], foldersRecordings[f][1], foldersRecordings[f][2][0], 'SICaImaging')
if caImgExistence:
(nframes,meanImg,meanImgE,scanZoomFactor,timeStamps) = eSD.getAnalyzedCaImagingData(eSD.analysisLocation+foldersRecordings[f][0],tiffList)
caImaging.append([nframes,meanImg,meanImgE,scanZoomFactor,timeStamps])
# combine all recordings from a session
if (not tracks) and (not frames) and (not caImaging):
pass
else:
allDataPerSession.append([foldersRecordings[f][0],tracks,frames,caImaging])
pickle.dump( allDataPerSession, open( eSD.analysisLocation + '/allDataPerSession.p', 'wb' ) ) #eSD.analysisLocation,
# generate overview figure for animal
cV.generateOverviewFigure(mouse,allDataPerSession,wheelCircumsphere)