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
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
u_dict = dict(zip(*u_id)) # DEFINE CONSTANTS H0 = 100 #km/s/Mpc # PRINT HALO FILE INFO for i in range(len(u_id[0])): x = (u_id[0][i] == data[opts.columns[0] - 1]) id = data[opts.columns[0] - 1, x][0] central = data[opts.columns[2] - 1, x][0] ra = np.median(np.array(data[opts.columns[3] - 1, x], dtype = 'f')) min_ra = np.min(np.array(data[opts.columns[3] - 1, x], dtype = 'f')) max_ra = np.max(np.array(data[opts.columns[3] - 1, x], dtype = 'f')) dec = np.median(np.array(data[opts.columns[4] - 1, x], dtype = 'f')) min_dec = np.min(np.array(data[opts.columns[4] - 1, x], dtype = 'f')) max_dec = np.max(np.array(data[opts.columns[4] - 1, x], dtype = 'f')) z = np.median(np.array(data[opts.columns[5] - 1, x], dtype = 'f')) rich = u_dict[id] mass = np.array(data[opts.columns[1] - 1, x][0], dtype = 'float') r200_val = r200(mass, H0, 0.0, *const.BASE) #Mpc da = cosmo2.d_angdi(z, *const.BASE) * cosmo2.d_H(H0) #Mpc r200_val_arcmin = astro.rad2deg(r200_val / da) * 60.0 #arcmin if rich >= opts.mem_limit: print id, central, ra, dec, z, rich, mass, r200_val_arcmin, min_ra, max_ra, min_dec, max_dec
u_dict = dict(zip(*u_id)) # DEFINE CONSTANTS H0 = 100 #km/s/Mpc # PRINT HALO FILE INFO for i in range(len(u_id[0])): x = (u_id[0][i] == data[opts.columns[0] - 1]) id = data[opts.columns[0] - 1, x][0] central = data[opts.columns[2] - 1, x][0] ra = np.median(np.array(data[opts.columns[3] - 1, x], dtype='f')) min_ra = np.min(np.array(data[opts.columns[3] - 1, x], dtype='f')) max_ra = np.max(np.array(data[opts.columns[3] - 1, x], dtype='f')) dec = np.median(np.array(data[opts.columns[4] - 1, x], dtype='f')) min_dec = np.min(np.array(data[opts.columns[4] - 1, x], dtype='f')) max_dec = np.max(np.array(data[opts.columns[4] - 1, x], dtype='f')) z = np.median(np.array(data[opts.columns[5] - 1, x], dtype='f')) rich = u_dict[id] mass = np.array(data[opts.columns[1] - 1, x][0], dtype='float') r200_val = r200(mass, H0, 0.0, *const.BASE) #Mpc da = cosmo2.d_angdi(z, *const.BASE) * cosmo2.d_H(H0) #Mpc r200_val_arcmin = astro.rad2deg(r200_val / da) * 60.0 #arcmin if rich >= opts.mem_limit: print id, central, ra, dec, z, rich, mass, r200_val_arcmin, min_ra, max_ra, min_dec, max_dec