Beispiel #1
0
def plot_hzszq(options,args):
    """Plot sz,hz, q"""
    if len(args) == 0.:
        print "Must provide a savefilename ..."
        print "Returning ..."
        return None
    nqs, nszs, nhzs= 31, 51, 51
    #nqs, nszs, nhzs= 5,5,5
    if os.path.exists(args[0]):
        #Load
        savefile= open(args[0],'rb')
        hzs= pickle.load(savefile)
        szs= pickle.load(savefile)
        qs= pickle.load(savefile)
        savefile.close()
    else:
        qs= numpy.linspace(0.5,1.,nqs)
        szs= numpy.linspace(15.,50.,nszs)
        hzs= numpy.zeros((nqs,nszs))
        for ii in range(nqs):
            print "Working on potential %i / %i ..." % (ii+1,nqs)
            #Setup potential
            lp= LogarithmicHaloPotential(normalize=1.,q=qs[ii])
            if options.aAmethod.lower() == 'staeckel':
                aA= actionAngleStaeckel(pot=lp,delta=0.45,c=True)
            else:
                aA=actionAngleAdiabaticGrid(pot=pot,nR=16,nEz=16,nEr=31,nLz=31,
                                            zmax=1.,Rmax=5.)
            for jj in range(nszs):
                qdf= quasiisothermaldf(options.hr/8.,2.*szs[jj]/220.,
                                       szs[jj]/220.,7./8.,7./8.,pot=lp,
                                       aA=aA,cutcounter=True)    
                hzs[ii,jj]= qdf.estimate_hz(1.,z=0.125)
        #Save
        save_pickles(args[0],hzs,szs,qs)
    #Re-sample
    hzsgrid= numpy.linspace(50.,1500.,nhzs)/8000.
    qs2d= numpy.zeros((nhzs,nszs))
    for ii in range(nszs):
        interpQ= interpolate.UnivariateSpline(hzs[:,ii],qs,k=3)
        qs2d[:,ii]= interpQ(hzsgrid)
        qs2d[(hzsgrid < hzs[0,ii]),ii]= numpy.nan
        qs2d[(hzsgrid > hzs[-1,ii]),ii]= numpy.nan
    #Now plot
    bovy_plot.bovy_print(fig_width=6.,
                         text_fontsize=20.,
                         legend_fontsize=24.,
                         xtick_labelsize=18.,
                         ytick_labelsize=18.,
                         axes_labelsize=24.)
    bovy_plot.bovy_dens2d(qs2d.T,origin='lower',cmap='jet',
                          interpolation='gaussian',
#                          interpolation='nearest',
                          ylabel=r'$\sigma_z\ [\mathrm{km\,s}^{-1}]$',
                          xlabel=r'$h_z\ [\mathrm{pc}]$',
                          zlabel=r'$\mathrm{flattening}\ q$',
                          yrange=[szs[0],szs[-1]],
                          xrange=[8000.*hzsgrid[0],8000.*hzsgrid[-1]],
#                          vmin=0.5,vmax=1.,
                           contours=False,
                           colorbar=True,shrink=0.78)
    _OVERPLOTMAPS= True
    if _OVERPLOTMAPS:
        fehs= monoAbundanceMW.fehs()
        afes= monoAbundanceMW.afes()
        npops= len(fehs)
        mapszs= []
        maphzs= []
        for ii in range(npops):
            thissz, thiserr= monoAbundanceMW.sigmaz(fehs[ii],afes[ii],err=True)
            if thiserr/thissz > 0.1:
                continue
            thishz, thiserr= monoAbundanceMW.hz(fehs[ii],afes[ii],err=True)
            if thiserr/thishz > 0.1:
                continue
            mapszs.append(thissz)
            maphzs.append(thishz)
        mapszs= numpy.array(mapszs)
        maphzs= numpy.array(maphzs)
        bovy_plot.bovy_plot(maphzs,mapszs,'ko',overplot=True,mfc='none',mew=1.5)
    bovy_plot.bovy_text(r'$h_R = %i\,\mathrm{kpc}$' % int(options.hr),
                        bottom_right=True)
    bovy_plot.bovy_end_print(options.plotfilename)
