Exemplo n.º 1
0
def plot1d(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))
    #Load into plotthis
    plotthis= 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[ii]= derivProps[ii][options.subtype.lower()]
    #Now plot
    bovy_plot.bovy_print()
    monoAbundanceMW.plotPixelFunc(fehs,afes,plotthis,
                                  zlabel=labels[options.subtype.lower()])
    bovy_plot.bovy_end_print(options.outfilename)
    return None        
Exemplo n.º 2
0
def plotbestpot(options,args):
    #Go through all of the bins
    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)
    npops= len(fehs)
    savefile.close()
    plotthis_rd= numpy.zeros(npops)+numpy.nan
    plotthis_fh= numpy.zeros(npops)+numpy.nan
    for ii in range(npops):
        sys.stdout.write('\r'+"Working on bin %i / %i ..." % (ii+1,npops))
        sys.stdout.flush()
        if _NOTDONEYET:
            spl= options.restart.split('.')
        else:
            spl= args[0].split('.')
        newname= ''
        for jj in range(len(spl)-1):
            newname+= spl[jj]
            if not jj == len(spl)-2: newname+= '.'
        newname+= '_%i.' % ii
        newname+= spl[-1]
        savefile= open(newname,'rb')
        try:
            if not _NOTDONEYET:
                params= pickle.load(savefile)
                mlogl= pickle.load(savefile)
            logl= pickle.load(savefile)
        except:
            continue
        finally:
            savefile.close()
        if _NOTDONEYET:
            logl[(logl == 0.)]= -numpy.finfo(numpy.dtype(numpy.float64)).max
        rds= numpy.linspace(1.5,4.5,logl.shape[0])
        fhs= numpy.linspace(0.,1.,logl.shape[3])
        if options.restrictdvt:
            logl= logl[:,:,:,:,:,:,:,1:4,:,:,:]
        hrs= numpy.log(numpy.linspace(1.5,5.,logl.shape[4])/_REFR0)
        srs= numpy.log(numpy.linspace(25.,70.,logl.shape[5])/_REFV0)
        szs= numpy.log(numpy.linspace(15.,60.,logl.shape[6])/_REFV0)
        if options.restrictdf:
            lnhrin, lnsrin, lnszin= approxFitResult(fehs[ii],afes[ii])
            hrindx= numpy.argmin((hrs-lnhrin)**2.)
            srindx= numpy.argmin((srs-lnsrin)**2.)
            szindx= numpy.argmin((szs-lnszin)**2.)
            minhrindx= hrindx-1
            maxhrindx= hrindx+1
            if minhrindx < 0: 
                minhrindx+= 1
                maxhrindx+= 1
            elif maxhrindx >= logl.shape[4]: 
                minhrindx-= 1
                maxhrindx-= 1
            minsrindx= srindx-1
            maxsrindx= srindx+1
            if minsrindx < 0: 
                minsrindx+= 1
                maxsrindx+= 1
            elif maxsrindx >= logl.shape[5]: 
                minsrindx-= 1
                maxsrindx-= 1
            minszindx= szindx-1
            maxszindx= szindx+1
            if minszindx < 0: 
                minszindx+= 1
                maxszindx+= 1
            elif maxszindx >= logl.shape[6]: 
                minszindx-= 1
                maxszindx-= 1
            logl= logl[:,:,:,:,minhrindx:maxhrindx+1,minsrindx:maxsrindx+1,
                               minszindx:maxszindx+1,:,:,:,:]
        #Find best-fit potential
        maxindx= numpy.unravel_index(numpy.argmax(logl),(logl.shape))
        plotthis_rd[ii]= rds[maxindx[0]]
        plotthis_fh[ii]= fhs[maxindx[3]]
    sys.stdout.write('\r'+_ERASESTR+'\r')
    sys.stdout.flush()
    #Now plot
    bovy_plot.bovy_print()
    monoAbundanceMW.plotPixelFunc(fehs,afes,plotthis_rd,
                                  vmin=1.5,vmax=4.5,
                                  zlabel=r'$R_d\ [\mathrm{kpc}]$')
    #Plotname
    spl= options.outfilename.split('.')
    newname= ''
    for jj in range(len(spl)-1):
        newname+= spl[jj]
        if not jj == len(spl)-2: newname+= '.'
    newname+= '_rd.'
    newname+= spl[-1]
    bovy_plot.bovy_end_print(newname)
    #fh
    bovy_plot.bovy_print()
    monoAbundanceMW.plotPixelFunc(fehs,afes,plotthis_fh,
                                  vmin=0.,vmax=1.,
                                  zlabel=r'$f_h$')
    #Plotname
    spl= options.outfilename.split('.')
    newname= ''
    for jj in range(len(spl)-1):
        newname+= spl[jj]
        if not jj == len(spl)-2: newname+= '.'
    newname+= '_fh.'
    newname+= spl[-1]
    bovy_plot.bovy_end_print(newname)
