def plotFidDF(options,args): #Setup potential params= numpy.array([-1.33663190049,0.998420232634,-3.49031638164,0.31949840593,-1.63965169376]) try: pot= setup_potential(params,options,0)#Assume that the potential parameters come from a file with a single set of df parameters first except RuntimeError: #if this set of parameters gives a nonsense potential raise ro= 1. vo= params[1] options.aAmethod='adiabatic' aA= setup_aA(pot,options) options.aAmethod='staeckel' aAS= setup_aA(pot,options) #Setup DF qdf= quasiisothermaldf(2./8.,0.25,0.3,1.,0.875,aA=aAS,pot=pot,cutcounter=True) qdfa= quasiisothermaldf(2./8.,0.25,0.3,1.,0.875,aA=aA,pot=pot,cutcounter=True) if options.type.lower() == 'lzjr': njs= 201 jrs= numpy.linspace(0.,500.,njs)/ro/vo/_REFR0/_REFV0 lzs= numpy.linspace(0.0,3600.,njs)/ro/vo/_REFR0/_REFV0 plotthis= qdf((numpy.tile(jrs,(njs,1)).flatten(), numpy.tile(lzs,(njs,1)).T.flatten(), numpy.zeros((njs,njs)).flatten())).reshape((njs,njs)) bovy_plot.bovy_print() bovy_plot.bovy_dens2d(plotthis.T,origin='lower',cmap='gist_yarg', xlabel=r'$L_z\ (220\,\mathrm{km\,s}^{-1}\,\mathrm{kpc})$', ylabel=r'$J_R\ (220\,\mathrm{km\,s}^{-1}\,\mathrm{kpc})$', xrange=[0.,3600./220.], yrange=[0.,500./220.], onedhists=True, interpolation='nearest', cntrmass=True,contours=True, levels= special.erf(0.5*numpy.arange(1,4))) elif options.type.lower() == 'jrjz': njs= 201 jrs= numpy.linspace(0.,500.,njs)/ro/vo/_REFR0/_REFV0 jzs= numpy.linspace(0.,250.,njs)/ro/vo/_REFR0/_REFV0 plotthis= qdf((numpy.tile(jrs,(njs,1)).T.flatten(), 0.9*numpy.ones((njs,njs)).flatten(), numpy.tile(jzs,(njs,1)).flatten())).reshape((njs,njs)) bovy_plot.bovy_print() bovy_plot.bovy_dens2d(plotthis.T,origin='lower',cmap='gist_yarg', xlabel=r'$J_R\ (220\,\mathrm{km\,s}^{-1}\,\mathrm{kpc})$', ylabel=r'$J_Z\ (220\,\mathrm{km\,s}^{-1}\,\mathrm{kpc})$', xrange=[0.,500./220.], yrange=[0.,250./220.], onedhists=True, interpolation='nearest', cntrmass=True,contours=True, levels= special.erf(0.5*numpy.arange(1,4))) elif options.type.lower() == 'tilt': zs= numpy.linspace(0.,5.,101) tilt= numpy.array([qdf.tilt(1.,z/ro/_REFR0,gl=True) for z in zs]) bovy_plot.bovy_print(text_fontsize=20., legend_fontsize=24., xtick_labelsize=18., ytick_labelsize=18., axes_labelsize=24.) line1= bovy_plot.bovy_plot(zs,tilt,'k-', xlabel=r'$Z\ (\mathrm{kpc})$', ylabel=r'$\mathrm{tilt\ of\ the\ velocity\ ellipsoid}\ (\mathrm{deg})$', xrange=[0.,5.], yrange=[-5.,30.]) line2= bovy_plot.bovy_plot(zs,zs*0.,'k--',overplot=True) pyplot.legend((line1[0],line2[0]), (r'$\mathrm{St\ddot{a}ckel\ actions}$', r'$\mathrm{Adiabatic\ actions}$'), loc='upper left',#bbox_to_anchor=(.91,.375), numpoints=2, prop={'size':18}, frameon=False) bovy_plot.bovy_plot(zs,numpy.arctan(zs/ro/_REFR0)/numpy.pi*180., '-',color='0.65', overplot=True) pyplot.errorbar(numpy.array([1.]), numpy.array([7.3]), yerr=numpy.array([1.8,1.8]).reshape((2,1)), color='k',fmt='o',ms=8) bovy_plot.bovy_text(.55,8.2,r'$\mathrm{S08}$',fontsize=14.) elif options.type.lower() == 'sigz': zs= numpy.linspace(0.,5.,101) sigz2= numpy.array([qdf.sigmaz2(1.,z/ro/_REFR0,gl=True) for z in zs]) sigz2a= numpy.array([qdfa.sigmaz2(1.,z/ro/_REFR0,gl=True) for z in zs]) bovy_plot.bovy_print(text_fontsize=20., legend_fontsize=24., xtick_labelsize=18., ytick_labelsize=18., axes_labelsize=24.) line1= bovy_plot.bovy_plot(zs,numpy.sqrt(sigz2)*vo*_REFV0,'k-', xlabel=r'$Z\ (\mathrm{kpc})$', ylabel=r'$\sigma_Z(Z)\ (\mathrm{km\,s}^{-1})$', xrange=[0.,5.], yrange=[0.,60.]) line2= bovy_plot.bovy_plot(zs,numpy.sqrt(sigz2a)*vo*_REFV0, 'k--',overplot=True) #pyplot.legend((line1[0],line2[0]), # (r'$\mathrm{St\ddot{a}ckel\ actions}$', # r'$\mathrm{Adiabatic\ actions}$'), # loc='lower left',#bbox_to_anchor=(.91,.375), # numpoints=2, # prop={'size':16}, # frameon=False) elif options.type.lower() == 'densz': zs= numpy.linspace(0.,5.,101) densz= numpy.array([qdf.density(1.,z/ro/_REFR0,gl=True) for z in zs]) densza= numpy.array([qdfa.density(1.,z/ro/_REFR0,gl=True) for z in zs]) bovy_plot.bovy_print(text_fontsize=20., legend_fontsize=24., xtick_labelsize=18., ytick_labelsize=18., axes_labelsize=24.) line1= bovy_plot.bovy_plot(zs,densz/densz[0],'k-', xlabel=r'$Z\ (\mathrm{kpc})$', ylabel=r'$\nu_*(R_0,Z)/\nu_*(R_0,0)$', xrange=[0.,5.], semilogy=True) line2= bovy_plot.bovy_plot(zs,densza/densza[0],'k--',overplot=True) pyplot.legend((line1[0],line2[0]), (r'$\mathrm{St\ddot{a}ckel\ actions}$', r'$\mathrm{Adiabatic\ actions}$'), loc='upper right',#bbox_to_anchor=(.91,.375), numpoints=2, prop={'size':18}, frameon=False) #Create inset with profile at different R denszr12= numpy.array([qdf.density(11./8.,z/ro/_REFR0,gl=True) for z in zs]) denszr4= numpy.array([qdf.density(5./8.,z/ro/_REFR0,gl=True) for z in zs]) insetAxes= pyplot.axes([0.15,0.12,0.4,0.4]) line1= insetAxes.semilogy(zs,densz/densz[0],'k-') line2= insetAxes.semilogy(zs,denszr12/denszr12[0],'k:') line3= insetAxes.semilogy(zs,denszr4/denszr4[0],'k--') nullfmt = NullFormatter() # no labels insetAxes.xaxis.set_major_formatter(nullfmt) insetAxes.yaxis.set_major_formatter(nullfmt) pyplot.legend((line3[0],line1[0],line2[0]), (r'$R = 5\,\mathrm{kpc}$', r'$R = 8\,\mathrm{kpc}$', r'$R = 11\,\mathrm{kpc}$'), loc='lower left',#bbox_to_anchor=(.91,.375), numpoints=2, prop={'size':12}, frameon=False) elif options.type.lower() == 'densr': rs= numpy.linspace(4.,15.,101) densr= numpy.array([qdf.density(r/ro/_REFR0,1./ro/_REFR0,gl=True) for r in rs]) densra= numpy.array([qdfa.density(r/ro/_REFR0,1./ro/_REFR0,gl=True) for r in rs]) bovy_plot.bovy_print(text_fontsize=20., legend_fontsize=24., xtick_labelsize=18., ytick_labelsize=18., axes_labelsize=24.) line1= bovy_plot.bovy_plot(rs,densr/densr[numpy.argmin((rs-8.)**2.)],'k-', xlabel=r'$R\ (\mathrm{kpc})$', ylabel=r'$\nu_*(R,1\,\mathrm{kpc})/\nu_*(R_0,1\,\mathrm{kpc})$', xrange=[4.,15.], semilogy=True) line2= bovy_plot.bovy_plot(rs,densra/densra[numpy.argmin((rs-8.)**2.)],'k--',overplot=True) line3= bovy_plot.bovy_plot(rs,numpy.exp(-(rs-8.)/2.),'-', overplot=True, color='0.65') #pyplot.legend((line1[0],line2[0]), # (r'$\mathrm{St\ddot{a}ckel\ actions}$', # r'$\mathrm{Adiabatic\ actions}$'), # loc='lower left',#bbox_to_anchor=(.91,.375), # numpoints=2, # prop={'size':16}, # frameon=False) bovy_plot.bovy_end_print(options.outfilename)
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)
def plot_hrhrvshr(options,args): """Plot hr^out/hr^in as a function of hr for various sr""" if len(args) == 0.: print "Must provide a savefilename ..." print "Returning ..." return None if os.path.exists(args[0]): #Load savefile= open(args[0],'rb') plotthis= pickle.load(savefile) hrs= pickle.load(savefile) srs= pickle.load(savefile) savefile.close() else: #Grid of models to test hrs= numpy.linspace(options.hrmin,options.hrmax,options.nhr) srs= numpy.linspace(options.srmin,options.srmax,options.nsr) #Tile hrs= numpy.tile(hrs,(options.nsr,1)).T srs= numpy.tile(srs,(options.nhr,1)) plotthis= numpy.zeros((options.nhr,options.nsr)) #Setup potential and aA poptions= setup_options(None) #poptions.potential= 'dpdiskplhalofixbulgeflatwgasalt' #params= [0.,0.,0.,0.,0.,0.,-1.16315,1.,-3.,0.4,0.] poptions.potential= 'btii' params= None #pot= MWPotential pot= setup_potential(params,poptions,1) if options.aAmethod.lower() == 'staeckel': aA= actionAngleStaeckel(pot=pot,delta=0.45,c=True) else: aA=actionAngleAdiabaticGrid(pot=pot,nR=16,nEz=16,nEr=31,nLz=31, zmax=1.,Rmax=5.) for ii in range(options.nhr): for jj in range(options.nsr): qdf= quasiisothermaldf(hrs[ii,jj]/8.,srs[ii,jj]/220., srs[ii,jj]/numpy.sqrt(3.)/220., 7./8.,1., pot=pot,aA=aA) plotthis[ii,jj]= qdf.estimate_hr(1.,z=0.8/8., dR=0.33, gl=True)/hrs[ii,jj]*8. print ii*options.nsr+jj+1, options.nsr*options.nhr, \ hrs[ii,jj], srs[ii,jj], plotthis[ii,jj] #Save save_pickles(args[0],plotthis,hrs,srs) #Now plot bovy_plot.bovy_print(fig_width=6., text_fontsize=20., legend_fontsize=24., xtick_labelsize=18., ytick_labelsize=18., axes_labelsize=24.) indx= 0 lines= [] colors= [cm.jet(ii/float(options.nsr-1.)*1.+0.) for ii in range(options.nsr)] lss= ['-' for ii in range(options.nsr)]#,'--','-.','..'] labels= [] lines.append(bovy_plot.bovy_plot(hrs[:,indx],plotthis[:,indx], color=colors[indx],ls=lss[indx], xrange=[0.5,5.5], yrange=[0.,2.], xlabel=r'$h^{\mathrm{in}}_R\ \mathrm{at}\ 8\,\mathrm{kpc}$', ylabel=r'$h^{\mathrm{out}}_R / h^{\mathrm{in}}_R$')) labels.append(r'$\sigma_R = %.0f \,\mathrm{km\,s}^{-1}$' % srs[0,indx]) for indx in range(1,options.nsr): lines.append(bovy_plot.bovy_plot(hrs[:,indx],plotthis[:,indx], color=colors[indx],ls=lss[indx], overplot=True)) labels.append(r'$\sigma_R = %.0f \,\mathrm{km\,s}^{-1}$' % srs[0,indx]) """ #Legend pyplot.legend(lines,#(line1[0],line2[0],line3[0],line4[0]), labels,#(r'$v_{bc} = 0$', # r'$v_{bc} = 1\,\sigma_{bc}$', # r'$v_{bc} = 2\,\sigma_{bc}$', # r'$v_{bc} = 3\,\sigma_{bc}$'), loc='lower right',#bbox_to_anchor=(.91,.375), numpoints=2, prop={'size':14}, frameon=False) """ #Add colorbar map = cm.ScalarMappable(cmap=cm.jet) map.set_array(srs[0,:]) map.set_clim(vmin=numpy.amin(srs[0,:]),vmax=numpy.amax(srs[0,:])) cbar= pyplot.colorbar(map,fraction=0.15) cbar.set_clim(numpy.amin(srs[0,:]),numpy.amax(srs[0,:])) cbar.set_label(r'$\sigma_R \,(\mathrm{km\,s}^{-1})$') bovy_plot.bovy_end_print(options.plotfilename)
def plot_szszvssz(options,args): """Plot sz^out/sz^in as a function of sz for various hr""" if len(args) == 0.: print "Must provide a savefilename ..." print "Returning ..." return None if os.path.exists(args[0]): #Load savefile= open(args[0],'rb') plotthis= pickle.load(savefile) szs= pickle.load(savefile) hrs= pickle.load(savefile) savefile.close() else: #Grid of models to test if options.subtype.lower() == 'sr': szs= numpy.linspace(options.srmin,options.srmax,options.nsz) else: szs= numpy.linspace(options.szmin,options.szmax,options.nsz) hrs= numpy.linspace(options.hrmin,options.hrmax,options.nhr) #Tile szs= numpy.tile(szs,(options.nhr,1)).T hrs= numpy.tile(hrs,(options.nsz,1)) plotthis= numpy.zeros((options.nsz,options.nhr)) #Setup potential and aA poptions= setup_options(None) #poptions.potential= 'dpdiskplhalofixbulgeflatwgasalt' #params= [0.,0.,0.,0.,0.,0.,-1.16315,1.,-3.,0.4,0.] poptions.potential= 'btii' params= None #pot= MWPotential pot= setup_potential(params,poptions,1) if options.aAmethod.lower() == 'staeckel': aA= actionAngleStaeckel(pot=pot,delta=0.45,c=True) else: aA=actionAngleAdiabaticGrid(pot=pot,nR=16,nEz=16,nEr=31,nLz=31, zmax=1.,Rmax=5.) for ii in range(options.nsz): for jj in range(options.nhr): if options.subtype.lower() == 'sr': qdf= quasiisothermaldf(hrs[ii,jj]/8., szs[ii,jj]/220., szs[ii,jj]/220./numpy.sqrt(3.), 7./8.,1., pot=pot,aA=aA) else: qdf= quasiisothermaldf(hrs[ii,jj]/8., szs[ii,jj]/220.*numpy.sqrt(3.), szs[ii,jj]/220., 7./8.,1., pot=pot,aA=aA) if options.subtype.lower() == 'sr': plotthis[ii,jj]= numpy.sqrt(qdf.sigmaR2(1.,0.8/8., gl=True))/szs[ii,jj]*220. else: plotthis[ii,jj]= numpy.sqrt(qdf.sigmaz2(1.,0.8/8., gl=True))/szs[ii,jj]*220. print ii*options.nhr+jj+1, options.nhr*options.nsz, \ szs[ii,jj], hrs[ii,jj], plotthis[ii,jj] #Save save_pickles(args[0],plotthis,szs,hrs) #Now plot bovy_plot.bovy_print(fig_width=6., text_fontsize=20., legend_fontsize=24., xtick_labelsize=18., ytick_labelsize=18., axes_labelsize=24.) indx= 0 lines= [] colors= [cm.jet(ii/float(options.nhr-1.)*1.+0.) for ii in range(options.nhr)] lss= ['-' for ii in range(options.nhr)]#,'--','-.','..'] labels= [] if options.subtype.lower() == 'sr': lines.append(bovy_plot.bovy_plot(szs[:,indx],plotthis[:,indx], color=colors[indx],ls=lss[indx], xrange=[10.,85.], yrange=[0.8,1.5], xlabel=r'$\sigma^{\mathrm{in}}_R\ \mathrm{at}\ R = 8\,\mathrm{kpc}$', ylabel=r'$\sigma^{\mathrm{out}}_R / \sigma^{\mathrm{in}}_R$')) else: lines.append(bovy_plot.bovy_plot(szs[:,indx],plotthis[:,indx], color=colors[indx],ls=lss[indx], xrange=[10.,115.], yrange=[0.5,1.2], xlabel=r'$\sigma^{\mathrm{in}}_Z\ \mathrm{at}\ R = 8\,\mathrm{kpc}$', ylabel=r'$\sigma^{\mathrm{out}}_Z / \sigma^{\mathrm{in}}_Z$')) for indx in range(1,options.nhr): lines.append(bovy_plot.bovy_plot(szs[:,indx],plotthis[:,indx], color=colors[indx],ls=lss[indx], overplot=True)) #Add colorbar map = cm.ScalarMappable(cmap=cm.jet) map.set_array(hrs[0,:]) map.set_clim(vmin=numpy.amin(hrs[0,:]),vmax=numpy.amax(hrs[0,:])) cbar= pyplot.colorbar(map,fraction=0.15) cbar.set_clim(numpy.amin(hrs[0,:]),numpy.amax(hrs[0,:])) cbar.set_label(r'$h_R\, (\mathrm{kpc})$') bovy_plot.bovy_end_print(options.plotfilename)
def testDFNormvo(params,fehs,afes,binned,options,normintstuff): """Test how the normalization fares wrt hr changes""" #setup potential pot= setup_potential(params,options,len(fehs)) aA= setup_aA(pot,options) ro= get_ro(params,options) vo= get_vo(params,options,len(fehs)) #Assume there is only a single bin indx= 0 dfparams= get_dfparams(params,indx,options,log=False) nalt= 6 vos= numpy.linspace(0.5,1.5,nalt) ns= [1000,10000,30000,60000,100000]#,1000000] #First calculate default if options.dfmodel.lower() == 'qdf': #Normalize hr= dfparams[0]/ro sr= dfparams[1]/vo sz= dfparams[2]/vo hsr= dfparams[3]/ro hsz= dfparams[4]/ro #Setup qdf= quasiisothermaldf(hr,sr,sz,hsr,hsz,pot=pot,aA=aA,cutcounter=True) defNorm= numpy.zeros((nalt,len(ns))) for ii, n in enumerate(ns): print ii, n options.nmc= n thisnormintstuff= copy.deepcopy(normintstuff) thisnormintstuff[indx].mock= normintstuff[indx].mock[0:n+1] defNorm[:,ii]= numpy.log(calc_normint(qdf,indx,thisnormintstuff,params,len(fehs),options)) print defNorm[0,:] #Then calculate alternative models altNorm= numpy.zeros((nalt,len(ns))) for ii in range(nalt): potparams= list(get_potparams(params,options,len(fehs))) potparams[0]= vo*vos[ii] params= set_potparams(potparams,params,options,len(fehs)) if options.dfmodel.lower() == 'qdf': #Normalize sr= dfparams[1]/vo/vos[ii] sz= dfparams[2]/vo/vos[ii] #Setup qdf= quasiisothermaldf(hr,sr,sz,hsr,hsz,pot=pot,aA=aA, cutcounter=True) for jj, n in enumerate(ns): if n > len(normintstuff[indx].mock): altNorm[ii,jj]= numpy.nan continue print ii, jj, n options.nmc= n thisnormintstuff= copy.deepcopy(normintstuff) thisnormintstuff[indx].mock= normintstuff[indx].mock[0:n] altNorm[ii,jj]= numpy.log(calc_normint(qdf,indx,thisnormintstuff, params,len(fehs),options)) #Plot left, bottom, width, height= 0.1, 0.3, 0.8, 0.6 axTop= pyplot.axes([left,bottom,width,height]) left, bottom, width, height= 0.1, 0.1, 0.8, 0.2 axSign= pyplot.axes([left,bottom,width,height]) fig= pyplot.gcf() fig.sca(axTop) pyplot.ylabel(r'$|\Delta \chi^2|$') pyplot.xlim(ns[0]/5.,ns[-1]*5.) nullfmt = NullFormatter() # no labels axTop.xaxis.set_major_formatter(nullfmt) pyplot.loglog(numpy.tile(numpy.array(ns),(nalt,1)).T, numpy.fabs((defNorm-altNorm)*10000.).T, marker='o',linestyle='none') fig.sca(axSign) pyplot.semilogx(numpy.tile(numpy.array(ns),(nalt,1)).T\ *(1.+0.4*(numpy.random.uniform(size=(len(ns),nalt))-0.5)), numpy.fabs((defNorm-altNorm)).T/(defNorm-altNorm).T, marker='o',linestyle='none') pyplot.xlim(ns[0]/5.,ns[-1]*5.) pyplot.ylim(-1.99,1.99) pyplot.xlabel(r'$N$') pyplot.ylabel(r'$\mathrm{sgn}(\Delta \chi^2)$') bovy_plot.bovy_end_print(options.outfilename)
def generate_fakeDFData(options,args): #Check whether the savefile already exists if os.path.exists(args[0]): savefile= open(args[0],'rb') print "Savefile already exists, not re-sampling and overwriting ..." return None #Read the data print "Reading the data ..." if options.sample.lower() == 'g': if options.select.lower() == 'program': raw= read_gdwarfs(_GDWARFFILE,logg=True,ebv=True,sn=options.snmin,nosolar=True,nocoords=True) else: raw= read_gdwarfs(logg=True,ebv=True,sn=options.snmin,nosolar=True,nocoords=True) elif options.sample.lower() == 'k': if options.select.lower() == 'program': raw= read_kdwarfs(_KDWARFFILE,logg=True,ebv=True,sn=options.snmin,nosolar=True,nocoords=True) else: raw= read_kdwarfs(logg=True,ebv=True,sn=options.snmin,nosolar=True, nocoords=True) if not options.bmin is None: #Cut on |b| raw= raw[(numpy.fabs(raw.b) > options.bmin)] if not options.fehmin is None: raw= raw[(raw.feh >= options.fehmin)] if not options.fehmax is None: raw= raw[(raw.feh < options.fehmax)] if not options.afemin is None: raw= raw[(raw.afe >= options.afemin)] if not options.afemax is None: raw= raw[(raw.afe < options.afemax)] if not options.plate is None and not options.loo: raw= raw[(raw.plate == options.plate)] elif not options.plate is None: raw= raw[(raw.plate != options.plate)] #Bin the data binned= pixelAfeFeh(raw,dfeh=options.dfeh,dafe=options.dafe) #Map the bins with ndata > minndata in 1D fehs, afes= [], [] for ii in range(len(binned.fehedges)-1): for jj in range(len(binned.afeedges)-1): data= binned(binned.feh(ii),binned.afe(jj)) if len(data) < options.minndata: continue fehs.append(binned.feh(ii)) afes.append(binned.afe(jj)) nabundancebins= len(fehs) fehs= numpy.array(fehs) afes= numpy.array(afes) if not options.singlefeh is None: if options.loo: pass else: #Set up single feh indx= binned.callIndx(options.singlefeh,options.singleafe) if numpy.sum(indx) == 0: raise IOError("Bin corresponding to singlefeh and singleafe is empty ...") data= copy.copy(binned.data[indx]) print "Using %i data points ..." % (len(data)) #Bin again binned= pixelAfeFeh(data,dfeh=options.dfeh,dafe=options.dafe) fehs, afes= [], [] for ii in range(len(binned.fehedges)-1): for jj in range(len(binned.afeedges)-1): data= binned(binned.feh(ii),binned.afe(jj)) if len(data) < options.minndata: continue fehs.append(binned.feh(ii)) afes.append(binned.afe(jj)) nabundancebins= len(fehs) fehs= numpy.array(fehs) afes= numpy.array(afes) #Setup the selection function #Load selection function plates= numpy.array(list(set(list(raw.plate))),dtype='int') #Only load plates that we use print "Using %i plates, %i stars ..." %(len(plates),len(raw)) sf= segueSelect(plates=plates,type_faint='tanhrcut', sample=options.sample,type_bright='tanhrcut', sn=options.snmin,select=options.select, indiv_brightlims=options.indiv_brightlims) platelb= bovy_coords.radec_to_lb(sf.platestr.ra,sf.platestr.dec, degree=True) if options.sample.lower() == 'g': grmin, grmax= 0.48, 0.55 rmin,rmax= 14.50001, 20.199999 #so we don't go out of the range if options.sample.lower() == 'k': grmin, grmax= 0.55, 0.75 rmin,rmax= 14.50001, 18.999999 colorrange=[grmin,grmax] mapfehs= monoAbundanceMW.fehs() mapafes= monoAbundanceMW.afes() #Setup params if not options.init is None: #Load initial parameters from file savefile= open(options.init,'rb') tparams= pickle.load(savefile) savefile.close() #Setup the correct form params= initialize(options,fehs,afes) params[0:6]= get_dfparams(tparams,options.index,options,log=True) params[6:11]= tparams[-5:len(tparams)] else: params= initialize(options,fehs,afes) #Setup potential if (options.potential.lower() == 'flatlog' or options.potential.lower() == 'flatlogdisk') \ and not options.flatten is None: #Set flattening potparams= list(get_potparams(params,options,len(fehs))) potparams[0]= options.flatten params= set_potparams(potparams,params,options,len(fehs)) pot= setup_potential(params,options,len(fehs)) aA= setup_aA(pot,options) if not options.multi is None: binned= fakeDFData_abundance_singles(binned,options,args,fehs,afes) else: for ii in range(len(fehs)): print "Working on population %i / %i ..." % (ii+1,len(fehs)) #Setup qdf dfparams= get_dfparams(params,ii,options,log=False) vo= get_vo(params,options,len(fehs)) ro= get_ro(params,options) if options.dfmodel.lower() == 'qdf': #Normalize hr= dfparams[0]/ro sr= dfparams[1]/vo sz= dfparams[2]/vo hsr= dfparams[3]/ro hsz= dfparams[4]/ro print hr, sr, sz, hsr, hsz qdf= quasiisothermaldf(hr,sr,sz,hsr,hsz,pot=pot,aA=aA,cutcounter=True) #Some more selection stuff data= binned(fehs[ii],afes[ii]) #feh and color feh= fehs[ii] fehrange= [feh-options.dfeh/2.,feh+options.dfeh/2.] #FeH fehdist= DistSpline(*numpy.histogram(data.feh,bins=5, range=fehrange), xrange=fehrange,dontcuttorange=False) #Color colordist= DistSpline(*numpy.histogram(data.dered_g\ -data.dered_r, bins=9,range=colorrange), xrange=colorrange) #Re-sample binned= fakeDFData(binned,qdf,ii,params,fehs,afes,options, rmin,rmax, platelb, grmin,grmax, fehrange, colordist, fehdist,feh,sf, mapfehs,mapafes, ro=None,vo=None) #Save to new file fitsio.write(args[0],binned.data) return None