示例#1
0
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 illustrate_track(plotfilename1,plotfilename2,plotfilename3):
    #Setup stream model
    lp= potential.LogarithmicHaloPotential(q=0.9,normalize=1.)
    aAI= actionAngleIsochroneApprox(b=0.8,pot=lp)
    obs= numpy.array([1.56148083,0.35081535,-1.15481504,
                      0.88719443,-0.47713334,0.12019596])
    sdf= streamdf(_SIGV/220.,progenitor=Orbit(obs),pot=lp,aA=aAI,
                  leading=True,nTrackChunks=_NTRACKCHUNKS,
                  tdisrupt=4.5/bovy_conversion.time_in_Gyr(220.,8.))
    #First calculate meanOmega and sigOmega
    mOs= numpy.array([sdf.meanOmega(t,oned=True) for t in sdf._thetasTrack])
    sOs= numpy.array([sdf.sigOmega(t) for t in sdf._thetasTrack])
    mOs-= sdf._progenitor_Omega_along_dOmega
    mOs*= -bovy_conversion.freq_in_Gyr(220.,8.)
    sOs*= bovy_conversion.freq_in_Gyr(220.,8.)
    progAngle= numpy.dot(sdf._progenitor_angle,sdf._dsigomeanProgDirection)
    bovy_plot.bovy_print(fig_width=8.25,fig_height=3.5)
    bovy_plot.bovy_plot(sdf._thetasTrack+progAngle,mOs,'ko',ms=8.,
                        xlabel=r'$\theta_\parallel$',
                        ylabel=r'$\Omega_\parallel\,(\mathrm{Gyr}^{-1})$',
                        xrange=[-0.2-1.14,1.6-1.14],
                        yrange=[22.05,22.55])
    bovy_plot.bovy_plot(sdf._thetasTrack+progAngle,mOs,'k-',lw=1.5,overplot=True)
    bovy_plot.bovy_plot(sdf._thetasTrack+progAngle,
                        mOs[0]*numpy.ones(len(sdf._thetasTrack))+0.03,
                        'ko',ls='--',dashes=(20,10),lw=1.5,overplot=True,
                        ms=6.)
    bovy_plot.bovy_plot(sdf._thetasTrack+progAngle,mOs+2*sOs,'ko',ms=6.,mfc='none',
                        zorder=1,overplot=True)
    bovy_plot.bovy_plot(sdf._thetasTrack+progAngle,mOs-2*sOs,'ko',ms=6.,mfc='none',
                        zorder=1,overplot=True)
    bovy_plot.bovy_plot(sdf._thetasTrack+progAngle,mOs+2*sOs,'k-.',lw=1.5,
                        zorder=0,overplot=True)
    bovy_plot.bovy_plot(sdf._thetasTrack+progAngle,mOs-2*sOs,'k-.',lw=1.5,
                        zorder=0,overplot=True)
    bovy_plot.bovy_plot(sdf._thetasTrack+progAngle,sdf._progenitor_Omega_along_dOmega*bovy_conversion.freq_in_Gyr(220.,8.)*numpy.ones(len(sdf._thetasTrack)),
                        'k--',lw=1.5,overplot=True)
    bovy_plot.bovy_plot((sdf._thetasTrack+progAngle)[0],(sdf._progenitor_Omega_along_dOmega*bovy_conversion.freq_in_Gyr(220.,8.)*numpy.ones(len(sdf._thetasTrack)))[0],
                        'ko',ms=6.,overplot=True)
    bovy_plot.bovy_text(1.05+progAngle,22.475,r'$\mathrm{progenitor\ orbit}$',size=16.)
    bovy_plot.bovy_text(progAngle+0.05,22.50,r'$\mathrm{current\ progenitor\ position}$',size=16.)
    bovy_plot.bovy_plot([progAngle+0.05,progAngle],[22.50,sdf._progenitor_Omega_along_dOmega*bovy_conversion.freq_in_Gyr(220.,8.)],'k:',overplot=True)
    bovy_plot.bovy_text(-1.2,22.35,r"$\mathrm{At\ the\ progenitor's}\ \theta_{\parallel}, \mathrm{we\ calculate\ an\ auxiliary\ orbit\ through}$"+'\n'+r"$(\mathbf{x}_a,\mathbf{v}_a) = (\mathbf{\Omega}_p+\Delta \mathbf{\Omega}^m,\boldsymbol{\theta}_p)\ \mathrm{using\ a\ linearized}\ (\mathbf{\Omega},\boldsymbol{\theta})\ \mathrm{to}\ (\mathbf{x},\mathbf{v}).$",size=16.)
    yarcs= numpy.linspace(22.30,22.39,101)
    bovy_plot.bovy_plot(sdf._thetasTrack[0]+progAngle-0.1*numpy.sqrt(1.-(yarcs-22.35)**2./0.05**2.),yarcs,'k:',
                        overplot=True)
    bovy_plot.bovy_text(-1.3,22.07,r'$\mathrm{At\ a\ small\ number\ of\ points, we\ calculate}$'+'\n'+r'$\partial(\mathbf{\Omega},\boldsymbol{\theta})/\partial (\mathbf{x},\mathbf{v}), \mathrm{the\ mean\ stream\ track\ in}\ (\mathbf{\Omega},\boldsymbol{\theta})^\dagger,$'+'\n'+r'$\mathrm{and\ estimate\ the\ spread\ around\ the\ track}.$',size=16.)
    bovy_plot.bovy_plot([-0.9,sdf._thetasTrack[1]+progAngle],
                        [22.185,mOs[1]+0.03],
                        'k:',overplot=True)
    bovy_plot.bovy_plot([-0.9,progAngle+sdf._thetasTrack[1]],
                        [22.185,mOs[1]],
                        'k:',overplot=True)
    bovy_plot.bovy_text(-0.18,22.265,r'$\mathrm{stream\ track\ +\ spread}$',
                         size=16.,
                        rotation=-20.)
    bovy_plot.bovy_end_print(plotfilename1)
    #Now plot Z,X
    bovy_plot.bovy_print(fig_width=8.25,fig_height=3.5)
    pyplot.figure()
    sdf.plotTrack(d1='z',d2='x',interp=True,
                  color='k',spread=2,overplot=True,lw=1.5,
                  scaleToPhysical=True)
    sdf.plotTrack(d1='z',d2='x',interp=False,marker='o',ms=8.,color='k',
                  overplot=True,ls='none',
                  scaleToPhysical=True)
    sdf.plotProgenitor(d1='z',d2='x',color='k',
                       overplot=True,ls='--',lw=1.5,dashes=(20,10),
                       scaleToPhysical=True)
    pyplot.plot(sdf._progenitor.z(sdf._trackts)*8.,
                sdf._progenitor.x(sdf._trackts)*8.,marker='o',ms=6.,
                ls='none',
                color='k')
    pyplot.xlim(8.,-3.)
    pyplot.ylim(12.,15.5)
    bovy_plot._add_ticks()
    bovy_plot._add_axislabels(r'$Z\,(\mathrm{kpc})$',r'$X\,(\mathrm{kpc})$')
    bovy_plot.bovy_text(0.,14.25,r'$\mathrm{auxiliary\ orbit}$',
                        size=16.,rotation=-20.)
    bovy_plot.bovy_text(1.,13.78,r'$\mathrm{stream\ track\ +\ spread}$',
                        size=16.,rotation=-25.)
    bovy_plot.bovy_text(7.5,14.2,r"$\mathrm{At\ these\ points, we\ calculate\ the\ stream\ position\ in}\ (\mathbf{x},\mathbf{v})\ \mathrm{from}$"+
                         '\n'+r"$\mathrm{the\ auxiliary's}\ (\mathbf{x}_a,\mathbf{v}_a) = (\mathbf{\Omega}_a,\boldsymbol{\theta}_a), \mathrm{the\ mean\ offset} (\Delta \mathbf{\Omega},\Delta \boldsymbol{\theta}),$"+'\n'+
                         r"$\mathrm{and}\ \left(\frac{\partial(\mathbf{\Omega},\boldsymbol{\theta})}{\partial (\mathbf{x},\mathbf{v})}\right)^{-1 \, \dagger}.$",
                        size=16.)
    bovy_plot.bovy_plot([sdf._progenitor.z(sdf._trackts[1])*8.,4.5],
                        [sdf._progenitor.x(sdf._trackts[1])*8.,14.8],
                        'k:',overplot=True)
    bovy_plot.bovy_text(5.6,12.4,r"$\mathrm{We\ interpolate\ the\ track\ between\ the}$"+'\n'+r"$\mathrm{calculated\ points\ and\ use\ slerp\ to}$"+'\n'+r"$\mathrm{interpolate\ the\ estimated\ 6D\ spread.}$",
                         size=16.)
    bovy_plot.bovy_plot([3.,sdf._interpolatedObsTrackXY[500,2]*8.],
                        [13.3,sdf._interpolatedObsTrackXY[500,0]*8.],
                        'k:',overplot=True)
    bovy_plot.bovy_end_print(plotfilename2)
    #Finally plot l vs. d
    bovy_plot.bovy_print(fig_width=8.25,fig_height=3.5)
    pyplot.figure()
    sdf.plotTrack(d1='ll',d2='dist',interp=True,
                  color='k',spread=2,overplot=True,lw=1.5)
    sdf.plotTrack(d1='ll',d2='dist',interp=False,marker='o',ms=8.,color='k',
                  overplot=True,ls='none')
    sdf.plotProgenitor(d1='ll',d2='dist',color='k',dashes=(20,10),
                       overplot=True,ls='--',lw=1.5)
    pyplot.plot(sdf._progenitor.ll(sdf._trackts,
                                        obs=[sdf._R0,0.,sdf._Zsun],ro=sdf._Rnorm),
                sdf._progenitor.dist(sdf._trackts,
                                        obs=[sdf._R0,0.,sdf._Zsun],ro=sdf._Rnorm),
                marker='o',ms=6.,
                ls='none',
                color='k')
    pyplot.xlim(157.,260.)
    pyplot.ylim(7.4,15.5)
    bovy_plot._add_ticks()
    bovy_plot._add_axislabels(r'$\mathrm{Galactic\ longitude\, (deg)}$',
                              r'$\mathrm{distance\, (kpc)}$')
    bovy_plot.bovy_text(165.,13.5,r"$\mathrm{Finally, the\ interpolated\ track\ in}\ (\mathbf{x},\mathbf{v})\ \mathrm{is}$"+'\n'+r"$\mathrm{converted\ to\ observable\ quantities\ (here}, l\ \mathrm{and}\ D).$",
                        size=16.)
    bovy_plot.bovy_plot([230.,sdf._interpolatedObsTrackLB[850,0]],
                        [13.25,sdf._interpolatedObsTrackLB[850,2]],
                        'k:',overplot=True)
    bovy_plot.bovy_text(170.,9.4,r"$\mathrm{The\ estimated\ spread\ is\ propagated}$"+'\n'+r"$\mathrm{at\ the\ points\ directly\ from}\ (\mathbf{\Omega},\boldsymbol{\theta})\ \mathrm{to}$"+'\n'+r"$(l,b,D,\ldots)\ \mathrm{and\ interpolated}$"+'\n'+r"$\mathrm{using\ slerp}.$",
                        size=16.)
    bovy_plot.bovy_plot([195.,sdf._ObsTrackLB[1,0]],
                        [9.7,sdf._ObsTrackLB[1,2]],
                        'k:',overplot=True)
    bovy_plot.bovy_end_print(plotfilename3)
    return None
