def plot_nfwfits_byrun(run, name, prompt=False): conf = lensing.files.read_config(run) d = lensing.sample_read(type='fit', sample=run, name=name) omega_m = conf['omega_m'] rvals = numpy.linspace(d['r'].min(), d['r'].max(),1000) for i in xrange(d.size): plt = FramedPlot() lensing.plotting.add_to_log_plot(plt, d['r'][i], d['dsig'][i], d['dsigerr'][i]) z = d['z_mean'][i] n = lensing.nfw.NFW(omega_m, z) yfit = n.dsig(rvals, d['r200_fit'][i],d['c_fit'][i]) plt.add(Curve(rvals,yfit,color='blue')) plt.xlog=True plt.ylog=True plt.xlabel = r'$r$ [$h^{-1}$ Mpc]' plt.ylabel = r'$\Delta\Sigma ~ [M_{sun} pc^{-2}]$' if prompt: plt.show() raw_input('hit a key: ') else: epsfile='/home/esheldon/tmp/plots/desmocks-nfwfit-%02i.eps' % i print 'Writing epsfile:',epsfile plt.write_eps(epsfile)
def plot_nfw_lin_fits_byrun(run, name, npts=100, prompt=False, withlin=True, ymin=0.01, ymax=2000.0): """ This should be made not specific for the m-z splits we used on the sims """ conf = lensing.files.cascade_config(run) if withlin: ex='lin' nex='lin' else: nex='' ex='' d = lensing.sample_read(type='fit',sample=run, name=name, extra=ex) omega_m = conf['cosmo_config']['omega_m'] rravel = d['r'].ravel() xrange = [0.5*rravel.min(), 1.5*rravel.max()] #for i in xrange(d.size): i=0 for dd in d: zrange = dd['z_range'] mrange = dd['m200_range'] if dd['rrange'][0] > 0: log_rmin = log10(dd['rrange'][0]) log_rmax = log10(dd['rrange'][1]) else: log_rmin = log10(dd['r'][0]) log_rmax = log10(dd['r'][-1]) rvals = 10.0**linspace(log_rmin,log_rmax,npts) plt = FramedPlot() lensing.plotting.add_to_log_plot(plt, dd['r'],dd['dsig'],dd['dsigerr']) z = dd['z_mean'] fitter = lensing.fit.NFWBiasFitter(omega_m,z,rvals,withlin=withlin) if withlin: yfit = fitter.nfw_lin_dsig(rvals, dd['r200_fit'],dd['c_fit'],dd['B_fit']) yfit_nfw = fitter.nfw.dsig(rvals,dd['r200_fit'],dd['c_fit']) yfit_lin = fitter.lin_dsig(rvals,dd['B_fit']) yfit = where(yfit < 1.e-5, 1.e-5, yfit) yfit_lin = where(yfit_lin < 1.e-5, 1.e-5, yfit_lin) cyfit = Curve(rvals,yfit,color='blue') cyfit_nfw = Curve(rvals,yfit_nfw,color='red') cyfit_lin = Curve(rvals,yfit_lin,color='orange') cyfit.label = 'Best Fit' cyfit_nfw.label = 'NFW' cyfit_lin.label = 'linear' key=PlotKey(0.1,0.3,[cyfit,cyfit_nfw,cyfit_lin]) plt.add(cyfit,cyfit_nfw,cyfit_lin,key) else: yfit_nfw = fitter.nfw.dsig(rvals,dd['r200_fit'],dd['c_fit']) cyfit_nfw = Curve(rvals,yfit_nfw,color='blue') plt.add(cyfit_nfw) zlab='%0.2f < z < %0.2f' % (zrange[0],zrange[1]) plt.add(PlotLabel(0.7,0.8,zlab)) ll = (log10(mrange[0]),log10(mrange[1])) mlab = r'$%0.2f < logM_{200} < %0.2f$' % ll plt.add(PlotLabel(0.7,0.9,mlab)) #yrange = [ymin,(dd['dsig']+dd['dsigerr']).max()*1.5] yrange = [ymin,ymax] plt.xrange = xrange plt.yrange = yrange plt.xlog=True plt.ylog=True plt.xlabel = r'$r$ [$h^{-1}$ Mpc]' plt.ylabel = r'$\Delta\Sigma ~ [M_{sun} pc^{-2}]$' plt.aspect_ratio=1 if prompt: plt.show() rinput = raw_input('hit a key: ') if rinput == 'q': return else: d = lensing.files.lensbin_plot_dir(run,name) if not os.path.exists(d): os.makedirs(d) epsfile=path_join(d,'desmocks-nfw%s-fit-%02i.eps' % (nex,i)) print 'Writing epsfile:',epsfile plt.write_eps(epsfile) i += 1