コード例 #1
0
ファイル: new_kdtree.py プロジェクト: EiffL/python_lib
def radius_search(tree, datapoint, radius):
    """ find all points within radius of datapoint """
    stack = [tree[0]]
    inside = []
    while stack:

        leaf_idx, leaf_data, left_hrect, \
                  right_hrect, left, right = stack.pop()

        # leaf
        if leaf_idx is not None:
            param=leaf_data.shape[0]
            
            #distance = np.sqrt(((leaf_data - datapoint.reshape((param,1)))**2).sum(axis=0))
            distance = astro.projected_distance(leaf_data[0], datapoint[0], leaf_data[1], datapoint[1])

            
            near = np.where(distance<=radius)
            if len(near[0]):
                idx = leaf_idx[near]
                distance = distance[near]
                inside += (zip(distance, idx))

        else:

            if intersect(left_hrect, radius, datapoint):
                stack.append(tree[left])

            if intersect(right_hrect, radius, datapoint):
                stack.append(tree[right])

    return np.array(inside)
コード例 #2
0
ファイル: new_kdtree.py プロジェクト: jodarie/python_lib
def radius_search(tree, datapoint, radius):
    """ find all points within radius of datapoint """
    stack = [tree[0]]
    inside = []
    while stack:

        leaf_idx, leaf_data, left_hrect, \
                  right_hrect, left, right = stack.pop()

        # leaf
        if leaf_idx is not None:
            param = leaf_data.shape[0]

            #distance = np.sqrt(((leaf_data - datapoint.reshape((param,1)))**2).sum(axis=0))
            distance = astro.projected_distance(leaf_data[0], datapoint[0],
                                                leaf_data[1], datapoint[1])

            near = np.where(distance <= radius)
            if len(near[0]):
                idx = leaf_idx[near]
                distance = distance[near]
                inside += (zip(distance, idx))

        else:

            if intersect(left_hrect, radius, datapoint):
                stack.append(tree[left])

            if intersect(right_hrect, radius, datapoint):
                stack.append(tree[right])

    return np.array(inside)
コード例 #3
0
ファイル: kdtree2.py プロジェクト: EiffL/python_lib
    def __init__(self, mem):
        self.mem = np.array(mem)
        self.size = len(self.mem)
        self.ra = np.median(self.mem[:, 0])
        self.dec = np.median(self.mem[:, 1])

        min_ra = min(self.mem[:, 0])
        min_dec = max(self.mem[:, 1])
        
        self.radius = astro.deg2rad(astro.projected_distance(self.ra, min_ra, self.dec, min_dec) / 60.0)
コード例 #4
0
ファイル: kdtree2.py プロジェクト: jodarie/python_lib
    def __init__(self, mem):
        self.mem = np.array(mem)
        self.size = len(self.mem)
        self.ra = np.median(self.mem[:, 0])
        self.dec = np.median(self.mem[:, 1])

        min_ra = min(self.mem[:, 0])
        min_dec = max(self.mem[:, 1])

        self.radius = astro.deg2rad(
            astro.projected_distance(self.ra, min_ra, self.dec, min_dec) /
            60.0)
コード例 #5
0
ファイル: kdtree.py プロジェクト: jodarie/python_lib
        def nn_search(node, query_point, radius, depth, best_neighbours):
            if node == None:
                return

            # if we have reached a leaf, let's add to current best neighbours,
            # (if it's better than the worst one or if there is not enough neighbours)
            if node.is_leaf():
                best_neighbours.add(node.point)
                return

            # this node is no leaf

            # select dimension for comparison (based on current depth)
            axis = depth % 2

            # figure out which subtree to search
            near_subtree = None  # near subtree
            far_subtree = None  # far subtree (perhaps we'll have to traverse it as well)

            # compare query_point and point of current node in selected dimension
            # and figure out which subtree is farther than the other
            if query_point[axis] < node.point[axis]:
                near_subtree = node.left
                far_subtree = node.right
            else:
                near_subtree = node.right
                far_subtree = node.left

            # recursively search through the tree until a leaf is found
            nn_search(near_subtree, query_point, radius, depth + 1,
                      best_neighbours)

            # while unwinding the recursion, check if the current node
            # is closer to query point than the current best,
            # also, until t points have been found, search radius is infinity
            best_neighbours.add(node.point)

            # check whether there could be any points on the other side of the
            # splitting plane that are closer to the query point than the current best
            if astro.projected_distance(node.point[0], query_point[0],
                                        node.point[1],
                                        query_point[1]) <= radius:
                nn_search(far_subtree, query_point, radius, depth + 1,
                          best_neighbours)

            return
