def plot_vr(plotfilename): #Read the APOGEE-RC data and pixelate it #APOGEE-RC data= apread.rcsample() if _ADDLLOGGCUT: data= data[data['ADDL_LOGG_CUT'] == 1] #Cut indx= (numpy.fabs(data['RC_GALZ']) < 0.25)*(data['METALS'] > -1000.) data= data[indx] #Get velocity field xmin, xmax= 5.5, 13.5 dx= 1. pix= pixelize_sample.pixelXY(data, xmin=xmin,xmax=xmax, ymin=-dx/2.,ymax=dx/2., dx=dx,dy=dx) # dx=_RCDX,dy=_RCDX) vr= pix.plot(lambda x: dvlosgal(x), returnz=True,justcalc=True) vrunc= pix.plot(lambda x: dvlosgal(x), func=lambda x: 1.4826*numpy.median(numpy.fabs(x-numpy.median(x)))/numpy.sqrt(len(x)), returnz=True,justcalc=True) sr= pix.plot(lambda x: dvlosgal(x), func=lambda x: 1.4826*numpy.median(numpy.fabs(x-numpy.median(x))), returnz=True,justcalc=True) srunc= pix.plot(lambda x: dvlosgal(x), func=disperror, returnz=True,justcalc=True) #print numpy.median(vr.flatten()[numpy.array([True,True,False,True,True,True,True,True,True],dtype='bool')]) print vr.flatten() print vrunc.flatten() print sr.flatten() print srunc.flatten() rs= numpy.arange(xmin+dx/2.,xmax-dx/2.+0.00001,dx) print rs bovy_plot.bovy_print() srAxes= pyplot.axes([0.1,0.5,0.8,0.4]) vrAxes= pyplot.axes([0.1,0.1,0.8,0.4]) pyplot.sca(srAxes) pyplot.errorbar(rs,sr.flatten(),yerr=srunc.flatten(), marker='o',ls='none',ms=6.,color='k') pyplot.xlim(0.,15.) pyplot.ylim(9.5,49.) #srAxes.set_yscale('log') bovy_plot._add_ticks(yticks=False) bovy_plot._add_axislabels(r'$ $', r'$\sigma_R\,(\mathrm{km\,s}^{-1})$') nullfmt = NullFormatter() # no labels srAxes.xaxis.set_major_formatter(nullfmt) pyplot.sca(vrAxes) pyplot.errorbar(rs,vr.flatten(),yerr=vrunc.flatten(), marker='o',ls='none',ms=6.,color='k') pyplot.plot([0.,20.],numpy.median(vr.flatten())*numpy.ones(2),'k--') bovy_plot._add_ticks() pyplot.xlim(0.,15.) pyplot.ylim(-14.,14.) bovy_plot._add_axislabels(r'$R\,(\mathrm{kpc})$', r'$\langle V_R\rangle\,(\mathrm{km\,s}^{-1})$') bovy_plot.bovy_end_print(plotfilename) return None
def determine_kxky_error(): #Load fiducial bar model spvlos= galpy_simulations.vlos('../sim/bar_rect_alpha0.015%s.sav' % _HIVRESSTR)[1::2,1::2] #spvlos= galpy_simulations.vlos('../sim/spiral_rect_omegas0.33_alpha-14%s.sav' % _HIVRESSTR)[1::2,1::2]*0.85 #spvlos= galpy_simulations.vlos('../sim/spiral_rect_omegas0.33_alpha-7%s.sav' % _HIVRESSTR)[1::2,1::2]*0.25 psd2d= bovy_psd.psd2d(spvlos) kmax= 1./_RCDX #Calculate maximum psd2d[psd2d.shape[0]/2-1:psd2d.shape[0]/2+2,psd2d.shape[1]/2-1:psd2d.shape[1]/2+2]= 0. tmax= numpy.unravel_index(numpy.argmax(psd2d),psd2d.shape) tmax0= float(psd2d.shape[0]/2-tmax[0])/psd2d.shape[0]*2 tmax1= float(tmax[1]-psd2d.shape[1]/2)/psd2d.shape[1]*2 print tmax0*kmax, tmax1*kmax bovy_plot.bovy_print() bovy_plot.bovy_dens2d(psd2d.T,origin='lower',cmap='jet', interpolation='nearest', xrange=[-kmax,kmax], yrange=[-kmax,kmax], xlabel=r'$k_x\,(\mathrm{kpc}^{-1})$', ylabel=r'$k_y\,(\mathrm{kpc}^{-1})$') bovy_plot.bovy_end_print('/Users/bovy/Desktop/test.png') #Read the data for the noise data= apread.rcsample() if _ADDLLOGGCUT: data= data[data['ADDL_LOGG_CUT'] == 1] #Cut indx= (numpy.fabs(data['RC_GALZ']) < 0.25)*(data['METALS'] > -1000.) print "Using %i stars for low-Z 2D kinematics analysis" % numpy.sum(indx) data= data[indx] #Get residuals dx= _RCDX pix= pixelize_sample.pixelXY(data, xmin=_RCXMIN,xmax=_RCXMAX, ymin=_RCYMIN,ymax=_RCYMAX, dx=dx,dy=dx) resvunc= pix.plot('VHELIO_AVG', func=lambda x: 1.4826*numpy.median(numpy.fabs(x-numpy.median(x)))/numpy.sqrt(len(x)), returnz=True,justcalc=True) #Now do 1000 MC simulations to determine the error on kmax nmc= 1000 kxmax= numpy.zeros(nmc) kymax= numpy.zeros(nmc) for ii in range(nmc): newresv= spvlos+numpy.random.normal(size=spvlos.shape)*resvunc/220. simpsd2d= bovy_psd.psd2d(newresv*220.) simpsd2d[simpsd2d.shape[0]/2-1:simpsd2d.shape[0]/2+2,simpsd2d.shape[1]/2-1:simpsd2d.shape[1]/2+2]= 0. tmax= numpy.unravel_index(numpy.argmax(simpsd2d),psd2d.shape) tmax0= float(psd2d.shape[0]/2-tmax[0])/psd2d.shape[0]*2 tmax1= float(tmax[1]-psd2d.shape[1]/2)/psd2d.shape[1]*2 kmax= 1./_RCDX kxmax[ii]= tmax0*kmax kymax[ii]= tmax1*kmax print numpy.mean(kxmax), numpy.std(kxmax) print numpy.mean(kymax), numpy.std(kymax) return None
def plot_psd_red(): data= readAndHackHoltz.readAndHackHoltz() dx= 1. binsize= .735 pix= pixelize_sample.pixelXY(data,xmin=5.,xmax=13, ymin=-3.,ymax=7., dx=dx,dy=dx) resv= pix.plot(lambda x: dvlosgal(x),returnz=True,justcalc=True) resvunc= pix.plot('VHELIO_AVG', func=lambda x: 1.4826*numpy.median(numpy.fabs(x-numpy.median(x)))/numpy.sqrt(len(x)), returnz=True,justcalc=True) psd1d= bovy_psd.psd1d(resv,dx,binsize=binsize) print psd1d #Simulations for constant 3.25 km/s nnoise= _NNOISE noisepsd= numpy.empty((nnoise,len(psd1d[0])-3)) for ii in range(nnoise): newresv= numpy.random.normal(size=resv.shape)*3.25 noisepsd[ii,:]= bovy_psd.psd1d(newresv,dx,binsize=binsize)[1][0:-3] scale= 4.*numpy.pi#3.25/numpy.median(numpy.sqrt(noisepsd)) print scale #Simulations for the actual noise nnoise= _NNOISE noisepsd= numpy.empty((nnoise,len(psd1d[0])-3)) for ii in range(nnoise): newresv= numpy.random.normal(size=resv.shape)*resvunc noisepsd[ii,:]= bovy_psd.psd1d(newresv,dx,binsize=binsize)[1][0:-3] ks= psd1d[0][0:-3] bovy_plot.bovy_plot(ks,scale*numpy.sqrt(psd1d[1][0:-3] -_SUBTRACTERRORS*numpy.median(noisepsd,axis=0)),'ko',mew=2., mfc='none',overplot=True) pyplot.errorbar(ks,scale*numpy.sqrt(psd1d[1][0:-3]-_SUBTRACTERRORS*numpy.median(noisepsd,axis=0)), yerr=scale*0.5*(psd1d[2][0:-3]**2. +_SUBTRACTERRORS*numpy.median(noisepsd,axis=0)**2.)**0.5/numpy.sqrt(psd1d[1][0:-3]), marker='None',ls='none',color='k') if False: interpindx= True-numpy.isnan(psd1d[1][0:-3]) interpspec= interpolate.InterpolatedUnivariateSpline(ks[interpindx], scale*numpy.sqrt(psd1d[1][0:-3])[interpindx], k=3) pks= numpy.linspace(ks[0],ks[-1],201) bovy_plot.bovy_plot(pks,interpspec(pks),'k-',overplot=True) #Simulations for the actual noise nnoise= _NNOISE noisepsd= numpy.empty((nnoise,len(psd1d[0])-3)) for ii in range(nnoise): newresv= numpy.random.normal(size=resv.shape)*resvunc noisepsd[ii,:]= bovy_psd.psd1d(newresv,dx,binsize=binsize)[1][0:-3] if _PLOTBAND: bovy_plot.bovy_plot(ks, scale*numpy.median(numpy.sqrt(noisepsd),axis=0), '-',lw=8.,zorder=9, color='0.65',overplot=True) return None
def determine_vsolar_mock(data,dfc,trueVsolar,spiral=False): #At the position of each real data point, generate a mock velocity data= create_mock_sample(data,dfc,trueVsolar,spiral=spiral) #Get velocity field pix= pixelize_sample.pixelXY(data, xmin=_RCXMIN,xmax=_RCXMAX, ymin=_RCYMIN,ymax=_RCYMAX, dx=_RCDX,dy=_RCDX) vsolars= numpy.linspace(0.,40.,51) lpower= large_scale_power(pix,vsolars,vc=220.,dx=_RCDX,beta=0.) p= numpy.polyfit(vsolars,lpower,2) minvsolar= -0.5*p[1]/p[0] return minvsolar
def plot_rcresidualkinematics(plotfilename,sbd10=False,vc=220.): #Read the APOGEE-RC data and pixelate it #APOGEE-RC data= apread.rcsample() if _ADDLLOGGCUT: data= data[data['ADDL_LOGG_CUT'] == 1] #Cut indx= (numpy.fabs(data['RC_GALZ']) < 0.25)*(data['METALS'] > -1000.) data= data[indx] #Get velocity field pixrc= pixelize_sample.pixelXY(data, xmin=_RCXMIN,xmax=_RCXMAX, ymin=_RCYMIN,ymax=_RCYMAX, dx=_RCDX,dy=_RCDX) bovy_plot.bovy_print() vmin, vmax= -16., 16. if sbd10: pixrc.plot(lambda x: dvlosgal(x,vc=vc,vtsun=vc+12.), zlabel=r'$\mathrm{median}\ \Delta V_{\mathrm{los,rot}}\,(\mathrm{km\,s}^{-1})$', vmin=vmin,vmax=vmax) pyplot.annotate(r'$V_c = %i\,\mathrm{km\,s}^{-1}, V_{\odot-c}= 12\,\mathrm{km\,s}^{-1}$' % vc, (0.5,1.1),xycoords='axes fraction', horizontalalignment='center', verticalalignment='top',size=18.) else: resv= pixrc.plot(lambda x: dvlosgal(x,vc=vc,vtsun=vc+24.), zlabel=r'$\mathrm{median}\ \Delta V_{\mathrm{los,rot}}\,(\mathrm{km\,s}^{-1})$', vmin=vmin,vmax=vmax,returnz=True) notNan= True-numpy.isnan(resv) print numpy.sum(notNan) print numpy.median(resv[notNan]) print 1.4826*numpy.median(numpy.fabs(resv[notNan]-numpy.median(resv[notNan]))) print numpy.mean(resv[notNan]) print numpy.std(resv[notNan]) pyplot.annotate(r'$V_c = %i\,\mathrm{km\,s}^{-1}, V_{\odot-c}= 24\,\mathrm{km\,s}^{-1}$' % vc, (0.5,1.1),xycoords='axes fraction', horizontalalignment='center', verticalalignment='top',size=18.) bovy_plot.bovy_end_print(plotfilename) return None
def plot_psd2d(plotfilename): data= apread.rcsample() if _ADDLLOGGCUT: data= data[data['ADDL_LOGG_CUT'] == 1] #Cut indx= (numpy.fabs(data['RC_GALZ']) < 0.25)*(data['METALS'] > -1000.) print "Using %i stars for low-Z 2D kinematics analysis" % numpy.sum(indx) data= data[indx] #Get residuals dx= _RCDX binsize= .8#.765 pix= pixelize_sample.pixelXY(data, xmin=_RCXMIN,xmax=_RCXMAX, ymin=_RCYMIN,ymax=_RCYMAX, dx=dx,dy=dx) resv= pix.plot(lambda x: dvlosgal(x,vtsun=220.+22.6), returnz=True,justcalc=True) resvunc= pix.plot('VHELIO_AVG', func=lambda x: 1.4826*numpy.median(numpy.fabs(x-numpy.median(x)))/numpy.sqrt(len(x)), returnz=True,justcalc=True) psd2d= bovy_psd.psd2d(resv) tmax= numpy.unravel_index(numpy.argmax(psd2d),psd2d.shape) tmax0= float(psd2d.shape[0]/2-tmax[0])/psd2d.shape[0]*2 tmax1= float(tmax[1]-psd2d.shape[1]/2)/psd2d.shape[1]*2 kmax= 1./_RCDX print tmax0*kmax, tmax1*kmax #kmax= numpy.amax(numpy.fft.fftfreq(resv.shape[0]*2,_RCDX)) bovy_plot.bovy_print() bovy_plot.bovy_dens2d(psd2d.T,origin='lower',cmap='jet', interpolation='nearest', xrange=[-kmax,kmax], yrange=[-kmax,kmax], xlabel=r'$k_x\,(\mathrm{kpc}^{-1})$', ylabel=r'$k_y\,(\mathrm{kpc}^{-1})$') bovy_plot.bovy_end_print(plotfilename) if True: spvlos= galpy_simulations.vlos('../sim/bar_rect_alpha0.015_hivres.sav')[1::2,1::2] potscale= 1.
def plot_2dkinematics(basesavefilename,datafilename=None): #Plot 2D los field #First read the sample if not datafilename is None: data= fitsio.read(datafilename) else: data= apread.rcsample() if _ADDLLOGGCUT: data= data[data['ADDL_LOGG_CUT'] == 1] #Cut indx= (numpy.fabs(data['RC_GALZ']) < 0.25)*(data['METALS'] > -1000.) print "Using %i stars for low-Z 2D kinematics analysis" % numpy.sum(indx) data= data[indx] pix= pixelize_sample.pixelXY(data) vmin, vmax= -75., 75. bovy_plot.bovy_print() pix.plot('VHELIO_AVG', zlabel=r'$\mathrm{median}\ V_{\mathrm{los}}\,(\mathrm{km\,s}^{-1})$', vmin=vmin,vmax=vmax) bovy_plot.bovy_text(r'$\mathrm{typical\ uncertainty\!:}\ 3\,\mathrm{km\,s}^{-1}$', bottom_left=True,size=18.) bovy_plot.bovy_text(r'$|Z| < 250\,\mathrm{pc}$',top_right=True,size=18.) bovy_plot.bovy_end_print(basesavefilename+'_XY.'+_EXT) #R,phi pix= pixelize_sample.pixelXY(data,rphi=True, ymin=-22.5,ymax=37.5, # dx=0.3,dy=2.) # dx=3.,dy=20.) dx=1.,dy=5.) bovy_plot.bovy_print() pix.plot('VHELIO_AVG', zlabel=r'$\mathrm{median}\ V_{\mathrm{los}}\,(\mathrm{km\,s}^{-1})$', vmin=vmin,vmax=vmax) #bovy_plot.bovy_text(r'$|Z| < 250\,\mathrm{pc}$',bottom_left=True,size=18.) bovy_plot.bovy_end_print(basesavefilename+'_RPHI.'+_EXT) #Plot the dispersion / sqrt(n) pix= pixelize_sample.pixelXY(data, dx=1.,dy=1.) bovy_plot.bovy_print() pix.plot('VHELIO_AVG', func=lambda x: 1.4826*numpy.median(numpy.fabs(x-numpy.median(x)))/numpy.sqrt(len(x)), zlabel=r'$\delta\ V_{\mathrm{los}}\,(\mathrm{km\,s}^{-1})$', vmin=0.,vmax=10.) #bovy_plot.bovy_text(r'$|Z| < 250\,\mathrm{pc}$',bottom_left=True,size=18.) bovy_plot.bovy_end_print(basesavefilename+'_RPHI_vlosunc.'+_EXT) #Plot the dispersion bovy_plot.bovy_print() pix.plot('VHELIO_AVG', func=lambda x: 1.4826*numpy.median(numpy.fabs(x-numpy.median(x))), zlabel=r'$\mathrm{MAD}\ V_{\mathrm{los}}\,(\mathrm{km\,s}^{-1})$', vmin=0.,vmax=40.) #bovy_plot.bovy_text(r'$|Z| < 250\,\mathrm{pc}$',bottom_left=True,size=18.) bovy_plot.bovy_end_print(basesavefilename+'_RPHI_vlosdisp.'+_EXT) #Now plot the los velocity corrected for the Solar motion #XY vmin, vmax= -250., 250. bovy_plot.bovy_print() resv= pix.plot(lambda x: vlosgal(x), zlabel=r'$\mathrm{median}\ V_{\mathrm{los,rot}}\,(\mathrm{km\,s}^{-1})$', vmin=vmin,vmax=vmax,returnz=True) bovy_plot.bovy_end_print(basesavefilename+'_Vrot_XY.'+_EXT) pix= pixelize_sample.pixelXY(data,rphi=True, ymin=-22.5,ymax=37.5, dx=1.,dy=5.) #R,phi vmin, vmax= -250., 250. bovy_plot.bovy_print() resv= pix.plot(lambda x: vlosgal(x), zlabel=r'$\mathrm{median}\ V_{\mathrm{los,rot}}\,(\mathrm{km\,s}^{-1})$', vmin=vmin,vmax=vmax,returnz=True) #Plot tangent point rs= numpy.linspace(6.,8.,101) bovy_plot.bovy_plot(rs,numpy.arccos(rs/8.)*180./numpy.pi,'k--',lw=2., overplot=True) bovy_plot.bovy_plot(rs,-numpy.arccos(rs/8.)*180./numpy.pi,'k--',lw=2., overplot=True) bovy_plot.bovy_end_print(basesavefilename+'_Vrot_RPHI.'+_EXT) #Now plot the residuals wrt the Bovy et al. (2012) disk model #R,phi vmin, vmax= -20., 20. bovy_plot.bovy_print() resv= pix.plot(lambda x: dvlosgal(x,beta=0.,vc=220.), zlabel=r'$\mathrm{median}\ \Delta V_{\mathrm{los}}\,(\mathrm{km\,s}^{-1})$', vmin=vmin,vmax=vmax,returnz=True) medindx= True-numpy.isnan(resv) meanresv= numpy.mean(resv[medindx]) sigresv= numpy.std(resv[medindx]) bovy_plot.bovy_text(r'$\mathrm{Residual} = %.1f \pm %.1f / %i\,\mathrm{km\,s}^{-1}$' % (meanresv,sigresv,round(numpy.sqrt(numpy.sum(medindx)))), top_left=True,size=16.) bovy_plot.bovy_end_print(basesavefilename+'_dVBovy12_RPHI.'+_EXT) #XY pixXY= pixelize_sample.pixelXY(data, xmin=5.,xmax=13, ymin=-3.,ymax=4., dx=1.,dy=1.) vmin, vmax= -20., 20. bovy_plot.bovy_print() pixXY.plot(lambda x: dvlosgal(x,beta=0.,vc=220.), zlabel=r'$\mathrm{median}\ \Delta V_{\mathrm{los}}\,(\mathrm{km\,s}^{-1})$', vmin=vmin,vmax=vmax,returnz=False) medindx= True-numpy.isnan(resv) meanresv= numpy.mean(resv[medindx]) sigresv= numpy.std(resv[medindx]) bovy_plot.bovy_text(r'$\mathrm{Residual} = %.1f \pm %.1f / %i\,\mathrm{km\,s}^{-1}$' % (meanresv,sigresv,round(numpy.sqrt(numpy.sum(medindx)))), top_left=True,size=16.) bovy_plot.bovy_end_print(basesavefilename+'_dVBovy12_XY.'+_EXT) #Plot a histogram of the residuals bovy_plot.bovy_print() bovy_plot.bovy_hist(resv[medindx],color='k',bins=11,xrange=[-25.,25.], yrange=[0.,15.], histtype='step',normed=False, xlabel=r'$\mathrm{median}\ \Delta V_{\mathrm{los}}\,(\mathrm{km\,s}^{-1})$') xs= numpy.linspace(-25.,25.,1001) bovy_plot.bovy_plot(xs, 50./11.*numpy.sum(medindx)/numpy.sqrt(2.*numpy.pi)/sigresv\ *numpy.exp(-0.5*(xs-meanresv)**2./sigresv**2.), 'k-',lw=2,overplot=True) bovy_plot.bovy_end_print(basesavefilename+'_dVBovy12_hist.'+_EXT) #Now plot the residuals wrt the Bovy et al. (2012) disk model w/ Vc-240 and standard solar motion #R,phi vmin, vmax= -20., 20. bovy_plot.bovy_print() resv= pix.plot(lambda x: dvlosgal(x,beta=0.,vc=240.,vtsun=252.), zlabel=r'$\mathrm{median}\ \Delta V_{\mathrm{los}}\,(\mathrm{km\,s}^{-1})$', vmin=vmin,vmax=vmax,returnz=True) medindx= True-numpy.isnan(resv) #bovy_plot.bovy_text(r'$\mathrm{Residual} = %.1f \pm %.1f / %i\,\mathrm{km\,s}^{-1}$' % (numpy.median(resv[medindx]),numpy.median(numpy.fabs(resv[medindx]-numpy.median(resv[medindx])))*1.4826,round(numpy.sqrt(numpy.sum(medindx)))), # top_left=True,size=16.) bovy_plot.bovy_end_print(basesavefilename+'_dVBovy12Vc240VsSBD_RPHI.'+_EXT) #Now plot the residuals wrt the Bovy et al. (2012) disk model w/ Vc-220 and standard solar motion #R,phi vmin, vmax= -20., 20. bovy_plot.bovy_print() resv= pix.plot(lambda x: dvlosgal(x,beta=0.,vc=220.,vtsun=232.), zlabel=r'$\mathrm{median}\ \Delta V_{\mathrm{los}}\,(\mathrm{km\,s}^{-1})$', vmin=vmin,vmax=vmax,returnz=True) medindx= True-numpy.isnan(resv) # bovy_plot.bovy_text(r'$\mathrm{Residual} = %.1f \pm %.1f / %i\,\mathrm{km\,s}^{-1}$' % (numpy.median(resv[medindx]),numpy.median(numpy.fabs(resv[medindx]-numpy.median(resv[medindx])))*1.4826,round(numpy.sqrt(numpy.sum(medindx)))), # top_left=True,size=16.) bovy_plot.bovy_end_print(basesavefilename+'_dVBovy12Vc220VsSBD_RPHI.'+_EXT) #FFT dx= 1. pix= pixelize_sample.pixelXY(data, xmin=5.,xmax=13, ymin=-3.,ymax=4., dx=dx,dy=dx) resv= pix.plot(lambda x: dvlosgal(x), zlabel=r'$\mathrm{median}\ \Delta V_{\mathrm{los}}\,(\mathrm{km\,s}^{-1})$', vmin=vmin,vmax=vmax,returnz=True) resvunc= pix.plot('VHELIO_AVG', func=lambda x: 1.4826*numpy.median(numpy.fabs(x-numpy.median(x)))/numpy.sqrt(len(x)), zlabel=r'$\delta\ V_{\mathrm{los}}\,(\mathrm{km\,s}^{-1})$', vmin=0.,vmax=10.,returnz=True) import psds binsize= 1.5 psd2d= psds.power_spectrum(resv, binsize=binsize,wavenumber=True) #Simulate the noise newresv= numpy.random.normal(size=resv.shape)*resvunc newresvuni= numpy.random.normal(size=resv.shape)*5. psd2dnoise= psds.power_spectrum(newresv, binsize=binsize,wavenumber=True) psd2duni= psds.power_spectrum(newresvuni, binsize=binsize,wavenumber=True) bovy_plot.bovy_print() ks= psd2d[0][1:]/dx bovy_plot.bovy_plot(ks,numpy.sqrt(psd2d[1]/numpy.prod(resv.shape)/16.\ /(ks[1]-ks[0]))[1:],'ko-', xlabel=r'$k\,(\mathrm{kpc}^{-1})$', ylabel=r'$\sqrt{P_k}\,(\mathrm{km\,s}^{-1}\,\mathrm{kpc}^{1/2})$', xrange=[0.,1./dx/2.], yrange=[0.,10.], semilogy=False) bovy_plot.bovy_plot(ks,numpy.sqrt(psd2dnoise[1]/numpy.prod(resv.shape)/16.\ /(ks[1]-ks[0]))[1:], '-',color='0.5',overplot=True,lw=2.) bovy_plot.bovy_plot(ks,numpy.sqrt(psd2duni[1]/numpy.prod(resv.shape)/16.\ /(ks[1]-ks[0]))[1:], '-',color='b',overplot=True,lw=2.) bovy_plot.bovy_end_print(basesavefilename+'_FFTPSD.'+_EXT) return None
def plot_rckinematics(plotfilename,subsun=False): #Set up 3 axes bovy_plot.bovy_print(fig_width=8.,axes_labelsize=14) axdx= 1./3. #APOGEE-RC observations tdy= (_RCYMAX-_RCYMIN+4.5)/(_RCXMAX-_RCXMIN+4.5)*axdx obsAxes= pyplot.axes([0.1,(1.-tdy)/2.,axdx,tdy]) pyplot.sca(obsAxes) data= apread.rcsample() if _ADDLLOGGCUT: data= data[data['ADDL_LOGG_CUT'] == 1] #Cut indx= (numpy.fabs(data['RC_GALZ']) < 0.25)*(data['METALS'] > -1000.) data= data[indx] #Get velocity field pixrc= pixelize_sample.pixelXY(data, xmin=_RCXMIN-2.25,xmax=_RCXMAX+2.25, ymin=_RCYMIN-2.25,ymax=_RCYMAX+2.25, dx=_RCDX,dy=_RCDX) if subsun: vmin, vmax= 0., 250. pixrc.plot(lambda x: vlosgal(x), func=lambda x: numpy.fabs(numpy.median(x)), zlabel=r'$|\mathrm{median}\ V^{\mathrm{GC}}_{\mathrm{los}}|\,(\mathrm{km\,s}^{-1})$', vmin=vmin,vmax=vmax) else: vmin, vmax= -75., 75. img= pixrc.plot('VHELIO_AVG', vmin=vmin,vmax=vmax,overplot=True, colorbar=False) resv= pixrc.plot('VHELIO_AVG', justcalc=True,returnz=True) #for later bovy_plot.bovy_text(r'$\mathrm{typical\ uncertainty\!:}\ 3\,\mathrm{km\,s}^{-1}$', bottom_left=True,size=8.25) bovy_plot.bovy_text(r'$|Z| < 250\,\mathrm{pc}$',top_right=True,size=10.) pyplot.annotate(r'$\mathrm{APOGEE\!-\!RC\ data}$', (0.5,1.09),xycoords='axes fraction', horizontalalignment='center', verticalalignment='top',size=10.) pyplot.axis([pixrc.xmin,pixrc.xmax,pixrc.ymin,pixrc.ymax]) bovy_plot._add_ticks() bovy_plot._add_axislabels(r'$X_{\mathrm{GC}}\,(\mathrm{kpc})$', r'$Y_{\mathrm{GC}}\,(\mathrm{kpc})$') #Colorbar cbaxes = pyplot.axes([0.1625,(1.-tdy)/2.+tdy+0.065,2.*axdx-0.195,0.02]) CB1= pyplot.colorbar(img,orientation='horizontal', cax=cbaxes)#,ticks=[-16.,-8.,0.,8.,16.]) CB1.set_label(r'$\mathrm{median}\ V_{\mathrm{los}}\,(\mathrm{km\,s}^{-1})$',labelpad=-35,fontsize=14.) #Now calculate the expected field xgrid= numpy.arange(_RCXMIN-2.25+_RCDX/2.,_RCXMAX+2.25+_RCDX/2.,_RCDX) ygrid= numpy.arange(_RCYMIN-2.25+_RCDX/2.,_RCYMAX+2.25+_RCDX/2.,_RCDX) xv,yv= numpy.meshgrid(xgrid,ygrid,indexing='ij') rs= numpy.sqrt(xv**2.+yv**2.) phis= numpy.arctan2(yv,xv) d,l= bovy_coords.rphi_to_dl_2d(rs/8.,phis) expec_vlos= numpy.empty((len(xgrid),len(ygrid))) for ii in range(len(xgrid)): for jj in range(len(ygrid)): expec_vlos[ii,jj]= modelvlosgal(rs[ii,jj],phis[ii,jj],l[ii,jj], vc=218.,vtsun=242.) modelAxes= pyplot.axes([0.03+axdx,(1.-tdy)/2.,axdx,tdy]) pyplot.sca(modelAxes) xlabel=r'$X_{\mathrm{GC}}\,(\mathrm{kpc})$' ylabel=r'$Y_{\mathrm{GC}}\,(\mathrm{kpc})$' indx= True-numpy.isnan(resv) plotthis= copy.copy(expec_vlos) plotthis[numpy.isnan(resv)]= numpy.nan #turn these off bovy_plot.bovy_dens2d(plotthis.T,origin='lower',cmap='jet', interpolation='nearest', xlabel=xlabel,ylabel=ylabel, xrange=[_RCXMIN-2.25,_RCXMAX+2.25], yrange=[_RCYMIN-2.25,_RCYMAX+2.25], contours=False, vmin=vmin,vmax=vmax,overplot=True,zorder=3) if True: #Now plot the pixels outside the APOGEE data set plotthis= copy.copy(expec_vlos) plotthis[True-numpy.isnan(resv)]= numpy.nan #turn these off bovy_plot.bovy_dens2d(plotthis.T,origin='lower',cmap='jet', interpolation='nearest', alpha=0.3, xrange=[_RCXMIN-2.25,_RCXMAX+2.25], yrange=[_RCYMIN-2.25,_RCYMAX+2.25], contours=False, vmin=vmin,vmax=vmax,overplot=True, zorder=0) pyplot.annotate(r'$\mathrm{Bovy\ et.\ al\ (2012)\ model}$', (1.02,1.09),xycoords='axes fraction', horizontalalignment='center', verticalalignment='top',size=10.,zorder=3) pyplot.axis([_RCXMIN-2.25,_RCXMAX+2.25,_RCYMIN-2.25,_RCYMAX+2.25]) bovy_plot._add_ticks() bovy_plot._add_axislabels(xlabel,r'$ $') #Finally, add a polar plot of the whole disk res= 51 rmin, rmax= 0.2, 2.4 xgrid= numpy.linspace(0.,2.*numpy.pi*(1.-1./res/2.), 2.*res) ygrid= numpy.linspace(rmin,rmax,res) nx= len(xgrid) ny= len(ygrid) savefile= 'expec_vlos.sav' if os.path.exists(savefile): savefile= open(savefile,'rb') expec_vlos= pickle.load(savefile) savefile.close() else: expec_vlos= numpy.zeros((nx,ny)) for ii in range(nx): for jj in range(ny): R, phi= ygrid[jj], xgrid[ii] d,l= bovy_coords.rphi_to_dl_2d(R,phi) expec_vlos[ii,jj]= modelvlosgal(R*8.,phi,l, vc=218.,vtsun=242.) save_pickles(savefile,expec_vlos) plotxgrid= numpy.linspace(xgrid[0]-(xgrid[1]-xgrid[0])/2., xgrid[-1]+(xgrid[1]-xgrid[0])/2., len(xgrid)+1) plotygrid= numpy.linspace(ygrid[0]-(ygrid[1]-ygrid[0])/2., ygrid[-1]+(ygrid[1]-ygrid[0])/2., len(ygrid)+1) fullmodelAxes= pyplot.axes([-0.05+2.*axdx,(1.-tdy)/2.,axdx,tdy],polar=True) ax= fullmodelAxes pyplot.sca(fullmodelAxes) vmin, vmax= -150., 150. zlabel= r'$\mathrm{line\!-\!of\!-\!sight\ velocity}\ (\mathrm{km\,s}^{-1})$' out= ax.pcolor(plotxgrid,plotygrid,expec_vlos.T,cmap='jet', vmin=vmin,vmax=vmax,clip_on=False) shrink= 0.8 if False: CB1= pyplot.colorbar(out,shrink=shrink) bbox = CB1.ax.get_position().get_points() CB1.ax.set_position(transforms.Bbox.from_extents(bbox[0,0]+0.025, bbox[0,1], bbox[1,0], bbox[1,1])) CB1.set_label(zlabel) from matplotlib.patches import FancyArrowPatch arr= FancyArrowPatch(posA=(numpy.pi+0.1,1.8), posB=(3*numpy.pi/2.+0.1,1.8), arrowstyle='->', connectionstyle='arc3,rad=%4.2f' % (numpy.pi/8.-0.05), shrinkA=2.0, shrinkB=2.0, mutation_scale=20.0, mutation_aspect=None,fc='k') ax.add_patch(arr) bovy_plot.bovy_text(numpy.pi+0.17,1.7,r'$\mathrm{Galactic\ rotation}$', rotation=-30.,size=9.) radii= numpy.array([0.5,1.,1.5,2.,2.5]) labels= [] for r in radii: ax.plot(numpy.linspace(0.,2.*numpy.pi,501,), numpy.zeros(501)+r,ls='-',color='0.65',zorder=1,lw=0.5) labels.append(r'$%i$' % int(r*8.)) pyplot.rgrids(radii,labels=labels,angle=147.5) thetaticks = numpy.arange(0,360,45) # set ticklabels location at x times the axes' radius ax.set_thetagrids(thetaticks,frac=1.16,backgroundcolor='w',zorder=3) bovy_plot.bovy_text(3.*numpy.pi/4.+0.06,2.095,r'$\mathrm{kpc}$',size=10.) pyplot.ylim(0.,2.8) #Plot the box xs= numpy.linspace(_RCXMIN-2.25,_RCXMAX+2.25,101) ys= numpy.ones(101)*(_RCYMIN-2.25) rs= numpy.sqrt(xs**2.+ys**2.)/8. phis= numpy.arctan2(ys,xs) ax.plot(phis,rs,'--',lw=1.25,color='k') #Plot the box xs= numpy.linspace(_RCXMIN-2.25,_RCXMAX+2.25,101) ys= numpy.ones(101)*(_RCYMAX+2.25) rs= numpy.sqrt(xs**2.+ys**2.)/8. phis= numpy.arctan2(ys,xs) ax.plot(phis,rs,'--',lw=1.25,color='k') #Plot the box ys= numpy.linspace(_RCYMIN-2.25,_RCYMAX+2.25,101) xs= numpy.ones(101)*(_RCXMIN-2.25) rs= numpy.sqrt(xs**2.+ys**2.)/8. phis= numpy.arctan2(ys,xs) ax.plot(phis,rs,'--',lw=1.25,color='k') #Plot the box ys= numpy.linspace(_RCYMIN-2.25,_RCYMAX+2.25,101) xs= numpy.ones(101)*(_RCXMAX+2.25) rs= numpy.sqrt(xs**2.+ys**2.)/8. phis= numpy.arctan2(ys,xs) ax.plot(phis,rs,'--',lw=1.25,color='k') #Plot the connectors on the modelAxes xlow=-4.*8. ylow= 2.77*8. xs= numpy.linspace(xlow,(_RCXMAX+2.25),101) ys= (ylow-(_RCYMAX+2.25))/(xlow-(_RCXMAX+2.25))*(xs-xlow)+ylow rs= numpy.sqrt(xs**2.+ys**2.)/8. phis= numpy.arctan2(ys,xs) line= ax.plot(phis,rs,':',lw=1.,color='k',zorder=2) line[0].set_clip_on(False) xlow=-4.*8. ylow= -2.77*8. xs= numpy.linspace(xlow,(_RCXMAX+2.25),101) ys= (ylow-(_RCYMIN-2.25))/(xlow-(_RCXMAX+2.25))*(xs-xlow)+ylow rs= numpy.sqrt(xs**2.+ys**2.)/8. phis= numpy.arctan2(ys,xs) line= ax.plot(phis,rs,':',lw=1.,color='k',zorder=2) line[0].set_clip_on(False) #Colorbar cbaxes = pyplot.axes([0.01+2.*axdx,(1.-tdy)/2.+tdy+0.065,axdx-0.125,0.02]) CB1= pyplot.colorbar(out,orientation='horizontal', cax=cbaxes,ticks=[-150.,-75.,0.,75.,150.]) #CB1.set_label(r'$\mathrm{median}\ V_{\mathrm{los}}\,(\mathrm{km\,s}^{-1})$',labelpad=-35,fontsize=14.) bovy_plot.bovy_end_print(plotfilename,dpi=300) return None
def plot_rckinematics(plotfilename,subsun=False): #Set up 3 axes bovy_plot.bovy_print(fig_width=8.,axes_labelsize=14) axdx= 1./3. #APOGEE-RC observations tdy= (_RCYMAX-_RCYMIN+4.5)/(_RCXMAX-_RCXMIN+4.5)*axdx obsAxes= pyplot.axes([0.1,(1.-tdy)/2.,axdx,tdy]) pyplot.sca(obsAxes) data= apread.rcsample() if _ADDLLOGGCUT: data= data[data['ADDL_LOGG_CUT'] == 1] #Cut indx= (numpy.fabs(data['RC_GALZ']) < 0.25)*(data['METALS'] > -1000.) data= data[indx] #Get velocity field pixrc= pixelize_sample.pixelXY(data, xmin=_RCXMIN-2.25,xmax=_RCXMAX+2.25, ymin=_RCYMIN-2.25,ymax=_RCYMAX+2.25, dx=_RCDX,dy=_RCDX) vmin, vmax= -16.,16. img= pixrc.plot(lambda x: dvlosgal(x,vtsun=220.+24.), vmin=vmin,vmax=vmax,overplot=True, colorbar=False) resv= pixrc.plot(lambda x: dvlosgal(x,vtsun=220.+24.), justcalc=True,returnz=True) #for later pyplot.annotate(r'$\mathrm{APOGEE\!-\!RC\ data}$', (0.5,1.09),xycoords='axes fraction', horizontalalignment='center', verticalalignment='top',size=10.) pyplot.axis([pixrc.xmin,pixrc.xmax,pixrc.ymin,pixrc.ymax]) bovy_plot._add_ticks() bovy_plot._add_axislabels(r'$X_{\mathrm{GC}}\,(\mathrm{kpc})$', r'$Y_{\mathrm{GC}}\,(\mathrm{kpc})$') #Colorbar cbaxes = pyplot.axes([0.1+axdx/2.,(1.-tdy)/2.+tdy+0.065,2.*axdx-0.195,0.02]) CB1= pyplot.colorbar(img,orientation='horizontal', cax=cbaxes)#,ticks=[-16.,-8.,0.,8.,16.]) CB1.set_label(r'$\mathrm{median}\ \Delta V_{\mathrm{los,rot}}\,(\mathrm{km\,s}^{-1})$',labelpad=-35,fontsize=14.) #Now calculate the expected field expec_vlos= galpy_simulations.vlos_altrect('../sim/bar_altrect_alpha0.015_hivres.sav')*220. modelAxes= pyplot.axes([0.03+axdx,(1.-tdy)/2.,axdx,tdy]) pyplot.sca(modelAxes) xlabel=r'$X_{\mathrm{GC}}\,(\mathrm{kpc})$' ylabel=r'$Y_{\mathrm{GC}}\,(\mathrm{kpc})$' indx= True-numpy.isnan(resv) plotthis= copy.copy(expec_vlos) plotthis[numpy.isnan(resv)]= numpy.nan #turn these off bovy_plot.bovy_dens2d(plotthis.T,origin='lower',cmap='jet', interpolation='nearest', xlabel=xlabel,ylabel=ylabel, xrange=[_RCXMIN-2.25,_RCXMAX+2.25], yrange=[_RCYMIN-2.25,_RCYMAX+2.25], contours=False, vmin=vmin,vmax=vmax,overplot=True,zorder=3) if True: #Now plot the pixels outside the APOGEE data set plotthis= copy.copy(expec_vlos) plotthis[True-numpy.isnan(resv)]= numpy.nan #turn these off bovy_plot.bovy_dens2d(plotthis.T,origin='lower',cmap='jet', interpolation='nearest', alpha=0.3, xrange=[_RCXMIN-2.25,_RCXMAX+2.25], yrange=[_RCYMIN-2.25,_RCYMAX+2.25], contours=False, vmin=vmin,vmax=vmax,overplot=True, zorder=0) pyplot.annotate(r'$\mathrm{Favored\ bar\ model}$', (1.02,1.09),xycoords='axes fraction', horizontalalignment='center', verticalalignment='top',size=10.,zorder=3) pyplot.axis([_RCXMIN-2.25,_RCXMAX+2.25,_RCYMIN-2.25,_RCYMAX+2.25]) bovy_plot._add_ticks() bovy_plot._add_axislabels(xlabel,r'$ $') #Finally, add a polar plot of the whole disk res= 51 rmin, rmax= 0.2, 2.4 xgrid= numpy.linspace(0.,2.*numpy.pi*(1.-1./res/2.), 2.*res) ygrid= numpy.linspace(rmin,rmax,res) expec_vlos= galpy_simulations.vlos_polar('../sim/bar_polar_alpha0.015_hivres.sav')*220. plotxgrid= numpy.linspace(xgrid[0]-(xgrid[1]-xgrid[0])/2., xgrid[-1]+(xgrid[1]-xgrid[0])/2., len(xgrid)+1) plotygrid= numpy.linspace(ygrid[0]-(ygrid[1]-ygrid[0])/2., ygrid[-1]+(ygrid[1]-ygrid[0])/2., len(ygrid)+1) fullmodelAxes= pyplot.axes([-0.05+2.*axdx,(1.-tdy)/2.,axdx,tdy],polar=True) ax= fullmodelAxes pyplot.sca(fullmodelAxes) out= ax.pcolor(plotxgrid,plotygrid,expec_vlos.T,cmap='jet', vmin=vmin,vmax=vmax,clip_on=False) from matplotlib.patches import FancyArrowPatch arr= FancyArrowPatch(posA=(numpy.pi+0.1,1.8), posB=(3*numpy.pi/2.+0.1,1.8), arrowstyle='->', connectionstyle='arc3,rad=%4.2f' % (numpy.pi/8.-0.05), shrinkA=2.0, shrinkB=2.0, mutation_scale=20.0, mutation_aspect=None,fc='k',zorder=10) ax.add_patch(arr) bovy_plot.bovy_text(numpy.pi+0.17,1.7,r'$\mathrm{Galactic\ rotation}$', rotation=-30.,size=9.) radii= numpy.array([0.5,1.,1.5,2.,2.5]) labels= [] for r in radii: ax.plot(numpy.linspace(0.,2.*numpy.pi,501,), numpy.zeros(501)+r,ls='-',color='0.65',zorder=1,lw=0.5) labels.append(r'$%i$' % int(r*8.)) pyplot.rgrids(radii,labels=labels,angle=147.5) thetaticks = numpy.arange(0,360,45) # set ticklabels location at x times the axes' radius ax.set_thetagrids(thetaticks,frac=1.16,backgroundcolor='w',zorder=3) bovy_plot.bovy_text(3.*numpy.pi/4.+0.06,2.095,r'$\mathrm{kpc}$',size=10.) pyplot.ylim(0.,2.8) # Plot the bar position ets= numpy.linspace(0.,2.*numpy.pi,501,) a= 0.421766 b= a*0.4 dtr= numpy.pi/180. ax.plot(ets, a*b/numpy.sqrt((b*numpy.cos(ets-25.*dtr))**2. +(a*numpy.sin(ets-25.*dtr))**2.), zorder=1,lw=1.5,color='w') #Plot the box xs= numpy.linspace(_RCXMIN-2.25,_RCXMAX+2.25,101) ys= numpy.ones(101)*(_RCYMIN-2.25) rs= numpy.sqrt(xs**2.+ys**2.)/8. phis= numpy.arctan2(ys,xs) ax.plot(phis,rs,'--',lw=1.25,color='k') #Plot the box xs= numpy.linspace(_RCXMIN-2.25,_RCXMAX+2.25,101) ys= numpy.ones(101)*(_RCYMAX+2.25) rs= numpy.sqrt(xs**2.+ys**2.)/8. phis= numpy.arctan2(ys,xs) ax.plot(phis,rs,'--',lw=1.25,color='k') #Plot the box ys= numpy.linspace(_RCYMIN-2.25,_RCYMAX+2.25,101) xs= numpy.ones(101)*(_RCXMIN-2.25) rs= numpy.sqrt(xs**2.+ys**2.)/8. phis= numpy.arctan2(ys,xs) ax.plot(phis,rs,'--',lw=1.25,color='k') #Plot the box ys= numpy.linspace(_RCYMIN-2.25,_RCYMAX+2.25,101) xs= numpy.ones(101)*(_RCXMAX+2.25) rs= numpy.sqrt(xs**2.+ys**2.)/8. phis= numpy.arctan2(ys,xs) ax.plot(phis,rs,'--',lw=1.25,color='k') #Plot the connectors on the modelAxes xlow=-4.*8. ylow= 2.77*8. xs= numpy.linspace(xlow,(_RCXMAX+2.25),101) ys= (ylow-(_RCYMAX+2.25))/(xlow-(_RCXMAX+2.25))*(xs-xlow)+ylow rs= numpy.sqrt(xs**2.+ys**2.)/8. phis= numpy.arctan2(ys,xs) line= ax.plot(phis,rs,':',lw=1.,color='k',zorder=2) line[0].set_clip_on(False) xlow=-4.*8. ylow= -2.77*8. xs= numpy.linspace(xlow,(_RCXMAX+2.25),101) ys= (ylow-(_RCYMIN-2.25))/(xlow-(_RCXMAX+2.25))*(xs-xlow)+ylow rs= numpy.sqrt(xs**2.+ys**2.)/8. phis= numpy.arctan2(ys,xs) line= ax.plot(phis,rs,':',lw=1.,color='k',zorder=2) line[0].set_clip_on(False) bovy_plot.bovy_end_print(plotfilename,dpi=300) return None
def plot_psd(plotfilename): data= apread.rcsample() if _ADDLLOGGCUT: data= data[data['ADDL_LOGG_CUT'] == 1] #Cut indx= (numpy.fabs(data['RC_GALZ']) < 0.25)*(data['METALS'] > -1000.) print "Using %i stars for low-Z 2D kinematics analysis" % numpy.sum(indx) data= data[indx] #Get residuals dx= _RCDX binsize= .8#.765 pix= pixelize_sample.pixelXY(data, xmin=_RCXMIN,xmax=_RCXMAX, ymin=_RCYMIN,ymax=_RCYMAX, dx=dx,dy=dx) resv= pix.plot(lambda x: dvlosgal(x,vtsun=220.+22.5), returnz=True,justcalc=True) resvunc= pix.plot('VHELIO_AVG', func=lambda x: 1.4826*numpy.median(numpy.fabs(x-numpy.median(x)))/numpy.sqrt(len(x)), returnz=True,justcalc=True) psd1d= bovy_psd.psd1d(resv,dx,binsize=binsize) print psd1d #Simulations for constant 3.25 km/s nnoise= _NNOISE noisepsd= numpy.empty((nnoise,len(psd1d[0])-4)) for ii in range(nnoise): newresv= numpy.random.normal(size=resv.shape)*3.25 noisepsd[ii,:]= bovy_psd.psd1d(newresv,dx,binsize=binsize)[1][1:-3] scale= 4.*numpy.pi#3.25/numpy.median(numpy.sqrt(noisepsd)) print scale #Simulations for the actual noise nnoise= _NNOISE noisepsd= numpy.empty((nnoise,len(psd1d[0])-4)) for ii in range(nnoise): newresv= numpy.random.normal(size=resv.shape)*resvunc noisepsd[ii,:]= bovy_psd.psd1d(newresv,dx,binsize=binsize)[1][1:-3] ks= psd1d[0][1:-3] if _ADDGCS: xrange=[.03,110.] else: xrange= [0.,1.] yrange= [0.,11.9] if _PROPOSAL: bovy_plot.bovy_print(fig_width=7.5,fig_height=3.) else: bovy_plot.bovy_print(fig_width=7.5,fig_height=4.5) apop= bovy_plot.bovy_plot(ks,scale*numpy.sqrt(psd1d[1][1:-3] -_SUBTRACTERRORS*numpy.median(noisepsd,axis=0)), 'ko',lw=2., zorder=12, xlabel=r'$k\,(\mathrm{kpc}^{-1})$', ylabel=r'$\sqrt{P_k}\,(\mathrm{km\,s}^{-1})$', semilogx=_ADDGCS, xrange=xrange,yrange=yrange) if _DUMP2FILE: with open('bovy-apogee-psd.dat','w') as csvfile: writer= csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL) csvfile.write('#APOGEE\n') for ii in range(len(ks)): writer.writerow([ks[ii], (scale*numpy.sqrt(psd1d[1][1:-3]-_SUBTRACTERRORS*numpy.median(noisepsd,axis=0)))[ii], (scale*0.5*(psd1d[2][1:-3]**2.+_SUBTRACTERRORS*numpy.median(noisepsd,axis=0)**2.)**0.5/numpy.sqrt(psd1d[1][1:-3]))[ii]]) if _PROPOSAL: pyplot.gcf().subplots_adjust(bottom=0.15) pyplot.errorbar(ks,scale*numpy.sqrt(psd1d[1][1:-3]-_SUBTRACTERRORS*numpy.median(noisepsd,axis=0)), yerr=scale*0.5*(psd1d[2][1:-3]**2. +_SUBTRACTERRORS*numpy.median(noisepsd,axis=0)**2.)**0.5/numpy.sqrt(psd1d[1][1:-3]), marker='None',ls='none',color='k') if _PLOTBAND: # bovy_plot.bovy_plot(ks, # scale*numpy.median(numpy.sqrt(noisepsd),axis=0), # '--',lw=2.,zorder=10, # color='0.85',overplot=True) # bovy_plot.bovy_plot(ks, # scale*numpy.sqrt(numpy.sort(noisepsd # -_SUBTRACTERRORS*numpy.median(noisepsd,axis=0),axis=0)[int(numpy.floor(0.99*_NNOISE)),:]), # zorder=1,ls='--',overplot=True, # color='0.65') pyplot.fill_between(ks, scale*numpy.sqrt(numpy.sort(noisepsd -_SUBTRACTERRORS*numpy.median(noisepsd,axis=0),axis=0)[int(numpy.floor(_SIGNIF*_NNOISE)),:]), zorder=0, color='0.65') #Add a simple model of a spiral potential if _ADDSIMPLESPIRAL: if False: alpha= -12.5 spvlos= simulate_vlos_spiral(alpha=alpha, gamma=1.2, xmin=_RCXMIN,xmax=_RCXMAX, ymin=_RCYMIN,ymax=_RCYMAX, dx=0.01) potscale= 1.35*1.2 print numpy.arctan(2./alpha)/numpy.pi*180., numpy.sqrt(0.035/numpy.fabs(alpha)/2.)*potscale*220., numpy.sqrt(0.035/numpy.fabs(alpha))*potscale*220. simpsd1d= bovy_psd.psd1d(spvlos*220.*potscale,0.01,binsize=binsize) tks= simpsd1d[0][1:-3] bovy_plot.bovy_plot(tks, scale*numpy.sqrt(simpsd1d[1][1:-3]), 'k--',lw=2.,overplot=True) #A better simulation # spvlos= galpy_simulations.vlos('../sim/spiral_rect_omegas0.33_alpha-14.sav') spvlos= galpy_simulations.vlos('../sim/bar_rect_alpha0.015_hivres.sav') potscale= 1. simpsd1d= bovy_psd.psd1d(spvlos*220.*potscale,0.33333333,binsize=binsize) tks= simpsd1d[0][1:-3] # alpha=-14. # print numpy.arctan(2./-14.)/numpy.pi*180., numpy.sqrt(0.075/numpy.fabs(alpha)/2.)*potscale*220., numpy.sqrt(0.075/numpy.fabs(alpha))*potscale*220. line1= bovy_plot.bovy_plot(tks, scale*numpy.sqrt(simpsd1d[1][1:-3]), 'k--',lw=2.,overplot=True) if _DUMP2FILE: with open('bovy-bar-psd.dat','w') as csvfile: writer= csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL) for ii in range(len(ks)): writer.writerow([tks[ii],(scale*numpy.sqrt(simpsd1d[1][1:-3]))[ii]]) #bovy_plot.bovy_plot(tks[tks > 0.7], # scale*numpy.sqrt(simpsd1d[1][1:-3][tks > 0.7]+4./scale**2.*(1.-numpy.tanh(-(tks[tks > 0.7]-0.9)/0.1))/2.), # 'k-.',lw=2.,overplot=True) #line2= bovy_plot.bovy_plot(tks, # scale*numpy.sqrt(simpsd1d[1][1:-3]+4./scale**2.), # 'k-.',lw=2.,overplot=True,dashes=(10,5,3,5)) l1= pyplot.legend((line1[0],), # (r'$\mathrm{Spiral}:\ \delta \phi_{\mathrm{rms}} = (10\,\mathrm{km\,s}^{-1})^2,$'+'\n'+r'$\mathrm{pitch\ angle} = 8^\circ$'+'\n'+r'$\mathrm{Sun\ near\ 2\!:\!1\ Lindblad\ resonance}$',), (r'$\mathrm{Bar}:\ F_{R,\mathrm{bar}} / F_{R,\mathrm{axi}} = 1.5\%,$'+'\n'+r'$\mathrm{angle} = 25^\circ,$'+'\n'+r'$\mathrm{Sun\ near\ 2\!:\!1\ Lindblad\ resonance}$',), loc='upper right',#bbox_to_anchor=(.91,.375), numpoints=8, prop={'size':14}, frameon=False) #Add the lopsided and ellipticity constraints from Rix/Zaritsky if _ADDRIX: pyplot.errorbar([1./16.],[5.6], yerr=[5.6/2.], marker='d',color='0.6', mew=1.5,mfc='none',mec='0.6') pyplot.errorbar([1./8./numpy.sqrt(2.)],[6.4], yerr=numpy.reshape(numpy.array([6.4/0.045*0.02,6.4/0.045*0.03]),(2,1)), marker='d',color='0.6',mec='0.6', mew=1.5,mfc='none') if _ADDGCS: ks_gcs, psd_gcs, e_psd_gcs, gcsp= plot_psd_gcs() if _ADDRAVE: ks_rave, psd_rave, e_psd_rave, ravep= plot_psd_rave() if _ADDRED: plot_psd_red() l2= pyplot.legend((apop[0],ravep[0],gcsp[0]), (r'$\mathrm{APOGEE}$', r'$\mathrm{RAVE}$', r'$\mathrm{GCS}$'), loc='upper right',bbox_to_anchor=(.95,.750), numpoints=1, prop={'size':14}, frameon=False) pyplot.gca().add_artist(l1) pyplot.gca().add_artist(l2) #Plot an estimate of the noise, based on looking at the bands nks= numpy.linspace(2.,120.,2) if not 'mba23' in socket.gethostname(): pyplot.fill_between(nks,[2.,2.],hatch='/',color='k',facecolor=(0,0,0,0), lw=0.) # edgecolor=(0,0,0,0)) pyplot.plot(nks,[2.,2.],color='k',lw=1.5) nks= numpy.linspace(0.17,2.,2) def linsp(x): return .8/(numpy.log(0.17)-numpy.log(2.))*(numpy.log(x)-numpy.log(0.17))+2.8 if not 'mba23' in socket.gethostname(): pyplot.fill_between(nks,linsp(nks),hatch='/',color='k',facecolor=(0,0,0,0), lw=0.) # edgecolor=(0,0,0,0)) #Plot lines pyplot.plot([0.17,0.17],[0.,2.8],color='k',lw=1.5) pyplot.plot(nks,linsp(nks)+0.01,color='k',lw=1.5) bovy_plot.bovy_text(0.19,.5,r'$95\,\%\,\mathrm{noise\ range}$', bbox=dict(facecolor='w',edgecolor='w'),fontsize=14.) if _INTERP: interpks= list(ks[:-5]) interppsd= list((scale*numpy.sqrt(psd1d[1][1:-3]-_SUBTRACTERRORS*numpy.median(noisepsd,axis=0)))[:-5]) interppsd_w= (scale*0.5*psd1d[2][1:-3]/numpy.sqrt(psd1d[1][1:-3]))[:-5] interppsd_w[:8]*= 0.025 #fiddling to get a decent fit interppsd_w[3:5]*= 0.001 interppsd_w= list(interppsd_w) interpks.append(0.025) interppsd.append(10.**-5.) interppsd_w.append(0.00001) interpks.append(110.) interppsd.append(1.) interppsd_w.append(0.00001) if _ADDGCS: interpks.extend(ks_gcs) interppsd.extend(psd_gcs) interppsd_w.extend(e_psd_gcs) if _ADDRAVE: interpks.extend(ks_rave[5:]) interppsd.extend(psd_rave[5:]) interppsd_w.extend(e_psd_rave[5:]) interpks= numpy.array(interpks) sortindx= numpy.argsort(interpks) interpks= interpks[sortindx] interppsd= numpy.array(interppsd)[sortindx] interppsd_w= interppsd/numpy.array(interppsd_w)[sortindx] interpindx= True-numpy.isnan(interppsd) #interpspec= interpolate.InterpolatedUnivariateSpline(interpks[interpindx], interpspec= interpolate.UnivariateSpline(numpy.log(interpks[interpindx]), numpy.log(interppsd[interpindx]/3.), w=interppsd_w, k=3,s=len(interppsd_w)*0.8) pks= numpy.linspace(interpks[0],interpks[-1],201) #bovy_plot.bovy_plot(pks, # 3.*numpy.exp(interpspec(numpy.log(pks))), # 'k-',overplot=True) def my_formatter(x, pos): return r'$%g$' % x def my_formatter2(x, pos): return r'$%g$' % (1./x) major_formatter = FuncFormatter(my_formatter) major_formatter2 = FuncFormatter(my_formatter2) ax= pyplot.gca() ax.xaxis.set_major_formatter(major_formatter) if not _PROPOSAL: ax2= pyplot.twiny() xmin, xmax= ax.xaxis.get_view_interval() ax2.set_xscale('log') ax2.xaxis.set_view_interval(1./xmin,1./xmax,ignore=True) ax2.set_xlabel('$\mathrm{Approximate\ scale}\,(\mathrm{kpc})$', fontsize=12.,ha='center',x=0.5) ax2.xaxis.set_major_formatter(major_formatter) bovy_plot.bovy_end_print(plotfilename,dpi=300) return None
def plot_psd_rave(): data= fitsio.read(os.path.join(os.getenv('DATADIR'),'rave','ravedr4_rc.fits')) dx= _RAVEDX binsize= 0.8#.735 pix= pix= pixelize_sample.pixelXY(data, xmin=_RAVEXMIN,xmax=_RAVEXMAX, ymin=_RAVEYMIN,ymax=_RAVEYMAX, dx=dx,dy=dx) resv= pix.plot(lambda x: dvlosgal(x,vtsun=230.),returnz=True,justcalc=True) resvunc= pix.plot('VHELIO_AVG', func=lambda x: 1.4826*numpy.median(numpy.fabs(x-numpy.median(x)))/numpy.sqrt(len(x)), returnz=True,justcalc=True) psd1d= bovy_psd.psd1d(resv,dx,binsize=binsize) print psd1d #Simulations for constant 3.25 km/s nnoise= _NNOISE noisepsd= numpy.empty((nnoise,len(psd1d[0])-4)) for ii in range(nnoise): newresv= numpy.random.normal(size=resv.shape)*3.25 noisepsd[ii,:]= bovy_psd.psd1d(newresv,dx,binsize=binsize)[1][1:-3] scale= 4.*numpy.pi#3.25/numpy.median(numpy.sqrt(noisepsd)) print scale #Simulations for the actual noise nnoise= _NNOISE noisepsd= numpy.empty((nnoise,len(psd1d[0])-4)) for ii in range(nnoise): newresv= numpy.random.normal(size=resv.shape)*resvunc noisepsd[ii,:]= bovy_psd.psd1d(newresv,dx,binsize=binsize)[1][1:-3] ks= psd1d[0][1:-3] ravep= bovy_plot.bovy_plot(ks,scale*numpy.sqrt(psd1d[1][1:-3] -_SUBTRACTERRORS*numpy.median(noisepsd,axis=0)),'k+',mew=2., overplot=True) pyplot.errorbar(ks,scale*numpy.sqrt(psd1d[1][1:-3]-_SUBTRACTERRORS*numpy.median(noisepsd,axis=0)), yerr=scale*0.5*(psd1d[2][1:-3]**2. +_SUBTRACTERRORS*numpy.median(noisepsd,axis=0)**2.)**0.5/numpy.sqrt(psd1d[1][1:-3]), marker='None',ls='none',color='k') if _DUMP2FILE: with open('bovy-apogee-psd.dat','a') as csvfile: writer= csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL) csvfile.write('#RAVE\n') for ii in range(len(ks)): writer.writerow([ks[ii], (scale*numpy.sqrt(psd1d[1][1:-3]-_SUBTRACTERRORS*numpy.median(noisepsd,axis=0)))[ii], (scale*0.5*(psd1d[2][1:-3]**2.+_SUBTRACTERRORS*numpy.median(noisepsd,axis=0)**2.)**0.5/numpy.sqrt(psd1d[1][1:-3]))[ii]]) if False: interpindx= True-numpy.isnan(psd1d[1][1:-3]) interpspec= interpolate.InterpolatedUnivariateSpline(ks[interpindx], scale*numpy.sqrt(psd1d[1][1:-3])[interpindx], k=3) pks= numpy.linspace(ks[0],ks[-1],201) bovy_plot.bovy_plot(pks,interpspec(pks),'k-',overplot=True) if _PLOTBAND: #bovy_plot.bovy_plot(ks, # scale*numpy.median(numpy.sqrt(noisepsd),axis=0), # '-',lw=8.,zorder=9, # color='0.65',overplot=True) # bovy_plot.bovy_plot(ks, # scale*numpy.sqrt(numpy.sort(noisepsd # -_SUBTRACTERRORS*numpy.median(noisepsd,axis=0),axis=0)[int(numpy.floor(0.99*_NNOISE)),:]), # zorder=1,ls='--',overplot=True, # color='0.65') pyplot.fill_between(ks, scale*numpy.sqrt(numpy.sort(noisepsd -_SUBTRACTERRORS*numpy.median(noisepsd,axis=0),axis=0)[int(numpy.floor(_SIGNIF*_NNOISE)),:]), zorder=0, color='0.65') #bovy_plot.bovy_plot(numpy.tile(ks,(_NNOISE,1)).T, # scale*numpy.sqrt(noisepsd).T, # '-',zorder=0,alpha=0.5, # color='0.45',overplot=True) return (ks, scale*numpy.sqrt(psd1d[1][1:-3] -_SUBTRACTERRORS*numpy.median(noisepsd,axis=0)), scale*0.5*psd1d[2][1:-3]/numpy.sqrt(psd1d[1][1:-3]), ravep)
def plot_psd_gcs(): data= hackGCS.hackGCS() dx= _GCSDX binsize= .8 pix= pixelize_sample.pixelXY(data, xmin=_GCSXMIN,xmax=_GCSXMAX, ymin=_GCSYMIN,ymax=_GCSYMAX, dx=dx,dy=dx) resv= pix.plot('VVel',returnz=True,justcalc=True) resvunc= pix.plot('VVel', func=lambda x: 1.4826*numpy.median(numpy.fabs(x-numpy.median(x)))/numpy.sqrt(len(x)), returnz=True,justcalc=True) psd1d= bovy_psd.psd1d(resv,dx,binsize=binsize) print psd1d #Simulations for constant 3.25 km/s nnoise= _NNOISE noisepsd= numpy.empty((nnoise,len(psd1d[0])-4)) for ii in range(nnoise): newresv= numpy.random.normal(size=resv.shape)*3.25 noisepsd[ii,:]= bovy_psd.psd1d(newresv,dx,binsize=binsize)[1][1:-3] scale= 4.*numpy.pi#3.25/numpy.median(numpy.sqrt(noisepsd)) print scale #Simulations for the actual noise nnoise= _NNOISE noisepsd= numpy.empty((nnoise,len(psd1d[0])-4)) for ii in range(nnoise): newresv= numpy.random.normal(size=resv.shape)*resvunc noisepsd[ii,:]= bovy_psd.psd1d(newresv,dx,binsize=binsize)[1][1:-3] ks= psd1d[0][1:-3] gcsp= bovy_plot.bovy_plot(ks,scale*numpy.sqrt(psd1d[1][1:-3] -_SUBTRACTERRORS*numpy.median(noisepsd,axis=0)),'kx',mew=2., overplot=True) pyplot.errorbar(ks,scale*numpy.sqrt(psd1d[1][1:-3]-_SUBTRACTERRORS*numpy.median(noisepsd,axis=0)), yerr=scale*0.5*(psd1d[2][1:-3]**2. +_SUBTRACTERRORS*numpy.median(noisepsd,axis=0)**2.)**0.5/numpy.sqrt(psd1d[1][1:-3]), marker='None',ls='none',color='k')#,lolims=True) if _DUMP2FILE: with open('bovy-apogee-psd.dat','a') as csvfile: writer= csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL) csvfile.write('#GCS\n') for ii in range(len(ks)): writer.writerow([ks[ii], (scale*numpy.sqrt(psd1d[1][1:-3]-_SUBTRACTERRORS*numpy.median(noisepsd,axis=0)))[ii], (scale*0.5*(psd1d[2][1:-3]**2.+_SUBTRACTERRORS*numpy.median(noisepsd,axis=0)**2.)**0.5/numpy.sqrt(psd1d[1][1:-3]))[ii]]) if _PLOTBAND: # bovy_plot.bovy_plot(ks, # scale*numpy.median(numpy.sqrt(noisepsd),axis=0), # '-',lw=2.,zorder=9, # color='0.65',overplot=True) # bovy_plot.bovy_plot(ks, # scale*numpy.sqrt(numpy.sort(noisepsd # -_SUBTRACTERRORS*numpy.median(noisepsd,axis=0),axis=0)[int(numpy.floor(0.99*_NNOISE)),:]), # zorder=1,ls='--',overplot=True, # color='0.65') pyplot.fill_between(ks, scale*numpy.sqrt(numpy.sort(noisepsd -_SUBTRACTERRORS*numpy.median(noisepsd,axis=0),axis=0)[int(numpy.floor(_SIGNIF*_NNOISE)),:]), zorder=0, color='0.65') return (ks, scale*numpy.sqrt(psd1d[1][1:-3] -_SUBTRACTERRORS*numpy.median(noisepsd,axis=0)), scale*0.5*psd1d[2][1:-3]/numpy.sqrt(psd1d[1][1:-3]), gcsp)
def plot_psd_model(plotfilename,type): #Load fiducial # spvlos= galpy_simulations.vlos('../sim/spiral_rect_omegas0.33_alpha-14%s.sav' % _HIVRESSTR) spvlos= galpy_simulations.vlos('../sim/bar_rect_alpha0.015%s.sav' % _HIVRESSTR) potscale= 1. simpsd1d= bovy_psd.psd1d(spvlos*potscale,0.33333333,binsize=0.8) tks= simpsd1d[0][1:-3] xrange=[.08,4.] if type.lower() == 'elliptical': eres= 31 p= 0. vloscp= galpy_simulations.vlos_elliptical(res=eres,cp=0.02,sp=0.,p=p) vlossp= galpy_simulations.vlos_elliptical(res=eres,sp=0.02,cp=0.,p=p) vloscpsp= galpy_simulations.vlos_elliptical(res=eres,p=p, sp=0.02/numpy.sqrt(2.), cp=0.02/numpy.sqrt(2.)) p=2. vloscpp2= galpy_simulations.vlos_elliptical(res=eres,cp=0.01,sp=0.,p=p) vlosspp2= galpy_simulations.vlos_elliptical(res=eres,sp=0.01,cp=0.,p=p) vloscpspp2= galpy_simulations.vlos_elliptical(res=eres,p=p, sp=0.01/numpy.sqrt(2.), cp=0.01/numpy.sqrt(2.)) p=-3. vloscppm3= galpy_simulations.vlos_elliptical(res=eres,cp=0.05,sp=0.,p=p) vlossppm3= galpy_simulations.vlos_elliptical(res=eres,sp=0.05,cp=0.,p=p) vloscpsppm3= galpy_simulations.vlos_elliptical(res=eres,p=p, sp=0.05/numpy.sqrt(2.), cp=0.05/numpy.sqrt(2.)) xgrid= numpy.linspace((_RCXMIN-8.)/8.+_RCDX/8./2., (_RCXMAX-8.)/8.-_RCDX/8./2., eres) dx= (xgrid[1]-xgrid[0])*8. psdcp= bovy_psd.psd1d(vloscp,dx,binsize=0.8) psdsp= bovy_psd.psd1d(vlossp,dx,binsize=0.8) psdcpsp= bovy_psd.psd1d(vloscpsp,dx,binsize=0.8) psdcpp2= bovy_psd.psd1d(vloscpp2,dx,binsize=0.8) psdspp2= bovy_psd.psd1d(vlosspp2,dx,binsize=0.8) psdcpspp2= bovy_psd.psd1d(vloscpspp2,dx,binsize=0.8) psdcppm3= bovy_psd.psd1d(vloscppm3,dx,binsize=0.8) psdsppm3= bovy_psd.psd1d(vlossppm3,dx,binsize=0.8) psdcpsppm3= bovy_psd.psd1d(vloscpsppm3,dx,binsize=0.8) ks= psdcp[0][1:-3] scale= 4.*numpy.pi*220. bovy_plot.bovy_print(fig_width=8.,fig_height=4.5,axes_labelsize=20) line1= bovy_plot.bovy_plot(ks,scale*numpy.sqrt(psdcp[1][1:-3]), 'k-',lw=2., semilogx=True, # xlabel=r'$k\,(\mathrm{kpc}^{-1})$', ylabel=r'$\sqrt{P_k}\,(\mathrm{km\,s}^{-1})$', xrange=xrange, yrange=[0.,11.9],zorder=1) line2= bovy_plot.bovy_plot(ks,scale*numpy.sqrt(psdsp[1][1:-3]), 'k--',lw=2., overplot=True,zorder=1) line3= bovy_plot.bovy_plot(ks,scale*numpy.sqrt(psdcpsp[1][1:-3]), 'k-.',lw=2.,zorder=1, overplot=True) line4= bovy_plot.bovy_plot(ks,scale*numpy.sqrt(psdcpp2[1][1:-3]), '-',lw=2.,color='c',zorder=1, overplot=True) line5= bovy_plot.bovy_plot(ks,scale*numpy.sqrt(psdspp2[1][1:-3]), '--',lw=2.,color='c',zorder=1, overplot=True) line6= bovy_plot.bovy_plot(ks,scale*numpy.sqrt(psdcpspp2[1][1:-3]), '-.',lw=2.,color='c',zorder=1, overplot=True) line7= bovy_plot.bovy_plot(ks,scale*numpy.sqrt(psdcppm3[1][1:-3]), '-',lw=2.,color='r',zorder=1, overplot=True) line8= bovy_plot.bovy_plot(ks,scale*numpy.sqrt(psdsppm3[1][1:-3]), '--',lw=2.,color='r',zorder=1, overplot=True) line9= bovy_plot.bovy_plot(ks,scale*numpy.sqrt(psdcpsppm3[1][1:-3]), '-.',lw=2.,color='r',zorder=1, overplot=True) pyplot.annotate(r'$\mathrm{Elliptical\ perturbation}\ (m=2\ \mathrm{mode})$', (0.5,1.08),xycoords='axes fraction', horizontalalignment='center', verticalalignment='top',size=20.) l1= pyplot.legend((line1[0],line2[0],line3[0]), (r'$\phi_b = 0^\circ$', r'$\phi_b = 45^\circ$', r'$\phi_b = 90^\circ$'), loc='lower left',#bbox_to_anchor=(.91,.375), numpoints=8, prop={'size':16}, frameon=False) l2= pyplot.legend((line1[0],line4[0],line7[0]), (r'$\epsilon(R) = 0.02$', r'$\epsilon(R) = 0.01\,\left(\frac{R}{R_0}\right)^2$', r'$\epsilon(R) = 0.05\,\left(\frac{R}{R_0}\right)^{-3}$'), loc='upper right',#bbox_to_anchor=(.91,.375), numpoints=8, prop={'size':16}, frameon=False) pyplot.gca().add_artist(l1) pyplot.gca().add_artist(l2) elif type.lower() == 'bar': vlosbar= galpy_simulations.vlos('../sim/bar_rect_alpha0.015%s.sav' % _HIVRESSTR) vlosslowbar= galpy_simulations.vlos('../sim/bar_rect_alpha0.015_slow%s.sav' % _HIVRESSTR) vlosbarsmallangle= galpy_simulations.vlos('../sim/bar_rect_alpha0.015_angle10%s.sav' % _HIVRESSTR) vlosbarlargeangle= galpy_simulations.vlos('../sim/bar_rect_alpha0.015_angle40%s.sav' % _HIVRESSTR) vlosbarsmallrolr= galpy_simulations.vlos('../sim/bar_rect_alpha0.015_rolr0.85%s.sav' % _HIVRESSTR) vlosbarlargerolr= galpy_simulations.vlos('../sim/bar_rect_alpha0.015_rolr0.95%s.sav' % _HIVRESSTR) eres= 19 xgrid= numpy.linspace((_RCXMIN-8.)/8.+_RCDX/8./2., (_RCXMAX-8.)/8.-_RCDX/8./2., eres) dx= (xgrid[1]-xgrid[0])*8. psdbar= bovy_psd.psd1d(vlosbar,dx,binsize=0.8) psdslowbar= bovy_psd.psd1d(vlosslowbar,dx,binsize=0.8) psdsbarsmallangle= bovy_psd.psd1d(vlosbarsmallangle,dx,binsize=0.8) psdsbarlargeangle= bovy_psd.psd1d(vlosbarlargeangle,dx,binsize=0.8) psdsbarsmallrolr= bovy_psd.psd1d(vlosbarsmallrolr,dx,binsize=0.8) psdsbarlargerolr= bovy_psd.psd1d(vlosbarlargerolr,dx,binsize=0.8) ks= psdbar[0][1:-3] scale= 4.*numpy.pi*220. bovy_plot.bovy_print(fig_width=8.,fig_height=4.5,axes_labelsize=20) line1= bovy_plot.bovy_plot(ks,scale*numpy.sqrt(psdbar[1][1:-3]), '-',lw=2.,color='0.65', semilogx=True, # xlabel=r'$k\,(\mathrm{kpc}^{-1})$', ylabel=r'$\sqrt{P_k}\,(\mathrm{km\,s}^{-1})$', xrange=xrange, yrange=[0.,11.9],zorder=1) line2= bovy_plot.bovy_plot(ks,scale*numpy.sqrt(psdslowbar[1][1:-3]), 'r-',lw=2., overplot=True,zorder=1) line3= bovy_plot.bovy_plot(ks,scale*numpy.sqrt(psdsbarsmallangle[1][1:-3])*0.9, '-',lw=2.,color='gold', overplot=True,zorder=1) line4= bovy_plot.bovy_plot(ks,scale*numpy.sqrt(psdsbarlargeangle[1][1:-3])*1.1, 'b-',lw=2., overplot=True,zorder=1) line5= bovy_plot.bovy_plot(ks,scale*numpy.sqrt(psdsbarsmallrolr[1][1:-3])*0.9, 'g-',lw=2., overplot=True,zorder=1) line6= bovy_plot.bovy_plot(ks,scale*numpy.sqrt(psdsbarlargerolr[1][1:-3]), 'c-',lw=2., overplot=True,zorder=1) pyplot.annotate(r'$\mathrm{Bar\ perturbation\ (rotating}\ m=2\ \mathrm{mode})$', (0.5,1.08),xycoords='axes fraction', horizontalalignment='center', verticalalignment='top',size=20.) l1= pyplot.legend((line1[0],line2[0]), (r'$\mathrm{Fast\ bar\ growth}$', r'$\mathrm{Slow\ bar\ growth}$'), loc='upper right',#bbox_to_anchor=(.91,.375), numpoints=8, prop={'size':16}, frameon=False) l2= pyplot.legend((line3[0],line4[0],line5[0],line6[0]), (r'$\mathrm{Fast}\ \&\ \mathrm{bar\ angle} = 10^\circ$', r'$\mathrm{Fast}\ \&\ \mathrm{bar\ angle} = 40^\circ$', r'$\mathrm{Fast}\ \&\ R_{\mathrm{OLR}} = 0.85\,R_0$', r'$\mathrm{Fast}\ \&\ R_{\mathrm{OLR}} = 0.95\,R_0$'), loc='lower left',#bbox_to_anchor=(.91,.375), numpoints=8, prop={'size':16}, frameon=False) pyplot.gca().add_artist(l1) pyplot.gca().add_artist(l2) elif type.lower() == 'spiral': vlosfid= galpy_simulations.vlos('../sim/spiral_rect_omegas0.33_alpha-14%s.sav' % _HIVRESSTR) vloslpitch= galpy_simulations.vlos('../sim/spiral_rect_omegas0.33_alpha-7%s.sav' % _HIVRESSTR) vlosdiffgamma= galpy_simulations.vlos('../sim/spiral_rect_omegas0.33_gamma0.3%s.sav' % _HIVRESSTR) vlosdiffomegas= galpy_simulations.vlos('../sim/spiral_rect_alpha-14%s.sav' % _HIVRESSTR) vlosdiffm= galpy_simulations.vlos('../sim/spiral_rect_m4_alpha-14%s.sav' % _HIVRESSTR) vlosdiffm2= galpy_simulations.vlos('../sim/spiral_rect_m4_alpha-14_gamma0.4%s.sav' % _HIVRESSTR) potscale= 0.85 eres= 19 xgrid= numpy.linspace((_RCXMIN-8.)/8.+_RCDX/8./2., (_RCXMAX-8.)/8.-_RCDX/8./2., eres) dx= (xgrid[1]-xgrid[0])*8. psdfid= bovy_psd.psd1d(vlosfid,dx,binsize=0.8) psdlpitch= bovy_psd.psd1d(vloslpitch,dx,binsize=0.8) psddiffgamma= bovy_psd.psd1d(vlosdiffgamma,dx,binsize=0.8) psddiffomegas= bovy_psd.psd1d(vlosdiffomegas,dx,binsize=0.8) psddiffm= bovy_psd.psd1d(vlosdiffm,dx,binsize=0.8) psddiffm2= bovy_psd.psd1d(vlosdiffm2,dx,binsize=0.8) ks= psdfid[0][1:-3] scale= 4.*numpy.pi*220. bovy_plot.bovy_print(fig_width=8.,fig_height=4.5,axes_labelsize=20) line1= bovy_plot.bovy_plot(ks,potscale*scale*numpy.sqrt(psdfid[1][1:-3]), 'k-',lw=2, semilogx=True, # xlabel=r'$k\,(\mathrm{kpc}^{-1})$', ylabel=r'$\sqrt{P_k}\,(\mathrm{km\,s}^{-1})$', xrange=xrange, yrange=[0.,11.9],zorder=1) potscale= 0.25 line2= bovy_plot.bovy_plot(ks,potscale*scale*numpy.sqrt(psdlpitch[1][1:-3]), '-',lw=2.,zorder=1,color='gold', overplot=True) potscale= 0.5 line3= bovy_plot.bovy_plot(ks,potscale*scale*numpy.sqrt(psddiffgamma[1][1:-3]), 'r-',lw=2.,zorder=1, overplot=True) line4= bovy_plot.bovy_plot(ks,4.*scale*numpy.sqrt(psddiffomegas[1][1:-3]), 'b-',lw=2.,zorder=1, overplot=True) line5= bovy_plot.bovy_plot(ks,10./7.*scale*numpy.sqrt(psddiffm[1][1:-3]), 'g-',lw=2.,zorder=1, overplot=True) line6= bovy_plot.bovy_plot(ks,10./6.*scale*numpy.sqrt(psddiffm2[1][1:-3]), 'c-',lw=2.,zorder=1, overplot=True) pyplot.annotate(r'$\mathrm{Spiral\ perturbation}$', (0.5,1.08),xycoords='axes fraction', horizontalalignment='center', verticalalignment='top',size=20.) l1= pyplot.legend((line1[0],line2[0],line3[0], line4[0],line5[0],line6[0]), (r'$\mathrm{Fiducial\ spiral}$', r'$\mathrm{Pitch\ angle} = 16^\circ$', r'$\gamma = 17^\circ$'), loc='upper right',#bbox_to_anchor=(.91,.375), numpoints=8, prop={'size':16}, frameon=False) l2= pyplot.legend((line4[0],line5[0],line6[0]), (r'$\Omega_s = 0.65\,\Omega_0$', r'$\Omega_s = 0.65\,\Omega_0\ \&\ m=4$', r'$\Omega_s = 0.65\,\Omega_0\ \&\ m=4\ \&\ \gamma = 23^\circ$'), loc='lower left',#bbox_to_anchor=(.91,.375), numpoints=8, prop={'size':16}, frameon=False) pyplot.gca().add_artist(l1) pyplot.gca().add_artist(l2) elif type.lower() == 'bird': _nSims= 8 #Read the Bird data birdData= numpy.load('../pecvel/dr12_1_5gyr_8pos.npz') #Get residuals for all simulations dx= _RCDX binsize= .8#.765 scale= 4.*numpy.pi tmp= bovy_psd.psd1d(birdData['dVlos1'],dx,binsize=binsize) #just to get the size ks= tmp[0][1:-3] psds= numpy.zeros((len(tmp[1]),_nSims)) if True: import apogee.tools.read as apread import pixelize_sample data= apread.rcsample() data= data[data['ADDL_LOGG_CUT'] == 1] #Cut indx= (numpy.fabs(data['RC_GALZ']) < 0.25)*(data['METALS'] > -1000.) print "Using %i stars for low-Z 2D kinematics analysis" % numpy.sum(indx) data= data[indx] #Get residuals dx= _RCDX pix= pixelize_sample.pixelXY(data, xmin=_RCXMIN,xmax=_RCXMAX, ymin=_RCYMIN,ymax=_RCYMAX, dx=dx,dy=dx) resv= pix.plot('VHELIO_AVG',returnz=True,justcalc=True) rc_mask= numpy.ones(resv.shape,dtype='bool') rc_mask[True-numpy.isnan(resv)]= False if _SUBTRACTERRORS: for ii in range(_nSims): sim= ii+1 tmpPsd= bovy_psd.psd1d(birdData['dVlos%i' % sim], dx,binsize=binsize)[1] #Simulations for the noise nnoise= _NNOISE noisepsd= numpy.empty((nnoise,len(tmpPsd))) for jj in range(nnoise): newresv= \ numpy.random.normal(size=birdData['dVlos%i' % sim].shape)\ *birdData['sig_dVlos%i' % sim].reshape((9,9))\ *(True-rc_mask) # *(True-birdData['rc_mask']) noisepsd[jj,:]= bovy_psd.psd1d(newresv,dx,binsize=binsize)[1] psds[:,ii]= tmpPsd-numpy.median(noisepsd,axis=0) #Calculate median PSD and spread around this medPsd= scale*numpy.median(numpy.sqrt(psds),axis=1)[1:-3] flucPsd=\ 1.4826*scale*numpy.median(numpy.fabs(numpy.sqrt(psds)[1:-3] -numpy.tile(medPsd/scale, (psds.shape[1],1)).T),axis=1) bovy_plot.bovy_print(fig_width=8.,fig_height=4.5,axes_labelsize=20) def my_formatter(x, pos): return r'$%g$' % x major_formatter = FuncFormatter(my_formatter) line1= bovy_plot.bovy_plot(ks,medPsd, 'k-',lw=2, semilogx=True, xlabel=r'$k\,(\mathrm{kpc}^{-1})$', ylabel=r'$\sqrt{P_k}\,(\mathrm{km\,s}^{-1})$', xrange=xrange, yrange=[0.,11.9],zorder=1) pyplot.gca().xaxis.set_major_formatter(major_formatter) goodIndx= True-numpy.isnan(flucPsd) pyplot.fill_between(ks[goodIndx],(medPsd-flucPsd)[goodIndx], y2=(medPsd+flucPsd)[goodIndx], color='0.45',zorder=-1) pyplot.annotate(r'$\mathrm{Cosmological\ simulation}$', (0.5,1.08),xycoords='axes fraction', horizontalalignment='center', verticalalignment='top',size=20.) bovy_plot.bovy_text(r'$\mathrm{Median\ and\ range\ from}$'+'\n' +r'$\mathrm{8\ APOGEE\!-\!like\ volumes}$', top_right=True,size=16.) bovy_plot.bovy_plot([0.4,0.65],[7.55,10.],'k-',overplot=True) #Also plot fiducial scale= 4.*numpy.pi*220. bovy_plot.bovy_plot(tks, scale*numpy.sqrt(simpsd1d[1][1:-3]), '-',color='0.65',lw=4.,overplot=True,zorder=0) if not type.lower() == 'bird': nullfmt = NullFormatter() # no labels pyplot.gca().xaxis.set_major_formatter(nullfmt) bovy_plot.bovy_end_print(plotfilename) return None
def plot_metallicity(basesavefilename, datafilename=None): # First read the sample if not datafilename is None: data = fitsio.read(datafilename) else: data = apread.rcsample() if _ADDLLOGGCUT: data = data[data["ADDL_LOGG_CUT"] == 1] # Cut indx = (numpy.fabs(data["RC_GALZ"]) < 0.05) * (data["METALS"] > -1000.0) print "Using %i stars for low-Z metallicity gradient analysis" % numpy.sum(indx) data = data[indx] # First do the metallicity gradient rs = numpy.arange(0.5, 18.5001, 0.85) fehs = numpy.zeros_like(rs) + numpy.nan sigfehs = numpy.zeros_like(rs) + numpy.nan efehs = numpy.zeros_like(rs) + numpy.nan for ii in range(len(rs) - 1): tindx = (data["RC_GALR"] > rs[ii]) * (data["RC_GALR"] <= rs[ii + 1]) if numpy.sum(tindx) < 20: continue fehs[ii] = numpy.median(data["METALS"][tindx]) sigfehs[ii] = numpy.std(data["METALS"][tindx]) efehs[ii] = numpy.std(data["METALS"][tindx]) / numpy.sqrt(numpy.sum(tindx)) # Plot bovy_plot.bovy_print(fig_width=6.0) bovy_plot.bovy_plot( rs + 0.5 * (rs[1] - rs[0]), fehs, "ko", xlabel=r"$R\,(\mathrm{kpc})$", ylabel=r"$\mathrm{median\ [Fe/H]}\,(\mathrm{dex})$", xrange=[0.0, 15.0], yrange=[-0.6, 0.5], zorder=10, ) pyplot.errorbar(rs + 0.5 * (rs[1] - rs[0]), fehs, yerr=efehs, marker="None", ls="none", color="k", zorder=9) # bovy_plot.bovy_plot(data['RC_GALR'],data['METALS'],'k,',overplot=True) # FIT indx = True - numpy.isnan(fehs) bestfit = optimize.curve_fit( linfit, (rs + 0.5 * (rs[1] - rs[0]))[indx], fehs[indx], sigma=efehs[indx], p0=(-0.1, 0.0) ) if _JACKERRS: fitrs = (rs + 0.5 * (rs[1] - rs[0]))[indx] fitfehs = fehs[indx] fitefehs = efehs[indx] np = len(fitfehs) fitp0 = [] fitp1 = [] for ii in range(np): findx = numpy.ones(np, dtype="bool") findx[ii] = False tbestfit = optimize.curve_fit(linfit, fitrs[findx], fitfehs[findx], sigma=fitefehs[findx], p0=(-0.1, 0.0)) fitp0.append(tbestfit[0][0]) fitp1.append(tbestfit[0][1]) fitp0 = numpy.array(fitp0) fitp1 = numpy.array(fitp1) p0err = numpy.sqrt((np - 1.0) * numpy.var(fitp0)) p1err = numpy.sqrt((np - 1.0) * numpy.var(fitp1)) print "radial metallicity errors" print bestfit[0][0], p0err print bestfit[0][1], p1err bovy_plot.bovy_plot( rs + 0.5 * (rs[1] - rs[0]), bestfit[0][0] * ((rs + 0.5 * (rs[1] - rs[0]) - 8.0)) + bestfit[0][1], "k--", overplot=True, ) bovy_plot.bovy_text(r"$|Z| < 50\,\mathrm{pc}$", top_right=True, size=18.0) bovy_plot.bovy_text( r"$[\mathrm{Fe/H}] = %.2f\,\frac{\mathrm{dex}}{\mathrm{kpc}}\,(R-8\,\mathrm{kpc}) + %.2f$" % (bestfit[0][0], bestfit[0][1]), bottom_left=True, size=18.0, ) bovy_plot.bovy_end_print(basesavefilename + "_radialgradient." + _EXT) # Now plot azimuthal stuff # First read the sample again if not datafilename is None: data = fitsio.read(datafilename) else: data = apread.rcsample() if _ADDLLOGGCUT: data = data[data["ADDL_LOGG_CUT"] == 1] # Cut indx = (numpy.fabs(data["RC_GALZ"]) < 0.25) * (data["METALS"] > -1000.0) print "Using %i stars for low-Z azimuthal metallicity gradient analysis" % numpy.sum(indx) data = data[indx] pix = pixelize_sample.pixelXY(data) bovy_plot.bovy_print() pix.plot("METALS", zlabel=r"$\mathrm{median\ [Fe/H]}\,(\mathrm{dex})$", vmin=-0.4, vmax=0.3) if "l30" in appath._APOGEE_REDUX: bovy_plot.bovy_text(r"$\mathrm{typical\ uncertainty\!:}\ 0.015\,\mathrm{dex}$", bottom_left=True, size=17.0) elif "v6" in appath._APOGEE_REDUX and int(appath._APOGEE_REDUX[1:]) > 600: bovy_plot.bovy_text(r"$\mathrm{typical\ uncertainty\!:}\ 0.015\,\mathrm{dex}$", bottom_left=True, size=17.0) else: bovy_plot.bovy_text(r"$\mathrm{typical\ uncertainty\!:}\ 0.02\,\mathrm{dex}$", bottom_left=True, size=18.0) bovy_plot.bovy_text(r"$|Z| < 250\,\mathrm{pc}$", top_right=True, size=18.0) bovy_plot.bovy_end_print(basesavefilename + "_XY." + _EXT) # R,phi pix = pixelize_sample.pixelXY(data, rphi=True, ymin=-22.5, ymax=37.5, dy=5.0) bovy_plot.bovy_print() metals2d = pix.plot( "METALS", # func=lambda x: 1.4826*numpy.median(numpy.fabs(x-numpy.median(x)))/numpy.sqrt(len(x)), zlabel=r"$\delta\,\mathrm{median\ [Fe/H]}\,(\mathrm{dex})$", # vmin=0.,vmax=0.05,submediany=False,returnz=True) vmin=-0.1, vmax=0.1, submediany=True, returnz=True, ) sigs = [] for ii in range(metals2d.shape[0]): tindx = True - numpy.isnan(metals2d[ii, :]) if numpy.sum(tindx) > 2: sigs.append(1.4826 * numpy.median(numpy.fabs(metals2d[ii, tindx]))) sigs = numpy.array(sigs) print numpy.median(sigs), numpy.amax(sigs), sigs # bovy_plot.bovy_text(r'$|Z| < 250\,\mathrm{pc}$',bottom_left=True,size=18.) bovy_plot.bovy_end_print(basesavefilename + "_RPHI." + _EXT) # vs. alpha # First read the sample if not datafilename is None: data = fitsio.read(datafilename) else: data = apread.rcsample() if _ADDLLOGGCUT: data = data[data["ADDL_LOGG_CUT"] == 1] # Cut indx = (numpy.fabs(data["RC_GALZ"]) < 0.1) * (data["METALS"] > -1000.0) data = data[indx] bovy_plot.bovy_print() bovy_plot.bovy_plot( data["METALS"], data["ALPHAFE"], "k.", ms=2.0, xlabel=r"$[\mathrm{Fe/H}]\,(\mathrm{dex})$", ylabel=r"$[\alpha/\mathrm{Fe}]\,(\mathrm{dex})$", xrange=[-1.0, 0.5], yrange=[-0.15, 0.35], onedhists=True, bins=31, ) bovy_plot.bovy_text(r"$|Z| < 100\,\mathrm{pc}$", top_right=True, size=18.0) bovy_plot.bovy_text(r"$\mathrm{raw\ sample\ counts}$", bottom_left=True, size=18.0) bovy_plot.bovy_end_print(basesavefilename + "_alpha." + _EXT) # vs. alpha # First read the sample if not datafilename is None: data = fitsio.read(datafilename) else: data = apread.rcsample() if _ADDLLOGGCUT: data = data[data["ADDL_LOGG_CUT"] == 1] # Cut indx = (numpy.fabs(data["RC_GALZ"]) > 0.5) * (numpy.fabs(data["RC_GALZ"]) < 1.0) * (data["METALS"] > -1000.0) data = data[indx] bovy_plot.bovy_print() bovy_plot.bovy_plot( data["METALS"], data["ALPHAFE"], "k.", ms=2.0, xlabel=r"$[\mathrm{Fe/H}]\,(\mathrm{dex})$", ylabel=r"$[\alpha/\mathrm{Fe}]\,(\mathrm{dex})$", xrange=[-1.0, 0.5], yrange=[-0.15, 0.35], onedhists=True, bins=31, ) bovy_plot.bovy_text(r"$0.5\,\mathrm{kpc} < |Z| < 1\,\mathrm{kpc}$", top_right=True, size=18.0) bovy_plot.bovy_text(r"$\mathrm{raw\ sample\ counts}$", bottom_left=True, size=18.0) bovy_plot.bovy_end_print(basesavefilename + "_alpha_0.5z1." + _EXT) # vs. alpha # First read the sample if not datafilename is None: data = fitsio.read(datafilename) else: data = apread.rcsample() if _ADDLLOGGCUT: data = data[data["ADDL_LOGG_CUT"] == 1] # Cut indx = (numpy.fabs(data["RC_GALZ"]) > 1.0) * (numpy.fabs(data["RC_GALZ"]) < 2.0) * (data["METALS"] > -1000.0) data = data[indx] bovy_plot.bovy_print() bovy_plot.bovy_plot( data["METALS"], data["ALPHAFE"], "k.", ms=2.0, xlabel=r"$[\mathrm{Fe/H}]\,(\mathrm{dex})$", ylabel=r"$[\alpha/\mathrm{Fe}]\,(\mathrm{dex})$", xrange=[-1.0, 0.5], yrange=[-0.15, 0.35], onedhists=True, bins=21, ) bovy_plot.bovy_text(r"$1\,\mathrm{kpc} < |Z| < 2\,\mathrm{kpc}$", top_right=True, size=18.0) bovy_plot.bovy_text(r"$\mathrm{raw\ sample\ counts}$", bottom_left=True, size=18.0) bovy_plot.bovy_end_print(basesavefilename + "_alpha_1z2." + _EXT) # vs. alpha # First read the sample if not datafilename is None: data = fitsio.read(datafilename) else: data = apread.rcsample() if _ADDLLOGGCUT: data = data[data["ADDL_LOGG_CUT"] == 1] # Cut indx = (data["STAT"] == 1) * (data["METALS"] > -1000.0) data = data[indx] hist, edges = numpy.histogramdd( numpy.array([data["METALS"], data["ALPHAFE"]]).T, bins=[15, 10], range=[[-1.0, 0.5], [-0.15, 0.35]] ) bovy_plot.bovy_print() bovy_plot.bovy_dens2d( hist.T, contours=False, shrink=0.78, cmap="gist_yarg", origin="lower", xrange=[-1.0, 0.5], yrange=[-0.15, 0.35], vmin=50.0, vmax=1000.0, xlabel=r"$[\mathrm{Fe/H}]\,(\mathrm{dex})$", ylabel=r"$[\alpha/\mathrm{Fe}]\,(\mathrm{dex})$", interpolation="nearest", colorbar=True, ) bovy_plot.bovy_text(r"$\mathrm{main\ sample}$", top_right=True, size=18.0) bovy_plot.bovy_text(r"$\mathrm{raw\ sample\ counts}$", bottom_left=True, size=18.0) bovy_plot.bovy_end_print(basesavefilename + "_alpha_main." + _EXT)
def determine_vsolar(plotfilename): #Read the APOGEE-RC data and pixelate it #APOGEE-RC data= apread.rcsample() if _ADDLLOGGCUT: data= data[data['ADDL_LOGG_CUT'] == 1] #Cut indx= (numpy.fabs(data['RC_GALZ']) < 0.25)*(data['METALS'] > -1000.) data= data[indx] #Get velocity field pixrc= pixelize_sample.pixelXY(data, xmin=_RCXMIN,xmax=_RCXMAX, ymin=_RCYMIN,ymax=_RCYMAX, dx=_RCDX,dy=_RCDX) vsolars= numpy.linspace(0.,40.,51) lpower= large_scale_power(pixrc,vsolars,vc=220.,dx=_RCDX) bovy_plot.bovy_print() line1= bovy_plot.bovy_plot(vsolars,lpower,'k-',lw=2., xrange=[vsolars[0],vsolars[-1]], yrange=[0.,22.9], xlabel=r'$V_{\odot-c}\,(\mathrm{km\,s}^{-1})$', ylabel=r'$\sqrt\langle P_k(0.2 < k / (\mathrm{kpc}^{-1}) < 0.9)\rangle\,(\mathrm{km\,s}^{-1})$') #Find the minimum by fitting a second order polynomial p= numpy.polyfit(vsolars,lpower,2) minvsolar= -0.5*p[1]/p[0] bovy_plot.bovy_plot([minvsolar,minvsolar],[-10.,100.],'k-',lw=0.8, overplot=True) bovy_plot.bovy_text(22.65,1., r'$V_{\odot-c}=%.1f\,\mathrm{km\,s}^{-1}$' % minvsolar, size=15.) lpower240= large_scale_power(pixrc,vsolars,vc=240.,dx=_RCDX) line2= bovy_plot.bovy_plot(vsolars,lpower240,'k--',lw=2.,overplot=True) lpower200= large_scale_power(pixrc,vsolars,vc=200.,dx=_RCDX) line3= bovy_plot.bovy_plot(vsolars,lpower200,'k-.',lw=2.,overplot=True) lpowerbetam0p2= large_scale_power(pixrc,vsolars,dx=_RCDX,beta=-0.1) line4= bovy_plot.bovy_plot(vsolars,lpowerbetam0p2, '--',dashes=(20,10), color='0.6',lw=3.,overplot=True) lpowerbetap0p2= large_scale_power(pixrc,vsolars,dx=_RCDX,beta=0.1) line5= bovy_plot.bovy_plot(vsolars,lpowerbetap0p2, '--',dashes=(20,10), color='0.4',lw=3.,overplot=True) lva= large_scale_power(pixrc,vsolars,vc=220.,dx=_RCDX,hs=6./8.,hR=3./8.) line6= bovy_plot.bovy_plot(vsolars,lva, '-',color='0.8',lw=5.,overplot=True,zorder=-1) #Add legend legend1= pyplot.legend((line3[0],line1[0],line2[0]), (r'$V_c = 200\,\mathrm{km\,s}^{-1}$', r'$V_c = 220\,\mathrm{km\,s}^{-1}$', r'$V_c = 240\,\mathrm{km\,s}^{-1}$'), loc='upper left',#bbox_to_anchor=(.91,.375), numpoints=2, prop={'size':14}, frameon=False) legend2= pyplot.legend((line4[0],line5[0]), (r'$\beta = -0.1$', r'$\beta = \phantom{-}0.1$'), loc='upper right',bbox_to_anchor=(1.,.96), numpoints=2, prop={'size':14}, frameon=False) legend3= pyplot.legend((line6[0],), (r'$\Delta V_a(R_0) =5\,\mathrm{km\,s}^{-1}$',), loc='lower left',#bbox_to_anchor=(1.,.96), numpoints=2, prop={'size':12}, frameon=False) pyplot.gca().add_artist(legend1) pyplot.gca().add_artist(legend2) pyplot.gca().add_artist(legend3) bovy_plot.bovy_end_print(plotfilename) return None