return gaze limit_seconds1 = [0, +2.5] epoch_length1 = limit_seconds1[1] - limit_seconds1[0] common.Number.frames1 = int(epoch_length1 * common.FS.eye) gaze = np.empty([ common.Number.frames1, common.Number.axes, common.Number.trials, common.Number.players, common.Number.sessions ]) gaze[:] = np.nan for SESSION in np.array(range(0, 20)): common.print_stars() print(SESSION) if SESSION == 1: print('missing eye data...') continue for PLAYER in range(0, common.Number.players): SUBJECT = PLAYER + SESSION * 2 print(SUBJECT) filename = '..\\eye_tracking\\preprocess_eye_data2\\' + common.Labels.session[ SESSION] + '.' + common.Labels.player[ PLAYER] + ".processedEye.mat" print(filename)
def export_endpoints_and_trajectories(): results_mat = scipy.io.loadmat( "..\\behavioural_performance\\endpoint_accuracy\\results.mat") curvature_mat = scipy.io.loadmat( "..\\behavioural_performance\\curvature_runner\\collated_curvature_results.mat" ) collated_curvature_results = curvature_mat[ 'collated_curvature_results'] # (960, 3, 20) # print(collated_curvature_results.shape) def get_endpoints_and_trajectories(SESSION, verbose=False): session = np.repeat(SESSION + 1, common.Number.trials) # (960,) trial = np.array((range(1, common.Number.trials + 1))) # (960,) control = results_mat['results'][SESSION]['control'][0].flatten( ) # (960,) control = np.array(control, dtype=object) control[control == 1] = common.Labels.control[0] control[control == 2] = common.Labels.control[1] target_position = results_mat['results'][SESSION]['target_position'][ 0].flatten() # (960,) endpoint = results_mat['results'][SESSION]['endpoint'][ 0] # (2, 960, 3) endpoint_displacement = results_mat['results'][SESSION][ 'endpoint_displacement'][0] # (960, 3) trajectory = results_mat['results'][SESSION]['trajectory'][ 0] # (2, 1008, 960, 3) # sort by best performer on endpoint displacement for TRIAL in range(1, common.Number.trials): index = np.argsort(endpoint_displacement[TRIAL, 0:2]) if verbose: print(endpoint_displacement[TRIAL, 0:2]) print(index) endpoint_displacement[TRIAL, 0:2] = endpoint_displacement[TRIAL, index] endpoint[:, TRIAL, 0:2] = endpoint[:, TRIAL, index] endpoint_HP_solo_x = endpoint[0, :, 0] endpoint_HP_solo_y = endpoint[1, :, 0] endpoint_LP_solo_x = endpoint[0, :, 1] endpoint_LP_solo_y = endpoint[1, :, 1] endpoint_Joint_x = endpoint[0, :, 2] endpoint_Joint_y = endpoint[1, :, 2] columns = [ 'session', 'trial', 'control', 'target_position', 'endpoint_HP_solo_x', 'endpoint_HP_solo_y', 'endpoint_LP_solo_x', 'endpoint_LP_solo_y', 'endpoint_Joint_x', 'endpoint_Joint_y' ] data = np.transpose( np.array([ session, trial, control, target_position, endpoint_HP_solo_x, endpoint_HP_solo_y, endpoint_LP_solo_x, endpoint_LP_solo_y, endpoint_Joint_x, endpoint_Joint_y ])) df_endpoint = pd.DataFrame(data, columns=columns) curvature = collated_curvature_results[:, :, SESSION] if SESSION == 20: curvature[705:common.Number. trials] = np.nan # controller disconnected # sort by best performer on trajectory displacement for TRIAL in range(1, common.Number.trials): index = np.argsort(curvature[TRIAL, 0:2]) curvature[TRIAL, 0:2] = curvature[TRIAL, index] trajectory[:, :, TRIAL, 0:2] = trajectory[:, :, TRIAL, index] trajectory_HP_solo_x = trajectory[0, :, :, 0].flatten('K') # (2, 1008, 960, 3) trajectory_HP_solo_y = trajectory[1, :, :, 0].flatten('K') # (2, 1008, 960, 3) trajectory_LP_solo_x = trajectory[0, :, :, 1].flatten('K') # (2, 1008, 960, 3) trajectory_LP_solo_y = trajectory[1, :, :, 1].flatten('K') # (2, 1008, 960, 3) trajectory_Joint_x = trajectory[0, :, :, 2].flatten('K') # (2, 1008, 960, 3) trajectory_Joint_y = trajectory[1, :, :, 2].flatten('K') # (2, 1008, 960, 3) session = np.repeat(SESSION + 1, common.Number.frames * common.Number.trials) # (967680,) trial = np.repeat(np.array((range(1, common.Number.trials + 1))), common.Number.frames) # (967680,) frame = np.resize(range(1, common.Number.frames + 1), common.Number.frames * common.Number.trials) # (967680,) control = np.repeat( results_mat['results'][SESSION]['control'][0].flatten(), common.Number.frames) # (967680,) control = np.array(control, dtype=object) control[control == 1] = common.Labels.control[0] control[control == 2] = common.Labels.control[1] target_position = np.repeat( results_mat['results'][SESSION]['target_position'][0].flatten(), common.Number.frames) # (967680,) columns = [ 'session', 'trial', 'control', 'target_position', 'frame', 'trajectory_HP_solo_x', 'trajectory_HP_solo_y', 'trajectory_LP_solo_x', 'trajectory_LP_solo_y', 'trajectory_Joint_x', 'trajectory_Joint_y' ] data = np.transpose( np.array([ session, trial, control, target_position, frame, trajectory_HP_solo_x, trajectory_HP_solo_y, trajectory_LP_solo_x, trajectory_LP_solo_y, trajectory_Joint_x, trajectory_Joint_y ])) df_trajectory = pd.DataFrame(data, columns=columns) if verbose: print(control.shape) print(target_position.shape) print(endpoint.shape) print(endpoint_displacement.shape) print(trajectory.shape) print(session.shape) print(trial.shape) print(data.shape) print(curvature.shape) return df_endpoint, df_trajectory df_endpoint_list = [] df_trajectory_list = [] for SESSION in range(0, common.Number.sessions): common.print_stars() print(SESSION) df_endpoint, df_trajectory = get_endpoints_and_trajectories( SESSION, False) df_endpoint_list.append(df_endpoint) df_trajectory_list.append(df_trajectory) df_endpoint = pd.concat(df_endpoint_list) df_trajectory = pd.concat(df_trajectory_list) df_endpoint.to_csv(output_directory + 'Fig. 3c.csv') df_trajectory.to_csv(output_directory + 'Fig. 3a.csv') ## plot endpoints endpoint_plot(df_endpoint) ## plot trajectories trajectory_plot(df_trajectory)