コード例 #6
0
ファイル: cluster.old.py プロジェクト: EiffL/python_lib
 def props(self, bg_expect):
     """
     Function that sets Cluster properties.
     """
     self.ra = np.median(self.g_ra)
     self.dec = np.median(self.g_dec)
     self.z = np.median(self.g_z)
     self.ngal = len(self.g_id)
     distances = []
     for i in range(self.ngal):
         distances.extend([astro.projected_distance(self.g_ra[i], self.ra, self.g_dec[i], self.dec)])
     self.size = np.mean(distances)
     self.area = self.size ** 2 * math.pi
     if bg_expect != None:
         self.sn = (self.ngal) / ((self.area * bg_expect) ** 0.5)
     else:
         self.sn = 0.0
コード例 #7
0
ファイル: pyfof.py プロジェクト: hoyleb/fof_cluster_finder
def friendship(zbin, gal1, gal2, mode):
    """
    Function that checks if two galaxies are friends in
    a given redshift bin.
    """
    if mode == 'spec':
        rfriend = zbin.link_r / gal1.da
    else:
        rfriend = zbin.rfriend
    dist =  astro.deg2rad(astro.projected_distance(gal1.ra, gal2.ra, gal1.dec, gal2.dec) / 60.0)
    check1 = (dist < rfriend)    
    if mode == 'spec':
        check2 = (math.fabs(gal1.v - gal2.v) <= zbin.link_z)
        check = (check1 & check2)
    else:
        check = check1
    return check
コード例 #8
0
ファイル: pyfof.py プロジェクト: ShanghuoLi/sfarrens-sfof
def friendship(zbin, gal1, gal2, mode):
    """
    Function that checks if two galaxies are friends in
    a given redshift bin.
    """
    if mode == 'spec':
        rfriend = zbin.link_r / gal1.da
    else:
        rfriend = zbin.rfriend
    dist = astro.deg2rad(
        astro.projected_distance(gal1.ra, gal2.ra, gal1.dec, gal2.dec) / 60.0)
    check1 = (dist < rfriend)
    if mode == 'spec':
        check2 = (math.fabs(gal1.v - gal2.v) <= zbin.link_z)
        check = (check1 & check2)
    else:
        check = check1
    return check
コード例 #9
0
ファイル: kdtree.py プロジェクト: EiffL/python_lib
        def nn_search(node, query_point, radius, depth, best_neighbours):
            if node == None:
                return
                        
            # if we have reached a leaf, let's add to current best neighbours,
            # (if it's better than the worst one or if there is not enough neighbours)
            if node.is_leaf():
                best_neighbours.add(node.point)
                return
            
            # this node is no leaf
            
            # select dimension for comparison (based on current depth)
            axis = depth % 2
            
            # figure out which subtree to search
            near_subtree = None # near subtree
            far_subtree = None # far subtree (perhaps we'll have to traverse it as well)
            
            # compare query_point and point of current node in selected dimension
            # and figure out which subtree is farther than the other
            if query_point[axis] < node.point[axis]:
                near_subtree = node.left
                far_subtree = node.right
            else:
                near_subtree = node.right
                far_subtree = node.left

            # recursively search through the tree until a leaf is found
            nn_search(near_subtree, query_point, radius, depth+1, best_neighbours)

            # while unwinding the recursion, check if the current node
            # is closer to query point than the current best,
            # also, until t points have been found, search radius is infinity
            best_neighbours.add(node.point)
            
            # check whether there could be any points on the other side of the
            # splitting plane that are closer to the query point than the current best
            if astro.projected_distance(node.point[0], query_point[0], node.point[1], query_point[1]) <= radius:
                nn_search(far_subtree, query_point, radius, depth+1, best_neighbours)
    
            return