示例#3
0
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
示例#4
0
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
示例#5
0
def astro_sampling(parser):
    options, args = parser.parse_args()
    if options.basti:
        zs = numpy.array([0.004, 0.008, 0.01, 0.0198, 0.03, 0.04])
    elif options.parsec:
        zs = numpy.arange(0.0005, 0.06005, 0.0005)
        # zs= numpy.arange(0.0005,0.06005,0.005)
    else:
        zs = numpy.arange(0.0005, 0.03005, 0.0005)
        # zs= numpy.arange(0.0005,0.03005,0.005)
    if os.path.exists(args[0]):
        savefile = open(args[0], "rb")
        plotthis = pickle.load(savefile)
        zs = pickle.load(savefile)
        lages = pickle.load(savefile)
        savefile.close()
        dlages = lages[1] - lages[0]
        if options.type == "massperrc":
            savefile = open(args[1], "rb")
            plotthis /= pickle.load(savefile)
            savefile.close()
        if options.type == "mass" and len(args) == 3:
            # Also load mass_coarseage and omega
            savefile = open(args[1], "rb")
            masscoarse = pickle.load(savefile)
            savefile.close()
            savefile = open(args[2], "rb")
            omega = pickle.load(savefile)
            savefile.close()
    else:
        nages = 31
        if options.type == "omega" or options.type == "numfrac" or options.coarseage:
            nages = 16
        lages = numpy.linspace(-1.0, 1.0, nages)
        dlages = lages[1] - lages[0]
        plotthis = numpy.zeros((len(zs), nages))
        multOut = multi.parallel_map(
            lambda x: _calc_one(zs[x], options, nages, lages, dlages), range(len(zs)), numcores=32
        )
        for ii in range(len(zs)):
            plotthis[ii, :] = multOut[ii]
        # Save
        savefile = open(args[0], "wb")
        pickle.dump(plotthis, savefile)
        pickle.dump(zs, savefile)
        pickle.dump(lages, savefile)
        savefile.close()
    # Plot
    # Fist cut out youngest ages, since they are irrelevant
    if _CUTLOWAGE:
        aindx = lages > numpy.log10(0.8)
        lages = lages[aindx]
        plotthis = plotthis[:, aindx]
    if options.type == "mass":
        vmin, vmax = 0.5, 2.3
        vmin2, vmax2 = 0.5, 2.0
        zlabel = r"$\langle M_{\mathrm{RC}} \rangle \,(M_\odot)$"
        # cmap= 'gist_yarg'
        cmap = "jet"
    elif options.type == "omega":
        vmin, vmax = 0.0, 0.03
        vmin2, vmax2 = 0.0, 0.015
        if options.allapogee:
            vmin, vmax = 0.0, 0.035
            zlabel = r"$\mathrm{Mass\ fraction\ in}\ (J-K_s)_0 > 0.5\ \mathrm{giants\ (\%)}$"
        elif options.redapogee:
            vmin, vmax = 0.0, 0.005
            vmin2, vmax2 = 0.0, 0.003
            zlabel = r"$\mathrm{Mass\ fraction\ in}\ (J-K_s)_0 > 0.8\ \mathrm{giants\ (\%)}$"
        else:
            zlabel = r"$\mathrm{Mass\ fraction\ in\ RC\ stars\ (\%)}$"
        # cmap= 'gist_yarg'
        cmap = "jet"
        plotthis *= 100.0
    elif options.type == "numfrac":
        vmin, vmax = 0.0, 0.005
        vmin2, vmax2 = 0.0, 0.004
        zlabel = r"$\mathrm{Number\ fraction\ in\ RC\ stars\ (\%)}$"
        # cmap= 'gist_yarg'
        cmap = "jet"
        plotthis *= 100.0
    elif options.type == "massperrc":
        vmin, vmax = 0.0, 50000.0
        vmin2, vmax2 = 0.0, 25000.0
        zlabel = r"$\mathrm{Stellar\ population\ mass\ per\ RC\ star}\,(M_\odot)$"
        # cmap= 'gist_yarg'
        cmap = "jet"
        if options.redapogee:
            vmin, vmax = 0.0, 100000.0
            vmin2, vmax2 = 0.0, 200000.0
            zlabel = r"$\mathrm{Mass\ fraction\ in}\ (J-K_s)_0 > 0.8\ \mathrm{giants\ (\%)}$"
    print numpy.nanmin(plotthis), numpy.nanmax(plotthis)
    if options.basti:  # Remap the Zs
        zs = numpy.array([0.004, 0.008, 0.01, 0.0198, 0.03, 0.04])
        regularzs = numpy.arange(0.0005, 0.03005, 0.0005) / 0.019 * 0.0198
        regularplotthis = numpy.zeros((nages, len(regularzs)))
        for jj in range(len(regularzs)):
            # Find z
            thisindx = numpy.argmin(numpy.fabs(regularzs[jj] - zs))
            for ii in range(nages):
                regularplotthis[ii, jj] = plotthis[ii, thisindx]
        zs = regularzs
        plotthis = regularplotthis
    if options.remapz:
        zs = zs[:-1]
        plotthis = plotthis[:-1, :]
        fehs = numpy.linspace(-1.05, isodist.Z2FEH(zs[-1], zsolar=0.017), len(zs))
        fehzs = isodist.FEH2Z(fehs, zsolar=0.017)
        new_plotthis = numpy.empty_like(plotthis)
        for ii in range(plotthis.shape[1]):
            goodz = True - numpy.isnan(plotthis[:, ii])
            tip = interpolate.InterpolatedUnivariateSpline(zs[goodz], plotthis[goodz, ii], k=3)
            new_plotthis[:, ii] = tip(fehzs)
            try:
                new_plotthis[fehs < numpy.nanmax(isodist.Z2FEH(zs[True - goodz], zsolar=0.017)), ii] = numpy.nan
            except ValueError:
                continue
        plotthis = new_plotthis
        xlabel = r"$[\mathrm{Fe/H}]\,(\mathrm{dex})$"
    else:
        xlabel = r"$Z$"
    bovy_plot.bovy_print(fig_height=7.0, fig_width=6.0)
    fig = pyplot.gcf()
    left, bottom, width, height = 0.1, 0.1, 0.8, 0.6
    axBottom = pyplot.axes([left, bottom, width, height])
    fig.sca(axBottom)
    if options.remapz:
        xlimits = [fehs[0], fehs[-1]]
    else:
        xlimits = [zs[0], zs[-1]]
    ylimits = [lages[0] - dlages, lages[-1] + dlages]
    bovy_plot.bovy_dens2d(
        plotthis.T,
        origin="lower",
        cmap=cmap,
        xrange=xlimits,
        yrange=ylimits,
        vmin=vmin,
        vmax=vmax,
        interpolation="nearest",
        colorbar=True,
        shrink=0.9,
        zlabel=zlabel,
        overplot=True,
    )
    extent = xlimits + ylimits
    pyplot.axis(extent)
    bovy_plot._add_axislabels(xlabel, r"$\log_{10}\,\mathrm{Age} / 1\,\mathrm{Gyr}$")
    bovy_plot._add_ticks()
    left, bottom, width, height = 0.1, 0.68, 0.64, 0.2
    axTop = pyplot.axes([left, bottom, width, height])
    fig.sca(axTop)
    # Plot the average over SFH
    lages = numpy.linspace(-1.0, 1.0, 16)
    if _CUTLOWAGE:
        aindx = lages > numpy.log10(0.8)
        lages = lages[aindx]
        if options.type == "mass":
            omega = omega[:, aindx]
            masscoarse = masscoarse[:, aindx]
    mtrend = numpy.zeros(len(zs))
    exppage = 10.0 ** lages * numpy.exp((10.0 ** (lages + 2.0)) / 800.0)  # e.g., Binney (2010)
    exexppage = 10.0 ** lages * numpy.exp((10.0 ** (lages + 2.0)) / 100.0)  # e.g., Binney (2010)
    page = 10.0 ** lages
    if options.type == "massperrc":
        mtrend = 1.0 / (numpy.sum(page * 1.0 / plotthis, axis=1) / numpy.sum(page))
        expmtrend = 1.0 / (numpy.sum(exppage * 1.0 / plotthis, axis=1) / numpy.sum(exppage))
        exexpmtrend = 1.0 / (numpy.sum(exexppage * 1.0 / plotthis, axis=1) / numpy.sum(exexppage))
    elif options.type == "mass" and len(args) == 3:
        if options.remapz:
            omega = omega[:-1, :]
            masscoarse = masscoarse[:-1, :]
        mtrend = numpy.nansum(page * omega, axis=1) / numpy.nansum(page * omega / masscoarse, axis=1)
        expmtrend = numpy.nansum(exppage * omega, axis=1) / numpy.nansum(exppage * omega / masscoarse, axis=1)
        exexpmtrend = numpy.nansum(exexppage * omega, axis=1) / numpy.nansum(exexppage * omega / masscoarse, axis=1)
    else:
        mtrend = numpy.sum(page * plotthis, axis=1) / numpy.sum(page)
        expmtrend = numpy.sum(exppage * plotthis, axis=1) / numpy.sum(exppage)
        exexpmtrend = numpy.sum(exexppage * plotthis, axis=1) / numpy.sum(exexppage)
    if options.remapz:
        zs = fehs
    pyplot.plot(zs, mtrend, "k-")
    pyplot.plot(zs, expmtrend, "k--")
    pyplot.plot(zs, exexpmtrend, "k-.")
    pyplot.ylim(vmin2, vmax2)
    pyplot.xlim(xlimits[0], xlimits[1])
    nullfmt = NullFormatter()  # no labels
    thisax = pyplot.gca()
    thisax.xaxis.set_major_formatter(nullfmt)
    bovy_plot._add_ticks()
    if options.type == "mass":
        pyplot.ylabel(zlabel)
    if options.basti:
        pyplot.annotate(
            r"$\mathrm{BaSTI}$",
            (0.5, 1.08),
            xycoords="axes fraction",
            horizontalalignment="center",
            verticalalignment="top",
            size=16.0,
        )
    elif options.imfmodel == "kroupa2003":
        pyplot.annotate(
            r"$\mathrm{Padova, Kroupa\ (2003)\ IMF}$",
            (0.5, 1.08),
            xycoords="axes fraction",
            horizontalalignment="center",
            verticalalignment="top",
            size=16.0,
        )
    elif "expsfh" in args[0]:
        pyplot.annotate(
            r"$\mathrm{Padova, p(\mathrm{Age}) \propto e^{\mathrm{Age}/(8\,\mathrm{Gyr})}}$",
            (0.5, 1.08),
            xycoords="axes fraction",
            horizontalalignment="center",
            verticalalignment="top",
            size=16.0,
        )
    elif options.parsec:
        pass
        # pyplot.annotate(r'$\mathrm{PARSEC}$',
        #                (0.5,1.08),xycoords='axes fraction',
        #                horizontalalignment='center',
        #                verticalalignment='top',size=16.)
    else:
        pyplot.annotate(
            r"$\mathrm{Padova}$",
            (0.5, 1.08),
            xycoords="axes fraction",
            horizontalalignment="center",
            verticalalignment="top",
            size=16.0,
        )
    bovy_plot.bovy_end_print(options.outfilename)
    return None
