本文整理汇总了Python中astropy.cosmology.FlatLambdaCDM.age方法的典型用法代码示例。如果您正苦于以下问题:Python FlatLambdaCDM.age方法的具体用法?Python FlatLambdaCDM.age怎么用?Python FlatLambdaCDM.age使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astropy.cosmology.FlatLambdaCDM
的用法示例。
在下文中一共展示了FlatLambdaCDM.age方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_fit_tofz
# 需要导入模块: from astropy.cosmology import FlatLambdaCDM [as 别名]
# 或者: from astropy.cosmology.FlatLambdaCDM import age [as 别名]
def test_fit_tofz():
z_table, t_table = UT.zt_table()
cosmo = FlatLambdaCDM(H0=70, Om0=0.274)
prettyplot()
fig = plt.figure()
sub = fig.add_subplot(111)
for deg in range(2,10):
coeff = UT.fit_tofz(deg)
if deg > 5:
print 'deg = ', deg, coeff
tofz = np.poly1d(coeff)
z_arr = np.arange(0., 2., 0.1)
t_arr = cosmo.age(z_arr).value
sub.plot(z_arr, (tofz(z_arr) - t_arr)/t_arr, label='Degree='+str(deg))
t_of_z = interpolate.interp1d(z_arr, t_arr, kind='cubic')
tint = t_of_z(z_table[1:20])#np.interp(t_table[:20], t_arr, z_arr)
sub.scatter(z_table[1:20], (t_table[1:20] - tint)/tint, c='k', s=30)
sub.plot(np.arange(0., 2., 0.1), np.repeat(-0.025, len(np.arange(0., 2., 0.1))), c='k', ls='--', lw=3)
sub.plot(np.arange(0., 2., 0.1), np.repeat(0.025, len(np.arange(0., 2., 0.1))), c='k', ls='--', lw=3)
sub.set_ylim([-0.05, 0.05])
sub.set_xlim([0., 2.])
sub.legend(loc='upper left')
plt.show()
示例2: predict_colour_for_loop
# 需要导入模块: from astropy.cosmology import FlatLambdaCDM [as 别名]
# 或者: from astropy.cosmology.FlatLambdaCDM import age [as 别名]
def predict_colour_for_loop(tq, tau, z):
cosmo = FlatLambdaCDM(H0 = 71.0, Om0 = 0.26)
age = cosmo.age(z)
print age
#time = N.arange(0, 0.01, 0.003)
#t = N.arange(0, 13.7, 0.01)
#time = N.append(time, t[1:])
time = N.arange(28.0)/2.0
dir ='/Users/becky/Projects/Green-Valley-Project/bc03/models/Padova1994/chabrier/ASCII/'
model = 'extracted_bc2003_lr_m62_chab_ssp.ised_ASCII'
data = N.loadtxt(dir+model)
sfr = N.zeros(len(time)*len(tq)*len(tau)).reshape(len(time), len(tq), len(tau))
nuv_u = N.zeros_like(sfr)
u_r = N.zeros_like(sfr)
nuv_u_age = N.zeros(len(age)*len(tq)*len(tau)).reshape(len(age),len(tq), len(tau))
u_r_age = N.zeros_like(nuv_u_age)
for m in range(len(tq)):
for n in range(len(tau)):
sfr[:,m,n] = expsfh(tau[n], tq[m], time)
total_flux = assign_fluxes.assign_total_flux(data[0,1:], data[1:,0], data[1:,1:], time*1E9, sfr[:,m,n])
nuv_u[:,m,n], u_r[:,m,n] = get_colours(total_flux, data)
nuv_u_age[:,m,n] = N.interp(age, time, nuv_u[:,m,n])
u_r_age[:,m,n] = N.interp(age, time, u_r[:,m,n])
return nuv_u_age, u_r_age
示例3: len
# 需要导入模块: from astropy.cosmology import FlatLambdaCDM [as 别名]
# 或者: from astropy.cosmology.FlatLambdaCDM import age [as 别名]
disc = colours[colours[:,3] > 0.8]
print len(disc)
red_s = colours[colours[:,0] > colours[:,10]]
print len(red_s)
blue_c = colours[colours[:,0] < colours[:,11]]
print len(blue_c)
#disc = colours[colours[:,3]==1]
#smooth = colours[colours[:,2]==1]
#inter = colours[[colours[:,2]!=1][:,3]!=1]
#Calculating the look back time from the observed redshift assuming this time is also the age of the galaxy at which you're observing it
age_save = '/Users/becky/Projects/Green-Valley-Project/bayesian/find_t_tau/age_red_seq.npy'
age_path = os.path.exists(age_save)
cosmo = FlatLambdaCDM(H0 = 71.0, Om0 = 0.26)
if age_path ==False:
age = N.array(cosmo.age(red_s[:,6]))
N.save(age_save, age)
else:
age = N.load(age_save)
print len(age)
#
#if len(age) != len(gv):
# raise SystemExit('Number of ages does not coincide with number of galaxies...')
# w is the prior conditions on my theta parameters - the mean and standard deviation of tq and tau for the disc and smooth populations
# w = [mu_tqs, mu_taus, mu_tqd, mu_taud, sig_tqs, sig_taus, sig_tqd, sig_taud]
w = [9.0, 1.25, 9.0, 1.25, 2.0, 0.5, 2.0, 0.5]
nwalkers = 100
start_time = time.time()
#The rest calls the emcee code and makes plots....
samples, fig = sample(4, nwalkers, w, red_s[:,0], red_s[:,4], red_s[:, 1], red_s[:, 5], age, red_s[:,3], red_s[:,2])
示例4: len
# 需要导入模块: from astropy.cosmology import FlatLambdaCDM [as 别名]
# 或者: from astropy.cosmology.FlatLambdaCDM import age [as 别名]
print len(smooth)
disc = colours[colours[:,3] > 0.8]
print len(disc)
red_s = colours[colours[:,0] > colours[:,10]]
print len(red_s)
blue_c = colours[colours[:,0] < colours[:,11]]
print len(blue_c)
inter = colours[colours[:,3] < 0.8]
inter = inter[inter[:,2] < 0.8]
print len(inter)
age_save = '/Users/becky/Projects/Green-Valley-Project/bayesian/find_t_tau/inter/age_inter.npy'
age_path = os.path.exists(age_save)
cosmo = FlatLambdaCDM(H0 = 71.0, Om0 = 0.26)
if age_path ==False:
age = N.array(cosmo.age(inter[:,6]))
N.save(age_save, age)
else:
age = N.load(age_save)
print len(age)
w = [7.5, 1.5, 7.0, 1.5, 4.0, 1.5, 4.0, 1.5]
nwalkers = 150
nsteps = 400
start = [7.5, 1.5, 7.5, 1.5]
f = open('/Users/becky/Projects/Green-Valley-Project/bayesian/find_t_tau/log.txt', 'a')
f.write('Run started at '+str(time.strftime('%H:%M'))+' on '+str(time.strftime('%d/%m/%y'))+'\n')
f.write('Reason for running iteration: ' +reason+'\n')
f.write('Number of walkers : '+str(nwalkers)+'\n')
f.write('Number of steps :'+str(nsteps)+'\n')
示例5: FlatLambdaCDM
# 需要导入模块: from astropy.cosmology import FlatLambdaCDM [as 别名]
# 或者: from astropy.cosmology.FlatLambdaCDM import age [as 别名]
from posterior import *
from astropy.cosmology import FlatLambdaCDM
import numpy as N
import sys
# Use sys to assign arguments for the galaxy data from the command line
u_r, err_u_r, nuv_u, err_nuv_u, z, dr8, ra, dec = sys.argv[1:]
# Use astropy to calculate the age from the redshift in the data
cosmo = FlatLambdaCDM(H0 = 71.0, Om0 = 0.26)
age = N.array(cosmo.age(float(z)))
# Define parameters needed for emcee
nwalkers = 100 # number of monte carlo chains
nsteps= 400 # number of steps in the monte carlo chain
start = [7.5, 1.5] # starting place of all the chains
burnin = 400 # number of steps in the burn in phase of the monte carlo chain
#The rest calls the emcee module which is initialised in the sample function of the posterior file.
samples, samples_save = sample(2, nwalkers, nsteps, burnin, start, float(u_r), float(err_u_r), float(nuv_u), float(err_nuv_u), age, dr8)
tq_mcmc, tau_mcmc, = map(lambda v: (v[1], v[2]-v[1], v[1]-v[0]), zip(*N.percentile(samples, [16,50,84],axis=0)))
fig = corner_plot(samples, labels = [r'$ t_{quench}$', r'$ \tau$'], extents=[[N.min(samples[:,0]), N.max(samples[:,0])],[N.min(samples[:,1]),N.max(samples[:,1])]], bf=[tq_mcmc, tau_mcmc], id=dr8)
fig.savefig('starpy_output_'+str(dr8)+'.pdf')
print 'Best fit [t, tau] values found by starpy for input parameters are : [', tq_mcmc[0], tau_mcmc[0], ']'
示例6: str
# 需要导入模块: from astropy.cosmology import FlatLambdaCDM [as 别名]
# 或者: from astropy.cosmology.FlatLambdaCDM import age [as 别名]
col[:,10] = gz2data.field('upper_GV')
col[:,11] = gz2data.field('lower_GV')
col[:,12] = gz2data.field('dr7objid')
col[:,13] = gz2data.field('dr8objid')
col[:,14] = gz2data.field('ra_1')
col[:,15] = gz2data.field('dec_1')
# Remove NaN values from data
non_nan = N.logical_not(N.isnan(col[:,1])).astype(int)
data = N.compress(non_nan, col, axis=0)
age_save = str(raw_input('Desired or current location of galaxy ages from astropy.cosmology, e.g. "~/starfpy/galaxy_data_ages.npy" : '))
age_path = os.path.exists(age_save)
cosmo = FlatLambdaCDM(H0 = 71.0, Om0 = 0.26)
if age_path ==False:
age = N.array(cosmo.age(data[:,6]))
N.save(age_save, age)
else:
age = N.load(age_save)
print len(age)
nwalkers = 100
nsteps= 400
start = [7.5, 1.5]
burnin = 400
start_time = time.time()
#The rest calls the emcee module through the 'posterior.py' functions and makes a plot....
for n in range(len(data)):
url = 'http://casjobs.sdss.org/ImgCutoutDR7/getjpeg.aspx?ra='+str(data[n,14])+'&dec='+str(data[n,15])+'&scale=0.099183&width=424&height=424'
f = wget.download(url, out=str(int(data[n,13]))+'.jpeg')
示例7: FlatLambdaCDM
# 需要导入模块: from astropy.cosmology import FlatLambdaCDM [as 别名]
# 或者: from astropy.cosmology.FlatLambdaCDM import age [as 别名]
import numpy as N
import pylab as P
import scipy as S
import pyfits as F
from t_tau_func import *
from astropy.cosmology import FlatLambdaCDM
cosmo = FlatLambdaCDM(H0 = 71.0, Om0 = 0.26)
av_z = 0.076401
age = cosmo.age(av_z)
font = {'family':'serif', 'size':12}
P.rc('font', **font)
P.rc('xtick', labelsize='small')
P.rc('ytick', labelsize='small')
dir ='/Users/becky/Projects/Green-Valley-Project/bc03/models/Padova1994/chabrier/ASCII/'
model = 'extracted_bc2003_lr_m62_chab_ssp.ised_ASCII'
data = N.loadtxt(dir+model)
tq = N.linspace(0.0, 13.6, 10)
tau = N.linspace(3.0, 0.001, 10)
ur = N.zeros((len(tq),len(tau)))
nuv = N.zeros_like(ur)
for n in range(len(tq)):
for m in range(len(tau)):
nuv[n,m], ur[n,m] = predict_c_one([tq[n], tau[m]], age)
N.save('ur.npy', ur)
示例8: len
# 需要导入模块: from astropy.cosmology import FlatLambdaCDM [as 别名]
# 或者: from astropy.cosmology.FlatLambdaCDM import age [as 别名]
disc = colours[colours[:, 3] > 0.8]
print len(disc)
red_s = colours[colours[:, 0] > colours[:, 10]]
print len(red_s)
blue_c = colours[colours[:, 0] < colours[:, 11]]
print len(blue_c)
# disc = colours[colours[:,3]==1]
# smooth = colours[colours[:,2]==1]
# inter = colours[[colours[:,2]!=1][:,3]!=1]
# Calculating the look back time from the observed redshift assuming this time is also the age of the galaxy at which you're observing it
age_save = "/Users/becky/Projects/Green-Valley-Project/bayesian/find_t_tau/blue_cloud/age_blue_cloud.npy"
age_path = os.path.exists(age_save)
cosmo = FlatLambdaCDM(H0=71.0, Om0=0.26)
if age_path == False:
age = N.array(cosmo.age(blue_c[:, 6]))
N.save(age_save, age)
else:
age = N.load(age_save)
print len(age)
#
# if len(age) != len(gv):
# raise SystemExit('Number of ages does not coincide with number of galaxies...')
# w is the prior conditions on my theta parameters - the mean and standard deviation of tq and tau for the disc and smooth populations
# w = [mu_tqs, mu_taus, mu_tqd, mu_taud, sig_tqs, sig_taus, sig_tqd, sig_taud]
w = [9.0, 1.25, 9.0, 1.25, 2.0, 0.5, 2.0, 0.5]
nwalkers = 100
start_time = time.time()
# The rest calls the emcee code and makes plots....
samples, fig = sample(
示例9: FlatLambdaCDM
# 需要导入模块: from astropy.cosmology import FlatLambdaCDM [as 别名]
# 或者: from astropy.cosmology.FlatLambdaCDM import age [as 别名]
#u_r_gal_sigma = N.array([0.01, 0.015])
#nuv_u_gal = N.array([0.5, 1.2])
#nuv_u_gal_sigma = N.array([0.02, 0.015])
u_r_gal = smooth[100:101,0]
print N.shape(u_r_gal)
print 'u_r_gal', u_r_gal
u_r_gal_sigma = smooth[100:101,16]
print 'u_r_gal_sigma', u_r_gal_sigma
nuv_u_gal = smooth[100:101,1]
nuv_u_gal_sigma = smooth[100:101,17]
age_save = '/Users/becky/Projects/Green-Valley-Project/bayesian/age_smooth.npy'
age_path = os.path.exists(age_save)
cosmo = FlatLambdaCDM(H0 = 71.0, Om0 = 0.26)
if age_path == True:
age = N.array(cosmo.age(smooth[100:101,18]))
N.save(age_save, age)
else:
age = N.load(age_save)
#age = cosmo.age(z_gal)
print age
print N.shape(age)
#
#col_gal = N.array([u_r_gal, nuv_u_gal])
#sigma_gal = N.array([u_r_gal_sigma, nuv_u_gal_sigma])
#Define model properties
#time = (N.arange(28.0)/2.0) # In Gyrs
#time = N.linspace(0.0, cosmo.age(0.0), 50) # In Gyrs
#tim = N.arange(0, 0.01, 0.003)
#times = N.arange(0, 13.7, 0.01)
示例10: FlatLambdaCDM
# 需要导入模块: from astropy.cosmology import FlatLambdaCDM [as 别名]
# 或者: from astropy.cosmology.FlatLambdaCDM import age [as 别名]
import numpy as N
import pylab as P
import scipy as S
import pyfits as F
from t_tau_func import *
from astropy.cosmology import FlatLambdaCDM
cosmo = FlatLambdaCDM(H0 = 71.0, Om0 = 0.26)
z = N.linspace(0.0001, 100, 500)
a = N.array(cosmo.age(z))
#av_z = 0.076401
#age = cosmo.age(av_z).value
age=12.878505072906682
font = {'family':'serif', 'size':16}
P.rc('font', **font)
P.rc('xtick', labelsize='medium')
P.rc('ytick', labelsize='medium')
P.rc('axes', labelsize='medium')
#
tq = N.linspace(0.0, 13.8, 75)
tau = N.linspace(0.001, 3, 75)
tqs = N.outer(tq, N.ones(len(tq)))
taus = N.outer(N.ones(len(tau)), tau)
time = N.arange(0, 0.01, 0.003)
t = N.linspace(0, 13.7, 200)
t = N.append(time, t[1:])
示例11: str
# 需要导入模块: from astropy.cosmology import FlatLambdaCDM [as 别名]
# 或者: from astropy.cosmology.FlatLambdaCDM import age [as 别名]
gvf = colours[colours[:, 8] == 1]
gv = gvf[gvf[:, 9] == 1]
red_s = colours[colours[:, 0] > colours[:, 10]]
blue_c = colours[colours[:, 0] < colours[:, 11]]
gv_s = gv[gv[:, 2] >= 0.8]
gv_d = gv[gv[:, 3] >= 0.8]
gv_clean = N.append(gv_s, gv_d, axis=0)
hund = blue_c[:10, :]
N.save("bc_" + str(len(hund)) + ".npy", hund)
cosmo = FlatLambdaCDM(H0=71.0, Om0=0.26)
age = N.array(cosmo.age(hund[:, 6]))
w = [7.5, 1.5, 7.0, 1.5, 4.0, 1.5, 4.0, 1.5]
nwalkers = 100
nsteps = 400
start = [7.5, 1.5]
burnin = 400
X = N.linspace(0, 14, 100)
Y = N.linspace(0, 5, 100)
sums = N.zeros((len(X) - 1, len(Y) - 1))
sumd = N.zeros((len(X) - 1, len(Y) - 1))
# w is the prior conditions on my theta parameters - the mean and standard deviation of tq and tau for the disc and smooth populations
# w = [mu_tqs, mu_taus, mu_tqd, mu_taud, sig_tqs, sig_taus, sig_tqd, sig_taud]
示例12: len
# 需要导入模块: from astropy.cosmology import FlatLambdaCDM [as 别名]
# 或者: from astropy.cosmology.FlatLambdaCDM import age [as 别名]
gv = gv_o[gv_o[:,5]==1]
print len(gv)
#Set properties
u_r_gal = gv[:,0]
u_r_gal_sigma = gv[:,6]
nuv_u_gal = gv[:,1]
nuv_u_gal_sigma = gv[:,7]
#Calculate ages of galaxies (assuming look back time) using measured redshift
age_save = '/Users/becky/Projects/Green-Valley-Project/bayesian/age_smooth.npy'
age_path = os.path.exists(age_save)
cosmo = FlatLambdaCDM(H0 = 71.0, Om0 = 0.26)
if age_path == False:
age = N.array(cosmo.age(smooth[:,8]))
N.save(age_save, age)
else:
age = N.load(age_save)
col_gal = N.array([u_r_gal, nuv_u_gal])
sigma_gal = N.array([u_r_gal_sigma, nuv_u_gal_sigma])
#Define model properties
time = N.linspace(0.0, cosmo.age(0.0), 50) # In Gyrs
tau = N.linspace(0.001, 2.5, 50)
taus = N.outer(tau, N.ones(len(tau)))
#tq = N.array([8,9,10])
tq = N.linspace(0.0, 13.7, 50)
tqs = N.outer(N.ones(len(tq)), tq)
ext = (N.min(tq), N.max(tq), N.min(tau), N.max(tau))