示例#1
0
def xy_pos(pos, centre, H0=100.0):

    da = cosmo2.d_angdi(centre[2], *const.BASE) * \
      cosmo2.d_H(H0)

    x = da *astro.deg2rad((centre[0] - pos[0]) * \
                           np.cos(astro.deg2rad(pos[1])))
    y = da * astro.deg2rad(pos[1] - centre[1])

    return x, y
示例#2
0
def xy_pos(pos, centre, H0 = 100.0):

    da = cosmo2.d_angdi(centre[2], *const.BASE) * \
      cosmo2.d_H(H0)
      
    x = da *astro.deg2rad((centre[0] - pos[0]) * \
                           np.cos(astro.deg2rad(pos[1])))
    y = da * astro.deg2rad(pos[1] - centre[1])
    
    return x, y
示例#3
0
文件: pyfof.py 项目: EiffL/python_lib
def friends_of_friends(zbin, gals, tree, mode, cluster_count):
    """
    Function that looks for galaxy friends in a given
    redshift bin and returns a list of the resulting
    Cluster instances.
    """
 #loop over galaxies
    cluster_list = []
    for i in range(len(gals)):
        if  mode == 'spec':
            link_zbin = z_bins[gals[i].bin]
        else:
            link_zbin = z_bins[zbin]    
        if bin_check(mode, gal[i], link_zbin):            
            #friends loop
            if gals[i].clt[zbin] == None:
                result = new_kdtree.radius_search(tree, np.array((gals[i].ra, gals[i].dec)),
                                                 astro.rad2deg(link_zbin.rfriend) * 60)
                if len(result) > 0:
                    for loop_element in range(len(result)):
                        j = int(result[loop_element, 1])
                        dist =  astro.deg2rad(result[loop_element, 0] / 60.0)
                        if ((bin_check(mode, gal[j], link_zbin)) & (gals[i].id != gals[j].id) & (gals[j].clt[zbin] == None)):
                            if friendship(link_zbin, gals[i], gals[j], dist, opts.mode):                              
                                if gals[i].clt[zbin] == None:
                                    gals[i].clt[zbin] = len(cluster_list)
                                    gals[j].clt[zbin] = gals[i].clt[zbin]
                                    cluster_list.append(Cluster(cluster_count))
                                    cluster_count += len(cluster_list)
                                    cluster_list[gals[i].clt[zbin]].extend([gals[i].num], [gals[i].id], [gals[i].ra], [gals[i].dec],
                                                                           [gals[i].z], [gals[i].xpos], [gals[i].ypos], [gals[i].zpos])
                                    cluster_list[gals[i].clt[zbin]].extend([gals[j].num], [gals[j].id], [gals[j].ra], [gals[j].dec],
                                                                           [gals[j].z], [gals[j].xpos], [gals[j].ypos], [gals[j].zpos])
                                else:
                                    gals[j].clt[zbin] = gals[i].clt[zbin]
                                    cluster_list[gals[i].clt[zbin]].extend([gals[j].num], [gals[j].id], [gals[j].ra], [gals[j].dec],
                                                                           [gals[j].z], [gals[j].xpos], [gals[j].ypos], [gals[j].zpos])
            #friends-of-friends loop
            if gals[i].clt[zbin] != None:
                clt_now = cluster_list[gals[i].clt[zbin]]
                for k in range(len(clt_now.g_id)):
                    if(gals[i].id != clt_now.g_id[k]):
                        result = new_kdtree.radius_search(tree, np.array((clt_now.g_ra[k], clt_now.g_dec[k])),
                                                         astro.rad2deg(link_zbin.rfriend) * 60)
                        if len(result) > 0:
                            for loop_element in range(len(result)):
                                l = int(result[loop_element, 1])
                                dist =  astro.deg2rad(result[loop_element, 0] / 60.0)
                                if ((bin_check(mode, gal[l], link_zbin)) & (clt_now.g_id[k] != gals[l].id)
                                    & (gals[l].clt[zbin] == None)):
                                    if friendship(link_zbin, gals[clt_now.g_num[k]], gals[l], dist, opts.mode):
                                        gals[l].clt[zbin] = gals[i].clt[zbin]
                                        cluster_list[gals[i].clt[zbin]].extend([gals[l].num], [gals[l].id], [gals[l].ra], [gals[l].dec],
                                                                               [gals[l].z], [gals[l].xpos], [gals[l].ypos], [gals[l].zpos])
    return cluster_list