示例#6
0
 def plot_popmass(self):
     """
     NAME:
        plot_popmass
     PURPOSE:
        plot the stellar-population mass for each RC star
     INPUT:
         bovy_plot.bovy_plot **kwargs
     OUTPUT:
        bovy_plot.bovy_plot output
     HISTORY:
        2014-02-28 - Written in this form - Bovy (IAS)
     """
     if not _BOVY_PLOT_LOADED:
         raise ImportError("galpy.util.bovy_plot could not be imported")
     fehs = numpy.linspace(-1., 0.5, 101)
     lages = self._coarselages
     plotthis = numpy.empty((len(fehs), len(lages)))
     for ii in range(len(fehs)):
         for jj in range(len(lages)):
             plotthis[ii, jj] = self.popmass(fehs[ii], lages[jj])
     fig = pyplot.gcf()
     left, bottom, width, height = 0.1, 0.1, 0.8, 0.6
     axBottom = pyplot.axes([left, bottom, width, height])
     fig.sca(axBottom)
     xlimits = [fehs[0], fehs[-1]]
     dlages = (lages[1] - lages[0])
     ylimits = [lages[0] - dlages, lages[-1] + dlages]
     vmin, vmax = 0., 50000.
     vmin2, vmax2 = 0., 25000.
     zlabel = r'$\mathrm{Stellar\ population\ mass\ per\ RC\ star}\,(M_\odot)$'
     xlabel = r'$[\mathrm{Fe/H}]\,(\mathrm{dex})$'
     out = bovy_plot.bovy_dens2d(plotthis.T,
                                 origin='lower',
                                 cmap='jet',
                                 xrange=xlimits,
                                 yrange=ylimits,
                                 vmin=vmin,
                                 vmax=vmax,
                                 interpolation='nearest',
                                 colorbar=True,
                                 shrink=.9,
                                 zlabel=zlabel,
                                 overplot=True)
     extent = xlimits + ylimits
     pyplot.axis(extent)
     bovy_plot._add_axislabels(
         xlabel, r'$\log_{10}\,\mathrm{Age} / 1\,\mathrm{Gyr}$')
     bovy_plot._add_ticks()
     left, bottom, width, height = 0.1, 0.68, 0.64, 0.2
     axTop = pyplot.axes([left, bottom, width, height])
     fig.sca(axTop)
     #Plot the average over SFH
     lages = numpy.linspace(-1., 1., 16)
     mtrend = numpy.zeros(len(self._zs))
     exppage = 10.**self._coarselages * numpy.exp(
         (10.**(self._coarselages + 2.)) / 800.)  #e.g., Binney (2010)
     exexppage = 10.**self._coarselages * numpy.exp(
         (10.**(self._coarselages + 2.)) / 100.)  #e.g., Binney (2010)
     page = 10.**self._coarselages
     plotthis = self._coarsemass[:-1, :] / self._omega[:-1, :]
     mtrend = 1. / (numpy.sum(page * 1. / plotthis, axis=1) /
                    numpy.sum(page))
     expmtrend = 1. / (numpy.sum(exppage * 1. / plotthis, axis=1) /
                       numpy.sum(exppage))
     exexpmtrend = 1. / (numpy.sum(exexppage * 1. / plotthis, axis=1) /
                         numpy.sum(exexppage))
     fehs = isodist.Z2FEH(self._zs[:-1], zsolar=zsolar())
     pyplot.plot(fehs, mtrend, 'k-')
     pyplot.plot(fehs, expmtrend, 'k--')
     pyplot.plot(fehs, exexpmtrend, 'k-.')
     pyplot.ylim(vmin2, vmax2)
     pyplot.xlim(xlimits[0], xlimits[1])
     nullfmt = NullFormatter()  # no labels
     thisax = pyplot.gca()
     thisax.xaxis.set_major_formatter(nullfmt)
     bovy_plot._add_ticks()
     return out
