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 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 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 large_scale_power(pix,vsolar,vc=220.,dx=None,beta=0.,hs=33.3,hR=3./8.): """Determine the power on large scales in the residuals for different solarmotions""" out= numpy.empty_like(vsolar) binsize= 0.8 scale= 4.*numpy.pi #0.522677552224 for ii in range(len(vsolar)): resv= pix.plot(lambda x: dvlosgal(x,vc=vc,vtsun=vc+vsolar[ii], beta=beta,hR=hR,hs=hs), returnz=True,justcalc=True) psd1d= bovy_psd.psd1d(resv,dx,binsize=binsize) indx= (psd1d[0] > 0.2)*(psd1d[0] < 0.9) out[ii]= scale*numpy.sqrt(numpy.sum(psd1d[1][indx]*(psd1d[1][indx]/psd1d[2][indx])**2.)/numpy.sum((psd1d[1][indx]/psd1d[2][indx])**2.)) return out
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_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)