def biweight_Rg(ra, dec, v, d): N = len(ra) dist_inverse = [] for i in range(0,N-1): for j in range(i+1,N): distij = angle(ra[i], dec[i], ra[j], dec[j]) if distij !=0 : dist_inverse.append( distij) dist_inverse = np.asarray(dist_inverse) n = len(dist_inverse) if n!=0: Med=np.median(dist_inverse) Rh_1 = Med for p in range(0,10): Rh_1 = st.biweight_location(dist_inverse, M=Med) Med = Rh_1 #Rg_radian = N*N/(n*st.biweight_location(dist_inverse)) #Rg_radian = N*N/dist_inverse.sum() Rg_radian = Rh_1#2*N*Rh_1/(N-1) #print dist_inverse #print N, ' ' ,st.biweight_location(dist_inverse), ' ', dist_inverse.sum()/n else: Rg_radian = float('nan') if d == 0 : d = v / H0 return d * Rg_radian
Bi_Weight = True if Bi_Weight: i = 0 while i < len(flag): if flag[i] == 2: j = i v_galaxies = [] gl_galaxies = [] gb_galaxies = [] i+=1 while flag[i] == 1: v_galaxies.append(Vls[i]) gl_galaxies.append(gl[i]) gb_galaxies.append(gb[i]) i+=1 mean = st.biweight_location(v_galaxies) # bi-weight mean radial velocity sigma = st.biweight_midvariance(v_galaxies) # bi-weight radial velocity Dispersion if isnan(mean): mean = Vls[j] if not isnan(sigma): sigmaP_dyn[j] = sigma Rg_bi = biweight_Rg(gl_galaxies, gb_galaxies, mean, mDist[j]) #if not isnan(Rg_bi): R2t_dyn[j] = Rg_bi * (pi*0.5/1.05/sqrt(1.5)) i-=1 i+=1 ################################################################# N = len(flag) filter = np.zeros((N,), dtype=np.int) f1 = np.zeros((N,), dtype=np.int) f1[np.where(Vls<100)] = 1 f2 = np.zeros((N,), dtype=np.int)
def groupWrite(outfile, G_list, galList): NoGroups = len(G_list) myTable = Table() empty = [] myTable.add_column(Column(data=empty, name='ID', dtype=np.dtype(int))) myTable.add_column(Column(data=empty, name='grpID', dtype=np.dtype(int))) myTable.add_column(Column(data=empty, name='flag', dtype=np.dtype(int))) myTable.add_column(Column(data=empty, name='ra', format='%0.4f')) myTable.add_column( Column(data=empty, name='dec', format='%0.4f', length=10)) myTable.add_column(Column(data=empty, name='MagK', format='%0.2f')) myTable.add_column(Column(data=empty, name='Ks', format='%0.2f')) myTable.add_column(Column(data=empty, name='logK', format='%0.4f')) myTable.add_column(Column(data=empty, name='Vls', format='%0.0f')) myTable.add_column(Column(data=empty, name='dist', format='%0.2f')) myTable.add_column(Column(data=empty, name='mDist', format='%0.2f')) myTable.add_column(Column(data=empty, name='R_theta', format='%0.5f')) myTable.add_column(Column(data=empty, name='sigmaP_dyn', format='%0.1f')) myTable.add_column(Column(data=empty, name='sigmaP_lum', format='%0.1f')) myTable.add_column(Column(data=empty, name='Mv_dyn', format='%1.2e')) myTable.add_column(Column(data=empty, name='Mv_lum', format='%1.2e')) myTable.add_column(Column(data=empty, name='Rg_angular', format='%0.3f')) myTable.add_column(Column(data=empty, name='Rg_dyn', format='%0.3f')) myTable.add_column(Column(data=empty, name='R2t_dyn', format='%0.3f')) myTable.add_column(Column(data=empty, name='R2t_lum', format='%0.3f')) myTable.add_column(Column(data=empty, name='r2t_lum', format='%0.3f')) myTable.add_column(Column(data=empty, name='tX_dyn', format='%1.2e')) myTable.add_column(Column(data=empty, name='tX_lum', format='%1.2e')) myTable.add_column( Column(data=empty, name='No_Galaxies', dtype=np.dtype(int))) myTable.add_column(Column(data=empty, name='nest', dtype=np.dtype(int))) #print "# of all groups: ", NoGroups for i in range(0, NoGroups): # for all groups if G_list[i][0].Vls <= 3500: dist = G_list[i][0].mDist if dist == 0: dist = G_list[i][0].Vls / H0 if dist < 1: dist = 1 Rg = dist * Rg_radian(G_list[i][1:]) # old version Rg_angular = dist * G_list[i][0].R_theta ra_lst = [] dec_lst = [] v_galaxies = [] for gal in G_list[i][1:]: ra_lst.append(gal.ra) dec_lst.append(gal.dec) v_galaxies.append(gal.Vls) mean = st.biweight_location(v_galaxies) Rg_bi = biweight_Rg(ra_lst, dec_lst, mean, dist) Rg = Rg_bi # bi-weight version #print 'Whisle ...:', pgc, dist , Rg_bi, Rg G_list[i][0].sigma = st.biweight_midvariance(v_galaxies) for j in range(0, len(G_list[i])): # for all galaxies galaxy = G_list[i][j] flag = galaxy.flag ID = galaxy.id grp_id = galaxy.grp_id ra = galaxy.ra dec = galaxy.dec Vls = galaxy.Vls logK = galaxy.logK Ks = galaxy.Ks dist = galaxy.dist mDist = galaxy.mDist if flag == 2: distance = mDist else: distance = dist if distance == 0: distance = Vls / H0 MagK = galaxy.Ks - 5 * log10(distance) - 30 + 5 subGalaxies = G_list[i][0].subGalaxies R_theta = G_list[i][0].R_theta sigmaP_dyn = G_list[i][0].sigma nest = G_list[i][0].nest Mv_lum = galaxy.M_v2 R2t_lum = galaxy.R_2t2 r2t_lum = galaxy.r2t sigmaP_lum = (Mv_lum / (2.0E6))**(1. / 3) tX_lum = Mpc_km * R2t_lum * 1.05 * sqrt( 1.5) / sigmaP_lum / sqrt(2.5) if j != 0: Rg = 0 # dynamical virial radius R_theta = 0 Rg_angular = 0 Mv_dyn = (1.E9 * (2.5 * pi / G / 2.) * (Mpc_km * Rg) * sigmaP_dyn**2) / M_sun # solar mass if sigmaP_dyn == 0: tX_dyn = 0 else: tX_dyn = Mpc_km * 0.5 * pi * Rg / sigmaP_dyn / sqrt(2.5) R2t_dyn = (Rg * pi * 0.5) / 1.05 / sqrt(1.5) myTable.add_row([ID,grp_id,flag,ra,dec,MagK,Ks,logK,Vls, dist, \ mDist, R_theta, sigmaP_dyn, sigmaP_lum, \ Mv_dyn, Mv_lum, Rg_angular, Rg, R2t_dyn, R2t_lum, r2t_lum, tX_dyn, tX_lum, subGalaxies, nest]) # writing individual galaxies for galaxy in galList: if galaxy.inGroup <= 0. and galaxy.Vls <= 3500: flag = galaxy.inGroup galaxy.flag = flag ID = galaxy.id grp_id = galaxy.grp_id ra = galaxy.ra dec = galaxy.dec Vls = galaxy.Vls logK = galaxy.logK Ks = galaxy.Ks dist = galaxy.dist if dist == 0: distance = 0.00001 else: distance = dist MagK = galaxy.Ks - 5 * log10(distance) - 30 + 5 mDist = galaxy.mDist subGalaxies = galaxy.subGalaxies R_theta = galaxy.R_theta sigmaP_dyn = galaxy.sigma nest = galaxy.nest Mv_lum = galaxy.M_v2 R2t_lum = galaxy.R_2t2 sigmaP_lum = (Mv_lum / (2.0E6))**(1. / 3) tX_lum = Mpc_km * R2t_lum * 1.05 * sqrt(1.5) / sigmaP_lum / sqrt( 2.5) Rg = 0 # dynamical virial radius Mv_dyn = 0 # solar mass tX_dyn = 0 R2t_dyn = 0 Rg_angular = 0 R_theta = 0 myTable.add_row([ID,grp_id,flag,ra,dec,MagK,Ks,logK,Vls, dist, \ mDist, R_theta, sigmaP_dyn, sigmaP_lum, \ Mv_dyn, Mv_lum, Rg_angular, Rg, R2t_dyn, R2t_lum, r2t_lum, tX_dyn, tX_lum, subGalaxies, nest]) ID = 999999999 ra = 999.9999 dec = -99.99 Ks = 99.99 MagK = -99.99 logK = 99.9999 Vls = 9999 dist = 99.99 mDist = 99.99 Mv_dyn = 9.99E99 Mv_lum = Mv_dyn tX_dyn = Mv_lum tX_lum = Mv_lum nest = 9999999 subGalaxies = 9999 myTable.add_row([ID,grp_id,flag,ra,dec,MagK,Ks,logK,Vls, dist, \ mDist, R_theta, sigmaP_dyn, sigmaP_lum, \ Mv_dyn, Mv_lum, Rg_angular, Rg, R2t_dyn, R2t_lum, r2t_lum, tX_dyn, tX_lum, subGalaxies, nest]) myTable.write(outfile, format='ascii.fixed_width', delimiter='|', bookend=False) # removing the last line, (it sits o adjust the column wodths) command = ["csh", "remove_lastline.csh", outfile] subprocess.call(command)