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)
def plotRdfh(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() for ii in range(npops): 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 if options.restrictdvt: logl= logl[:,:,:,:,:,:,:,1:4,:,:,:] if options.restrictdf: 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) 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,:,:,:,:] marglogl= numpy.zeros((logl.shape[0],logl.shape[3])) marglogldvt0= numpy.zeros((logl.shape[0],logl.shape[3])) condfh= numpy.zeros((logl.shape[3])) condlogp= numpy.zeros(logl.shape[0]) condfhdvt0= numpy.zeros((logl.shape[3])) condlogpdvt0= numpy.zeros(logl.shape[0]) if ii == 0: allmarglogl= numpy.zeros((logl.shape[0],logl.shape[3],npops)) for jj in range(marglogl.shape[0]): for kk in range(marglogl.shape[1]): indx= True-numpy.isnan(logl[jj,0,0,kk,:,:,:,:,:,:,:].flatten()) indxdvt0= True-numpy.isnan(logl[jj,0,0,kk,:,:,:,2,:,:,:].flatten()) if numpy.sum(indx) > 0: marglogl[jj,kk]= misc.logsumexp(logl[jj,0,0,kk,:,:,:,:,:,:,:].flatten()[indx]) else: marglogl[jj,kk]= -numpy.finfo(numpy.dtype(numpy.float64)).max if numpy.sum(indxdvt0) > 0: marglogldvt0[jj,kk]= misc.logsumexp(logl[jj,0,0,kk,:,:,:,2,:,:,:].flatten()[indxdvt0]) else: marglogldvt0[jj,kk]= -numpy.finfo(numpy.dtype(numpy.float64)).max condlogp[jj]= misc.logsumexp(marglogl[jj,:]) condlogl= marglogl[jj,:]-misc.logsumexp(marglogl[jj,:]) condfh[jj]= numpy.sum(numpy.exp(condlogl)*numpy.linspace(0.,1.,logl.shape[3]))/numpy.sum(numpy.exp(condlogl)) condlogpdvt0[jj]= misc.logsumexp(marglogldvt0[jj,:]) condlogldvt0= marglogldvt0[jj,:]-misc.logsumexp(marglogldvt0[jj,:]) condfhdvt0[jj]= numpy.sum(numpy.exp(condlogldvt0)*numpy.linspace(0.,1.,logl.shape[3]))/numpy.sum(numpy.exp(condlogldvt0)) if monoAbundanceMW.hr(fehs[ii],afes[ii]) < 3.5 \ and numpy.amax(logl) < 0.: #latter removes ridiculous bins allmarglogl[:,:,ii]= marglogl #Normalize alogl= marglogl-numpy.amax(marglogl) bovy_plot.bovy_print() bovy_plot.bovy_dens2d(numpy.exp(alogl).T, origin='lower',cmap='gist_yarg', interpolation='nearest', xrange=[1.5,4.5],yrange=[0.,1.], xlabel=r'$R_d$',ylabel=r'$f_h$') s= 2.*condlogp s-= numpy.amax(s) s+= 16. s*= 3. bovy_plot.bovy_plot(numpy.linspace(1.5,4.5,logl.shape[0]), condfh,color='0.75',ls='-', overplot=True,zorder=2) bovy_plot.bovy_plot(numpy.linspace(1.5,4.5,logl.shape[0]), condfh,color='0.75',marker='o', s=s,scatter=True,overplot=True,zorder=10) maxindx= numpy.argmax(s) bovy_plot.bovy_plot(numpy.linspace(1.5,4.5,logl.shape[0])[maxindx], condfh[maxindx],color='blue',marker='o', ls='none', ms=8.,mec='none', overplot=True,zorder=13) #dvt0 s= 2.*condlogpdvt0 s-= numpy.amax(s) s+= 16. s*= 3. if not options.restrictdvt: bovy_plot.bovy_plot(numpy.linspace(1.5,4.5,logl.shape[0]), condfhdvt0,color='0.25',ls='-', overplot=True,zorder=1) bovy_plot.bovy_plot(numpy.linspace(1.5,4.5,logl.shape[0]), condfhdvt0,color='0.25',marker='o', s=s,scatter=True,overplot=True,zorder=11) maxindx= numpy.argmax(s) bovy_plot.bovy_plot(numpy.linspace(1.5,4.5,logl.shape[0])[maxindx], condfhdvt0[maxindx],color='red',marker='o', ls='none', ms=8.,mec='none', overplot=True,zorder=12) #Plotname spl= options.outfilename.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] if options.restrictdf and not options.restrictdvt: bovy_plot.bovy_text(r'$\mathrm{Restricted\ DF\ parameters}$', top_right=True,size=14.) elif options.restrictdvt and not options.restrictdf: bovy_plot.bovy_text(r'$\mathrm{Restricted}\ \Delta \bar{V}_T\ \mathrm{range}$', top_right=True,size=14.) elif options.restrictdvt and options.restrictdf: bovy_plot.bovy_text(r'$\mathrm{Restricted\ DF\ parameters}$' +'\n' +r'$\mathrm{Restricted}\ \Delta \bar{V}_T\ \mathrm{range}$', top_right=True,size=14.) bovy_plot.bovy_end_print(newname) #Now plot combined alogl= numpy.sum(allmarglogl,axis=2)\ -numpy.amax(numpy.sum(allmarglogl,axis=2)) bovy_plot.bovy_print() bovy_plot.bovy_dens2d(numpy.exp(alogl).T, origin='lower',cmap='gist_yarg', interpolation='nearest', xrange=[1.5,4.5],yrange=[0.,1.], xlabel=r'$R_d$',ylabel=r'$f_h$') bovy_plot.bovy_end_print(options.outfilename)
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)
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)