本文整理匯總了Python中astropy.cosmology.Planck13.luminosity_distance方法的典型用法代碼示例。如果您正苦於以下問題:Python Planck13.luminosity_distance方法的具體用法?Python Planck13.luminosity_distance怎麽用?Python Planck13.luminosity_distance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類astropy.cosmology.Planck13
的用法示例。
在下文中一共展示了Planck13.luminosity_distance方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from astropy.cosmology import Planck13 [as 別名]
# 或者: from astropy.cosmology.Planck13 import luminosity_distance [as 別名]
def main():
fil = pysysp.StarSpectrum()
fil.setwavelength(np.arange(1000, 30000, 0.4))
fil.setflux( 1e-15 * (fil.wavelength/10000.0)**(-1.5))
i = pysysp.BandPass('/Users/jselsing/github/pysysp/pysysp/filters/ugriz/i.dat')
dl = (cosmo.luminosity_distance(1.2)) * 1e5
Mz0 = -5 * np.log10(dl.value) + fil.apmag(band=i, mag='AB')
print('Mz0 = '+str(Mz0))
i.wavelength /= (1 + 2)
# fil.flux = fil.flux * (1 + 2)
i.update_bandpass()
dl = (cosmo.luminosity_distance(1.2)) * 1e5
Mz2 = -5 * np.log10(dl.value) + fil.apmag(band=i, mag='AB') #- 2.5 * np.log10(1 + 2)
print('Mz2 = '+str(Mz2))
# i.wavelength *= (1 + 2)
# i.update_bandpass()
# fil.wavelength = fil.wavelength * (1 + 2)
# fil.flux = fil.flux / (1 + 2)
# dl = (cosmo.luminosity_distance(1.2)) * 1e5
# Mz2 = -5 * np.log10(dl.value) + fil.apmag(band=i, mag='AB')
# print('Mz2 = '+str(Mz2))
print('Mz0 - Mz2 = '+str(Mz0 - Mz2))
示例2: sersic_mag_tot_to_Ieff
# 需要導入模塊: from astropy.cosmology import Planck13 [as 別名]
# 或者: from astropy.cosmology.Planck13 import luminosity_distance [as 別名]
def sersic_mag_tot_to_Ieff(mag_tot,Reff,ndex,z,Rcut=100): # g band
bn = 2.0*ndex-1/3.0+0.009876/ndex
xtmp = bn*(Rcut)**(1.0/ndex)
ktmp = 2.0*np.pi*ndex*(np.e**bn/(bn**(2.0*ndex)))*spf.gammainc(2.0*ndex,xtmp)*spf.gamma(2.0*ndex)
Dl_s = p13.luminosity_distance(z).value*1e6
Ieff = 10.0**((5.12-2.5*np.log10(ktmp)-5.0*np.log10(Reff)+5.0*np.log10(Dl_s/10)-mag_tot)*0.4) # L_sun/pc^2
return Ieff
示例3: bolometric
# 需要導入模塊: from astropy.cosmology import Planck13 [as 別名]
# 或者: from astropy.cosmology.Planck13 import luminosity_distance [as 別名]
def bolometric(model, luminosity=True):
phase = model.source._phase
flux = np.sum(model.source.flux(phase, model.source._wave) * dwave, axis=1)
if luminosity:
z = model.get('z')
dl = Planck13.luminosity_distance(z).to('cm').value
L = 4 * np.pi * flux * dl * dl
return L
return flux
示例4: bolometric
# 需要導入模塊: from astropy.cosmology import Planck13 [as 別名]
# 或者: from astropy.cosmology.Planck13 import luminosity_distance [as 別名]
def bolometric(model, luminosity=True, dl=None):
phase = model.source._phase
dwave = np.gradient(model.source._wave)
flux = np.sum(model.source.flux(phase, model.source._wave) * dwave, axis=1)
if luminosity:
z = model.get('z')
if dl is None:
dl = Planck13.luminosity_distance(z).to('cm').value
else:
dl = (dl * u.Mpc).to('cm').value
L = 4 * np.pi * flux * dl * dl
return L
return flux
示例5: sersic_mag_in_Rcut
# 需要導入模塊: from astropy.cosmology import Planck13 [as 別名]
# 或者: from astropy.cosmology.Planck13 import luminosity_distance [as 別名]
def sersic_mag_in_Rcut(Ieff,Reff,ndex,z,Rcut=100): # g band
LB = sersic_L_Rcut(Ieff,Reff,ndex)
Dl_l = p13.luminosity_distance(z).value*1e6
res = 5.12 - 2.5*np.log10(LB) + 5.0*np.log10(Dl_l/10)
return res
示例6: make_r_coor
# 需要導入模塊: from astropy.cosmology import Planck13 [as 別名]
# 或者: from astropy.cosmology.Planck13 import luminosity_distance [as 別名]
resa = 0.4
resb = 0.2
stheta = 35.0
source_cat = [ys1, ys2, mag_srcs, resa, resb, stheta, ndex, zs]
lens_cat = [xl1, xl2, ql, vd, phi, zd, lid]
dsx = 0.01
nnn = 1000
xi1, xi2 = make_r_coor(nnn,dsx)
lensed_images = producing_lensed_images(xi1,xi2,source_cat,lens_cat)
Dl_s = p13.luminosity_distance(zs).value
Da_s = p13.angular_diameter_distance(zs).value
Reff_arc = np.sqrt(resa*resb)
Reff = Reff_arc*Da_s/apr*1e6 # pc
ndex = 4.0
Ieff = sersic_mag_tot_to_Ieff(mag_srcs,Reff,ndex,zs)
Ltot = sersic_L_Rcut(Ieff,Reff,ndex)
MAG = sersic_Abs_MAG_Rcut(Ieff,Reff,ndex)
mueff = sersic_mag_tot_to_mueff(24,Reff,ndex,2.0)
Ieff2 = 10.0**((21.572+5.12-mueff)*0.4)
#Ltmp = np.sum(sersic_2d(xi1,xi2,0.0,0.0,Ieff,Reff_arc,0.5,35.0,ndex))*(dsx*Da_s/apr*1e6)**2.0
Ltmp = np.sum(lensed_images)*(dsx*Da_s/apr*1e6)**2.0
magtmp = 5.12 - 2.5*np.log10(Ltmp)+5.0*np.log10(Dl_s*1e6/10.0)
pyfits.writeto(str(magtmp)+"_lensed_images.fits",lensed_images, clobber=True)
示例7: calculate_averages_pdf
# 需要導入模塊: from astropy.cosmology import Planck13 [as 別名]
# 或者: from astropy.cosmology.Planck13 import luminosity_distance [as 別名]
#.........這裏部分代碼省略.........
for m in range(len(y)):
cdf[m] = np.sum(y[:m])
cdf = cdf / np.max(cdf)
#fig,ax=plt.subplots()
#ax.tick_params(labelsize=20)
#ax.plot(prop+9.0,probs/np.max(probs),'k.',label='Individual fits')
#ax.plot(xdf+9.0,y/np.max(y),'r--',linewidth=2.0,label='Likelihood distribution')
#xlim_in = (np.min(xdf[np.where(y/np.max(y)>0.01)])+9.0,np.max(xdf[np.where(y/np.max(y)>0.01)])+9.0)
#plt.plot(xdf,cdf,'b-')
#ax.set_ylabel("Likelihood",fontsize=22)
#ax.set_xlabel("Age / log(yrs)",fontsize=22)
#ax.legend(loc='upper left', shadow=True,prop={'size':20})
#out_plot_string = './plots/likelihood_'+str(np.mean(prop))+'.eps'
#plt.savefig(out_plot_string,format='eps',transparent=True,bbox_inches='tight')
#plt.close()
area_probspace = y*(xdf[1]-xdf[0])
area_probspace = area_probspace/np.sum(area_probspace)
indx_probspace = np.argsort(area_probspace)[::-1]
desc_probspace = np.sort(area_probspace)[::-1]
cdf_probspace = np.zeros(np.shape(desc_probspace))
for m in range(len(desc_probspace)):
cdf_probspace[m] = np.sum(desc_probspace[:m])
def find_closest(A, target):
#A must be sorted
idx = A.searchsorted(target)
idx = np.clip(idx, 1, len(A)-1)
left = A[idx-1]
right = A[idx]
idx -= target - left < right - target
return idx
# Median, + / - 1 sig, + / - 2 sig, + / - 3 sig
#av_sigs = [0.5,0.6827/2.0+0.5,0.5-0.6827/2.0,0.95/2.0+0.5,0.5-0.95/2.0,0.997/2.0+0.5,0.5-0.997/2.0]
av_sigs = [0.6827,0.9545,0.9973]
# Sorts results by likelihood and calculates confidence intervals on sorted space
index_close = find_closest(cdf_probspace, av_sigs)
best_fit = xdf[indx_probspace[0]]
upper_onesig,lower_onesig = np.max(xdf[indx_probspace[:index_close[0]]]),np.min(xdf[indx_probspace[:index_close[0]]])
upper_twosig,lower_twosig = np.max(xdf[indx_probspace[:index_close[1]]]),np.min(xdf[indx_probspace[:index_close[1]]])
upper_thrsig,lower_thrsig = np.max(xdf[indx_probspace[:index_close[2]]]),np.min(xdf[indx_probspace[:index_close[2]]])
# Takes whole pdf and computes median, confidence intervals
#index_close = find_closest(cdf, av_sigs)
if np.size(xdf) == 0:
raise Exception('No solutions found??? FIREFLY error (see statistics.py)')
#return xdf[index_close]
return [best_fit,upper_onesig,lower_onesig,upper_twosig,lower_twosig,upper_thrsig,lower_thrsig]
log_age = np.log10(age)
log_age[np.isnan(log_age)|np.isinf(log_age)] = 0.0
av = {}
av['light_age'],av['light_age_1_sig_plus'],av['light_age_1_sig_minus'],\
av['light_age_2_sig_plus'],av['light_age_2_sig_minus'],\
av['light_age_3_sig_plus'],av['light_age_3_sig_minus'] \
= averages_and_errors(probs,np.dot(light_weights,log_age),sampling)
av['light_metal'],av['light_metal_1_sig_plus'],av['light_metal_1_sig_minus'],\
av['light_metal_2_sig_plus'],av['light_metal_2_sig_minus'],\
av['light_metal_3_sig_plus'],av['light_metal_3_sig_minus'] \
= averages_and_errors(probs,np.dot(light_weights,metal),sampling)
av['mass_age'],av['mass_age_1_sig_plus'],av['mass_age_1_sig_minus'],\
av['mass_age_2_sig_plus'],av['mass_age_2_sig_minus'],\
av['mass_age_3_sig_plus'],av['mass_age_3_sig_minus'] \
= averages_and_errors(probs,np.dot(mass_weights,log_age),sampling)
av['mass_metal'],av['mass_metal_1_sig_plus'],av['mass_metal_1_sig_minus'],\
av['mass_metal_2_sig_plus'],av['mass_metal_2_sig_minus'],\
av['mass_metal_3_sig_plus'],av['mass_metal_3_sig_minus'] \
= averages_and_errors(probs,np.dot(mass_weights,metal),sampling)
dist_lum = Planck13.luminosity_distance(redshift)*10.0**6 * 3.09 * 10.0**18
conversion_factor = 10.0**(-17) * 4*math.pi*dist_lum.value**2.0
tot_mass = np.log10(np.sum(unnorm_mass,1) * conversion_factor)
av['stellar_mass'],av['stellar_mass_1_sig_plus'],av['stellar_mass_1_sig_minus'],\
av['stellar_mass_2_sig_plus'],av['stellar_mass_2_sig_minus'],\
av['stellar_mass_3_sig_plus'],av['stellar_mass_3_sig_minus'] \
= averages_and_errors(probs,tot_mass,sampling)
#plotting.files_of_light_weights(log_age,metal,light_weights,probs,"output_test")
#plotting.files_of_mass_weights(log_age,metal,light_weights,probs,"output_test_mass")
return av
示例8: savemyplot
# 需要導入模塊: from astropy.cosmology import Planck13 [as 別名]
# 或者: from astropy.cosmology.Planck13 import luminosity_distance [as 別名]
fig = plt.figure()
plt.title("Color vs Apparent Magnitude @ z~"+str(z_mean))
plt.xlabel("m "+filter2)
plt.ylabel(filter1+" - "+filter2)
#plt.xlim([27,19])
#plt.ylim([-1,4])
#plt.hist(t['F675W'], bins = 50)
plt.hist2d(t[filter2], t[filter1] - t[filter2], bins = 50, range=np.array([(19, 27), (-1, 4)]), norm=LogNorm())
plt.axis([27, 19, -1, 4])
#plt.show()
savemyplot("Color_ApparentMagnitude_"+str(z_mean))
plt.close()
#DL = cosmology.luminosity_distance(t['zb_1'], cosmology.Planck13).to(units.pc)/units.pc
DL = cosmo.luminosity_distance(t['zb_1']).to(units.pc)/units.pc
absmag = t[filter2] - 5.*np.log10(DL) + 5.
# Color vs Absolute Magnitude
fig = plt.figure()
plt.title("Color vs Absolute Magnitude @ z~"+str(z_mean))
plt.xlabel("M "+filter2)
plt.ylabel(filter1+" - "+filter2)
plt.hist2d(absmag, t[filter1] - t[filter2], bins = 50, range=np.array([(-26, -12), (-1, 4)]), norm=LogNorm())
plt.axis([-12, -26, -1, 4])
#plt.show()
savemyplot("Color_AbsoluteMagnitude_"+str(z_mean))
plt.close()
# Stellar Mass distribution per sub-sample
示例9: main
# 需要導入模塊: from astropy.cosmology import Planck13 [as 別名]
# 或者: from astropy.cosmology.Planck13 import luminosity_distance [as 別名]
#.........這裏部分代碼省略.........
wl_new = np.arange(short, tall, step)
n_wl = len(wl_new)
flux_new = np.zeros((n_obj,n_wl))
flux_cont_new = np.zeros((n_obj,n_wl))
fluxerr_new = np.zeros((n_obj,n_wl))
bp_map_new = np.zeros((n_obj,n_wl))
filt_new = np.zeros((n_obj,n_wl))
for n in range(n_obj):
#de-reddening
flux_0[n] = cardelli_reddening(wl_obs[n], flux_0[n], ebv[n])
flux_cont_0[n] = cardelli_reddening(wl_obs[n], flux_cont_0[n], ebv[n])
fluxerr_0[n] = cardelli_reddening(wl_obs[n], fluxerr_0[n], ebv[n])
for n in range(n_obj):
#Interpolate
flux_new[n] = common_wavelength(wl[n], wl_new, flux_0[n])
flux_cont_new[n] = common_wavelength(wl[n], wl_new, flux_cont_0[n])
fluxerr_new[n] = common_wavelength(wl[n], wl_new, fluxerr_0[n], fill_value=1.0)
bp_map_new[n] = common_wavelength(wl[n], wl_new, bp_map[n], fill_value=1.0)
# print(flux_new)
# flux_cont_new = np.vstack((flux_cont_new , 1e-15 * (wl_new/10000.0)**(-1.5)))
# redshifts = np.concatenate((redshifts, [1.2]))
# obj_list.append('Pure power law')
from astropy.cosmology import Planck13 as cosmo
L5100 = []
for n in range(n_obj):
mask = ((wl_new > 5050) & (wl_new < 5150))
f5100 = np.mean(flux_cont_new[n][mask])
L5100.append(np.log10(f5100*4 * np.pi* (((cosmo.luminosity_distance(redshifts[n]).value)*3e24)**2) *5100))
print(np.mean(L5100), np.std(L5100))
# filter = glob.glob('/Users/jselsing/Work/X-Shooter/CompositeRedQuasar/processed_data/sdss_filtercurves/u.dat')[0]
# filter = np.genfromtxt(filter)
# wl_filt = filter[:,0]
# filt = filter[:,1]
# from astropy.cosmology import Planck13 as cosmo
# filt_new = common_wavelength(wl_filt, wl_new, filt, fill_value=0.0)
# miz0 = []
# u_mag = []
# for n in range(n_obj+1):
# prod = medfilt(filt_new * flux_cont_new[n], 29)
# numerator = np.sum(prod * wl_new)
# denom = np.sum(filt_new * (3e18/wl_new))
# f_nu = numerator / denom
# i_band_mag = -2.5 * np.log10(f_nu) - 48.6
# u_mag.append(i_band_mag)
# dl = (cosmo.luminosity_distance(redshifts[n])) * 1e5
# M = -5 * np.log10(dl.value) + i_band_mag
# miz0.append(M)
# # print(obj_list[n])
# # print(M, i_band_mag, redshifts[n])
# filter = glob.glob('/Users/jselsing/Work/X-Shooter/CompositeRedQuasar/processed_data/sdss_filtercurves/g.dat')[0]
# filter = np.genfromtxt(filter)
# wl_filt = filter[:,0]
# filt = filter[:,1]
# from astropy.cosmology import Planck13 as cosmo
# filt_new = common_wavelength(wl_filt, wl_new, filt, fill_value=0.0)