AstroPy basic



Lesson 1: 計算不同redshift時的Hubble constant


from astropy.cosmology import WMAP9 as cosmo
import matplotlib.pyplot as plt
import scipy as sp
redShift = sp.arange(0, 10, 0.1)
HubberC = []
for i in redShift:
	print(cosmo.H(i))
	HubberC = sp.append(HubberC, cosmo.H(i))
plt.plot(redShift, HubberC )
plt.xlabel('redshift(z)');
plt.ylabel('Hubble constant');
plt.show()
Note and Comments
from astropy.cosmology import WMAP9 as cosmo #comology package can choose WMAP5, WMAP7, WMAP9, Planck13, Planck15 as parameter
import matplotlib.pyplot as plt
import scipy as sp
redShift = sp.arange(0, 10, 0.1) # create a redshift list from 0 to 10
HubberC = []
for i in redShift:
	print(cosmo.H(i))
	HubberC = sp.append(HubberC, cosmo.H(i)) #cosmo.H(redshift) returns the hubber cotant value by imput redshift  
plt.plot(redShift, HubberC )
plt.xlabel('redshift(z)');
plt.ylabel('Hubble constant');
plt.show()
result


Lesson 2: 計算不同redshift時的Parsec


from astropy.cosmology import WMAP9 as cosmo
import matplotlib.pyplot as plt
import scipy as sp
redShift = [0.0000001] #設定redshift序列由0.0000001 開始, 並以1.5倍的倍數增加
for i in range(45):
	redShift = sp.append(redShift, redShift[-1]*1.5)
print(redShift)
Mpc = cosmo.comoving_distance(redShift) #依redshift回傳Mparsec
plt.figure(1)
plt.loglog(redShift[:30], Mpc[:30] )
plt.xlabel('redshift(z)');
plt.ylabel('M parsec');
plt.grid()
plt.figure(2)
plt.loglog(redShift[30:], Mpc[30:] )
plt.xlabel('redshift(z)');
plt.ylabel('M parsec');
plt.grid()
plt.show()
Note and Comments
from astropy.cosmology import WMAP9 as cosmo
import matplotlib.pyplot as plt
import scipy as sp
redShift = [0.0000001]
for i in range(45):
	redShift = sp.append(redShift, redShift[-1]*1.5)
print(redShift)
Mpc = cosmo.comoving_distance(redShift) 
plt.figure(1)
plt.loglog(redShift[:30], Mpc[:30] )
plt.xlabel('redshift(z)');
plt.ylabel('M parsec');
plt.grid()
plt.figure(2)
plt.loglog(redShift[30:], Mpc[30:] )
plt.xlabel('redshift(z)');
plt.ylabel('M parsec');
plt.grid()
plt.show()

result




Lesson 3: units of cosmology


from astropy.cosmology import WMAP9 as cosmo
H0 = cosmo.H(0)
print("H0.value is ", H0.value)
print("H0.unit is ", H0.unit) 
output
H0.value 69.32
H0.unit km / (Mpc s)