def get_angle_of_saccade(trajec, sac_range, method='integral', smoothed=True): if method != 'integral': f0 = sac_range[0] f1 = sac_range[-1] obj_ori_0 = trajec.velocities[f0] / np.linalg.norm(trajec.velocities[f0]) obj_ori_1 = trajec.velocities[f1] / np.linalg.norm(trajec.velocities[f1]) obj_ori_0_3vec = np.hstack( ( obj_ori_0, 0) ) obj_ori_1_3vec = np.hstack( (obj_ori_1, 0 ) ) sign_of_angle_of_saccade = np.sign( np.sum(np.cross( obj_ori_0, obj_ori_1 ) ) ) cosangleofsaccade = np.dot(obj_ori_0, obj_ori_1) angleofsaccade = np.arccos(cosangleofsaccade) signed_angleofsaccade = -1*angleofsaccade*sign_of_angle_of_saccade return floris_math.fix_angular_rollover(signed_angleofsaccade) else: if smoothed is False: return floris_math.fix_angular_rollover(np.sum(trajec.heading_smooth_diff[sac_range]/100.)*-1) else: return floris_math.fix_angular_rollover(np.sum( floris_math.diffa(trajec.heading)[sac_range])*-1)
def get_frame_at_distance(trajec, distance, singleframe=True, frames=None): if frames is None: frames = np.arange(0, trajec.frame_nearest_to_post).tolist() dist_to_post = trajec.xy_distance_to_post[frames] #print trajec.key, 'frames: ', frames try: dist_crossovers = np.where( floris_math.diffa(np.sign(dist_to_post - distance)) != 0 )[0] except: #print 'could not find dist_crossovers!' return None if len(dist_crossovers) > 0: if singleframe: return dist_crossovers[-1]+frames[0] else: return dist_crossovers+frames[0] else: return None