def veldist_1d_rolr(plotfilename,phi=_DEFAULTPHI,R=_DEFAULTR, ngrid=201,saveDir='../bar/1dvar/'): """ NAME: veldist_1d_rolr PURPOSE: make a plot showing the influence of the bar R_OLR INPUT: plotfilename - filename for figure phi - Galactocentric azimuth R - Galactocentric radius ngrid - number of grid-points to calculate the los velocity distribution on saveDir - save pickles here OUTPUT: Figure in plotfilename HISTORY: 2010-09-11 - Written - Bovy (NYU) """ rolrs= [0.85,0.9,0.95] vloslinspace= (-.9,.9,ngrid) vloss= sc.linspace(*vloslinspace) vlosds= [] basesavefilename= os.path.join(saveDir,'rolr_') for rolr in rolrs: thissavefilename= basesavefilename+'%.3f.sav' % rolr if os.path.exists(thissavefilename): print "Restoring los-velocity distribution at R_OLR %.2f" % rolr savefile= open(thissavefilename,'r') vlosd= pickle.load(savefile) savefile.close() else: print "Calculating los-velocity distribution at R_OLR %.2f" % rolr potparams= (rolr,0.01,25.*_degtorad,.8,None) vlosd= predictVlos(vloslinspace, l=phi, d=R, distCoord='GCGC', pot='bar',beta=0., potparams=potparams) vlosd= vlosd/(sc.nansum(vlosd)*(vloss[1]-vloss[0])) savefile= open(thissavefilename,'w') pickle.dump(vlosd,savefile) savefile.close() vlosds.append(vlosd) #Plot plot.bovy_print() plot.bovy_plot(vloss,vlosds[1],'k-',zorder=3, xrange=[vloslinspace[0],vloslinspace[1]], yrange=[0.,sc.amax(sc.array(vlosds).flatten())*1.1], xlabel=r'$v_{\mathrm{los}} / v_0$') plot.bovy_plot(vloss,vlosds[0],ls='-',color='0.75', overplot=True,zorder=2,lw=2.) plot.bovy_plot(vloss,vlosds[2],ls='-',color='0.5', overplot=True,zorder=2,lw=1.5) plot.bovy_text(r'$\mathrm{bar}\ R_{\mathrm{OLR}}$',title=True) plot.bovy_text(0.36,.75,r'$R_{\mathrm{OLR}} = 0.95\ R_0$'+'\n'+r'$R_{\mathrm{OLR}} = 0.90\ R_0$'+ '\n'+r'$R_{\mathrm{OLR}} = 0.85\ R_0$') plot.bovy_end_print(plotfilename)
def veldist_1d_Rphi(plotfilename,nx=100,ny=20,dx=_XWIDTH/20.,dy=_YWIDTH/20., ngrid=201,rrange=[0.7,1.3], phirange=[-m.pi/2.,m.pi/2.], saveDir='../bar/1dLarge/',normalize=True, row=None): """ NAME: veldist_1d_Rphi PURPOSE: plot how the los-velocity distribution changes as a function of R and phi INPUT: nx - number of plots in the x-direction ny - number of plots in the y direction dx - x-spacing dy - y-spacing ngrid - number of gridpoints to evaluate the density on rrange - range of Galactocentric radii to consider phirange - range of Galactic azimuths to consider saveDir - directory to save the pickles in normalize - if True (default), normalize the los-vd to integrate to one row - if set to a row number, calculate the los-velocity distributions for this row only, and do not plot anything (just save for later) OUTPUT: plot! HISTORY: 2010-04-21 - Written - Bovy (NYU) """ if row == None: rowStart= 0 rowEnd= nx calcOnly= False else: rowStart= row rowEnd= rowStart+1 calcOnly= True vloslinspace= (-.9,.9,ngrid) vloss= sc.linspace(*vloslinspace) picklebasename= '1d_%i_%i_%i_%.1f_%.1f_%.1f_%.1f' % (nx,ny,ngrid,rrange[0],rrange[1],phirange[0],phirange[1]) if not os.path.exists(saveDir): os.mkdir(saveDir) left, bottom = 0.1, 0.1 width= (nx*_XWIDTH+(nx-1)*dx)/(1.-2.*left) height= (ny*_YWIDTH+(ny-1)*dy)/(1.-2.*bottom) if not calcOnly: plot.bovy_print(fig_width=width,fig_height=height, xtick_major_size=2.,ytick_major_size=2., xtick_minor_size=0.,ytick_minor_size=0.) fig= pyplot.figure() #Make theta-R axes fudge= 8.0 thisax= fig.add_axes([left-_XWIDTH/width/fudge, bottom-_XWIDTH/height/fudge, 1.+2*_XWIDTH/width/fudge-2*left, 1.+2*_XWIDTH/height/fudge-2*bottom]) xrange= sc.array(phirange)*_radtodeg yrange=rrange thisax.xaxis.set_label_text(r'$\mathrm{Galactocentric\ azimuth}\ [\mathrm{deg}]$') thisax.set_xlim(-90.01,90.01) thisax.yaxis.set_label_text(r'$\mathrm{Galactocentric\ radius}\ / R_0$') thisax.set_ylim(yrange[0],yrange[1]) thisax.xaxis.set_major_locator(ticker.MultipleLocator(10.)) for ii in range(rowStart,rowEnd): for jj in range(ny): if not calcOnly: thisax= fig.add_axes([left+ii*(_XWIDTH+dx)/width, bottom+jj*(_YWIDTH+dy)/height, _XWIDTH/width,_YWIDTH/height]) thisR= (rrange[0]+(rrange[1]-rrange[0])/ (ny*_YWIDTH+(ny-1)*dy)*(jj*(_YWIDTH+dy)+_YWIDTH/2.)) thisphi= (phirange[0]+(phirange[1]-phirange[0])/ (nx*_XWIDTH+(nx-1)*dx)*(ii*(_XWIDTH+dx)+_XWIDTH/2.)) thissavefilename= os.path.join(saveDir,picklebasename+'_%i_%i.sav' %(ii,jj)) if os.path.exists(thissavefilename): print "Restoring los-velocity distribution at %.1f, %.1f ..." %(thisR,thisphi) savefile= open(thissavefilename,'r') vlosd= pickle.load(savefile) axivlosd= pickle.load(savefile) savefile.close() else: print "Calculating los-velocity distribution at %.1f, %.1f ..." %(thisR,thisphi) vlosd= predictVlos(vloslinspace, l=thisphi, d=thisR, distCoord='GCGC', pot='bar',beta=0., potparams=(0.9,0.01,25.*_degtorad,.8,None)) axivlosd= predictVlos(vloslinspace, l=thisphi, d=thisR, distCoord='GCGC', pot='bar',beta=0.,t=-0.00001, potparams=(0.9,0.0,25.*_degtorad,.8,None)) if normalize: vlosd= vlosd/(sc.nansum(vlosd)*(vloss[1]-vloss[0])) axivlosd= axivlosd/(sc.nansum(axivlosd)*(vloss[1]-vloss[0])) savefile= open(thissavefilename,'w') pickle.dump(vlosd,savefile) pickle.dump(axivlosd,savefile) savefile.close() if calcOnly: continue fig.sca(thisax) plot.bovy_plot(vloss,vlosd,'k', overplot=True,zorder=3) plot.bovy_plot(vloss,axivlosd,ls='-',color='0.5', overplot=True,zorder=2) thisax.set_xlim(vloslinspace[0],vloslinspace[1]) thisax.set_ylim(0.,sc.amax(sc.concatenate((axivlosd,vlosd)))*1.1) thisax.xaxis.set_ticklabels('') thisax.yaxis.set_ticklabels('') if not calcOnly: plot.bovy_end_print(plotfilename)
def apogee_figures( plotfilename, savefilename=None, bar_angle=25.0, dt=None, l=None, rolr=None, bar_strength=None, slope=None, vlosgrid=201, dgrid=101, conditional=False, dmax=10.0 / 8.0, ): """ NAME: apogee_figures PURPOSE: make a vlos-d plot for APOGEE INPUT: plotfilename - name of the file the figure will be saved to savefilename - name of the file the velocity distributions will be saved to bar_angle= angle between the GC-Sun lin and the bar major axis dt= - time to integrate for (in bar-periods) l= - Galactic longitude rolr= radius of outer lindblad radius bar_strength= strength of the bar slop= slope of the rotation curve (power-law index) conditional= if True, normalize each velocity distribution independently OUTPUT: saves velocity distributions to pickle save file and produces plot HISTORY: 2011-03-19 - Written - Bovy (NYU) """ # Grid vlosgrid = _VLOSGRID dgrid = _DGRID vloslinspace = (-0.9, 0.9, vlosgrid) vloss = sc.linspace(*vloslinspace) dlinspace = (0.0001, dmax, dgrid) ds = sc.linspace(*dlinspace) # Set up parameters potparams = (rolr, bar_strength, bar_angle * _degtorad, 0.8, None) if os.path.exists(savefilename): savefile = open(savefilename, "rb") vlosds = pickle.load(savefile) dd = pickle.load(savefile) savefile.close() else: vlosds = [] dd = 0 while dd < dgrid: print "Working on %i / %i ..." % (dd + 1, dgrid) # Calculate vlos for this distance if dt is None: vlosd = predictVlos( vloslinspace, l=(l * _degtorad), d=ds[dd], distCoord="Sun", pot="bar", beta=slope, potparams=potparams ) else: vlosd = predictVlos( vloslinspace, l=(l * _degtorad), d=ds[dd], distCoord="Sun", pot="bar", beta=slope, potparams=potparams, t=dt, ) vlosds.append(vlosd) dd += 1 # Save savefile = open(savefilename, "wb") pickle.dump(vlosds, savefile) pickle.dump(dd, savefile) savefile.close() # Plot if conditional: newvlosds = [] for vlosd in vlosds: newvlosds.append(vlosd / (sc.nansum(vlosd) * (vloss[1] - vloss[0]))) vlosds = newvlosds bovy_plot.bovy_print() bovy_plot.bovy_dens2d( sc.array(vlosds).T, origin="lower", cmap="gist_yarg", aspect=0.66, xlabel=r"$d\ /\ R_0$", ylabel=r"$(v_{\mathrm{los}} - \vec{v}_c \cdot \vec{d})\ /\ v_0$", yrange=sc.array([vloslinspace[0], vloslinspace[1]]), xrange=sc.array([dlinspace[0], dlinspace[1]]), contours=True, cntrmass=True, cntrcolors=["w", "w", "w", "w", "w", "k", "k", "k", "k", "k"], ) if bar_strength == 0.0: bovy_plot.bovy_text(r"$l = %i^\circ$" % int(l), top_right=True) else: bovy_plot.bovy_text( r"$l = %i^\circ$" % int(l) + "\n" + r"$R_{\mathrm{OLR}} = %3.1f$" % rolr + "\n" + r"$\alpha = %5.3f$" % bar_strength + "\n" + r"$\phi_{\mathrm{bar}} = %i^\circ$" % int(bar_angle), top_right=True, ) bovy_plot.bovy_end_print(plotfilename)
def veldist_1d_apogee(plotfilename,l=250./180.*m.pi,d=0.25, ngrid=201,saveDir='../bar/apogee/'): """ NAME: veldist_1d_apogee PURPOSE: make a plot showing a 1d velocity distribution in an apogee los INPUT: plotfilename - filename for figure l - Galactic longitude d - distance from the Sun ngrid - number of grid-points to calculate the los velocity distribution on saveDir - save pickles here OUTPUT: Figure in plotfilename HISTORY: 2010-05-28 - Written - Bovy (NYU) """ vloslinspace= (-.9,.9,ngrid) vloss= sc.linspace(*vloslinspace) basesavefilename= os.path.join(saveDir,'apogee_') thissavefilename= basesavefilename+'%.2f_%.2f.sav' % (d,l) if os.path.exists(thissavefilename): print "Restoring apogee los-velocity distribution at d,l = %.2f,%.2f" % (d,l) savefile= open(thissavefilename,'r') vlosd= pickle.load(savefile) axivlosd= pickle.load(savefile) savefile.close() else: print "Calculating apogee los-velocity distribution at d,l = %.2f,%.2f" % (d,l) potparams= (0.9,0.01,25.*_degtorad,.8,None) vlosd= predictVlos(vloslinspace, l=l, d=d, distCoord='sun', pot='bar',beta=0., potparams=potparams) vlosd= vlosd/(sc.nansum(vlosd)*(vloss[1]-vloss[0])) potparams= (0.9,0.00,25.*_degtorad,.8,None) axivlosd= predictVlos(vloslinspace, l=l, d=d, t=0.01, distCoord='sun', pot='bar',beta=0., potparams=potparams) axivlosd= axivlosd/(sc.nansum(axivlosd)*(vloss[1]-vloss[0])) savefile= open(thissavefilename,'w') pickle.dump(vlosd,savefile) pickle.dump(axivlosd,savefile) savefile.close() #Plot plot.bovy_print() plot.bovy_plot(vloss,vlosd,'k', xlabel=r'$v_{\mathrm{los}} / v_0$',zorder=3) plot.bovy_plot(vloss,axivlosd,ls='-',color='0.5', overplot=True,zorder=2) thisax= pyplot.gca() thisax.set_xlim(vloslinspace[0],vloslinspace[1]) thisax.set_ylim(0.,sc.amax(sc.concatenate((axivlosd,vlosd)))*1.1) plot.bovy_text(r'$d = %.2f R_0$' % d + '\n'+r'$l = %.0f^\circ$' %(l/m.pi*180.), top_right=True) plot.bovy_end_print(plotfilename)
def veldist_1d_slope(plotfilename,phi=_DEFAULTPHI,R=_DEFAULTR, ngrid=201,saveDir='../bar/1dvar/'): """ NAME: veldist_1d_slope PURPOSE: make a plot showing the influence of the shape of the rotation curve INPUT: plotfilename - filename for figure phi - Galactocentric azimuth R - Galactocentric radius ngrid - number of grid-points to calculate the los velocity distribution on saveDir - save pickles here OUTPUT: Figure in plotfilename HISTORY: 2010-05-15 - Written - Bovy (NYU) """ slopes= [-0.2,-0.1,0.,0.1,0.2] vloslinspace= (-.9,.9,ngrid) vloss= sc.linspace(*vloslinspace) vlosds= [] basesavefilename= os.path.join(saveDir,'slope_') for slope in slopes: thissavefilename= basesavefilename+'%.1f.sav' % slope if os.path.exists(thissavefilename): print "Restoring los-velocity distribution at slope %.1f" % slope savefile= open(thissavefilename,'r') vlosd= pickle.load(savefile) savefile.close() else: print "Calculating los-velocity distribution at slope %.1f" % slope potparams= (0.9,0.01,25.*_degtorad,.8,None) vlosd= predictVlos(vloslinspace, l=phi, d=R, distCoord='GCGC', pot='bar',beta=slope, potparams=potparams) vlosd= vlosd/(sc.nansum(vlosd)*(vloss[1]-vloss[0])) savefile= open(thissavefilename,'w') pickle.dump(vlosd,savefile) savefile.close() vlosds.append(vlosd) #Plot plot.bovy_print() plot.bovy_plot(vloss,vlosds[2],'k-',zorder=3, xrange=[vloslinspace[0],vloslinspace[1]], yrange=[0.,sc.nanmax(sc.array(vlosds).flatten())*1.1], xlabel=r'$v_{\mathrm{los}} / v_0$') plot.bovy_plot(vloss,vlosds[0],ls='-',color='0.75', overplot=True,zorder=2,lw=2.) plot.bovy_plot(vloss,vlosds[1],ls='-',color='0.60', overplot=True,zorder=2,lw=2.) plot.bovy_plot(vloss,vlosds[3],ls='-',color='0.45', overplot=True,zorder=2,lw=1.5) plot.bovy_plot(vloss,vlosds[4],ls='-',color='0.3', overplot=True,zorder=2,lw=1.5) plot.bovy_text(r'$\mathrm{shape\ of\ the\ rotation\ curve}$',title=True) plot.bovy_text(0.5,.5,r'$\beta = -0.2$'+'\n'+r'$\beta = -0.1$'+ '\n'+ r'$\beta = \phantom{-}0.0$'+'\n'+ r'$\beta= \phantom{-}0.1$'+'\n'+ r'$\beta= \phantom{-}0.2$') plot.bovy_end_print(plotfilename)
def veldist_1d_df(plotfilename,phi=_DEFAULTPHI,R=_DEFAULTR, ngrid=201,saveDir='../bar/1dvar/'): """ NAME: veldist_1d_df PURPOSE: make a plot showing the influence of the DF INPUT: plotfilename - filename for figure phi - Galactocentric azimuth R - Galactocentric radius ngrid - number of grid-points to calculate the los velocity distribution on saveDir - save pickles here OUTPUT: Figure in plotfilename HISTORY: 2010-05-15 - Written - Bovy (NYU) """ dftypes= ['dehnen','dehnen','dehnen','dehnen','shu'] scalelengths= [1./3.,1./3.,1./4.,4./10.,1./3] sigscales= [1.,2./3.,3./4.,12./10.,1.] vloslinspace= (-.9,.9,ngrid) vloss= sc.linspace(*vloslinspace) vlosds= [] basesavefilename= os.path.join(saveDir,'df_') ndfs= len(dftypes) for ii in range(ndfs): thissavefilename= basesavefilename+dftypes[ii]+'_%.3f_%.3f.sav' % (scalelengths[ii],sigscales[ii]) if os.path.exists(thissavefilename): print "Restoring los-velocity distribution at df: "+dftypes[ii]+' %.3f and %.3f' % (scalelengths[ii],sigscales[ii]) savefile= open(thissavefilename,'r') vlosd= pickle.load(savefile) savefile.close() else: print "Calculating los-velocity distribution at df: "+dftypes[ii]+' %.3f and %.3f' % (scalelengths[ii],sigscales[ii]) potparams= (0.9,0.01,25.*_degtorad,.8,None) dftype= dftypes[ii] dfparams= (scalelengths[ii],sigscales[ii],0.2) vlosd= predictVlos(vloslinspace, l=phi, d=R, distCoord='GCGC', pot='bar',beta=0., potparams=potparams, dftype=dftype,dfparams=dfparams) vlosd= vlosd/(sc.nansum(vlosd)*(vloss[1]-vloss[0])) savefile= open(thissavefilename,'w') pickle.dump(vlosd,savefile) savefile.close() vlosds.append(vlosd) #Plot plot.bovy_print() plot.bovy_plot(vloss,vlosds[0],'k-',zorder=3, xrange=[vloslinspace[0],vloslinspace[1]], yrange=[0.,sc.amax(sc.array(vlosds).flatten())*1.1], xlabel=r'$v_{\mathrm{los}} / v_0$') plot.bovy_plot(vloss,vlosds[1],ls='-',color='0.75', overplot=True,zorder=2,lw=2.) plot.bovy_plot(vloss,vlosds[2],ls='-',color='0.60', overplot=True,zorder=2,lw=2.) plot.bovy_plot(vloss,vlosds[3],ls='-',color='0.45', overplot=True,zorder=2,lw=1.5) plot.bovy_plot(vloss,vlosds[4],ls='-',color='0.3', overplot=True,zorder=2,lw=1.5) plot.bovy_text(r'$\mathrm{distribution\ function}$',title=True) plot.bovy_text(0.53,.3,r'$R_s = 0.25 R_0$'+'\n' +r'$R_{\sigma} = 2 R_s$'+'\n' +r'$\mathrm{fiducial}$'+'\n' +r'$\mathrm{Shu\ DF}$'+'\n' +r'$R_s = 0.4 R_0$',size=10.) plot.bovy_end_print(plotfilename)
def veldist_1d_convolve(plotfilename,phi=_DEFAULTPHI,R=_DEFAULTR, ngrid=201,saveDir='../bar/1dvar/'): """ NAME: veldist_1d_convolve PURPOSE: make a plot showing the influence of the distance uncertainties INPUT: plotfilename - filename for figure phi - Galactocentric azimuth R - Galactocentric radius ngrid - number of grid-points to calculate the los velocity distribution on saveDir - save pickles here OUTPUT: Figure in plotfilename HISTORY: 2010-05-15 - Written - Bovy (NYU) """ convolves= [0.,0.2,0.3] vloslinspace= (-.9,.9,ngrid) vloss= sc.linspace(*vloslinspace) vlosds= [] basesavefilename= os.path.join(saveDir,'convolve_') for distsig in convolves: thissavefilename= basesavefilename+'%.1f.sav' % distsig if os.path.exists(thissavefilename): print "Restoring los-velocity distribution at distance uncertainties %.1f" % distsig savefile= open(thissavefilename,'r') vlosd= pickle.load(savefile) savefile.close() else: print "Calculating los-velocity distribution at distance uncertainties %.1f" % distsig potparams= (0.9,0.01,25.*_degtorad,.8,None) if distsig == 0.: vlosd= predictVlos(vloslinspace, l=phi, d=R, distCoord='GCGC', pot='bar',beta=0., potparams=potparams) else: vlosd= predictVlosConvolve(vloslinspace, l=phi, d=R, distCoord='GCGC', pot='bar',beta=0., potparams=potparams, convolve=distsig) vlosd= vlosd/(sc.nansum(vlosd)*(vloss[1]-vloss[0])) savefile= open(thissavefilename,'w') pickle.dump(vlosd,savefile) savefile.close() vlosds.append(vlosd) #Plot plot.bovy_print() plot.bovy_plot(vloss,vlosds[0],'k-',zorder=3, xrange=[vloslinspace[0],vloslinspace[1]], yrange=[0.,sc.nanmax(sc.array(vlosds).flatten())*1.1], xlabel=r'$v_{\mathrm{los}} / v_0$') plot.bovy_plot(vloss,vlosds[1],ls='-',color='0.75', overplot=True,zorder=2,lw=2.) plot.bovy_plot(vloss,vlosds[2],ls='-',color='0.6', overplot=True,zorder=2,lw=2.) #plot.bovy_plot(vloss,vlosds[3],ls='-',color='0.45', # overplot=True,zorder=2,lw=2.) plot.bovy_text(r'$\mathrm{distance\ uncertainties}$',title=True) plot.bovy_text(0.5,.65,r'$\sigma_d = 0$'+'\n'+r'$\sigma_d = 20 \%$'+'\n'+r'$\sigma_d = 30 \%$') plot.bovy_end_print(plotfilename)