def get_avrg_alignment_v(input_posi_list, angle_size, count_edge=3): """ :param overlap_range: if False, no overlap beam regions :param input_posi_list: col from display dataframe, list like str :param angle_size: beam size that use to scan the whole displays :return: number of beams that contained 1-6 discs """ # convert the str to list input_posi_list = str_to_list(input_posi_list) # get the polar coordinate of all positions polar_posis = get_polar_coordinates(input_posi_list) # the initial start edge ini_start_angle = polar_posis[0][0] # the end edge ini_end_angle = ini_start_angle + angle_size # get result ranges ranges_overlap = get_angle_range(polar_posis, ini_start_angle=ini_start_angle, ini_end_angle=ini_end_angle) align_v_list = list() for i in range(0, len(ranges_overlap)): ranges = get_angle_range_no_overlap(ranges_overlap, start_n=i) # for each region, calculate the number of discs ndisc_list = list() for beam in ranges: ndisc = count_ndisc_in_range(polar_posis, beam[0], beam[1]) ndisc_list.append(ndisc) # count the occurrence count_beams = Counter(ndisc_list) count_beams_output = counter2list(count_beams) align_v = cal_alignment_value(count_beams_output, count_edge=count_edge) align_v_list.append(align_v) alignment_v = statistics.mean(align_v_list) return alignment_v
def get_start_angle(posilist: List[Tuple[float]]): # get sorted polar posi c_polar_sort = get_polar_coordinates(posilist, sort=True) # get ranges with beam size of 6 deg my_range_overlap = get_angle_range(c_polar_sort, ini_start_angle=c_polar_sort[0][0], ini_end_angle=c_polar_sort[0][0] + 6) my_range = get_angle_range_no_overlap(my_range_overlap, start_n=0) # start theta takes the first value of each range theta_list = [range[0] for range in my_range] # degree to radians theta_list = [math.radians(theta) for theta in theta_list] # align start line to the center of the discs theta_list = [theta + math.radians(6) / 2 for theta in theta_list] return theta_list
def get_beam_n(input_posi_list, angle_size): # convert the str to list input_posi_list = str_to_list(input_posi_list) # get the polar coordinate of all positions polar_posis = get_polar_coordinates(input_posi_list) # the initial start edge ini_start_angle = polar_posis[0][0] # the end edge ini_end_angle = ini_start_angle + angle_size # get result ranges ranges_overlap = get_angle_range(polar_posis, ini_start_angle=ini_start_angle, ini_end_angle=ini_end_angle) ndisc_list = list() for beams in ranges_overlap: n_disc = count_ndisc_in_range(polar_posis, beams[0], beams[1]) ndisc_list.append(n_disc) count_beams = Counter(ndisc_list) count_beams_output = counter2list(count_beams) return count_beams_output
if __name__ == '__main__': # TODO crowding demo or no-crowding demo crowding = 1 savefig = True # input positions if crowding == 1: posis = SamplePosiExp1.exp1_c elif crowding == 0: posis = SamplePosiExp1.exp1_nc # get start angle to draw start_thetas = get_start_angle(posis) # plot starts here fig, ax = plt.subplots(subplot_kw={'projection': 'polar'}, figsize=(4, 3)) # ini discs plot in polar coordinates for polar_posi in get_polar_coordinates(posis, sort=True): ax.plot(math.radians(polar_posi[0]), polar_posi[1], "ko", markersize=2) # beams # data: how long the blue beam region data = np.full((len(start_thetas), ), 500) # where each beam starts theta = np.array(start_thetas) # size of the beam = 6 deg width = np.full((len(start_thetas), ), math.radians(6)) # plot ax.bar(theta, data, alpha=0.5, width=width) # set plot parameter ax.set_rlim(0, 500) ax.grid(False) ax.set_yticklabels([]) ax.set_frame_on(False)
# handles, labels = axes[1].get_legend_handles_labels() # labels = ["no-crowding", "crowding"] for i, ax in enumerate(axes): # if i == 1: # ax.legend(handles[:], labels, loc = "best") ax.get_legend().remove() plt.show() # fig.savefig("try.svg") # %% individual display alignment value if indi_display: display_n = 99 # 0-249 posis_str = stimuli_df.positions_list[display_n] posis = str_to_list(posis_str) # get polar positions for a single display polar_posis = get_polar_coordinates(posis) # some parameters, started and ended where ini_start_angle = polar_posis[0][0] angle_size = 6 ini_end_angle = ini_start_angle + angle_size # get the ranges my_range_overlap = get_angle_range(polar_posis, ini_start_angle = ini_start_angle, ini_end_angle = ini_end_angle) align_v_list = list() n_beamlist = list() for i in range(0, len(my_range_overlap)): # get different ranges starting from each disc my_range = get_angle_range_no_overlap(my_range_overlap, start_n = i) # get number of discs in each range ndisc_list = list() for beam in my_range:
def __get_count_list(curr_positions: list) -> list: curr_positions_list = process_str.str_to_list(curr_positions) polar = polar_point.get_polar_coordinates(curr_positions_list, int = True) count_list = count_point.get_point_count_list(polar) return count_list