-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathextractSwingStancePhases.py
98 lines (82 loc) · 4.46 KB
/
extractSwingStancePhases.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
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 pickle
import os
import pdb
import matplotlib.pyplot as plt
import numpy as np
import h5py
import scipy.stats as stats
mouseD = '210214_m15' # id of the mouse to analyze
expDateD = 'all910' # specific date e.g. '180214', 'some' for manual selection or 'all'
recordingsD='all910' # 'all or 'some'
DLCinstance = 'DLC_resnet_50_2021Jun_PawExtraction_m15Jun16shuffle3_200000'
readDataAgain = True
# in case mouse, and date were specified as input arguments
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 expDateD == 'all910' or expDateD == 'all820':
pickleFileName = eSD.analysisLocation + '/allSingStanceDataPerSession_%s.p' % (expDate)
#########################################################
# Get paws coordinates
if os.path.isfile(pickleFileName) and not readDataAgain:
recordingsM = pickle.load( open( pickleFileName, 'rb' ) )
else:
recordingsM = []
for f in range(len(foldersRecordings)):
# loop over all recordings in that folder
tracks = []
pawTracks = []
rungMotion = []
swingPhases = []
for r in range(len(foldersRecordings[f][2])):
# read rotary encoder data for wheel speed
(rotaryExistence, rotFileHandle) = eSD.checkIfDeviceWasRecorded(foldersRecordings[f][0],foldersRecordings[f][1],foldersRecordings[f][2][r],'RotaryEncoder')
if rotaryExistence:
(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]])
# read paw data
(camExistence, camFileHandle) = eSD.checkIfDeviceWasRecorded(foldersRecordings[f][0], foldersRecordings[f][1], foldersRecordings[f][2][r], 'CameraGigEBehavior')
if camExistence:
(rawPawPositionsFromDLC, pawTrackingOutliers, jointNamesFramesInfo, pawSpeed, recStartTime,rawPawSpeed,pawPos,croppingParameters) = eSD.readPawTrackingData(foldersRecordings[f][0], foldersRecordings[f][2][r], DLCinstance)
pawTracks.append([rawPawPositionsFromDLC, pawTrackingOutliers, jointNamesFramesInfo, pawSpeed, recStartTime, pawPos, croppingParameters])
rungPositions = eSD.getRungMotionData(mouse,foldersRecordings[f][0],foldersRecordings[f][2][r])
rungMotion.append([mouse,foldersRecordings[f][0],foldersRecordings[f][2][r],rungPositions])
if rotaryExistence and camExistence:
(swingP,forFit) = dataAnalysis.findStancePhases(tracks[-1],pawTracks[-1],rungMotion[-1],showFigFit=False,showFigPaw=False)
#pdb.set_trace()
print(len(swingP[0][1]),len(swingP[1][1]),len(swingP[2][1]),len(swingP[3][1]))
swingPhases.append([mouse,foldersRecordings[f][0],foldersRecordings[f][2][r],swingP,forFit])
recordingsM.append([foldersRecordings[f][0],tracks,pawTracks,rungMotion,swingPhases])
#pdb.set_trace()
pickle.dump(recordingsM, open(pickleFileName, 'wb')) # eSD.analysisLocation,
cV.createSwingStanceFigure(recordingsM,expDate)
#cV.createSwingTraceFigure(recordingsM,linear=False)
#cV.createSwingTraceFigure(recordingsM,linear=True)
cV.createSwingSpeedProfileFigure(recordingsM,expDate,linear=False)
cV.createRungCrossingFigure(recordingsM,expDate)