def __init__(self, zd=0.3, zs=2., h=0.7, rein=1., rc=1e-4, gamma=2., images=[], source=0., \ obs_images=None, obs_gamma=None): self.zd = zd self.zs = zs self.h = h self.rein = rein self.rc = rc self.gamma = gamma self.caustic = None self.radcrit = None self.xminmag = None self.yminmag = None self.magmin = None self.source = source self.images = images self.timedelay = None self.grids = None self.radmag_ratio = None self.imA = None self.imB = None self.obs_gamma = obs_gamma self.obs_images = obs_images self.ds = distance.angular_diameter_distance(self.zs, **default_cosmo) self.dds = distance.angular_diameter_distance(self.zs, self.zd, **default_cosmo) self.dd = distance.angular_diameter_distance(self.zd, **default_cosmo) self.S_cr = cgs.c**2/(4.*np.pi*cgs.G)*self.ds*self.dd/self.dds*cgs.Mpc*cgs.arcsec2rad**2 self.arcsec2kpc = cgs.arcsec2rad*self.dd*1000. self.Dt = self.dd*self.ds/self.dds*cgs.Mpc*(1. + self.zd)
def timeDelayDistanceForSIS(velocityDispersion, zLens, zSource): ''' At the moment, i have saved the fermat potential in unitless SIS i.e deltaPHI so i need to times by eta0^2 Ds / (Dls*Dl)*(1+z) eta0 = 4 pi (v/c)^2 * Dl Dls / Dls ''' cosmo = {'omega_M_0': 0.3, 'omega_lambda_0': 0.7, 'h': 1.} cosmo = dist.set_omega_k_0(cosmo) Dl = dist.angular_diameter_distance(zLens, **cosmo) Dls = dist.angular_diameter_distance(zSource, z0=zLens, **cosmo) Ds = dist.angular_diameter_distance(zSource, **cosmo) cInKmPerSecond = 3e5 cInMpcPerDay = 9.7156e-15 * 60. * 60. * 24 Eta0 = 4. * np.pi * (velocityDispersion / cInKmPerSecond) * Dl * Dls / Ds TimeDelayDistance = (1 + zLens) / cInMpcPerDay * Ds / (Dl * Dls) * Eta0**2 return TimeDelayDistance
def getAnalyticExpression(logTimeDelay, velocityDispersion, zSource=1., zLens=0.2, kernelSize=3.): cosmo = {'omega_M_0': 0.3, 'omega_lambda_0': 0.7, 'h': 1.} cosmo = dist.set_omega_k_0(cosmo) Dl = dist.angular_diameter_distance(zLens, **cosmo) Dls = dist.angular_diameter_distance(zSource, z0=zLens, **cosmo) Ds = dist.angular_diameter_distance(zSource, **cosmo) cInKmPerSecond = 3e5 cInMpcPerSecond = 9.7156e-15 seconds2days = 1. / 60. / 60. / 24 timeDelayDistance = getTimeDelayDistance(zLens, zSource, 100.) lensPlaneDistanceMpc = np.arange(500) / 1000. * 1e-4 angle = lensPlaneDistanceMpc / Dl analytic = 8. * np.pi * ( velocityDispersion / cInKmPerSecond )**2 * timeDelayDistance * Dls / Ds * angle * seconds2days maxTimeDelay = np.log10( 32. * np.pi**2 * (velocityDispersion / cInKmPerSecond)**4 * Dl * Dls / Ds * (1. + zLens) / cInMpcPerSecond * seconds2days) #logTimeDelay = np.linspace(-3,maxTimeDelay,100) probability = (10**logTimeDelay)**2 probability = probability / probability[np.argmin( np.abs(logTimeDelay - maxTimeDelay))] probability[logTimeDelay > maxTimeDelay] = 0 dX = logTimeDelay[1] - logTimeDelay[0] #probability = gauss(probability, 1) #characterstic scale in kpc epsilon0 = 4.*np.pi*(velocityDispersion/cInKmPerSecond)**2\ *Dl*Dls/Ds*1e3 subsample = 4. dy = 0.1 / epsilon0 * Dl / Ds / subsample timeDelayOnePixel = dy / 10**maxTimeDelay #timeDelayOnePixel/dX #pdb.set_trace() box_kernel = Box1DKernel(kernelSize) probability = convolve(probability, box_kernel) probability /= np.sum(probability * dX) print("convolution kernel size is ", dX * kernelSize) return logTimeDelay, probability
def plot_DA(filename): """ The dimensionless angular diameter distance DA/DH. """ # Set up an array of redshift values. dz = 0.1 z = numpy.arange(0., 10. + 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 angular diameter distance. da, da_err1, da_err2 = cd.angular_diameter_distance(z, **cosmo) # Make plots. plot_dist(z, dz, om, dom, da, dh, 'angular diameter distance', r'D_A', filename) plot_dist_ony(z, dz, om, dom, da, dh, 'angular diameter distance', r'D_A', filename)
def plot_DA(filename): """The dimensionless angular diameter distance DA/DH. """ # Set up an array of redshift values. dz = 0.1 z = numpy.arange(0., 10. + 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 angular diameter distance. da = cd.angular_diameter_distance(z, **cosmo) # Make plots. plot_dist(z, dz, om, dom, da, dh, 'angular diameter distance', r'D_A', filename) plot_dist_ony(z, dz, om, dom, da, dh, 'angular diameter distance', r'D_A', filename)
def fill_free_electron_parameters(rm, tau20=0.001): # tau20 is the optical depth to Thomson scattering for a # CMB photon traversing through the center of a Lambda=20 cluster. ncl = len(rm['ra']) tau = [] theta_c = [] dang = distance.angular_diameter_distance(rm['z_spec'], **cosmo) for i in range(ncl): this_lambda = rm['lam'][i] this_tau = tau20*(this_lambda/20.)#tmpp, how should it scale w mass? #this_tau = tau20*(this_lambda/20.)**(1./3.)#tmpp, how should it scale w mass? this_rc_mpc = 0.3 #tmpp. should scale with some power of lambda. #this_rc_mpc = 0.3*(this_lambda/20.)**(1./3.) this_theta_c = this_rc_mpc/dang[i] tau.append(this_tau) theta_c.append(this_theta_c) tau = np.array(tau) theta_c = np.array(theta_c) rm['tau'] = tau rm['theta_c'] = theta_c t0 = -(rm['vlos']/constants.c_light_Mpc_s)*TCMB*rm['tau'] rm['t0'] = t0 return
def val_dA( z ): """This returns angular-diameter distance in [cm comoving], or in other words, the comoving radial distance [in cm comoving]. It only takes z.""" cosmo = {'omega_M_0' : Omatter, 'omega_lambda_0' : Olambda, 'h' : h0} cosmo = cd.set_omega_k_0( cosmo ) res = cd.angular_diameter_distance( z, **cosmo ) * Mpc_in_cm * ( 1 + z ) return res
def test_figure2(): """Plot Hogg fig. 2: The dimensionless angular diameter distance DA/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] -- High lambda, (0.2, 0.8) [dashed] Hubble distance DH = c / H0 z from 0--5 DA / DH from 0--0.5 """ 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) da = cd.angular_diameter_distance(z, **cosmo) # Also test the pathway with non-zero z0 da2 = cd.angular_diameter_distance(z, z0=1e-8, **cosmo) pylab.figure(figsize=(6,6)) for i in range(len(linestyle)): pylab.plot(z, (da/dh)[i], ls=linestyle[i]) pylab.plot(z, (da2/dh)[i], ls=linestyle[i]) pylab.xlim(0,5) pylab.ylim(0,0.5) pylab.xlabel("redshift z") pylab.ylabel(r"angular diameter distance $D_A/D_H$") pylab.title("compare to " + inspect.stack()[0][3].replace('test_', '') + " (astro-ph/9905116v4)")
def __init__(self, zd=0.3, zs=2., h=0.7, mstar=1e11, mdme=1e11, beta=1., reff_phys=1., rs_phys=10., images=[], source=0., \ obs_images=None, obs_lmstar=None, obs_radmagrat=None, obs_timedelay=None, delta_halo=200.): self.zd = zd self.zs = zs self.h = h self.halo = None self.mstar = mstar self.mdme = mdme self.beta = beta self.rs_phys = rs_phys self.delta_halo = delta_halo self.reff_phys = reff_phys self.caustic = None self.radcrit = None self.source = source self.images = images self.timedelay = None self.grids = None self.radmag_ratio = None self.dyndic = None self.rein = None self.imA = None self.imB = None self.rvir = None self.rs = None self.gammap = None self.obs_lmstar = obs_lmstar self.obs_radmagrat = obs_radmagrat self.obs_images = obs_images self.obs_timedelay = obs_timedelay self.ds = distance.angular_diameter_distance(self.zs, **default_cosmo) self.dds = distance.angular_diameter_distance(self.zs, self.zd, **default_cosmo) self.dd = distance.angular_diameter_distance(self.zd, **default_cosmo) self.S_cr = cgs.c**2/(4.*np.pi*cgs.G)*self.ds*self.dd/self.dds*cgs.Mpc/cgs.M_Sun*cgs.arcsec2rad**2 self.arcsec2kpc = cgs.arcsec2rad*self.dd*1000. self.reff = self.reff_phys/self.arcsec2kpc self.rs = self.rs_phys/self.arcsec2kpc self.Dt = self.dd*self.ds/self.dds*cgs.Mpc*(1. + self.zd) self.rhoc = density.cosmo_densities(**default_cosmo)[0]*distance.e_z(self.zd, **default_cosmo)**2 self.xmin = 1.01*max(self.reff/50., 0.1*self.rs/50.) self.xmax = 0.99*min(10.*self.reff, 100.*self.rs/50.)
def test_figure2(): """Plot Hogg fig. 2: The dimensionless angular diameter distance DA/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] -- High lambda, (0.2, 0.8) [dashed] Hubble distance DH = c / H0 z from 0--5 DA / DH from 0--0.5 """ 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) da = cd.angular_diameter_distance(z, **cosmo) # Also test the pathway with non-zero z0 da2 = cd.angular_diameter_distance(z, z0=1e-8, **cosmo) pylab.figure(figsize=(6, 6)) for i in range(len(linestyle)): pylab.plot(z, (da / dh)[i], ls=linestyle[i]) pylab.plot(z, (da2 / dh)[i], ls=linestyle[i]) pylab.xlim(0, 5) pylab.ylim(0, 0.5) pylab.xlabel("redshift z") pylab.ylabel(r"angular diameter distance $D_A/D_H$") pylab.title("compare to " + inspect.stack()[0][3].replace('test_', '') + " (astro-ph/9905116v4)")
def dvdz(z): ''' dv/dz to impose uniformity in redshift ''' cosmo = {'omega_M_0':0.3, 'omega_lambda_0':0.7, 'omega_k_0':0.0, 'h':0.72} d_a = cd.angular_diameter_distance(z, **cosmo) #angular diameter distance h = cd.e_z(z, **cosmo) #hubble parameter dvdz = (1+z)**2. * d_a **2 * h **-1. #dv/dz return dvdz
def zdistance(self,clus_z,H0=100.0): """ Finds the angular diameter distance for an array of cluster center redshifts. Instead, use angular distance file precalculated and upload. """ cosmo = {'omega_M_0':0.3,'omega_lambda_0':0.7,'h':H0/100.0} cosmo = cd.set_omega_k_0(cosmo) ang_d = cd.angular_diameter_distance(clus_z,**cosmo) lum_d = cd.luminosity_distance(clus_z,**cosmo) return ang_d,lum_d
def zdistance(self, clus_z, H0=100.0): """ Finds the angular diameter distance for an array of cluster center redshifts. Instead, use angular distance file precalculated and upload. """ cosmo = {'omega_M_0': 0.3, 'omega_lambda_0': 0.7, 'h': H0 / 100.0} cosmo = cd.set_omega_k_0(cosmo) ang_d = cd.angular_diameter_distance(clus_z, **cosmo) lum_d = cd.luminosity_distance(clus_z, **cosmo) return ang_d, lum_d
def __init__(self, zd=0.3, zs=2., h70=1.0, mstar=1e11, mhalo=1e13, reff_phys=1., ns=4., cvir=5., images=[], \ source=0., obs_images=None, obs_lmstar=None, obs_radmagrat=None, obs_timedelay=None, delta_halo=200.): self.zd = zd self.zs = zs self.h70 = h70 self.bulge = None self.halo = None self.mstar = mstar self.mhalo = mhalo self.delta_halo = delta_halo self.reff_phys = reff_phys self.ns = ns self.caustic = None self.radcrit = None self.source = source self.images = images self.timedelay = None self.grids = None self.radmag_ratio = None self.dyndic = None self.rein = None self.imA = None self.imB = None self.rvir = None self.rs = None self.gammap = None self.obs_lmstar = obs_lmstar self.obs_radmagrat = obs_radmagrat self.obs_images = obs_images self.obs_timedelay = obs_timedelay self.ds = distance.angular_diameter_distance(self.zs, **default_cosmo) self.dds = distance.angular_diameter_distance(self.zs, self.zd, **default_cosmo) self.dd = distance.angular_diameter_distance(self.zd, **default_cosmo) self.S_cr = cgs.c**2/(4.*np.pi*cgs.G)*self.ds*self.dd/self.dds*cgs.Mpc/cgs.M_Sun*cgs.arcsec2rad**2 self.arcsec2kpc = cgs.arcsec2rad*self.dd*1000. self.reff = self.reff_phys/self.arcsec2kpc self.cvir = cvir self.Dt = self.dd*self.ds/self.dds*cgs.Mpc/cgs.c*(1. + self.zd)/cgs.c self.rhoc = density.cosmo_densities(**default_cosmo)[0]*distance.e_z(self.zd, **default_cosmo)**2
def getTimeDelayDistance(zLens, zSource, HubbleConstant, omegaLambda=1.0): ''' Get the time delay distance for this particle lens ''' #Wessels distance class omegaMatter = 1. - omegaLambda OmegaK = 1. - omegaMatter - omegaLambda cosmo = {'omega_M_0' : 0.3, 'omega_lambda_0' : 0.7, 'h' : HubbleConstant/100.} cosmo = dist.set_omega_k_0(cosmo) Dls = dist.angular_diameter_distance(zSource, z0=zLens, **cosmo) Dl = dist.angular_diameter_distance(zLens,**cosmo) Ds = dist.angular_diameter_distance(zSource, **cosmo) cInMpcPerSecond = 9.7156e-15 return (1.+zLens)*Dl*Ds/Dls/cInMpcPerSecond
def testCosmo(): ''' ''' import cosmolopy.distance as cosmology ### Constants z = 2.4 ### Magneville: # omegaM = 0.267804 # omegaL = 0.73 # omegaK = 0.002117 # h = 0.71 ### Fiduciel BAOFIT # omegaM = 0.27 # omegaL = 0.73 # omegaK = 0 # h = 0.7 # rd = 149.7 cosmoCMV = {'omega_M_0':0.267804, 'omega_lambda_0':0.73, 'omega_k_0':0.002117, 'h':0.71} cosmoFID = {'omega_M_0':0.27, 'omega_lambda_0':0.73, 'omega_k_0':0, 'h':0.70} DAZ_CMV = cosmology.angular_diameter_distance(z,**cosmoCMV) HZ_CMV = cosmology.hubble_distance_z(z,**cosmoCMV) #cosmology.hubble_z(z,**cosmoCMV)*3.085677581e22/1.e3 DAZ_FID = cosmology.angular_diameter_distance(z,**cosmoFID) HZ_FID = cosmology.hubble_distance_z(z,**cosmoFID) #cosmology.hubble_z(z,**cosmoFID)*3.085677581e22/1.e3 print DAZ_CMV, DAZ_FID print HZ_CMV, HZ_FID print DAZ_FID/DAZ_CMV print HZ_FID/HZ_CMV return
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 err_Dv(z): '''___________DA__________________________''' cosmo = {'omega_M_0' : 0.24, 'omega_lambda_0' : 0.76, 'h' : 0.73} cosmo = cd.set_omega_k_0(cosmo) d_a = cd.angular_diameter_distance(z, **cosmo) '''___________Hz___________________________''' H_z = cd.hubble_distance_z(z, **cosmo) '''________________The error on Dv___________________''' part1 = ( dasigma/ d_a ) **2 part2 = (Hsigma/ H_z)**2 part3 = 0.0 #(cov_DaH/ (d_a* H_z)) sigma_Dv = sqrt(Dv(Z)**2 * (part1 + part2 + part3 )) return sigma_Dv
def __init__(self, zd=0.3, zs=2., rein=1., gamma=2., beta=0., images=[], source=0., h=0.7): self.zd = zd self.zs = zs self.h = h self.rein = rein self.gamma = gamma self.beta = beta self.caustic = None self.radcrit = None self.source = source self.images = images self.timedelay = None self.grids = None self.radmag_ratio = None self.ds = distance.angular_diameter_distance(self.zs, **default_cosmo) self.dds = distance.angular_diameter_distance(self.zs, self.zd, **default_cosmo) self.dd = distance.angular_diameter_distance(self.zd, **default_cosmo) self.S_cr = cgs.c**2/(4.*np.pi*cgs.G)*self.ds*self.dd/self.dds*cgs.Mpc/cgs.M_Sun*cgs.arcsec2rad**2 self.arcsec2kpc = cgs.arcsec2rad*self.dd*1000. self.Dt = self.dd*self.ds/self.dds*cgs.Mpc*(1. + self.zd)
def lnprior(z, zmin , zmax): ''' dv/dz to impose uniformity in redshift ''' if z<0.01: return -np.inf elif z>2.0: return -np.inf else: d_a = cd.angular_diameter_distance(z, **cosmo) #angular diameter distance h = cd.e_z(z, **cosmo) #hubble parameter dvdz = (1+z)**2. * d_a **2 * h **-1. #dv/dz #for the sake of numerical stability we devide dvdz by 10000.0 return np.log(dvdz / 10000.0)
def da(z): # Planck best-fit parameters cosmo = {'omega_M_0': 0.316, 'omega_lambda_0': 0.684, 'omega_b_0': 0.049, 'N_eff': 3.046, 'h': 0.67, 'ns': 0.962, 'sigma_8': 0.834, 'gamma': 0.55, 'w0': -1., 'wa': 0., 'sigma_nl': 7.} cosmo = cd.set_omega_k_0(cosmo) d_a = cd.angular_diameter_distance(z, **cosmo)/(h) print "Angular diameter distance = %.1f Mpc)" % (d_a) return d_a
def da(z): '''This function is to calculate the angular diameter distance The units are in Mpc The cosmological parameters are Planck best-fit parameters Note: you need to install cosmolopy and import cosmolopy.constants as cc and import cosmolopy.distance as cd ''' # cosmo = {'omega_M_0': 0.316, 'omega_lambda_0': 0.684, 'omega_b_0': 0.049, 'N_eff': 3.046, 'h': 0.67, 'ns': 0.962, 'sigma_8': 0.834, 'gamma': 0.55, 'w0': -1., 'wa': 0., 'sigma_nl': 7.} cosmo = cd.set_omega_k_0(cosmo) d_a = cd.angular_diameter_distance(z, **cosmo)*(cosmo['h']) #print "Angular diameter distance = %.1f Mpc)" % (d_a) return d_a
import numpy as np def mass(theta, dl, ds, dls, c=3 * (10**8), G=4.3 * (10**-3)): """ theta in units of rad dmin in units of ??? dl, ds, dls in units of Mpc c in units of m/s G in units of m^2 Mpc Msun^-1 s^-2 """ return theta**2 * ((c**2) / (4 * G)) * (dl * ds / dls) if __name__ == '__main__': theta = [np.radians(v / (60. * 60.)) for v in [1.20, 1.50]] zlens = 0.222 zring = 0.609 # of the inner ring params = {'omega_M_0': 0.3, 'omega_lambda_0': 0.7, 'h': 0.72} params = cosmo.set_omega_k_0(params) dl = cosmo.angular_diameter_distance(zlens, **params) ds = cosmo.angular_diameter_distance(zring, **params) dls = cosmo.angular_diameter_distance(zring, zlens, **params)[0] print('DL = {0}\nDS = {1}\nDLS = {2}'.format(dl, ds, dls)) for th in theta: m = mass(th, dl, ds, dls) print('Mlens = {0}'.format(m))
def DA_cosmo(z): '''___________DA__________________________''' cosmo = {'omega_M_0' : 0.24, 'omega_lambda_0' : 0.76, 'h' : 0.73} cosmo = cd.set_omega_k_0(cosmo) d_a = cd.angular_diameter_distance(z, **cosmo) return d_a
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) #See equation 30 of David Hogg's arXiv:astro-ph/9905116v4. Units are s. agetl = cd.age(z[i],**Cosmology)
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) #See equation 30 of David Hogg's arXiv:astro-ph/9905116v4. Units are s. agetl = cd.age(z[i], **Cosmology)
def D(z): cosmo = {'omega_M_0' : 0.24, 'omega_lambda_0' : 1. - 0.24-0.0418, 'h' : 0.73} return cd.angular_diameter_distance(z , **cosmo) * h
def a_distance(var): return cd.angular_diameter_distance(var, **cosmo)
def distance(redshift): return cd.angular_diameter_distance(redshift, **cosmo)
def distance(variable): return cd.angular_diameter_distance(variable, **cosmo)
import numpy as np import cosmolopy.distance as cd cosmo = {'omega_M_0': 0.308, 'omega_lambda_0': 0.692, 'omega_k_0': 0.0, 'h': 0.678} # Angular diameter distance L = cd.angular_diameter_distance(2, z0=0, **cosmo) # (proper) width = height of the observed volume D = 200 * L #Volume V = L * D**2 print("L = " + str(L) + " Mpc") print("D = "+ str(D) + " Mpc") print("V = " + str(V) + "Mpc^3")
def D(z): h = 0.72 return cd.angular_diameter_distance(z , **cosmo) * h
yploterr_2 = interpolate.splev(xplot_2, tckerr_2, der=0) yplot_2 = interpolate.splev(xplot_2, tck_2, der=0) plt.errorbar(xplot_2, yplot_2, yerr=yploterr_2, color='black', ecolor='yellow', label='Pourtsidou et al. 2014 (z=2)') for redshift in range(2, 3): constantfactor[redshift] = (9 / 4) * np.power(H0 / c, 4) * np.power( omegam0, 2) * (fgrowth(redshift, 0.308, unnormed=False) * (1 + redshift))**2 # This should be angular diameter distance #chi_s[redshift] = cd.comoving_distance(redshift, **cosmo) # upper limit of integration chi_s[redshift] = cd.angular_diameter_distance( redshift, **cosmo) # upper limit of integration # Filling the angular power spectrum array for L in range(l_plot_low_limit, l_plot_upp_limit): print("Calculating ang. pow. spec. for L = " + str(L)) angpowspec_without_j[L] = angpowspec_integration_without_j(L, redshift) for j in range(j_low_limit, j_upp_limit): angpowspec_with_j[L, j] = angpowspec_integration_with_j( L, j, redshift) # Error bars for angular power spectrum for L in range(l_plot_low_limit + 10, l_plot_upp_limit, err_stepsize): noise_denominator_for_this_j = 0 noise_denominator_sum = 0 N3_for_this_j = 0
from math import *
den=sumg/vol globaldensity.append(den) ###########CALCULATING NGALS PER CLUSTER############# print print 'matching galaxies within test radii' #get cluster centers etc. central_ra=rac central_dec=decc central_z=z cluster_id=cid galid=np.array(galid) ang_diam_dist=cd.angular_diameter_distance(central_z,z0=0,**cosmo) rmax=3.0 #maximum test radius in mpc. rmax will always be included as a test radius regardless of rmin,step rmin=0.1 #minimum test radius in mpc. rmin always included as test radius step=0.1 #step size, stepping from rmin to rmax, in mpc radii=np.r_[rmin:rmax:step,rmax] def gaussian(x,mu,sigma): return 1/(sigma*np.sqrt(2*np.pi))*np.exp(-(x-mu)**2/(2*sigma**2)) totalgals=[] backgroundgals=[] ngals=[] density=[] background_dense=[]
m_tot float default -999,BT float default -999, n_bulge float default -999,r_bulge float default -999, m_bulge float default -999, ba_bulge float default -999, pa_bulge float default -999, r_disk float default -999,m_disk float default -999, ba_disk float default -999,pa_disk float default -999);""".format(**all_info) try: print cmd cursor.execute(cmd) except: pass for model in all_info['model_list']: for redshift in np.arange(all_info['z_range']['start'], all_info['z_range']['stop'], all_info['z_range']['scale']): kpc_scale = distance.angular_diameter_distance(redshift, **all_info['cosmo'])*1000.0*np.pi/(180.0*3600.0) #kpc_per_arcsec dismod = magnitudes.distance_modulus(redshift, **all_info['cosmo']) print "redshift:%.2f, scale:%.1f, DM:%.1f" %(redshift, kpc_scale, dismod) cmd = """insert into {dba}.{out_table} (model, galcount, name, kpc_per_arcsec, dismod, zeropoint, z, BT, n_bulge, ba_bulge, pa_bulge, ba_disk, pa_disk) select '{model}', b.galcount, b.name, {kpc_scale}, {dismod}, -1.0*c.aa_r-c.kk_r*c.airmass_r, {z}, b.BT, b.n, b.eb,b.bpa+90.0, b.ed, b.dpa+90.0 from {dba}.CAST as c, {dba}.{in_table} as b, {dba}.DERT as d where d.galcount = b.galcount and b.galcount = c.galcount;""".format(model=model, kpc_scale = kpc_scale, dismod = dismod, z=redshift, **all_info).format(model=model) print cmd cursor.execute(cmd)