本文整理汇总了Python中astropy.cosmology.WMAP9.comoving_distance方法的典型用法代码示例。如果您正苦于以下问题:Python WMAP9.comoving_distance方法的具体用法?Python WMAP9.comoving_distance怎么用?Python WMAP9.comoving_distance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astropy.cosmology.WMAP9
的用法示例。
在下文中一共展示了WMAP9.comoving_distance方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_light_cone
# 需要导入模块: from astropy.cosmology import WMAP9 [as 别名]
# 或者: from astropy.cosmology.WMAP9 import comoving_distance [as 别名]
def build_light_cone(fileglob, zs=np.array([6, 6.5, 7]), boxtype='delta_T'):
zs = np.array(zs)
files = glob(fileglob)
zind = {'delta_T': 5, 'Ts_z': 1, 'xH_': 2, 'deltax': 3}
zsim = []
dims = []
lengths = []
files_keep = []
for f in files:
if not os.path.basename(f).startswith(boxtype):
if not 'updated_smoothed_' + boxtype in os.path.basename(f):
continue
files_keep.append(f)
parms = os.path.basename(f).split('_')
zsim.append(np.float(parms[zind[boxtype]][1:])) # redshifts
dims.append(np.int(parms[-2])) # dim of box
lengths.append(np.float(parms[-1][0:-3])) # length in Mpc
files = files_keep
if (np.max(np.diff(dims)) > 0) or (np.max(np.diff(lengths)) > 0):
raise(ValueError('Boxes are not all the same size'))
if (np.max(zs) > np.max(zsim)) or (np.min(zs) < np.min(zsim)):
raise(ValueError('Requested redshifts outside range of sim.'))
order = np.argsort(zsim)
files = [files[i] for i in order]
zsim = np.array([zsim[i] for i in order])
zsim0 = zsim[0]
dim = dims[0]
length = lengths[0]
dx = length / dim
lightcube = np.zeros((dim, dim, len(zs)), dtype=np.float32)
Ds = cosmo.comoving_distance(zs).value - cosmo.comoving_distance(zsim0).value
pix1 = map(int, np.floor(Ds / dx) % dim)
wp1 = Ds / dx - np.floor(Ds / dx)
pix2 = map(int, np.ceil(Ds / dx) % dim)
wp2 = 1 - wp1
box1 = [np.argmax(zsim[zsim <= z]) for z in zs]
box2 = [i + 1 for i in box1]
wb2 = (zs - zsim[box1]) / (zsim[box2] - zsim[box1])
wb1 = (zsim[box2] - zs) / (zsim[box2] - zsim[box1])
for i, z in enumerate(zs):
data = np.fromfile(files[box1[i]], dtype=np.float32)
data = data.reshape((dim, dim, dim))
slice11 = data[:, :, pix1[i]]
slice12 = data[:, :, pix2[i]]
data = np.fromfile(files[box2[i]], dtype=np.float32)
data = data.reshape((dim, dim, dim))
slice21 = data[:, :, pix1[i]]
slice22 = data[:, :, pix2[i]]
lightcube[:, :, i] = (slice11 * wb1[i] * wp1[i] + slice12 * wb1[i] * wp2[i] +
slice21 * wb2[i] * wp1[i] + slice21 * wb2[i] * wp2[i])
return lightcube
示例2: lens_astropy
# 需要导入模块: from astropy.cosmology import WMAP9 [as 别名]
# 或者: from astropy.cosmology.WMAP9 import comoving_distance [as 别名]
def lens_astropy():
import pylab as pl
from astropy.cosmology import WMAP9
zl = np.linspace(0.01, 1.9, 100)
zs = 2.
wa = []
wc = []
angs = WMAP9.angular_diameter_distance(zs).value
chis = WMAP9.comoving_distance(zs).value
for zi in zl:
angl = WMAP9.angular_diameter_distance(zi).value
angls = WMAP9.angular_diameter_distance_z1z2(zi,zs).value
chil = WMAP9.comoving_distance(zi).value
chils = WMAP9.comoving_distance(zs).value-WMAP9.comoving_distance(zi).value
wa.append(angl * angls / angs)
wc.append(chil * chils / chis / (1+zi))
pl.plot(zl, wa)
pl.plot(zl, wc, ls='--')
pl.show()