def main(): fclusters = sys.argv[1] fsatellites = sys.argv[2] #print fclusters,fsatellites ra, dec, z, rich, Ms, Izspec = np.loadtxt(fclusters, unpack=True, skiprows=1) xx1, xx2, xx3, xx4, ras, decs, mss, Pmem = np.loadtxt(fsatellites, unpack=True, skiprows=1) for i in range(len(ra)): if rich[i] >= 10.0 and rich[i] < 30000.0 and z[i] >= 0.55 and z[ i] < 1.10: rax = ra[i] decx = dec[i] zx = z[i] dl = cosmos.Da(zx) ix = xx1 == rax iy = Pmem >= 0.8 idx = ix & iy rr1 = ras[idx] rr2 = decs[idx] for j in range(len(xx1[idx])): sep = dl * separation(rax, decx, rr1[j], rr2[j]) * (1.0 + zx) if sep >= 0.1 and sep <= 0.2: print rr1[j], rr2[j], zx, Pmem[j]
def readsource(filename, iredshift): ra,dec,e1,e2,res,wt,m,c1,c2,erms,z1,\ z2,z3,z4,z5,z6=np.loadtxt(filename,unpack=True) if iredshift == 1: zs = z1 if iredshift == 2: zs = z2 if iredshift == 3: zs = z3 if iredshift == 4: zs = z4 if iredshift == 5: zs = z5 if iredshift == 6: zs = z6 dis = np.zeros(len(ra)) for i in range(len(ra)): dis[i] = cosmos.Da(zs[i]) ix = res > 1.0 / 3.0 shapes = {"ra":ra[ix],"dec":dec[ix],"z":zs[ix],\ "dis":dis[ix],"e1":e1,"e2":e2,\ "erms":erms,"res":res,"m":m,"c1":c1,"c2":c2} return shapes
def run_main(): #---------------------------------------------------------------------- SnapID = 135 HaloID = 50 zl = 0.5 zs = 2.0 nnn = 512 dm = il.snapshot.loadHalo(basePath, SnapID, HaloID, 'dm') #npp = dm['count'] x1 = dm['Coordinates'][:, 0] #/1e3/(1.0+zl) # Mpc/h, comoving x2 = dm['Coordinates'][:, 1] #/1e3/(1.0+zl) # Mpc/h, comoving x3 = dm['Coordinates'][:, 2] #/1e3/(1.0+zl) # Mpc/h, comoving ptnl_p = dm['Potential'] idx_ptnl_p_min = ptnl_p == ptnl_p.min() xcp1 = x1[idx_ptnl_p_min] xcp2 = x2[idx_ptnl_p_min] xcp3 = x3[idx_ptnl_p_min] bsz = 50.0 # kpc/h sdens = read_sdens_from_illustris(dm, x1 - xcp1, x2 - xcp2, x3 - xcp3, bsz, nnn) #kappa = sdens/mm.sigma_crit(zl,zs) #---------------------------------------------------------------------- bsz = bsz / 1e3 / mm.Da(zl) * mm.apr #arcsec dsx = bsz / nnn #arcsec xi1, xi2 = make_r_coor(nnn, dsx) ai1, ai2 = pcs.call_cal_alphas0(sdens, nnn, bsz, zl, zs) yi1 = xi1 - ai1 yi2 = xi2 - ai2 phi = pcs.call_cal_phi(sdens, nnn, bsz, zl, zs) mua = pcs.call_alphas_to_mu(ai1, ai2, nnn, dsx) #---------------------------------------------------------------------- ys1 = 0.0 ys2 = 0.0 xroot1, xroot2, nroots = trf.roots_zeros(xi1, xi2, ai1, ai2, ys1, ys2) #pl.figure() #pl.plot(ys1,ys2,'ko') #pl.plot(xroot1,xroot2,'rs') #pl.contour(xi1,xi2,mua) #pl.contour(yi1,yi2,mua) #pl.colorbar() muii = pcs.call_inverse_cic_single(mua, xroot1, xroot2, dsx) phii = pcs.call_inverse_cic_single(phi, xroot1, xroot2, dsx) Kc = (1.0 + zl) / mm.vc * (mm.Da(zl) * mm.Da(zs) / mm.Da2( zl, zs)) * mm.Mpc / (1e3 * mm.dy) / mm.apr / mm.apr td = Kc * (0.5 * ((xroot1 - ys1)**2.0 + (xroot2 - ys2)**2.0) - phii) time_days, mags = np.loadtxt("./SN_opsim.csv", dtype='string', delimiter=',', usecols=(1, 4), unpack=True) time_days = time_days.astype("double") ldays = np.zeros((nroots, len(time_days))) #for i in xrange(nroots): #ldays[i,:] = time_days+td[i] ldays[0, :] = time_days + td[0] ldays[1, :] = time_days + td[1] ldays[2, :] = time_days + td[2] mags = mags.astype("double") lmags = np.zeros((nroots, len(time_days))) #for i in xrange(nroots): #lmags[i,:] = mags-2.5*np.log10(np.abs(muii[i])) lmags[0, :] = mags - 2.5 * np.log10(np.abs(muii[0])) lmags[1, :] = mags - 2.5 * np.log10(np.abs(muii[1])) lmags[2, :] = mags - 2.5 * np.log10(np.abs(muii[2])) cmap = mpl.cm.jet_r #------------------------------------------------------------------------------ #linestyle=linestyle, color=color pl.figure(figsize=(8, 8)) pl.xlabel("Days") pl.ylabel("Mags") pl.ylim(27, 21) #for i in xrange(nroots): #pl.plot(ldays[i,:]-49500+820,lmags[i,:],linestyle='-',color=cmap(i/float(nroots))) pl.plot(ldays[0, :] - 49500 + 820, lmags[0, :], linestyle='-', color="r") pl.plot(ldays[1, :] - 49500 + 820, lmags[1, :], linestyle='-', color="g") pl.plot(ldays[2, :] - 49500 + 820, lmags[2, :], linestyle='-', color="b") pl.figure(figsize=(8, 8)) pl.xlim(-5.0, 5.0) pl.ylim(-5.0, 5.0) pl.xlabel("arcsec") pl.ylabel("arcsec") #for i in xrange(nroots): #pl.plot(xroot1[i],xroot2[i],marker='o',color=cmap(i/float(nroots))) #markersize=10 pl.plot(xroot1[0], xroot2[0], marker='o', color="r", markersize=10) pl.plot(xroot1[1], xroot2[1], marker='o', color="g", markersize=10) pl.plot(xroot1[2], xroot2[2], marker='o', color="b", markersize=10) pl.contour(xi1, xi2, mua, colors=('r', )) pl.contour(yi1, yi2, mua, colors=('g', )) pl.plot(ys1, ys2, 'ks') print td
def re_sv(sv, z1, z2): res = 4.0 * np.pi * (sv**2.0 / mm.vc**2.0) * mm.Da2( z1, z2) / mm.Da(z2) * mm.apr return res
def run_main(): #---------------------------------------------------------------------- SnapID = 135 HaloID = 50 bsz = 200.0 # kpc/h zl = 0.5 zs = 2.0 #zs0= 10.0 nnn = 512 dsi = 0.03 dm = il.snapshot.loadHalo(basePath, SnapID, HaloID, 'dm') #npp = dm['count'] x1 = dm['Coordinates'][:, 0] #/1e3/(1.0+zl) # Mpc/h, comoving x2 = dm['Coordinates'][:, 1] #/1e3/(1.0+zl) # Mpc/h, comoving x3 = dm['Coordinates'][:, 2] #/1e3/(1.0+zl) # Mpc/h, comoving ptnl_p = dm['Potential'] idx_ptnl_p_min = ptnl_p == ptnl_p.min() xcp1 = x1[idx_ptnl_p_min] xcp2 = x2[idx_ptnl_p_min] xcp3 = x3[idx_ptnl_p_min] sdens = read_sdens_from_illustris(dm, x1 - xcp1, x2 - xcp2, x3 - xcp3, bsz, nnn) #kappa = sdens/mm.sigma_crit(zl,zs) #---------------------------------------------------------------------- bsz = bsz / 1e3 / mm.Da(zl) * mm.apr #arcsec dsx = bsz / nnn #arcsec print bsz print dsx xi1, xi2 = make_r_coor(nnn, dsx) ai1, ai2 = pcs.call_cal_alphas0(sdens, nnn, bsz, zl, zs) yi1 = xi1 - ai1 yi2 = xi2 - ai2 phi = pcs.call_cal_phi(sdens, nnn, bsz, zl, zs) mua = pcs.call_alphas_to_mu(ai1, ai2, nnn, dsx) #---------------------------------------------------------------------- ys1 = 0.0 ys2 = 0.0 xroot1, xroot2, nroots = trf.roots_zeros(xi1, xi2, ai1, ai2, ys1, ys2) #pl.figure() #pl.plot(ys1,ys2,'ko') #pl.plot(xroot1,xroot2,'rs') #pl.contour(xi1,xi2,mua) #pl.contour(yi1,yi2,mua) #pl.colorbar() muii = pcs.call_inverse_cic_single(mua, xroot1, xroot2, dsx) phii = pcs.call_inverse_cic_single(phi, xroot1, xroot2, dsx) Kc = (1.0 + zl) / mm.vc * (mm.Da(zl) * mm.Da(zs) / mm.Da2( zl, zs)) * mm.Mpc / (1e3 * mm.dy) / mm.apr / mm.apr td = Kc * (0.5 * ((xroot1 - ys1)**2.0 + (xroot2 - ys2)**2.0) - phii) time_days, mags = np.loadtxt("./SN_opsim.csv", dtype='string', delimiter=',', usecols=(1, 4), unpack=True) time_days = time_days.astype("double") #------------------------------------------------------------------------------ ldays = np.zeros((nroots, len(time_days))) for i in xrange(nroots): ldays[i, :] = time_days + td[i] mags = mags.astype("double") lmags = np.zeros((nroots, len(time_days))) for i in xrange(nroots): lmags[i, :] = mags - 2.5 * np.log10(np.abs(muii[i])) #cmap = mpl.cm.jet_r cmap = mpl.cm.gist_earth pl.figure(figsize=(8, 8)) pl.xlabel("Days") pl.ylabel("Mags") pl.ylim(30, 22) for i in xrange(nroots): pl.plot(ldays[i, :] - 49500 + 31010 - 50, lmags[i, :], linestyle='-', color=cmap(i / float(nroots)), markersize=10) #pl.plot(ldays[0,:]-49500+31010-50,lmags[0,:],linestyle='-',color="k") #pl.plot(ldays[1,:]-49500+31010-50,lmags[1,:],linestyle='-',color="b") #pl.plot(ldays[2,:]-49500+31010-50,lmags[2,:],linestyle='-',color="g") #pl.plot(ldays[3,:]-49500+31010-50,lmags[3,:],linestyle='-',color="m") #pl.plot(ldays[4,:]-49500+31010-50,lmags[4,:],linestyle='-',color="r") pl.figure(figsize=(8, 8)) #pl.xlim(-bsz/2.0,bsz/2.0) #pl.ylim(-bsz/2.0,bsz/2.0) pl.xlim(-10.0, 10.0) pl.ylim(-10.0, 10.0) pl.xlabel("arcsec") pl.ylabel("arcsec") for i in xrange(nroots): pl.plot(xroot1[i], xroot2[i], marker='o', color=cmap(i / float(nroots)), markersize=10) #pl.plot(xroot1[0],xroot2[0],marker='o',color="k",markersize=15) # #pl.plot(xroot1[1],xroot2[1],marker='o',color="b",markersize=15) # #pl.plot(xroot1[2],xroot2[2],marker='o',color="g",markersize=15) # #pl.plot(xroot1[3],xroot2[3],marker='o',color="m",markersize=15) # #pl.plot(xroot1[4],xroot2[4],marker='o',color="r",markersize=15) # pl.contour(xi1, xi2, mua, colors=('r', )) pl.contour(yi1, yi2, mua, colors=('g', )) pl.plot(ys1, ys2, 'cs') print td #------------------------------------------------------------------------------ ysc1 = 0.0 ysc2 = 0.0 g_source = pyfits.getdata( "./dry_run_pipeline/439.0_149.482739_1.889989_processed.fits") g_source = np.array(g_source, dtype="<d") pl.figure() pl.contourf(g_source) pl.colorbar() std_srcs = np.std(g_source) print std_srcs, std_srcs * 4.0 gthhd = 6.0 * std_srcs g_source = g_source - gthhd g_source[g_source <= 0.0] = 0.0 lensed_img = lv4.call_ray_tracing(g_source, yi1, yi2, ysc1, ysc2, dsi) #lensed_img = pcs.call_ray_tracing_single(ai1,ai2,nnn,bsz,zl) lenses_img = slf.loadin_fits(HaloID, zl, bsz, nnn) lroots = 10.0**((lmags - 25.523) / (-2.5)) final_img = lensed_img + lenses_img / 100.0 res = stacking_points_and_galaxies(xroot1, xroot2, lroots[:, 70], final_img, bsz, nnn) pl.figure() pl.contourf(xi1, xi2, res) pl.colorbar() pyfits.writeto("all.fits", res, clobber=True) return res
def run_main(): HaloID = 0 SnapID = 135 bsz = 500.0 # ckpc zl = 0.5 zs0 = 10.0 nnn = 512 dm = il.snapshot.loadHalo(basePath, SnapID, HaloID, 'dm') #npp = dm['count'] x1 = dm['Coordinates'][:, 0] #/1e3/(1.0+zl) # Mpc/h, comoving x2 = dm['Coordinates'][:, 1] #/1e3/(1.0+zl) # Mpc/h, comoving x3 = dm['Coordinates'][:, 2] #/1e3/(1.0+zl) # Mpc/h, comoving ptnl_p = dm['Potential'] idx_ptnl_p_min = ptnl_p == ptnl_p.min() xcp1 = x1[idx_ptnl_p_min] xcp2 = x2[idx_ptnl_p_min] xcp3 = x3[idx_ptnl_p_min] #sdens = pcs.call_sph_sdens_arrays(x1,x2,x3,xc1,xc2,xc3,bsz,nnn,npp,pmass)*1e6 sdens = read_sdens_from_illustris(dm, x1 - xcp1, x2 - xcp2, x3 - xcp3, bsz, nnn) * (1.0 + zl)**2.0 #kappa = sdens/mm.sigma_crit(zl,zs0) #pl.figure() #pl.contourf(sdens) #pl.colorbar() ##print np.max(kappa) #---------------------------------------------------------------------- bsz = bsz / 1e3 / mm.Da(zl) * mm.apr #arcsec dsx = bsz / nnn #arcsec print bsz xi1, xi2 = make_r_coor(nnn, dsx) ai1, ai2 = pcs.call_cal_alphas0(sdens, nnn, bsz, zl, zs0) lensed_img = pcs.call_ray_tracing_single(ai1, ai2, nnn, bsz, zl) lenses_img = slf.loadin_fits(HaloID, zl, bsz, nnn) #---------------------------------------------------------------------- #zs = 2.0 #dsi = 0.03 #ysc1 = 0.0 #ysc2 = 0.0 #ai1,ai2 = pcs.call_cal_alphas0(sdens,nnn,bsz,zl,zs) #yi1 = xi1-ai1 #yi2 = xi2-ai2 #g_source = pyfits.getdata("./dry_run_pipeline/439.0_149.482739_1.889989_processed.fits") #g_source = np.array(g_source,dtype="<d") #g_source[g_source<=0.0001] = 1e-6 #lensed_img = lv4.call_ray_tracing(g_source,yi1,yi2,ysc1,ysc2,dsi) #---------------------------------------------------------------------- pl.figure() pl.contourf(lensed_img) pl.colorbar() final_img = lensed_img + lenses_img / 100.0 pyfits.writeto("test.fits", final_img, clobber=True) pl.figure() pl.contourf(final_img) pl.colorbar() return 0
import numpy import mycosmology as cosmos z1 = 0.01 z2 = 0.2 omega_north = 2.14 Da1 = cosmos.Da(z1) * (1.0 + z1) Da2 = cosmos.Da(z2) * (1.0 + z2) volume = omega_north * (1.0 / 3.0) * (Da2**3 - Da1**3) z1 = 0.01 z2 = 1.0 Da1 = cosmos.Da(z1) * (1.0 + z1) Da2 = cosmos.Da(z2) * (1.0 + z2) volume2 = omega_north * (1.0 / 3.0) * (Da2**3 - Da1**3) print(volume2 / volume) #print 3660.0*400**3/volume