|
#Plot the *correct* surface-mass density profile |
|
import math |
|
import cPickle as pickle |
|
import numpy |
|
from scipy import integrate, interpolate |
|
from galpy.util import bovy_plot |
|
import monoAbundanceMW |
|
from matplotlib import pyplot |
|
_R0= 8. #kpc |
|
_hR= 3.8 #kpc |
|
_hz= 0.9 #kpc |
|
_TWOPIG= 2.*numpy.pi*4.302 |
|
_NMC= 10001 |
|
_OUTPUTRESULT= False |
|
def sigmaz(z,hr=_hR,tsigmaUW=None,hrthick=_hR,varhz=False): |
|
k3= 1./hr+1./hrthick-1./_R0 |
|
tsigmaW= sigmaW(z) |
|
dsigmaWdz= 2.7 |
|
if tsigmaUW is None: tsigmaUW= sigmaUW(z) |
|
if varhz: |
|
hz= monoAbundanceMW.meanhz(z*1000.)/1000. |
|
else: |
|
hz= _hz |
|
return 1./_TWOPIG*(tsigmaW**2./hz - 2.*tsigmaW*dsigmaWdz + k3*tsigmaUW) |
|
|
|
def mcsigmaz(z,hr=_hR,tsigmaUW=None,hrthick=_hR,varhz=False): |
|
k3= 1./hr+1./hrthick-1./_R0 |
|
#Draw coefficients |
|
wa= numpy.random.normal(size=_NMC)*0.8+40.6 |
|
wb= numpy.random.normal(size=_NMC)*0.3+2.7 |
|
uwa= numpy.random.normal(size=_NMC)*100.+1522. |
|
uwb= numpy.random.normal(size=_NMC)*30.+366. |
|
samples= numpy.zeros(_NMC) |
|
if varhz: |
|
hz= monoAbundanceMW.meanhz(z*1000.)/1000. |
|
else: |
|
hz= _hz |
|
for ii in range(_NMC): |
|
tsigmaW= sigmaW(z,a=wa[ii],b=wb[ii]) |
|
dsigmaWdz= wb[ii] |
|
tsigmaUW= sigmaUW(z,a=uwa[ii],b=uwb[ii]) |
|
samples[ii]= 1./_TWOPIG*(tsigmaW**2./hz - 2.*tsigmaW*dsigmaWdz + k3*tsigmaUW) |
|
return samples |
|
|
|
def mbsigmaz(z,hr=_hR,sigmaUW=None): |
|
k1= 3./_R0/hr-2./hr**2. |
|
k2= -1/_R0/hr |
|
k3= 3./hr-2./_R0 |
|
#k3= 2./hr-1./_R0 |
|
sigmaW= 40.6+2.7*(z-2.5) |
|
dsigmaWdz= 2.7 |
|
if sigmaUW is None: sigmaUW= 1522.+366*(z-2.5) |
|
planarpart= numpy.zeros(len(z)) |
|
for ii in range(len(z)): planarpart[ii]= integrate.quad((lambda x: k1*sigmaU(x)**2+k2*sigmaV(x)**2.),0.,z[ii])[0] |
|
return 1./_TWOPIG*(planarpart+sigmaW**2./_hz - 2.*sigmaW*dsigmaWdz + k3*sigmaUW) |
|
|
|
def mcmbsigmaz(z,hr=_hR,tsigmaUW=None): |
|
k1= 3./_R0/hr-2./hr**2. |
|
k2= -1/_R0/hr |
|
k3= 3./hr-2./_R0 |
|
#Draw coefficients |
|
ua= numpy.random.normal(size=_NMC)*3.2+82.9 |
|
ub= numpy.random.normal(size=_NMC)*1.1+6.3 |
|
va= numpy.random.normal(size=_NMC)*3.1+62.2 |
|
vb= numpy.random.normal(size=_NMC)*1.0+4.1 |
|
wa= numpy.random.normal(size=_NMC)*0.8+40.6 |
|
wb= numpy.random.normal(size=_NMC)*0.3+2.7 |
|
uwa= numpy.random.normal(size=_NMC)*100.+1522. |
|
uwb= numpy.random.normal(size=_NMC)*30.+366. |
|
samples= numpy.zeros(_NMC) |
|
for ii in range(_NMC): |
|
tsigmaW= sigmaW(z,a=wa[ii],b=wb[ii]) |
|
dsigmaWdz= wb[ii] |
|
tsigmaUW= sigmaUW(z,a=uwa[ii],b=uwb[ii]) |
|
planarpart= integrate.quad((lambda x: k1*sigmaU(x,a=ua[ii],b=ub[ii])**2+k2*sigmaV(x,a=va[ii],b=vb[ii])**2.),0.,z)[0] |
|
samples[ii]= 1./_TWOPIG*(planarpart+tsigmaW**2./_hz - 2.*tsigmaW*dsigmaWdz + k3*tsigmaUW) |
|
return samples |
|
|
|
def sigmaW(z,a=40.6,b=2.7): |
|
return a+b*(z-2.5) |
|
def sigmaU(z,a=82.9,b=6.3): |
|
return a+b*(z-2.5) |
|
def sigmaV(z,a=62.2,b=4.1): |
|
return a+b*(z-2.5) |
|
def sigmaUW(z,a=1522.,b=366.): |
|
return a+b*(z-2.5) |
|
def meanV(z): |
|
return 220.-25.-30.*z |
|
|
|
def rhoOM(z): |
|
return 20.6*10.**-3.*(8.01**2./(8.01**2.+_R0**2.+z**2.)) |
|
|
|
def sigmaVIS(z): |
|
#Needs to be normalized later |
|
return 2000.*integrate.quad(rhoVIS,0.,z)[0] |
|
|
|
def rhoVIS(z): |
|
#Thin + thick + halo from Juric+ 2008 |
|
return numpy.exp(-z/0.3)+.12*numpy.exp(-z/0.9)+0.005*(_R0/numpy.sqrt(_R0**2.+(z/0.64)**2.))**2.8 |
|
|
|
def sigmaOM(z): |
|
return 2000.*integrate.quad(rhoOM,0.,z)[0] |
|
|
|
def rhoDM(z,R,alpha,beta,gamma,Rc,rhoo,q): |
|
r= numpy.sqrt(R**2.+(z/q)**2.) |
|
return rhoo*(r/_R0)**-alpha*((1.+(r/Rc)**beta)/(1.+(_R0/Rc)**beta))**-gamma |
|
|
|
def sigmaDM(z,R=_R0,alpha=1.,beta=1.,gamma=2.,Rc=10.8,rhoo=8.4*10.**-3.,q=1.): |
|
return 2000.*integrate.quad(rhoDM,0.,z,args=(R,alpha,beta,gamma,Rc,rhoo,q))[0] |
|
|
|
def plot_sigmaz(): |
|
zs= numpy.linspace(1.5,4.,1001) |
|
sigmazs= sigmaz(zs) |
|
#Also generate samples |
|
sampleszs= numpy.array([1.8,2.8,3.8]) |
|
dev= numpy.zeros((2,len(sampleszs))) |
|
sigmazatsamples= sigmaz(sampleszs) |
|
slopes= numpy.zeros(_NMC) |
|
for ii in range(len(sampleszs)): |
|
sigmazsamples= mcsigmaz(sampleszs[ii]) |
|
if ii == 0.: |
|
slopes-= sigmazsamples |
|
elif ii == (len(sampleszs)-1): |
|
slopes+= sigmazsamples |
|
dev[0,ii]= sigmazatsamples[ii]-sorted(sigmazsamples)[int(numpy.round(0.16*_NMC))] |
|
dev[1,ii]= sorted(sigmazsamples)[int(numpy.round(0.84*_NMC))]-sigmazatsamples[ii] |
|
print 'slope', (sigmazs[-1]-sigmazs[0])/(zs[-1]-zs[0]), '+/-',\ |
|
numpy.std(slopes)/(sampleszs[-1]-sampleszs[0]) |
|
mbsigmazs= mbsigmaz(zs) |
|
#Also generate samples |
|
mbdev= numpy.zeros((2,len(sampleszs))) |
|
mbsigmazatsamples= mbsigmaz(sampleszs) |
|
for ii in range(len(sampleszs)): |
|
sigmazsamples= mcmbsigmaz(sampleszs[ii]) |
|
mbdev[0,ii]= mbsigmazatsamples[ii]-sorted(sigmazsamples)[int(numpy.round(0.16*_NMC))] |
|
mbdev[1,ii]= sorted(sigmazsamples)[int(numpy.round(0.84*_NMC))]-mbsigmazatsamples[ii] |
|
#sigmazsuwzero= sigmaz(zs,sigmaUW=0.) |
|
sigmazs2kpc= sigmaz(zs,hrthick=2.) |
|
#Also generate samples |
|
dev2kpc= numpy.zeros((2,len(sampleszs))) |
|
sigmaz2kpcatsamples= sigmaz(sampleszs,hrthick=2.) |
|
slopes= numpy.zeros(_NMC) |
|
for ii in range(len(sampleszs)): |
|
sigmazsamples= mcsigmaz(sampleszs[ii],hrthick=2.) |
|
if ii == 0.: |
|
slopes-= sigmazsamples |
|
elif ii == (len(sampleszs)-1): |
|
slopes+= sigmazsamples |
|
dev2kpc[0,ii]= sigmaz2kpcatsamples[ii]-sorted(sigmazsamples)[int(numpy.round(0.16*_NMC))] |
|
dev2kpc[1,ii]= sorted(sigmazsamples)[int(numpy.round(0.84*_NMC))]-sigmaz2kpcatsamples[ii] |
|
print 'slope', (sigmazs2kpc[-1]-sigmazs2kpc[0])/(zs[-1]-zs[0]), '+/-',\ |
|
numpy.std(slopes)/(sampleszs[-1]-sampleszs[0]) |
|
sigmazsvarhz= sigmaz(zs,varhz=True,hrthick=2.) |
|
#Also generate samples |
|
devvarhz= numpy.zeros((2,len(sampleszs))) |
|
sigmazvarhzatsamples= sigmaz(sampleszs,hrthick=2.,varhz=True) |
|
slopes= numpy.zeros(_NMC) |
|
for ii in range(len(sampleszs)): |
|
sigmazsamples= mcsigmaz(sampleszs[ii],hrthick=2.,varhz=True) |
|
if ii == 0.: |
|
slopes-= sigmazsamples |
|
elif ii == (len(sampleszs)-1): |
|
slopes+= sigmazsamples |
|
dev[0,ii]= sigmazvarhzatsamples[ii]-sorted(sigmazsamples)[int(numpy.round(0.16*_NMC))] |
|
dev[1,ii]= sorted(sigmazsamples)[int(numpy.round(0.84*_NMC))]-sigmazvarhzatsamples[ii] |
|
print 'slope', (sigmazsvarhz[-1]-sigmazsvarhz[0])/(zs[-1]-zs[0]), '+/-',\ |
|
numpy.std(slopes)/(sampleszs[-1]-sampleszs[0]) |
|
#Calculate expected |
|
tzs= numpy.linspace(0.,5.,1001) |
|
vis= numpy.zeros(len(tzs)) |
|
for ii in range(len(tzs)): vis[ii]= sigmaVIS(tzs[ii]) |
|
vis/= sigmaVIS(1.1)/40. #Normalization at z=1.1 kpc |
|
vis+= 13. #ISM |
|
om= numpy.zeros(len(tzs)) |
|
for ii in range(len(tzs)): om[ii]= sigmaOM(tzs[ii])+vis[ii] |
|
shm= numpy.zeros(len(tzs)) |
|
for ii in range(len(tzs)): shm[ii]= sigmaDM(tzs[ii])+vis[ii] |
|
n97= numpy.zeros(len(tzs)) |
|
for ii in range(len(tzs)): n97[ii]= sigmaDM(tzs[ii],Rc=20.,rhoo=6.1*10.**-3.)+vis[ii] |
|
min= numpy.zeros(len(tzs)) |
|
for ii in range(len(tzs)): min[ii]= sigmaDM(tzs[ii],alpha=0.,beta=2.,gamma=1.,Rc=5.,rhoo=5.3*10.**-3.)+vis[ii] |
|
bovy_plot.bovy_print() |
|
bovy_plot.bovy_plot(zs,sigmazs,'k-', |
|
xrange=[0.,5.], |
|
yrange=[20.,160.], |
|
xlabel=r'$Z\ [\mathrm{kpc}]$', |
|
ylabel=r'$\Sigma(Z)\ [M_\odot\ \mathrm{pc}^{-2}]$', |
|
zorder=2) |
|
#Errors |
|
pyplot.errorbar(sampleszs,sigmazatsamples, |
|
yerr=dev, |
|
fmt=',',marker='None',ecolor='k',lw=0.5) |
|
bovy_plot.bovy_plot(zs,mbsigmazs,'k-',overplot=True) |
|
#Errors |
|
pyplot.errorbar(sampleszs,mbsigmazatsamples, |
|
yerr=mbdev, |
|
fmt=',',marker='None',ecolor='k',lw=0.5) |
|
bovy_plot.bovy_plot(zs,sigmazs2kpc,'k--',overplot=True) |
|
#Errors |
|
pyplot.errorbar(sampleszs,sigmaz2kpcatsamples, |
|
yerr=dev2kpc, |
|
fmt=',',marker='None',ecolor='k',lw=0.5) |
|
#bovy_plot.bovy_plot(zs,sigmazsvarhz,'k-.',overplot=True) |
|
#bovy_plot.bovy_plot(zs,sigmazsuwzero,'k-.',overplot=True,zorder=1) |
|
bovy_plot.bovy_plot(tzs,vis, |
|
'-',color='0.7',lw=2.,overplot=True,zorder=0) |
|
bovy_plot.bovy_plot(tzs,shm,'-',color='0.7',lw=2.,overplot=True,zorder=0) |
|
bovy_plot.bovy_plot(tzs,n97,'-',color='0.7',lw=2.,overplot=True,zorder=0) |
|
bovy_plot.bovy_plot(tzs,min,'-',color='0.7',lw=2.,overplot=True,zorder=0) |
|
bovy_plot.bovy_plot(tzs,om,'-',color='0.7',lw=2.,overplot=True,zorder=0) |
|
#Load approximation and apply |
|
savefile= open('approx.sav','rb') |
|
xzs= pickle.load(savefile) |
|
x1= pickle.load(savefile) |
|
x2= pickle.load(savefile) |
|
savefile.close() |
|
#Interpolate |
|
x1Interp= interpolate.InterpolatedUnivariateSpline(xzs,x1) |
|
x2Interp= interpolate.InterpolatedUnivariateSpline(xzs,x2) |
|
ul= sigmazs/(1.-x1Interp(zs/_R0)) |
|
ll= sigmazs/(1.-x2Interp(zs/_R0)) |
|
print 'slope', (ul[-1]-ul[0])/(zs[-1]-zs[0]) |
|
print 'slope', (ll[-1]-ll[0])/(zs[-1]-zs[0]) |
|
#Plot as fill_between |
|
pyplot.fill_between(zs,ul,ll,color='0.85',zorder=-10) |
|
#Labels |
|
bovy_plot.bovy_text(4.1,147.,r'$\mathrm{OM}$',rotation=30.) |
|
bovy_plot.bovy_text(4.1,130.,r'$\mathrm{SHM}$',rotation=25.) |
|
bovy_plot.bovy_text(4.1,110.,r'$\mathrm{N97}$',rotation=17.) |
|
bovy_plot.bovy_text(4.1,95.,r'$\mathrm{MIN}$',rotation=15.) |
|
bovy_plot.bovy_text(4.1,60.,r'$\mathrm{VIS}$') |
|
#Lines |
|
bovy_plot.bovy_text(1.4,35.5,r'$\mathrm{incorrect}\ \frac{\partial \bar{V}}{\partial R} = 0$'+'\n'+r'$\mathrm{approximation}$') |
|
bovy_plot.bovy_plot([1.6,1.8],[48.,mbsigmaz(numpy.array([1.8]))],'-',color='0.8',overplot=True) |
|
bovy_plot.bovy_text(2.7,68.,r'$\mathrm{correct}\ \frac{\partial V_c}{\partial R} = 0$'+'\n'+r'$\mathrm{approximation}$') |
|
bovy_plot.bovy_plot([2.5,2.65],[sigmaz(2.5),79.],'-',color='0.8',overplot=True) |
|
bovy_plot.bovy_text(1.4,125.,r'$\mathrm{correct}$'+'\n'+r'$+ h_{R,\mathrm{thick}} = 2\ \mathrm{kpc}$') |
|
bovy_plot.bovy_plot([1.8,2.4],[123.,sigmaz(2.4,2.)],'-',color='0.8',overplot=True) |
|
bovy_plot.bovy_text(.4,99.,r'$\mathrm{effect\ of}\ \frac{\partial V_c}{\partial R} = 0$'+'\n'+r'$\mathrm{approximation}$') |
|
bovy_plot.bovy_plot([1.7,2.5],[97.,sigmaz(2.5)/(1.-x1Interp(2.5/_R0))], |
|
'-',color='0.8',overplot=True) |
|
#TITLE |
|
#bovy_plot.bovy_text('$\mathrm{Dark\ matter\ near\ the\ Sun\ is\ A\!\!-\!\!OK}$', |
|
#title=True) |
|
#bovy_plot.bovy_end_print('/home/bovy/Desktop/correct_monibidin12.png') |
|
bovy_plot.bovy_end_print('test.png') |
|
#bovy_plot.bovy_end_print('../tex/correct_monibidin12.ps') |
|
if _OUTPUTRESULT: |
|
output= numpy.zeros((len(zs),4)) |
|
output[:,0]= zs |
|
output[:,1]= sigmazs2kpc |
|
output[:,2]= ll/sigmazs*sigmazs2kpc |
|
output[:,3]= ul/sigmazs*sigmazs2kpc |
|
numpy.savetxt('bovytremaine_mb12_Sigmaz.dat',output,delimiter='|') |
|
|
|
if __name__ == '__main__': |
|
numpy.random.seed(1) |
|
plot_sigmaz() |