def filt_density(f_name, fr_area, x_mr, y_mr, mag_mr, cent_rad, vor_flag, area_frac_range, dens_frac, mean_filt_area): ''' Apply density filter. ''' save_to_log(f_name, 'Obtaining groups densities', 'a') tot_sols = len(cent_rad) milestones = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100] # Frame's density. fr_dens_area = len(x_mr) / fr_area # Obtain integrated magnitude for each defined circle. dens_accp_groups, dens_rej_groups = [], [] for c_x, c_y, r in cent_rad: # Count stars within this circle, using stars that passed the # magnitude filter. clust_mags, N = [], 0 for i, (x, y) in enumerate(zip(*[x_mr, y_mr])): if in_radius(c_x, c_y, r, x, y): # This is used later on in the I/A filter function. clust_mags.append(mag_mr[i]) N += 1 # Obtain density for this cluster, normalized to 1. for the frame's # density. clust_dens = (float(N) / (np.pi * (r ** 2))) / fr_dens_area # If the overdensity has a density larger than a given fraction of # the frame's density, keep (j=0). Else, discard (j=1). if clust_dens > dens_frac: dens_accp_groups.append([c_x, c_y, r, clust_dens, clust_mags]) else: dens_rej_groups.append([c_x, c_y, r, clust_dens, clust_mags]) # Print percentage done. milestones = print_perc(i, tot_sols, milestones) # If the center coords and radii were read from file, obtain the min and # max fraction of mean Voronoi area for these clusters. if vor_flag != 'voronoi': all_fracs = [] # Obtain, for each accepted cluster, its area/N divided by the mean # Voronoi area value. for g in dens_accp_groups: cl_dens = (1. / fr_dens_area) * (1. / g[3]) all_fracs.append(cl_dens / mean_filt_area) area_frac_range = [min(all_fracs), max(all_fracs)] save_to_log(f_name, 'Obtained area range: [{:.2f}, {:.2f}]'.format( *area_frac_range), 'a') return dens_accp_groups, dens_rej_groups, area_frac_range
def get_cent_rad(f_name, coords_flag, cr_file_cols, m_m_n, vor_flag, ra_cent, dec_cent, acp_pts, acp_mags, pts_area, pts_vert, mean_filt_area, area_frac_range): ''' Assign a center and a radius for each overdensity/group identified. Use an automatic algorithm based on a Voronoi diagram and grouping neighbor stars, or a file with center coordinates and radii already stored. ''' if vor_flag == 'voronoi': # Apply maximum area filter. pts_area_thres, mag_area_thres, vert_area_thres = area_filter( acp_pts, acp_mags, pts_area, pts_vert, mean_filt_area, area_frac_range) save_to_log(f_name, "\nStars filtered by area range: {}".format( len(pts_area_thres)), 'a') save_to_log(f_name, 'Detect shared vertex', 'a') all_groups = shared_vertex(vert_area_thres) # This is a costly process. save_to_log(f_name, 'Assign points to groups', 'a') neighbors, neig_mags = group_stars(pts_area_thres, mag_area_thres, vert_area_thres, all_groups) save_to_log(f_name, 'Groups found: {}'.format(len(neighbors)), 'a') # Keep only those groups with a higher number of members than # min_neighbors. pts_neighbors, mags_neighbors = neighbors_filter(neighbors, neig_mags, m_m_n) save_to_log(f_name, '\nGroups filtered by number of members: {}'.format( len(pts_neighbors)), 'a') # Check if at least one group was defined with the minimum # required number of neighbors. if pts_neighbors: # Obtain center and radius for each overdensity identified. cent_rad = [] for g in pts_neighbors: pts = np.array(zip(*g)) mean_pts = np.mean(pts, 0) # Translate towards origin pts -= mean_pts result = make_circle(pts) # Move back to correct position. c_r = (result[0] + mean_pts[0], result[1] + mean_pts[1], result[2]) cent_rad.append([c_r[0], c_r[1], c_r[2]]) else: cent_rad = [] save_to_log(f_name, "No groups found with members in range {}". format(m_m_n), 'a') else: # Get data from file. cent_rad = get_cents_rad_file(coords_flag, vor_flag, cr_file_cols, ra_cent, dec_cent) pts_area_thres, mag_area_thres = [[0., 0.], [0., 0.]], [0.] pts_neighbors, mags_neighbors = [[[0.], [0.]]], [0] return cent_rad, pts_area_thres, mag_area_thres, pts_neighbors,\ mags_neighbors