Exemplo n.º 3
0
def plotDF4fidpot(options,args):
    #Go through all of the bins
    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)
    npops= len(fehs)
    savefile.close()
    plotthis= numpy.zeros(npops)+numpy.nan
    for ii in range(npops):
        sys.stdout.write('\r'+"Working on bin %i / %i ..." % (ii+1,npops))
        sys.stdout.flush()
        if _NOTDONEYET:
            spl= options.restart.split('.')
        else:
            spl= args[0].split('.')
        newname= ''
        for jj in range(len(spl)-1):
            newname+= spl[jj]
            if not jj == len(spl)-2: newname+= '.'
        newname+= '_%i.' % ii
        newname+= spl[-1]
        savefile= open(newname,'rb')
        try:
            if not _NOTDONEYET:
                params= pickle.load(savefile)
                mlogl= pickle.load(savefile)
            logl= pickle.load(savefile)
        except:
            continue
        finally:
            savefile.close()
        if _NOTDONEYET:
            logl[(logl == 0.)]= -numpy.finfo(numpy.dtype(numpy.float64)).max
        hrs= numpy.log(numpy.linspace(1.5,5.,logl.shape[4])/_REFR0)
        srs= numpy.log(numpy.linspace(25.,70.,logl.shape[5])/_REFV0)
        szs= numpy.log(numpy.linspace(15.,60.,logl.shape[6])/_REFV0)
        if options.restrictdvt:
            logl= logl[:,:,:,:,:,:,:,1:4,:,:,:]
        if options.restrictdf:
            lnhrin, lnsrin, lnszin= approxFitResult(fehs[ii],afes[ii])
            hrindx= numpy.argmin((hrs-lnhrin)**2.)
            srindx= numpy.argmin((srs-lnsrin)**2.)
            szindx= numpy.argmin((szs-lnszin)**2.)
            minhrindx= hrindx-1
            maxhrindx= hrindx+1
            if minhrindx < 0: 
                minhrindx+= 1
                maxhrindx+= 1
            elif maxhrindx >= logl.shape[4]: 
                minhrindx-= 1
                maxhrindx-= 1
            minsrindx= srindx-1
            maxsrindx= srindx+1
            if minsrindx < 0: 
                minsrindx+= 1
                maxsrindx+= 1
            elif maxsrindx >= logl.shape[5]: 
                minsrindx-= 1
                maxsrindx-= 1
            minszindx= szindx-1
            maxszindx= szindx+1
            if minszindx < 0: 
                minszindx+= 1
                maxszindx+= 1
            elif maxszindx >= logl.shape[6]: 
                minszindx-= 1
                maxszindx-= 1
            logl= logl[:,:,:,:,minhrindx:maxhrindx+1,minsrindx:maxsrindx+1,
                               minszindx:maxszindx+1,:,:,:,:]
        #Find best-fit df for the fiducial potential
        indx= numpy.unravel_index(options.index,(logl.shape[0],logl.shape[3]))
        logl= logl[indx[0],0,0,indx[1],:,:,:,:,:,:,:]
        maxindx= numpy.unravel_index(numpy.argmax(logl),(logl.shape))
        if options.subtype.lower() == 'hr':
            plotthis[ii]= numpy.exp(hrs[maxindx[0]])*_REFR0
        elif options.subtype.lower() == 'sr':
            plotthis[ii]= numpy.exp(srs[maxindx[1]])*_REFV0
        elif options.subtype.lower() == 'sz':
            plotthis[ii]= numpy.exp(szs[maxindx[2]])*_REFV0
    sys.stdout.write('\r'+_ERASESTR+'\r')
    sys.stdout.flush()
    #Now plot
    if options.subtype.lower() == 'hr':
        vmin, vmax= 1.35,4.5
        zlabel=r'$\mathrm{Input\ radial\ scale\ length\ [kpc]}$'
    elif options.subtype.lower() == 'sr':
        vmin, vmax= 30., 60.
        zlabel= r'$\mathrm{Input\ radial\ velocity\ dispersion\ [km\,s}^{-1}]$'
    elif options.subtype.lower() == 'sz':
        vmin, vmax= 10., 80.
        zlabel= r'$\mathrm{Input\ vertical\ velocity\ dispersion\ [km\,s}^{-1}]$'
    bovy_plot.bovy_print()
    monoAbundanceMW.plotPixelFunc(fehs,afes,plotthis,
                                  vmin=vmin,vmax=vmax,
                                  zlabel=zlabel)
    bovy_plot.bovy_end_print(options.outfilename)