Beispiel #2
0
import monoAbundanceMW as mam

colormap = matplotlib.cm.jet

def _squeeze(o,omin,omax):
    return (o-omin)/(omax-omin)

d = pickle.load(open('01024/g1536.01024.z0agedecomp.dat'))
hz = d['hz']*1000
hzerr = d['hzerr']*1000
rexp = d['rexp'][(d['hzerr'] < 99)]
rexperr = d['rexperr'][(d['hzerr'] < 99)]
mass = d['mass'][(d['hzerr'] < 99)]

#Bovy stuff
bovyhz,bovyhzerr=zip(*[mam.hz(u[0],u[1],err=True) for u in zip(mam.fehs(),mam.afes())])
bovyrexp,bovyrexperr=zip(*[mam.hr(u[0],u[1],err=True) for u in zip(mam.fehs(),mam.afes())])
bovymass=np.array([mam.abundanceDist(u[0],u[1]) for u in zip(mam.fehs(),mam.afes())])

maxhr = 5
maxhz = 2000
bovyplotrexp = np.copy(bovyrexp)
bighr = bovyrexp > maxhr
bovyplotrexp[bighr] = maxhr-0.3

ax = plt.subplot(1,1,1)

ages = [i['mean'] for i in d['age']]
sizes = 10*(d['mass']/4e8)
print sizes
scat = plt.scatter(d['rexp'],hz,c=ages,s=sizes,edgecolors='none')
Beispiel #3
0
def plot2d(options,args):
    """Make a plot of a quantity's best-fit vs. FeH and aFe"""
    if options.sample.lower() == 'g':
        npops= 62
    elif options.sample.lower() == 'k':
        npops= 54
    if options.sample.lower() == 'g':
        savefile= open('binmapping_g.sav','rb')
    elif options.sample.lower() == 'k':
        savefile= open('binmapping_k.sav','rb')
    fehs= pickle.load(savefile)
    afes= pickle.load(savefile)
    savefile.close()
    #First calculate the derivative properties
    if not options.multi is None:
        derivProps= multi.parallel_map((lambda x: calcAllDerivProps(x,options,args)),
                                  range(npops),
                                  numcores=numpy.amin([options.multi,
                                                       npops,
                                                       multiprocessing.cpu_count()]))
    else:
        derivProps= []
        for ii in range(npops):
            derivProps.append(calcAllDerivProps(ii,options,args))
    xprop= options.subtype.split(',')[0]
    yprop= options.subtype.split(',')[1]
    if xprop == 'fracfaint' or yprop == 'fracfaint':
        #Read the data
        print "Reading the data ..."
        raw= read_rawdata(options)
        #Bin the data
        binned= pixelAfeFeh(raw,dfeh=0.1,dafe=0.05)
        for ii in range(npops):
            if numpy.log(monoAbundanceMW.hr(fehs[ii],afes[ii],
                                            k=(options.sample.lower() == 'k')) /8.) > -0.5 \
                                            or (options.sample.lower() == 'g' and (ii == 50 or ii == 57)) \
                                            or (options.sample.lower() == 'k' and ii < 7):
                                            continue
            data= binned(fehs[ii],afes[ii])
            indx= (data.dered_r > 17.8)
            derivProps[ii]['fracfaint']= numpy.sum(indx)/float(len(indx))
            derivProps[ii]['fracfaint_err']= 0.
    if xprop == 'nfaint' or yprop == 'nfaint':
        #Read the data
        print "Reading the data ..."
        raw= read_rawdata(options)
        #Bin the data
        binned= pixelAfeFeh(raw,dfeh=0.1,dafe=0.05)
        for ii in range(npops):
            if numpy.log(monoAbundanceMW.hr(fehs[ii],afes[ii],
                                            k=(options.sample.lower() == 'k')) /8.) > -0.5 \
                                            or (options.sample.lower() == 'g' and ii < 6) \
                                            or (options.sample.lower() == 'k' and ii < 7):
                                            continue
            data= binned(fehs[ii],afes[ii])
            indx= (data.dered_r > 17.8)
            derivProps[ii]['nfaint']= numpy.sum(indx)
            derivProps[ii]['nfaint_err']= 0.
    if xprop == 'hz' or yprop == 'hz':
        for ii in range(npops):
            if numpy.log(monoAbundanceMW.hr(fehs[ii],afes[ii],
                                            k=(options.sample.lower() == 'k')) /8.) > -0.5 \
                                            or (options.sample.lower() == 'g' and ii < 6) \
                                            or (options.sample.lower() == 'k' and ii < 7):
                                            continue
            hz, hzerr= monoAbundanceMW.hz(fehs[ii],afes[ii],
                                          k=(options.sample.lower() == 'k'),
                                          err=True)
            derivProps[ii]['hz']= hz
            derivProps[ii]['hz_err']= hzerr    
    if xprop == 'hr' or yprop == 'hr':
        for ii in range(npops):
            if numpy.log(monoAbundanceMW.hr(fehs[ii],afes[ii],
                                            k=(options.sample.lower() == 'k')) /8.) > -0.5 \
                                            or (options.sample.lower() == 'g' and ii < 6) \
                                            or (options.sample.lower() == 'k' and ii < 7):
                                            continue
            hr, hrerr= monoAbundanceMW.hr(fehs[ii],afes[ii],
                                          k=(options.sample.lower() == 'k'),
                                          err=True)
            derivProps[ii]['hr']= hr
            derivProps[ii]['hr_err']= hrerr    
    #Load into plotthis
    plotthis_x= numpy.zeros(npops)+numpy.nan
    plotthis_y= numpy.zeros(npops)+numpy.nan
    plotthis_x_err= numpy.zeros(npops)+numpy.nan
    plotthis_y_err= numpy.zeros(npops)+numpy.nan
    for ii in range(npops):
        if numpy.log(monoAbundanceMW.hr(fehs[ii],afes[ii],
                                         k=(options.sample.lower() == 'k')) /8.) > -0.5 \
                or (options.sample.lower() == 'g' and ii < 6) \
                or (options.sample.lower() == 'k' and ii < 7):
            continue
        plotthis_x[ii]= derivProps[ii][xprop]
        plotthis_y[ii]= derivProps[ii][yprop]
        plotthis_x_err[ii]= derivProps[ii][xprop+'_err']
        plotthis_y_err[ii]= derivProps[ii][yprop+'_err']
    #Now plot
    bovy_plot.bovy_print(fig_width=6.)
    bovy_plot.bovy_plot(plotthis_x,plotthis_y,
                        s=25.,c=afes,
                        cmap='jet',
                        xlabel=labels[xprop],ylabel=labels[yprop],
                        clabel=r'$[\alpha/\mathrm{Fe}]$',
                        xrange=ranges[xprop],yrange=ranges[yprop],
                        vmin=0.,vmax=0.5,
                        scatter=True,edgecolors='none',
                        colorbar=True)
    colormap = cm.jet
    for ii in range(npops):
        if numpy.isnan(plotthis_x[ii]): continue
        pyplot.errorbar(plotthis_x[ii],
                        plotthis_y[ii],
                        xerr=plotthis_x_err[ii],
                        yerr=plotthis_y_err[ii],
                        color=colormap(_squeeze(afes[ii],
                                                numpy.amax([numpy.amin(afes)]),
                                                            numpy.amin([numpy.amax(afes)]))),
                        elinewidth=1.,capsize=3,zorder=0)  
    bovy_plot.bovy_end_print(options.outfilename)
    return None