示例#4
0
def xy_centre(data, centre=None, H0=100.0):

    if not centre:
        centre = (data.ra.median(), data.dec.median(), data.z.median())

    da = cosmo2.d_angdi(centre[2], *const.BASE) * \
      cosmo2.d_H(H0)

    x = da *astro.deg2rad((centre[0] - data.ra) * \
                           np.cos(astro.deg2rad(data.dec)))
    y = da * astro.deg2rad(data.dec - centre[1])
    r = np.sqrt(x**2 + y**2)

    return data.join(pd.DataFrame({'x': x, 'y': y, 'r': r}))
示例#5
0
 def __init__(self, data, number):
     """
     Function that initialises a Galaxy instance.
     """
     self.num = number
     self.id = data[opts.id_col - 1]
     self.ra = float(data[opts.ra_col - 1])
     self.dec = float(data[opts.dec_col - 1])
     self.z = float(data[opts.z_col - 1])
     self.dz = float(data[opts.dz_col - 1])
     self.v = self.z / (1 + self.z)
     self.da = ((opts.c / opts.H0) * cosmo.angdidis(self.z, opts.Omega_M, opts.Omega_L))
     self.x = math.sin(astro.deg2rad(90 - self.dec)) * math.cos(astro.deg2rad(self.ra)) * self.da
     self.y = math.sin(astro.deg2rad(90 - self.dec)) * math.sin(astro.deg2rad(self.ra)) * self.da
     self.photoz_bins = []
示例#6
0
def xy_centre(data, centre = None,  H0 = 100.0):

    if not centre:
        centre = (data.ra.median(), data.dec.median(),
                  data.z.median())

    da = cosmo2.d_angdi(centre[2], *const.BASE) * \
      cosmo2.d_H(H0)
      
    x = da *astro.deg2rad((centre[0] - data.ra) * \
                           np.cos(astro.deg2rad(data.dec)))
    y = da * astro.deg2rad(data.dec - centre[1])
    r = np.sqrt(x ** 2 + y ** 2)
    
    return data.join(pd.DataFrame({'x' : x, 'y' : y, 'r' : r}))
示例#7
0
 def __init__(self, data, number):
     """
     Function that initialises a Galaxy instance.
     """
     self.num = number
     self.id = data[opts.id_col - 1]
     self.ra = float(data[opts.ra_col - 1])
     self.dec = float(data[opts.dec_col - 1])
     self.z = float(data[opts.z_col - 1])
     self.dz = float(data[opts.dz_col - 1])
     self.v = self.z / (1 + self.z)
     self.da = ((opts.c / opts.H0) *
                cosmo.angdidis(self.z, opts.Omega_M, opts.Omega_L))
     self.x = math.sin(astro.deg2rad(90 - self.dec)) * math.cos(
         astro.deg2rad(self.ra)) * self.da
     self.y = math.sin(astro.deg2rad(90 - self.dec)) * math.sin(
         astro.deg2rad(self.ra)) * self.da
     self.photoz_bins = []
示例#8
0
    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)
示例#9
0
    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)
示例#10
0
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
示例#11
0
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
示例#12
0
                             dtype = 'float')
cluster_num = float(sys.argv[3])
sncl = data[8, data[0] == cluster_num]

index = cluster[0] == cluster_num

# cluster properties
racl = np.median(cluster[4, index])
decl = np.median(cluster[5, index])
zcl = np.median(cluster[6, index])
dists = astro.ang_sep([cluster[4, index], cluster[5, index]], [racl,  decl]) * 60.0
area = np.pi * np.mean(dists) ** 2 # arcmin^2

# Mpc per arcmin scale
da = cosmo2.d_angdi(zcl, omega_m, omega_l) * cosmo2.d_H(h0)
mpca = astro.deg2rad(da / 60.0)

# coordinates wrt cluster center
gx = 60. * (racl - cluster[4, index]) * np.cos(astro.deg2rad(cluster[5, index]))
gy = 60. * (cluster[5, index] - decl)   # arcmin      