示例#7
0
文件: rc.py 项目: Chaotique/apogee
 def plot_popmass(self):
     """
     NAME:
        plot_popmass
     PURPOSE:
        plot the stellar-population mass for each RC star
     INPUT:
         bovy_plot.bovy_plot **kwargs
     OUTPUT:
        bovy_plot.bovy_plot output
     HISTORY:
        2014-02-28 - Written in this form - Bovy (IAS)
     """
     if not _BOVY_PLOT_LOADED:
         raise ImportError("galpy.util.bovy_plot could not be imported")
     fehs= numpy.linspace(-1.,0.5,101)
     lages= self._coarselages
     plotthis= numpy.empty((len(fehs),len(lages)))
     for ii in range(len(fehs)):
         for jj in range(len(lages)):
             plotthis[ii,jj]= self.popmass(fehs[ii],lages[jj])
     fig= pyplot.gcf()
     left, bottom, width, height= 0.1, 0.1, 0.8, 0.6
     axBottom= pyplot.axes([left,bottom,width,height])
     fig.sca(axBottom)
     xlimits= [fehs[0],fehs[-1]]
     dlages= (lages[1]-lages[0])
     ylimits= [lages[0]-dlages,lages[-1]+dlages]
     vmin, vmax= 0.,50000.
     vmin2, vmax2= 0.,25000.
     zlabel= r'$\mathrm{Stellar\ population\ mass\ per\ RC\ star}\,(M_\odot)$'
     xlabel= r'$[\mathrm{Fe/H}]\,(\mathrm{dex})$'
     out= bovy_plot.bovy_dens2d(plotthis.T,origin='lower',cmap='jet',
                                xrange=xlimits,
                                yrange=ylimits,
                                vmin=vmin,vmax=vmax,
                                interpolation='nearest',
                                colorbar=True,
                                shrink=.9,
                                zlabel=zlabel,
                                overplot=True)
     extent= xlimits+ylimits
     pyplot.axis(extent)
     bovy_plot._add_axislabels(xlabel,
                               r'$\log_{10}\,\mathrm{Age} / 1\,\mathrm{Gyr}$')
     bovy_plot._add_ticks()
     left, bottom, width, height= 0.1, 0.68, 0.64, 0.2
     axTop= pyplot.axes([left,bottom,width,height])
     fig.sca(axTop)
     #Plot the average over SFH
     lages= numpy.linspace(-1.,1.,16)
     mtrend= numpy.zeros(len(self._zs))
     exppage= 10.**self._coarselages*numpy.exp((10.**(self._coarselages+2.))/800.) #e.g., Binney (2010)
     exexppage= 10.**self._coarselages*numpy.exp((10.**(self._coarselages+2.))/100.) #e.g., Binney (2010)
     page= 10.**self._coarselages
     plotthis= self._coarsemass[:-1,:]/self._omega[:-1,:]
     mtrend= 1./(numpy.sum(page*1./plotthis,axis=1)/numpy.sum(page))
     expmtrend= 1./(numpy.sum(exppage*1./plotthis,axis=1)/numpy.sum(exppage))
     exexpmtrend= 1./(numpy.sum(exexppage*1./plotthis,axis=1)/numpy.sum(exexppage))
     fehs= isodist.Z2FEH(self._zs[:-1],zsolar=zsolar())
     pyplot.plot(fehs,mtrend,'k-')
     pyplot.plot(fehs,expmtrend,'k--')
     pyplot.plot(fehs,exexpmtrend,'k-.')
     pyplot.ylim(vmin2,vmax2)
     pyplot.xlim(xlimits[0],xlimits[1])
     nullfmt   = NullFormatter()         # no labels
     thisax= pyplot.gca()
     thisax.xaxis.set_major_formatter(nullfmt)
     bovy_plot._add_ticks()
     return out
