def plot_DM(filename): """ The dimensionless proper motion distance DM/DH. """ # Set up an array of redshift values. dz = 0.1 z = numpy.arange(0., 10. + 1.1 * dz, dz) # Set up a cosmology dictionary, with an array of matter density values. cosmo = {} dom = 0.01 om = numpy.atleast_2d(numpy.linspace(0.1, 1.0, (1. - 0.1) / dom)).transpose() cosmo['omega_M_0'] = om cosmo['omega_lambda_0'] = 1. - cosmo['omega_M_0'] cosmo['h'] = 0.701 cosmo['omega_k_0'] = 0.0 # Calculate the hubble distance. dh = cd.hubble_distance_z(0, **cosmo) # Calculate the comoving distance. dm, dm_err = cd.comoving_distance_transverse(z, **cosmo) # Make plots. plot_dist(z, dz, om, dom, dm, dh, 'proper motion distance', r'D_M', filename) plot_dist_ony(z, dz, om, dom, dm, dh, 'proper motion distance', r'D_M', filename)
def plot_DM(filename): """The dimensionless proper motion distance DM/DH. """ # Set up an array of redshift values. dz = 0.1 z = numpy.arange(0., 10. + 1.1 * dz, dz) # Set up a cosmology dictionary, with an array of matter density values. cosmo = {} dom = 0.01 om = numpy.atleast_2d(numpy.linspace(0.1, 1.0, (1. - 0.1) / dom)).transpose() cosmo['omega_M_0'] = om cosmo['omega_lambda_0'] = 1. - cosmo['omega_M_0'] cosmo['h'] = 0.701 cosmo['omega_k_0'] = 0.0 # Calculate the hubble distance. dh = cd.hubble_distance_z(0, **cosmo) # Calculate the comoving distance. dm = cd.comoving_distance_transverse(z, **cosmo) # Make plots. plot_dist(z, dz, om, dom, dm, dh, 'proper motion distance', r'D_M', filename) plot_dist_ony(z, dz, om, dom, dm, dh, 'proper motion distance', r'D_M', filename)
def test_distances(threshold = 1e-3): """Compare distance measures with calculations from http://icosmo.org/""" cosmo = cosmo_wmap_5() print "Comparing distances with calculations from http://icosmo.org/" # load external distance calculations # z DA(z) DT(z) DL(z) distance_file = os.path.dirname(os.path.abspath(__file__)) distance_file = os.path.join(distance_file, 'icosmo_testdata', 'distances.txt') ic_dists = numpy.loadtxt(distance_file) z = ic_dists[:,0] cd_da = cd.angular_diameter_distance(z, **cosmo) cd_dt = cd.light_travel_distance(z, **cosmo) cd_dl = cd.luminosity_distance(z, **cosmo) cd_dm = cd.comoving_distance_transverse(z, **cosmo) cd_dists = numpy.vstack((cd_dm, cd_da, cd_dt, cd_dl)) labels = [ r'$D_M$', r'$D_A$', r'$D_T$', r'$D_L$'] threshold = [1e-7, 1e-7, 1e-3, 1e-7 ] # print ic_dists[-1].transpose() # print cd_dists[:,-1] pylab.figure() for i in range(len(labels)): pylab.plot(ic_dists[:,0], ic_dists[:,i+1], label=labels[i] +' IC', ls=':') pylab.plot(z, cd_dists[i], label=labels[i] +' distance.py', ls='-') pylab.legend(loc='best') pylab.figure() for i in range(len(labels)): diff = (cd_dists[i] - ic_dists[:,i+1]) / ic_dists[:,i+1] maxdiff = numpy.max(numpy.abs(diff[ic_dists[:,i+1] > 0])) print "Maximum fraction difference in %s is %e." % (labels[i], maxdiff) assert(numpy.all(maxdiff < threshold[i])) pylab.plot(ic_dists[:,0], diff, label=labels[i], ls='-') #pylab.plot(z, err2, label=labels[1] + ' err.', ls=':') #pylab.plot(z, err3, label=labels[2] + ' err.', ls=':') #pylab.plot(z, err5, label=labels[3] + ' err.', ls=':') #pylab.plot(z, err6, label=labels[0] + ' err.', ls=':') pylab.legend(loc='best')
def test_distances(threshold = 1e-3): """Compare distance measures with calculations from http://icosmo.org/""" cosmo = cosmo_wmap_5() print("Comparing distances with calculations from http://icosmo.org/") # load external distance calculations # z DA(z) DT(z) DL(z) distance_file = os.path.dirname(os.path.abspath(__file__)) distance_file = os.path.join(distance_file, 'icosmo_testdata', 'distances.txt') ic_dists = numpy.loadtxt(distance_file) z = ic_dists[:,0] cd_da = cd.angular_diameter_distance(z, **cosmo) cd_dt = cd.light_travel_distance(z, **cosmo) cd_dl = cd.luminosity_distance(z, **cosmo) cd_dm = cd.comoving_distance_transverse(z, **cosmo) cd_dists = numpy.vstack((cd_dm, cd_da, cd_dt, cd_dl)) labels = [ r'$D_M$', r'$D_A$', r'$D_T$', r'$D_L$'] threshold = [1e-7, 1e-7, 1e-3, 1e-7 ] # print ic_dists[-1].transpose() # print cd_dists[:,-1] pylab.figure() for i in range(len(labels)): pylab.plot(ic_dists[:,0], ic_dists[:,i+1], label=labels[i] +' IC', ls=':') pylab.plot(z, cd_dists[i], label=labels[i] +' distance.py', ls='-') pylab.legend(loc='best') pylab.figure() for i in range(len(labels)): diff = (cd_dists[i] - ic_dists[:,i+1]) / ic_dists[:,i+1] maxdiff = numpy.max(numpy.abs(diff[ic_dists[:,i+1] > 0])) print("Maximum fraction difference in %s is %e." % (labels[i], maxdiff)) assert(numpy.all(maxdiff < threshold[i])) pylab.plot(ic_dists[:,0], diff, label=labels[i], ls='-') #pylab.plot(z, err2, label=labels[1] + ' err.', ls=':') #pylab.plot(z, err3, label=labels[2] + ' err.', ls=':') #pylab.plot(z, err5, label=labels[3] + ' err.', ls=':') #pylab.plot(z, err6, label=labels[0] + ' err.', ls=':') pylab.legend(loc='best')
def test_figure1(): """Plot Hogg fig. 1: The dimensionless proper motion distance DM/DH. The three curves are for the three world models, Einstein-de Sitter (omega_M, omega_lambda) = (1, 0), solid; low-density, (0.05, 0), dotted; and high lambda, (0.2, 0.8), dashed. Hubble distance DH = c / H0 z from 0--5 DM / DH from 0--3 """ z = numpy.arange(0, 5.05, 0.05) cosmo = {} cosmo['omega_M_0'] = numpy.array([[1.0], [0.05], [0.2]]) cosmo['omega_lambda_0'] = numpy.array([[0.0], [0.0], [0.8]]) cosmo['h'] = 0.5 cd.set_omega_k_0(cosmo) linestyle = ['-', ':', '--'] dh = cd.hubble_distance_z(0, **cosmo) dm = cd.comoving_distance_transverse(z, **cosmo) pylab.figure(figsize=(6, 6)) for i in range(len(linestyle)): pylab.plot(z, (dm / dh)[i], ls=linestyle[i]) #pylab.plot(z, (dm_err/dh)[i], ls=linestyle[i]) pylab.xlim(0, 5) pylab.ylim(0, 3) pylab.xlabel("redshift z") pylab.ylabel(r"proper motion distance $D_M/D_H$") pylab.title("compare to " + inspect.stack()[0][3].replace('test_', '') + " (astro-ph/9905116v4)")
def test_figure1(): """Plot Hogg fig. 1: The dimensionless proper motion distance DM/DH. The three curves are for the three world models, Einstein-de Sitter (omega_M, omega_lambda) = (1, 0), solid; low-density, (0.05, 0), dotted; and high lambda, (0.2, 0.8), dashed. Hubble distance DH = c / H0 z from 0--5 DM / DH from 0--3 """ z = numpy.arange(0, 5.05, 0.05) cosmo = {} cosmo['omega_M_0'] = numpy.array([[1.0],[0.05],[0.2]]) cosmo['omega_lambda_0'] = numpy.array([[0.0],[0.0],[0.8]]) cosmo['h'] = 0.5 cd.set_omega_k_0(cosmo) linestyle = ['-', ':', '--'] dh = cd.hubble_distance_z(0, **cosmo) dm = cd.comoving_distance_transverse(z, **cosmo) pylab.figure(figsize=(6,6)) for i in range(len(linestyle)): pylab.plot(z, (dm/dh)[i], ls=linestyle[i]) #pylab.plot(z, (dm_err/dh)[i], ls=linestyle[i]) pylab.xlim(0,5) pylab.ylim(0,3) pylab.xlabel("redshift z") pylab.ylabel(r"proper motion distance $D_M/D_H$") pylab.title("compare to " + inspect.stack()[0][3].replace('test_', '') + " (astro-ph/9905116v4)")
def plot_DM(): """The dimensionless proper motion distance DM/DH. """ # Set up an array of redshift values. dz = 0.01 z = numpy.arange(0., 10. + 1.1 * dz, dz) # Set up a cosmology dictionary, with an array of matter density values. cosmo = {} dom = 0.01 om = numpy.atleast_2d(numpy.linspace(0.1, 1.0, (1.-0.1)/dom)).transpose() dzt = 0.01 zt = numpy.atleast_2d(numpy.linspace(0.1, 1.0, (1.-0.1)/dzt)).transpose() cosmo['omega_M_0'] = om cosmo['transition_redshift'] = zt cosmo['omega_lambda_0'] = 1/2 * cosmo['omega_M_0'] * (1 + cosmo['transition_redshift'])**3 cosmo['h'] = 0.701 cosmo['omega_k_0'] = 1 - cosmo['omega_M_0'] - 1/2 * cosmo['omega_M_0'] * ( cosmo['transition_redshift'] + 1 )**3 # Calculate the hubble distance. dhc = cd.comoving_distance(z,z0=0, **cosmo) # Calculate the comoving distance. dm = cd.comoving_distance_transverse(z, **cosmo) # Make plots print om.ravel() fig = plt.figure() ax = fig.gca(projection='3d') om, zt = meshgrid(om.ravel(),zt.ravel()) hub = cd.comoving_distance(1,z0=0,**cosmo) surf = ax.plot_surface(om,zt,hub,rstride=1,cstride=1,cmap=cm.jet,linewidth=0,antialiased=False) # ax.set_zlim() plt.show()
def r2z(r): zrange = np.linspace(0, 6, 1000) r_to_z = sp.interpolate.interp1d( cd.comoving_distance_transverse(zrange, **params.cosmo), zrange) return r_to_z(r).astype('float32')
PlotNumber = 8 N = 200 z = numpy.arange(0.001, 5, 1. / N) val = numpy.zeros(len(z)) for i in xrange(len(z)): #Hubble Distance dh = cd.hubble_distance_z(z[i], **Cosmology) * cd.e_z(z[i], **Cosmology) #In David Hogg's (arXiv:astro-ph/9905116v4) formalism, this is equivalent to D_H / E(z) = c / (H_0 E(z)) [see his eq. 14], which #appears in the definitions of many other distance measures. dm = cd.comoving_distance_transverse(z[i], **Cosmology) #See equation 16 of David Hogg's arXiv:astro-ph/9905116v4 da = cd.angular_diameter_distance(z[i], **Cosmology) #See equations 18-19 of David Hogg's arXiv:astro-ph/9905116v4 dl = cd.luminosity_distance(z[i], **Cosmology) #Units are Mpc dVc = cd.diff_comoving_volume(z[i], **Cosmology) #The differential comoving volume element dV_c/dz/dSolidAngle. #Dimensions are volume per unit redshift per unit solid angle. #Units are Mpc**3 Steradians^-1. #See David Hogg's arXiv:astro-ph/9905116v4, equation 28 tl = cd.lookback_time(z[i], **Cosmology)
zrec_cst = inhodist.x2z_inho_lightcone(lightcone_cst, h) theseed=None lightcone = ln.lightcone_1d(xmax, nnx, seed=theseed, pklib=pklib, omegam=(omegac+omegab)/h2, smoothing=None) clf() plot(lightcone.xx, lightcone.alldelta[0,:]) np.mean(lightcone.alldelta[0,:]) zrec = inhodist.x2z_inho_lightcone(lightcone, h) zvals = np.linspace(0,np.max(zrec_cst),1000) open = cd.set_omega_k_0({'omega_M_0' : (omegac+omegab)/h2, 'omega_lambda_0' : 0., 'h' : 0.7}) d_open = cd.comoving_distance_transverse(zvals, **open) lcdm = cd.set_omega_k_0({'omega_M_0' : (omegac+omegab)/h2, 'omega_lambda_0' : 0.7, 'h' : 0.7}) d_lcdm = cd.comoving_distance_transverse(zvals, **lcdm) empty = cd.set_omega_k_0({'omega_M_0' : 0, 'omega_lambda_0' : 0., 'h' : 0.7}) d_empty = cd.comoving_distance_transverse(zvals, **empty) clf() plot(zvals, d_open/d_lcdm, lw=2, label='Standard: Open $\Omega_m=0.3$') plot(zvals, d_lcdm/d_lcdm, lw=2, label='Standard: $\Lambda$CDM') plot(zvals, d_empty/d_lcdm, lw=2, label='Standard: Empty $\Omega_m=0.$') plot(zrec_cst, lightcone_cst.xx/np.interp(zrec_cst, zvals, d_lcdm), '--', lw=2, label='JC: Uniform Open $\Omega_m=0.3$') plot(zrec, lightcone.xx/np.interp(zrec, zvals, d_lcdm), lw=2, label='JC: Inhomogeneous Open $\Omega_m=0.3$') legend(loc='upper left', fontsize=10, frameon=False)
import cosmolopy import cosmolopy.distance as cd qso_zmin = 2.2 qso_zmax = 2.8 area =5800 #deg2 zvals = np.linspace(0,1e5,1e5) lcdm = cd.set_omega_k_0({'omega_M_0' : 0.3, 'omega_lambda_0' : 0.7, 'h' : 0.7}) d_lcdm = cd.comoving_distance_transverse(zvals, **lcdm) clf() plot(zvals,d_lcdm) xscale('log') d_bb = np.max(d_lcdm) d_min = cd.comoving_distance_transverse(qso_zmin, **lcdm) d_min = cd.comoving_distance_transverse(qso_zmin, **lcdm)
def D_transverse(z): return cd.comoving_distance_transverse(z, **cosmo) / h # Mpc/h
N=200 z=numpy.arange(0.001,5,1./N) val = numpy.zeros(len(z)) for i in xrange(len(z)): #Hubble Distance dh = cd.hubble_distance_z(z[i],**Cosmology)*cd.e_z(z[i],**Cosmology) #In David Hogg's (arXiv:astro-ph/9905116v4) formalism, this is equivalent to D_H / E(z) = c / (H_0 E(z)) [see his eq. 14], which #appears in the definitions of many other distance measures. dm = cd.comoving_distance_transverse(z[i],**Cosmology) #See equation 16 of David Hogg's arXiv:astro-ph/9905116v4 da = cd.angular_diameter_distance(z[i],**Cosmology) #See equations 18-19 of David Hogg's arXiv:astro-ph/9905116v4 dl = cd.luminosity_distance(z[i],**Cosmology) #Units are Mpc dVc = cd.diff_comoving_volume(z[i], **Cosmology) #The differential comoving volume element dV_c/dz/dSolidAngle. #Dimensions are volume per unit redshift per unit solid angle. #Units are Mpc**3 Steradians^-1. #See David Hogg's arXiv:astro-ph/9905116v4, equation 28 tl = cd.lookback_time(z[i],**Cosmology)
xscale('log') #### P(K) library at various redshifts nz = 100 zmin = 0 zmax = 1100 # BUILD IT ############################################################################### #pklib = ln.build_pklib(params, zmin, zmax, nz) # RESTORE IT ############################################################################## pklib = ln.read_pklib(zmin, zmax, nz) #### Skewers library with the same seed at different reshifts # set the x range so that it extends well beyond the distance at maximum redshift zvals = np.linspace(0,zmax,1000) lcdm = cd.set_omega_k_0({'omega_M_0' : 0.3, 'omega_lambda_0' : 0.7, 'h' : 0.7}) d_lcdm = cd.comoving_distance_transverse(zvals, **lcdm) maxd = np.max(d_lcdm)*1.2 theseed = 1 nn = 2**18 lightcone = ln.lightcone_1d(maxd, nn, pklib, seed=theseed) thezinit = linspace(0,zmax, 10000) dinit = cd.comoving_distance_transverse(thezinit, **lcdm) nbvals = 2**19 zz = linspace(0, zmax*0.99, nbvals) dd = np.interp(zz, thezinit, dinit)