Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
driving-simulation/wayPoint_functions.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
62 lines (48 sloc)
2.86 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
# Waypoint fixation implementation | |
def convert_time_increment_to_index(time_increment,simulation_resolution): | |
possible_time_increments = np.asarray(np.arange(simulation_resolution,1,simulation_resolution) ) | |
desired_timestep_idx = np.abs(possible_time_increments - time_increment).argmin() | |
return(possible_time_increments,desired_timestep_idx) | |
# Static version that doesn't modify main loop | |
def waypoint_fixation(velocity, time_duration, center_x_array, center_y_array): | |
resolution = int(velocity * time_duration) | |
# You're only grabbing every _th element, depending on the resolution (e.g. if v= 13.8, time_dur = .1s; then res = 1.38) | |
percevied_x_array = center_x_array[::resolution] | |
percevied_y_array = center_y_array[::resolution] | |
# Add last point on center x and y so it doesn't too pre-maturely | |
last_x = center_x_array[-1] | |
last_y = center_y_array[-1] | |
waypoint_x = np.append(percevied_x_array,last_x) | |
waypoint_y = np.append(percevied_y_array,last_y) | |
return(waypoint_x,waypoint_y) | |
def set_update_frequency_of_farpoint(desired_time_increment, resolution_of_loop): | |
update_every_nth_loop = int(round(desired_time_increment/resolution_of_loop)) | |
return(update_every_nth_loop) | |
def specify_array_of_frames_for_wayPoint(update_every_nth_loop,number_of_frames): | |
array_of_all_frames = np.arange(0,number_of_frames,1) | |
frame_array = array_of_all_frames[::update_every_nth_loop] | |
return(frame_array) | |
def specify_array_of_frames_for_delta_alpha(frame_array): | |
frame_array_for_delta_alpha = [] | |
for i in range(0,len(frame_array)): | |
current_frame = frame_array[i] | |
current_frame_plus_1 = current_frame + 1 | |
frame_array_for_delta_alpha.append(current_frame) | |
#frame_array_for_delta_alpha.append(current_frame_plus_1) | |
return(frame_array_for_delta_alpha) | |
# time_duration = 0.1 # humans make saccades every 200ms typically | |
# perceived_x_center, perceived_y_center = replicate_Kountouriotis_et_al_2016.waypoint_fixation(velocity, time_duration, center_X, center_Y) | |
def wayPoint_mode(choice,simulation_resolution,number_of_frames,*time_increment): | |
if choice == "yes": | |
int1,int2 = time_increment | |
wayPoint_time_increment = int1 | |
elif choice == "no": | |
wayPoint_time_increment = simulation_resolution | |
possible_time_increments,selected_increment_idx = convert_time_increment_to_index(wayPoint_time_increment,simulation_resolution) | |
update_every_nth_loop = set_update_frequency_of_farpoint(possible_time_increments[selected_increment_idx],simulation_resolution) | |
waypoint_frame_array = specify_array_of_frames_for_wayPoint(update_every_nth_loop,number_of_frames) | |
delta_alpha_array = specify_array_of_frames_for_delta_alpha(waypoint_frame_array) | |
waypoint_set = set(waypoint_frame_array) | |
delta_alpha_set = set(delta_alpha_array) | |
return(waypoint_set,delta_alpha_set) | |