示例#8
0
def plotDFResults1D(options,args):
    #First load the results
    #Load g and k fits
    options.sample= 'g'
    options.select= 'all'
    gfits= calcDFResults(options,[_GFIT])
    options.sample= 'k'
    options.select= 'program'   
    kfits= calcDFResults(options,[_KFIT])
    #Setup plane
    tightbinned= pixelAfeFeh(None,dfeh=options.dfeh,dafe=options.dafe,
                             fehmin=-1.6,fehmax=0.5,afemin=-0.05,
                             afemax=0.55) 
    #Setup plotting
    bovy_plot.bovy_print(fig_height=8.,fig_width=8.,
                         axes_labelsize=11,xtick_labelsize=7,
                         ytick_labelsize=7,
                         xtick_major_size=2,
                         xtick_minor_size=1,
                         ytick_major_size=2,
                         ytick_minor_size=1)
    nullfmt   = NullFormatter()         # no labels
    if options.subtype.lower() == 'regular':
        npanels= 5
        keys= ['rd','zh','dlnvcdlnr','plhalo','vc']
        scale= [_REFR0,_REFR0*1000.,1.,1.,1.]
        ranges=[[1.5,4.5],
                [100.,800.],
                [-0.3,0.1],
                [0.,3.],
                [180.,260.]]
        labels=[r'$R_d^{\mathrm{MN}}\ [\mathrm{kpc}]$',
                r'$z_h^{\mathrm{MN}}\ [\mathrm{pc}]$',
                r'$\mathrm{d}\ln V_c / \mathrm{d}\ln R\, (R_0)$',
                r'$\alpha\ \mathrm{in}\ \rho_{\mathrm{halo}} \propto 1/r^\alpha$',
                r'$V_c\ [\mathrm{km\,s}^{-1}]$']                
        ticks= [[2.,3.,4.],
                [100.,300.,500.,700.],
                [-0.3,-0.1,0.1],
                [0.,1.5,3.],
                [180.,220.,260.]]
    elif options.subtype.lower() == 'valueadded':
        npanels= 4
        keys= ['rdexp','zhexp','surfzdisk','rhodm']
        scale= [_REFR0,_REFR0*1000.,1.,1.]
        ranges=[[1.5,4.5],
                [100.,800.],
                [40.,80.],
                [0.,0.02]]
        ticks= [[2.,3.,4.],
                [100.,300.,500.,700.],
                [40.,60.,80.],
                [0.,0.01,0.02]]
        labels=[r'$R_d^{\mathrm{Exp}}\ [\mathrm{kpc}]$',
                r'$z_h^{\mathrm{Exp}}\ [\mathrm{pc}]$',
                r'$\Sigma_{\mathrm{disk}}(R_0)\ [M_{\odot}\,\mathrm{pc}^{-2}]$',
                r'$\rho_{\mathrm{DM}}\,(R_0,0)\ [M_{\odot}\,\mathrm{pc}^{-3}]$']
    nrows= 2
    xrange=[-1.6,0.5]
    yrange=[-0.05,0.55]
    dx= 0.8/npanels
    dy= dx#*(yrange[1]-yrange[0])/(xrange[1]-xrange[0])
    allaxes= []
    for jj in range(nrows):
        for ii in range(npanels):
            if jj == 0: thesefits= gfits
            else: thesefits= kfits
            #Gather results
            plotthis= numpy.zeros((tightbinned.npixfeh(),tightbinned.npixafe()))
            key= keys[ii]
            for tt in range(tightbinned.npixfeh()):
                for rr in range(tightbinned.npixafe()):
                    tfeh= tightbinned.feh(tt)
                    tafe= tightbinned.afe(rr)
                    if numpy.amin((thesefits['feh']-tfeh)**2./options.dfeh**2.+(thesefits['afe']-tafe)**2./options.dafe**2.) > 0.:
                        plotthis[tt,rr]= numpy.nan
                        continue
                    tindx= numpy.argmin((thesefits['feh']-tfeh)**2./options.dfeh**2.+(thesefits['afe']-tafe)**2./options.dafe**2.)
                    plotthis[tt,rr]= thesefits[key][tindx]
            left, bottom, width, height= 0.1+ii*dx, 0.1+dy*(1-jj), dx, dy
            ax= pyplot.axes([left,bottom,width,height])
            allaxes.append(ax)
            fig= pyplot.gcf()
            fig.sca(ax)
            out= bovy_plot.bovy_dens2d(plotthis.T*scale[ii],
                                       origin='lower',cmap='jet',
                                       interpolation='nearest',
                                       xrange=xrange,yrange=yrange,
                                       vmin=ranges[ii][0],vmax=ranges[ii][1],
                                       contours=False,overplot=True,
                                       colorbar=False,aspect='auto')
            if jj == 1:
                bovy_plot._add_axislabels(r'$[\mathrm{Fe/H}]$',None)
            if ii == 0:
                bovy_plot._add_axislabels(None,r'$[\alpha/\mathrm{Fe}]$')
            if jj == 0:
                ax.xaxis.set_major_formatter(nullfmt)
            if ii > 0:
                ax.yaxis.set_major_formatter(nullfmt)
            if jj == 0:
                #Add colorbar
                left, bottom, width, height= 0.1+ii*dx, 0.1+2.*dy*(1-jj), dx, dy
                ax= pyplot.axes([left,bottom,width,height],frameon=False)
                ax.xaxis.set_major_formatter(nullfmt)
                ax.yaxis.set_major_formatter(nullfmt)
                ax.yaxis.set_tick_params(size=0)
                ax.xaxis.set_tick_params(size=0)
                allaxes.append(ax)
                fig.sca(ax)
                CB1= pyplot.colorbar(out,shrink=0.85,orientation='horizontal',
                                     fraction=0.25,ticks=ticks[ii])
                CB1.set_label(labels[ii],labelpad=-30)
    bovy_plot.bovy_end_print(options.outfilename)
    return None