Exemplo n.º 4
0
def plotbestr(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: calcAllSurfErr(x,options,args)),
                                  range(npops),
                                  numcores=numpy.amin([options.multi,
                                                       npops,
                                                       multiprocessing.cpu_count()]))
    else:
        derivProps= []
        for ii in range(npops):
            derivProps.append(calcAllSurfErr(ii,options,args))
    #If a second argument is given, this gives a set of rs at which also to calculate the surface density
    if len(args) > 1:
        if os.path.exists(args[1]):
            surffile= open(args[1],'rb')
            altsurfrs= pickle.load(surffile)
            surffile.close()
            calcExtra= True
        else:
            raise IOError("extra savefilename with surface-densities has to exist when it is specified")
    else:
        calcExtra= False
    if not calcExtra: #Fiducial, for which we also calculate everything at the mean radius of each MAP
        #Load g orbits
        orbitsfile= 'gOrbitsNew.sav'
        savefile= open(orbitsfile,'rb')
        orbits= pickle.load(savefile)
        savefile.close()
        #Cut to S/N, logg, and EBV
        indx= (orbits.sna > 15.)*(orbits.logga > 4.2)*(orbits.ebv < 0.3)
        orbits= orbits[indx]
        #Load the orbits into the pixel structure
        pix= pixelAfeFeh(orbits,dfeh=0.1,dafe=0.05)
        #Now calculate meanr
        rmean= numpy.zeros(npops)
        for ii in range(npops):
            data= pix(fehs[ii],afes[ii])
            vals= data.densrmean*8.
            if False:#True:
                rmean[ii]= numpy.mean(vals)
            else:
                rmean[ii]= numpy.median(vals)
    #Load into plotthis
    plotthis= numpy.zeros(npops)+numpy.nan
    plotthis_y= numpy.zeros(npops)+numpy.nan
    plotthis_y_err= numpy.zeros(npops)+numpy.nan
    plotthiskz_y= numpy.zeros(npops)+numpy.nan
    plotthiskz_y_err= numpy.zeros(npops)+numpy.nan
    altplotthis= numpy.zeros(npops)+numpy.nan
    altplotthis_y= numpy.zeros(npops)+numpy.nan
    altplotthis_y_err= numpy.zeros(npops)+numpy.nan
    altplotthiskz_y= numpy.zeros(npops)+numpy.nan
    altplotthiskz_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 < 0 or ii == 50)) \
                or (options.sample.lower() == 'k' and ii < 7):
            continue
        #Determine best-r
        #indx= numpy.argmin(derivProps[ii][:,2]/numpy.fabs(derivProps[ii][:,1]))
        indx= numpy.argmin(numpy.fabs(derivProps[ii][:,2]))
        if indx == 0: indx= int(numpy.floor(numpy.random.uniform()*10))
        plotthis[ii]= derivProps[ii][indx,0]
        plotthis_y[ii]= derivProps[ii][indx,1]
        plotthis_y_err[ii]= derivProps[ii][indx,3]
        plotthiskz_y[ii]= derivProps[ii][indx,4]
        plotthiskz_y_err[ii]= derivProps[ii][indx,5]
        if calcExtra:
            indx= numpy.argmin(numpy.fabs(derivProps[ii][:,0]-altsurfrs[ii]))
            altplotthis[ii]= derivProps[ii][indx,0]
            altplotthis_y[ii]= derivProps[ii][indx,1]
            altplotthis_y_err[ii]= derivProps[ii][indx,3]           
            altplotthiskz_y[ii]= derivProps[ii][indx,4]
            altplotthiskz_y_err[ii]= derivProps[ii][indx,5]           
        else:
            indx= numpy.argmin(numpy.fabs(derivProps[ii][:,0]-rmean[ii]))
            altplotthis[ii]= derivProps[ii][indx,0]
            altplotthis_y[ii]= derivProps[ii][indx,1]
            altplotthis_y_err[ii]= derivProps[ii][indx,3]           
            altplotthiskz_y[ii]= derivProps[ii][indx,4]
            altplotthiskz_y_err[ii]= derivProps[ii][indx,5]           
    #Now plot
    bovy_plot.bovy_print()
    monoAbundanceMW.plotPixelFunc(fehs,afes,plotthis,
                                  zlabel=r'$R_\Sigma\ (\mathrm{kpc})$')
    bovy_plot.bovy_end_print(options.outfilename)
    bovy_plot.bovy_print()
    print plotthis, plotthis_y
    bovy_plot.bovy_plot(plotthis,plotthis_y,'ko',
                        xlabel=r'$R\ (\mathrm{kpc})$',
                        ylabel=r'$\Sigma(R,|Z| \leq 1.1\,\mathrm{kpc})\ (M_\odot\,\mathrm{pc}^{-2})$',
                        xrange=[4.,10.],
                        yrange=[10,1050.],#,numpy.nanmin(plotthis_y)-10.,
#                                numpy.nanmax(plotthis_y)+10.],
                        semilogy=True)
    pyplot.errorbar(plotthis,
                    plotthis_y,
                    yerr=plotthis_y_err,
                    elinewidth=1.,capsize=3,zorder=0,
                    color='k',linestyle='none')  
    trs= numpy.linspace(4.3,9.,1001)
    pyplot.plot(trs,72.*numpy.exp(-(trs-8.)/3.),'k--')
    pyplot.plot(trs,72.*numpy.exp(-(trs-8.)/2.),'k-.')
    pyplot.plot(trs,72.*numpy.exp(-(trs-8.)/4.),'k:')
    #Fit exponential
    #indx= (plotthis < 8.)
    #plotthis= plotthis[indx]
    #plotthis_y= plotthis_y[indx]
    #plotthis_y_err= plotthis_y_err[indx]
    exp_params= optimize.fmin_powell(expcurve,
                                     numpy.log(numpy.array([72.,2.5])),
                                     args=(plotthis,plotthis_y,plotthis_y_err))
    pyplot.plot(trs,numpy.exp(exp_params[0]-(trs-8.)/numpy.exp(exp_params[1])),
                'k-',lw=2.)
    print numpy.exp(exp_params) 
    bovy_plot.bovy_end_print(options.outfilename.replace('.png','_rvssurf.png'))
    #Save
    if calcExtra:
        save_pickles(options.outfilename.replace('.png','_rvssurf.sav'),
                     plotthis,plotthis_y,plotthis_y_err,
                     plotthiskz_y,plotthiskz_y_err,
                     altplotthis,altplotthis_y,altplotthis_y_err,
                     altplotthiskz_y,altplotthiskz_y_err)
    else:
        save_pickles(options.outfilename.replace('.png','_rvssurf.sav'),
                     plotthis,plotthis_y,plotthis_y_err,
                     plotthiskz_y,plotthiskz_y_err,
                     altplotthis,altplotthis_y,altplotthis_y_err,
                     altplotthiskz_y,altplotthiskz_y_err)
    return None        
