示例#1
0
def group_stars(pts_thres, mag_thres, vert_thres, all_groups):
    '''
    For each defined group, find the points that correspond to it.
    '''

    tot_sols = element_count(all_groups, pts_thres)
    milestones, c = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100], 0

    neighbors = [[] for _ in range(len(all_groups))]
    neig_mags = [[] for _ in range(len(all_groups))]
    # For each group defined.
    for i, g in enumerate(all_groups):
        # For each point in each group.
        for vert_pt in g:
            # For each point above threshold.
            for j, p in enumerate(pts_thres):
                c += 1
                verts = vert_thres[j]
                if verts == vert_pt:
                    neighbors[i].append(p)
                    neig_mags[i].append(mag_thres[j])

                # Print percentage done.
                milestones = print_perc(c, tot_sols, milestones)

    return neighbors, neig_mags
示例#2
0
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
示例#3
0
def consolidate(sets):
    # http://rosettacode.org/wiki/Set_consolidation#Python:_Iterative
    setlist = [s for s in sets if s]

    tot_sols = len(setlist)
    milestones = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]

    for i, s1 in enumerate(setlist):
        if s1:
            for s2 in setlist[i+1:]:
                intersection = s1.intersection(s2)
                if intersection:
                    s2.update(s1)
                    s1.clear()
                    s1 = s2

        # Print percentage done.
        milestones = print_perc(i, tot_sols, milestones)

    return [s for s in setlist if s]