コード例 #10
0
 def props(self, bg_expect):
     """
     Function that sets Cluster properties.
     """
     self.ra = np.median(self.g_ra)
     self.dec = np.median(self.g_dec)
     self.z = np.median(self.g_z)
     self.ngal = len(self.g_id)
     distances = []
     for i in range(self.ngal):
         distances.extend([
             astro.projected_distance(self.g_ra[i], self.ra, self.g_dec[i],
                                      self.dec)
         ])
     self.size = np.mean(distances)
     self.area = self.size**2 * math.pi
     if bg_expect != None:
         self.sn = (self.ngal) / ((self.area * bg_expect)**0.5)
     else:
         self.sn = 0.0
コード例 #11
0
for i in range(cluster.size):                                           
    c_bin_count[c_rich_bin_index[i], c_z_bin_index[i]] += 1
for i in range(mock.size):
    m_bin_count[m_rich_bin_index[i], m_z_bin_index[i]] += 1
    if m_match_flag[i] == -1:
        #Find clusters that match primary matching conditions.
        index1 = np.where((c_match_flag == -1) &
                          (np.fabs(mock.z[i] - cluster.z) <= (z_factor * opts.delta_z * (1 + mock.z[i]))) &
                        (cluster.ra >= mock.minra[i]) & (cluster.ra <= mock.maxra[i]) &
                        (cluster.dec >= mock.mindec[i]) & (cluster.dec <= mock.maxdec[i]))[0]
        if len(index1) > 0:       
            #Calculate the projected distance to halo centre for these clusters.
            dists = []
            for j in index1:
                dist = astro.projected_distance(mock.ra[i], cluster.ra[j], mock.dec[i], cluster.dec[j])
                dists.extend([dist])
            dists = np.array(dists)
            #Find clusters within r200.            
            index2 = np.where(dists <= mock.r200[i])[0]
            if len(index2) > 0:
                dists = dists[index2]
                index1 = index1[index2]
                #Check if any of these have the same N_gal value.
                index3 = np.where(cluster.rich[index1] == cluster.rich[index1[0]])[0]
                if len(index3) > 0:
                    dists = dists[index3]
                    index1 = index1[index3]
                    #Choose the cluster closest to the halo.
                    index4 = np.argmin(dists)
                    index1 = index1[index4]
コード例 #12
0
ファイル: kdtree.py プロジェクト: jodarie/python_lib
 def add(self, point):
     #angular separation in arcminutes
     ang_sep = astro.projected_distance(point[0], self.query_point[0],
                                        point[1], self.query_point[1])
     if ang_sep <= self.radius:
         self.current_best.append([point[2]])
コード例 #13
0
ファイル: pycymatch_v3.py プロジェクト: jodarie/python_lib
for i in range(mock.size):
    m_bin_count[m_rich_bin_index[i], m_z_bin_index[i]] += 1
    if m_match_flag[i] == -1:
        #Find clusters that match primary matching conditions.
        index1 = np.where((c_match_flag == -1)
                          & (np.fabs(mock.z[i] - cluster.z) <=
                             (z_factor * opts.delta_z *
                              (1 + mock.z[i]))) & (cluster.ra >= mock.minra[i])
                          & (cluster.ra <= mock.maxra[i])
                          & (cluster.dec >= mock.mindec[i])
                          & (cluster.dec <= mock.maxdec[i]))[0]
        if len(index1) > 0:
            #Calculate the projected distance to halo centre for these clusters.
            dists = []
            for j in index1:
                dist = astro.projected_distance(mock.ra[i], cluster.ra[j],
                                                mock.dec[i], cluster.dec[j])
                dists.extend([dist])
            dists = np.array(dists)
            #Find clusters within r200.
            index2 = np.where(dists <= mock.r200[i])[0]
            if len(index2) > 0:
                dists = dists[index2]
                index1 = index1[index2]
                #Check if any of these have the same N_gal value.
                index3 = np.where(
                    cluster.rich[index1] == cluster.rich[index1[0]])[0]
                if len(index3) > 0:
                    dists = dists[index3]
                    index1 = index1[index3]
                    #Choose the cluster closest to the halo.
                    index4 = np.argmin(dists)
コード例 #14
0
ファイル: kdtree.py プロジェクト: EiffL/python_lib
 def add(self, point):
     #angular separation in arcminutes
     ang_sep = astro.projected_distance(point[0], self.query_point[0], point[1], self.query_point[1])
     if ang_sep <= self.radius:
         self.current_best.append([point[2]])