Exemplo n.º 5
0
def plotQdfPreviousFits(options,args):
    #Get the bins
    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()
    #Run through them and get the apprimxate results
    lnhrin= numpy.empty(len(fehs))
    lnsrin= numpy.empty(len(fehs))
    lnszin= numpy.empty(len(fehs))
    for ii in range(len(fehs)):
        out= approxFitResult(fehs[ii],afes[ii])
        lnhrin[ii]= out[0]
        lnsrin[ii]= out[1]
        lnszin[ii]= out[2]
    #Now plot: hR
    bovy_plot.bovy_print(text_fontsize=20.,
                         legend_fontsize=24.,
                         xtick_labelsize=18.,
                         ytick_labelsize=18.,
                         axes_labelsize=20.)
    monoAbundanceMW.plotPixelFunc(fehs,afes,numpy.exp(lnhrin)*8.,
                                  vmin=1.5,vmax=4.86,
                                  zlabel=r'$h^{\mathrm{in}}_R\ (\mathrm{kpc})$')
    #Plotname
    spl= options.outfilename.split('.')
    newname= ''
    for jj in range(len(spl)-1):
        newname+= spl[jj]
        if not jj == len(spl)-2: newname+= '.'
    newname+= '_hrin.'
    newname+= spl[-1]
    bovy_plot.bovy_end_print(newname)
    #Now plot: sR
    bovy_plot.bovy_print(text_fontsize=20.,
                         legend_fontsize=24.,
                         xtick_labelsize=18.,
                         ytick_labelsize=18.,
                         axes_labelsize=20.)
    monoAbundanceMW.plotPixelFunc(fehs,afes,numpy.exp(lnsrin)*220.,
                                  vmin=30.,vmax=60.,
                                  zlabel=r'$\sigma^{\mathrm{in}}_R\ (\mathrm{km\,s}^{-1})$')
    #Plotname
    spl= options.outfilename.split('.')
    newname= ''
    for jj in range(len(spl)-1):
        newname+= spl[jj]
        if not jj == len(spl)-2: newname+= '.'
    newname+= '_srin.'
    newname+= spl[-1]
    bovy_plot.bovy_end_print(newname)
    #Now plot: sZ
    bovy_plot.bovy_print(text_fontsize=20.,
                         legend_fontsize=24.,
                         xtick_labelsize=18.,
                         ytick_labelsize=18.,
                         axes_labelsize=20.)
    monoAbundanceMW.plotPixelFunc(fehs,afes,numpy.exp(lnszin)*220.,
                                  vmin=10.,vmax=80.,
                                  zlabel=r'$\sigma^{\mathrm{in}}_Z\ (\mathrm{km\,s}^{-1})$')
    #Plotname
    spl= options.outfilename.split('.')
    newname= ''
    for jj in range(len(spl)-1):
        newname+= spl[jj]
        if not jj == len(spl)-2: newname+= '.'
    newname+= '_szin.'
    newname+= spl[-1]
    bovy_plot.bovy_end_print(newname)