def get_randomized_speed_profiles(sessions): avgSpeeds_allsess = [] trialTypes_allsess = [] # Select Session for s in sessions: # Load trials rawtrials = trajectories.genfromtxt(s) validtrials = trajectories.heightfilter(rawtrials,430,590) [plt.plot(t[:,0],t[:,1],'k',alpha=0.1) for t in validtrials.tolist()] plt.gca().invert_yaxis() numTrials = validtrials.slices.shape[0] print numTrials # There is some misalignment for sessions on the last 4 animals..there session 0 is other session 1 # if a >= 10: # s = s-1 # Look at all Trajectories traj = validtrials preprocess.make_videoanalysis(os.path.join(s,'Analysis')) vtimepath = os.path.join(s, 'Analysis/videotime.csv') vtime = np.genfromtxt(vtimepath) trajtrials = trials.gettrialindices(s) stepstate = trials.gettrialstate(os.path.join(s,'step3_trials.csv'),trajtrials) #print str.format('a:s {0}:{1} {2} {3}', a, s, numTrials, len(validtrials.slices)) # Set Valid Trials (No exploration or tracking errors) crossings = traj # Set Binning and Range avgSpeeds = np.zeros((numTrials, numBins)) trialTypes = np.zeros((numTrials, 1)) for t in range(0,numTrials): #label_indices = np.array(pt.get_labeled_indices(labels,labelFilters[l])) #c = crossings[t] # Load X Trajectories and flip all of 'Left' trialX = crossings.data[crossings.slices[t],0] if trialX[0] > trialX[-1]: # ALign on 2 important rails (the center of rail 3 is 550) # and the centr of rail 4 is 737, therefore, the first encounter # is at 550 going "right", and when flipped, (1280-737 = 543) # going "left"...therefore, to correct for the shift, I subteact 1273 # and align the left and right trials trialX = np.abs(trialX-1273) # Load Y Trajectories trialY = crossings.data[crossings.slices[t],1] # Load and Parse Times trialT = vtime[crossings.slices[t]] # Measure Progression Speed diffX = np.diff(trialX) diffT = np.diff(trialT) # Time interval in seconds speedX = np.concatenate((np.zeros(1) , diffX/diffT)) # Find enter/exit and crop trials # indR = np.where(trialX > 1200) # indL = np.where(trialX < 150) # if (np.size(indR) > 0) and (np.size(indL) > 0): # exitInd = indR[0][0]+1 # enterInd = indL[0][-1] # # trialX = trialX[enterInd:exitInd] # trialY = trialY[enterInd:exitInd] # speedX = speedX[enterInd:exitInd] # Bin (progrssion - X) Speed Profiles (from position 200 to 1200) for b in range(0,numBins): bins = np.where((trialX >= (200+(b*binSize))) & (trialX < (200+(b*binSize)+binSize))) if np.size(bins) > 0: avgSpeeds[t, b] = np.mean(speedX[bins]) else: avgSpeeds[t, b] = np.NaN # Correct for starting speed - - first Third of assay baseSpeed = stats.nanmean(avgSpeeds[t, 0:14]) avgSpeeds[t,:] = avgSpeeds[t,:]/baseSpeed # Get Lables if stepstate[crossings.slices[t].start]: trialTypes[t] = 0 else: trialTypes[t] = 1 # Pool All Average Speeds/TrialTypes Across Sessions avgSpeeds_allsess.append(avgSpeeds) trialTypes_allsess.append(trialTypes) avgSpeeds = np.concatenate(avgSpeeds_allsess) trialTypes = np.concatenate(trialTypes_allsess) return avgSpeeds,trialTypes
""" import os import trials import preprocess import trajectories import numpy as np import matplotlib.pyplot as plt # Load trajectories path = r'D:/Protocols/Behavior/Shuttling/LightDarkServoStable/Data/JPAK_20/2013_04_04-11_40' path = r'D:/Protocols/Behavior/Shuttling/LightDarkServoStable/Data/JPAK_21/2013_04_04-12_14' path = r'D:/Protocols/Behavior/Shuttling/LightDarkServoStable/Data/JPAK_21/2013_04_16-11_35' path = r'D:/Protocols/Behavior/Shuttling/LightDarkServoStable/Data/JPAK_23/2013_04_23-14_49' #path = r'D:/Random/Data/JPAK_21/2013_04_16-11_35' preprocess.make_videoanalysis(os.path.join(path, 'Analysis')) traj = trajectories.genfromtxt(path) traj = trajectories.scale(traj) # Plot trajectories #p = [plt.plot(t[:,0],t[:,1]) for t in traj.tolist()] # Load video time vtimepath = os.path.join(path, 'Analysis/videotime.csv') vtime = np.genfromtxt(vtimepath) # Filter trajectories by height ftraj = trajectories.heightfilter(traj, 0, 5) print ftraj.slices.shape # Filter trajectories by step activity
""" import os import trials import preprocess import trajectories import numpy as np import matplotlib.pyplot as plt # Load trajectories path = r'D:/Protocols/Behavior/Shuttling/LightDarkServoStable/Data/JPAK_20/2013_04_04-11_40' path = r'D:/Protocols/Behavior/Shuttling/LightDarkServoStable/Data/JPAK_21/2013_04_04-12_14' path = r'D:/Protocols/Behavior/Shuttling/LightDarkServoStable/Data/JPAK_21/2013_04_16-11_35' path = r'D:/Protocols/Behavior/Shuttling/LightDarkServoStable/Data/JPAK_23/2013_04_23-14_49' #path = r'D:/Random/Data/JPAK_21/2013_04_16-11_35' preprocess.make_videoanalysis(os.path.join(path,'Analysis')) traj = trajectories.genfromtxt(path) traj = trajectories.scale(traj) # Plot trajectories #p = [plt.plot(t[:,0],t[:,1]) for t in traj.tolist()] # Load video time vtimepath = os.path.join(path, 'Analysis/videotime.csv') vtime = np.genfromtxt(vtimepath) # Filter trajectories by height ftraj = trajectories.heightfilter(traj,0,5) print ftraj.slices.shape # Filter trajectories by step activity