# adaptive kernel density map
gadk = ss.gaussian_kde(np.vstack([gx * mpca, gy * mpca]), bw_method = 'silverman')

xedges = np.linspace(-0.6, 0.6, 100)
yedges = np.linspace(-1.0, 1.0, 100)
xx, yy = np.meshgrid(xedges, yedges)
gridpoints = np.array([xx.ravel(), yy.ravel()])
zz = np.reshape(gadk(gridpoints), xx.shape)
indices = np.unravel_index(zz.argmax(), zz.shape)
示例#13
0
def friends_of_friends(zbin, gals, tree, mode, cluster_count):
    """
    Function that looks for galaxy friends in a given
    redshift bin and returns a list of the resulting
    Cluster instances.
    """
    #loop over galaxies
    cluster_list = []
    for i in range(len(gals)):
        if mode == 'spec':
            link_zbin = z_bins[gals[i].bin]
        else:
            link_zbin = z_bins[zbin]
        if bin_check(mode, gal[i], link_zbin):
            #friends loop
            if gals[i].clt[zbin] == None:
                result = new_kdtree.radius_search(
                    tree, np.array((gals[i].ra, gals[i].dec)),
                    astro.rad2deg(link_zbin.rfriend) * 60)
                if len(result) > 0:
                    for loop_element in range(len(result)):
                        j = int(result[loop_element, 1])
                        dist = astro.deg2rad(result[loop_element, 0] / 60.0)
                        if ((bin_check(mode, gal[j], link_zbin)) &
                            (gals[i].id != gals[j].id) &
                            (gals[j].clt[zbin] == None)):
                            if friendship(link_zbin, gals[i], gals[j], dist,
                                          opts.mode):
                                if gals[i].clt[zbin] == None:
                                    gals[i].clt[zbin] = len(cluster_list)
                                    gals[j].clt[zbin] = gals[i].clt[zbin]
                                    cluster_list.append(Cluster(cluster_count))
                                    cluster_count += len(cluster_list)
                                    cluster_list[gals[i].clt[zbin]].extend(
                                        [gals[i].num], [gals[i].id],
                                        [gals[i].ra], [gals[i].dec],
                                        [gals[i].z], [gals[i].xpos],
                                        [gals[i].ypos], [gals[i].zpos])
                                    cluster_list[gals[i].clt[zbin]].extend(
                                        [gals[j].num], [gals[j].id],
                                        [gals[j].ra], [gals[j].dec],
                                        [gals[j].z], [gals[j].xpos],
                                        [gals[j].ypos], [gals[j].zpos])
                                else:
                                    gals[j].clt[zbin] = gals[i].clt[zbin]
                                    cluster_list[gals[i].clt[zbin]].extend(
                                        [gals[j].num], [gals[j].id],
                                        [gals[j].ra], [gals[j].dec],
                                        [gals[j].z], [gals[j].xpos],
                                        [gals[j].ypos], [gals[j].zpos])
            #friends-of-friends loop
            if gals[i].clt[zbin] != None:
                clt_now = cluster_list[gals[i].clt[zbin]]
                for k in range(len(clt_now.g_id)):
                    if (gals[i].id != clt_now.g_id[k]):
                        result = new_kdtree.radius_search(
                            tree, np.array(
                                (clt_now.g_ra[k], clt_now.g_dec[k])),
                            astro.rad2deg(link_zbin.rfriend) * 60)
                        if len(result) > 0:
                            for loop_element in range(len(result)):
                                l = int(result[loop_element, 1])
                                dist = astro.deg2rad(result[loop_element, 0] /
                                                     60.0)
                                if ((bin_check(mode, gal[l], link_zbin)) &
                                    (clt_now.g_id[k] != gals[l].id)
                                        & (gals[l].clt[zbin] == None)):
                                    if friendship(link_zbin,
                                                  gals[clt_now.g_num[k]],
                                                  gals[l], dist, opts.mode):
                                        gals[l].clt[zbin] = gals[i].clt[zbin]
                                        cluster_list[gals[i].clt[zbin]].extend(
                                            [gals[l].num], [gals[l].id],
                                            [gals[l].ra], [gals[l].dec],
                                            [gals[l].z], [gals[l].xpos],
                                            [gals[l].ypos], [gals[l].zpos])
    return cluster_list