def plotProfile(datfilebase, c, label, labelZ = True): mass, concen, redshift = readtxtfile.readtxtfile('%s.dat' % datfilebase)[0] cat = ldac.openObjectFile('%s.cat' % datfilebase) zlens = cat.hdu.header['ZLENS'] rscale = nfwutils.rscaleConstM(mass/nfwutils.global_cosmology.h, concen, zlens, 200) r_mpc = np.ascontiguousarray(cat['r_mpc'], dtype='<d') clean = r_mpc > 0.05 rho_c_over_sigma_c = 1.5 * nfwutils.global_cosmology.angulardist(zlens) * nfwutils.global_cosmology.beta([1e6], zlens)[0] * nfwutils.global_cosmology.hubble2(zlens) / nfwutils.global_cosmology.v_c**2 gamma = nfwmodeltools.NFWShear(r_mpc[clean], concen, rscale, rho_c_over_sigma_c) kappa = nfwmodeltools.NFWKappa(r_mpc[clean], concen, rscale,rho_c_over_sigma_c) gpred = cat['beta_s'][clean]*gamma / (1 - (cat['beta_s2'][clean]*kappa/cat['beta_s'][clean])) signalpred = gpred / (cat['beta_s'][clean]*nfwutils.global_cosmology.beta([1e6], zlens)*nfwutils.global_cosmology.angulardist(zlens)) # print signalpred if labelZ: flabel='%s z=%1.2f' % (label, zlens) else: flabel =label pylab.errorbar(cat['r_mpc']*nfwutils.global_cosmology.h, cat['ghat'], cat['ghatdistrosigma']/(np.sqrt(cat['ndat'])), linestyle='None', marker='o', color=c, label=flabel) pylab.plot(cat['r_mpc'][clean]*nfwutils.global_cosmology.h, signalpred, marker='None', linestyle=':', color=c, linewidth=2)
def deltaShear(zspec, zphot, zcluster = 0.2): ginfpredict = nfwmodeltools.NFWShear(ones(1), 4.0, 1., zcluster) beta_s_spec = nfwutils.beta_s(zspec, zcluster) beta_s_phot = nfwutils.beta_s(zphot, zcluster) return (beta_s_spec - beta_s_phot)*ginfpredict
def reducedShear(scaledm200): m200 = 1e14 * scaledm200 c = duffy(m200, zcluster) rs = nfwutils.rscaleConstM(m200, c, zcluster, 200) gamma = tools.NFWShear(r_mpc, c, rs, rho_c_over_sigma_c) kappa = tools.NFWKappa(r_mpc, c, rs, rho_c_over_sigma_c) g = beta_s * gamma / (1 - beta_cor * kappa) return g
def NFWModel(r, r_scale): nfw_shear = beta_s * tools.NFWShear(r, concentration, r_scale, zcluster, D_lens) nfw_kappa = beta_s * tools.NFWKappa(r, concentration, r_scale, zcluster, D_lens) g = (1 + (beta_s2 / beta_s**2 - 1) * nfw_kappa) * nfw_shear / (1 - nfw_kappa) return g
def create_nfwmodel_shapedata(concentration, scale_radius, zcluster, ngals, zs, rs): realBetas = nfwutils.beta_s(zs, zcluster) gamma = realBetas * tools.NFWShear(rs, concentration, scale_radius, zcluster) kappa = realBetas * tools.NFWKappa(rs, concentration, scale_radius, zcluster) g = gamma / (1 - kappa) return g, gamma, kappa
def NFWModel(coords, r_scale): r = coords[:, 0] beta_s = coords[:, 1] nfw_shear = beta_s * tools.NFWShear(r, concentration, r_scale, zcluster) nfw_kappa = beta_s * tools.NFWKappa(r, concentration, r_scale, zcluster) g = nfw_shear / (1 - nfw_kappa) return g
def createPerfectProfile(m200, c, zcluster, r_mpc, beta_s): rho_c_over_sigma_c = 1.5 * nfwutils.global_cosmology.angulardist( zcluster) * nfwutils.global_cosmology.beta( [1e6], zcluster)[0] * nfwutils.global_cosmology.hubble2( zcluster) / nfwutils.global_cosmology.v_c**2 r_scale = nfwutils.rscaleConstM(m200, c, zcluster, 200) nfw_shear_inf = tools.NFWShear(r_mpc, c, r_scale, rho_c_over_sigma_c) nfw_kappa_inf = tools.NFWKappa(r_mpc, c, r_scale, rho_c_over_sigma_c) g = beta_s * nfw_shear_inf / (1 - (beta_s * nfw_kappa_inf)) return g
def scaleShear(controller, rs, concen = 4., cosmology = nfwutils.std_cosmology): #assumes BentVoigt3Shapedistro inputcat = controller.inputcat z_b = inputcat['z_b'] zcluster = controller.zcluster cluster_exclusion = np.logical_and(zcluster-0.05 < z_b, z_b < zcluster + 0.1) inputcat = inputcat.filter(np.logical_not(cluster_exclusion)) r_mpc = inputcat['r_mpc'] ghats = inputcat['ghats'] size = inputcat['size'] z_b = inputcat['z_b'] comovingdist = nfwutils.ComovingDistMemoization(cosmology) pivot, m_slope, m_b, m_cov, c = controller.modelbuilder.psfDependence('interp', controller.psfsize) betainf = nfwutils.beta([1e6], zcluster, comovingdist = comovingdist) #matching definitions with Taylor et al 2011 -> need to get rid of beta_inf in shear amp shear = nfwmodeltools.NFWShear(r_mpc, concen, rs, zcluster, comovingdist = comovingdist) / betainf kappa = nfwmodeltools.NFWKappa(r_mpc, concen, rs, zcluster, comovingdist = comovingdist) m = np.zeros_like(size) m[size >= pivot] = m_b m[size < pivot] = m_slope*(size[size < pivot] - pivot) + m_b beta_s = nfwutils.beta_s(z_b, zcluster, comovingdist = comovingdist) estimators = (ghats - c)*(1-beta_s*kappa)/((1+m)*shear) comoving_cluster = comovingdist(zcluster) scaledZ = np.array([comovingdist(zi)/comoving_cluster for zi in z_b]) estimators[scaledZ < 1] = ((ghats - c)/(1+m))[scaledZ < 1] return scaledZ, estimators
def residual(binbase): mass, concen, redshift = readtxtfile.readtxtfile('%s.dat' % binbase)[0] cat = ldac.openObjectFile('%s.cat' % binbase) zlens = cat.hdu.header['ZLENS'] rscale = nfwutils.rscaleConstM(mass/nfwutils.global_cosmology.h, concen, zlens, 200) gamma = nfwmodeltools.NFWShear(cat['r_mpc'], concen, rscale, zlens) kappa = nfwmodeltools.NFWKappa(cat['r_mpc'], concen, rscale, zlens) gpred = cat['beta_s']*gamma / (1 - (cat['beta_s2']*kappa/cat['beta_s'])) fig = pylab.figure() # pylab.errorbar(cat['r_mpc']*nfwutils.global_cosmology.h, cat['ghat']/gpred, cat['ghatdistrosigma']/(np.sqrt(cat['ndat'])*gpred), fmt='bo') # pylab.errorbar(cat['r_mpc']*nfwutils.global_cosmology.h, cat['ghat']/gpred, cat['ghatdistrosigma']/(gpred), fmt='bo') pylab.errorbar(cat['r_mpc'], cat['ghat'], cat['ghatdistrosigma']/np.sqrt(cat['ndat']), fmt='bo') # ax = pylab.gca() ax.set_xscale('log') pylab.axhline(0.0, c='k', linewidth=2) pylab.xlabel('Radius [Mpc/h]', fontsize=16) pylab.ylabel('<g_meas/g_pred> - 1)', fontsize=16) # pylab.ylabel('<g_meas - g_pred>', fontsize=16) pylab.axis([0.05, 10, -.55, 0.35]) # ax2 = ax.twinx() # pylab.plot(cat['r_mpc'], gpred, 'k--') # ax2.errorbar(cat['r_mpc'], cat['ghat'], cat['ghatdistrosigma']/np.sqrt(cat['ndat']), fmt='rs') # ax2.set_ylabel('<g_meas - g_pred>', color='r', fontsize=16) # ax2.set_ylim(-0.2, 0.1) # # pylab.title('Redshift=%1.2f Mass=%1.2fx10^14 Concen=%1.2f' % (zlens, mass/1e14, concen)) # pylab.tight_layout() pylab.savefig('%s.png' % binbase) return fig
def profileFromMass(mcrelation, mdelta, delta, r_mpc, simcat): zcluster = simcat.hdu.header['ZLENS'] concentration = mcrelation(mdelta, zcluster, delta) r_scale = nfwutils.rscaleConstM(mdelta, concentration, zcluster, delta) nfw_shear_inf = tools.NFWShear(r_mpc, concentration, r_scale, zcluster) nfw_kappa_inf = tools.NFWKappa(r_mpc, concentration, r_scale, zcluster) beta_s = np.mean(simcat['beta_s']) beta_s2 = np.mean(simcat['beta_s']**2) g = beta_s * nfw_shear_inf / (1 - ((beta_s2 / beta_s) * nfw_kappa_inf)) return g
def createNLikelihood(mcluster, zcluster, z0, sigz0, rmin=0.75, rmax=3.0, c=4.0, massrad=1.5, gsig=0.25, npoints=200000): rs = nfwutils.RsMassInsideR(mcluster, c, zcluster, massrad) linmin = rmin / np.sqrt(2) linmax = rmax / np.sqrt(2) r_points = np.sqrt( np.random.uniform(linmin, linmax, size=npoints)**2 + np.random.uniform(linmin, linmax, size=npoints)**2) z_points = z0 + sigz0 * np.random.standard_normal(npoints) gamma_inf = nfwmodeltools.NFWShear(r_points, c, rs, zcluster) kappa_inf = nfwmodeltools.NFWKappa(r_points, c, rs, zcluster) beta_s = nfwutils.beta_s(z_points, zcluster) g0 = beta_s * gamma_inf / (1 - beta_s * kappa_inf) ghat_points = g0 + gsig * np.random.standard_normal(npoints) dzt = 0.01 pdzrange = np.arange(z0 - 5 * sigz0, z0 + 5 * sigz0, dzt) pdz = stats.Gaussian(pdzrange, z0, sigz0) * dzt betas = np.array(nfwutils.beta_s(pdzrange, zcluster)) def nloglike(Mguess): #units of 1e14 Mguess = Mguess * 1e14 rs_guess = nfwutils.RsMassInsideR(Mguess, c, zcluster, massrad) return -pdzperturbtools.nloglike_loop(r_points, z_points, ghat_points, betas, pdz, gsig, rs_guess, c, zcluster) return nloglike
def __call__(self, x, m200, c200): if m200 == 0.: return np.zeros_like(x) isNegative=m200 < 0 if isNegative: m200 = np.abs(m200) r_scale = nfwutils.rscaleConstM(m200*self.massScale, c200, self.zcluster, self.overdensity) nfw_shear_inf = tools.NFWShear(x, c200, r_scale, self.rho_c_over_sigma_c) nfw_kappa_inf = tools.NFWKappa(x, c200, r_scale, self.rho_c_over_sigma_c) if isNegative: nfw_shear_inf = -nfw_shear_inf g = self.beta_s*nfw_shear_inf / (1 - ((self.beta_s2/self.beta_s)*nfw_kappa_inf) ) return g
def alteredCosmology(cat, om): cosmology = nfwutils.Cosmology(om, 1. - om) comovingdist = nfwutils.ComovingDistMemoization(cosmology) betas = nfwutils.beta_s(cat['z'], 0.3, comovingdist) dl = nfwutils.angulardist(0.3, comovingdist=comovingdist) r_mpc = cat['r_pix'] * 0.2 * (1. / 3600.) * (np.pi / 180.) * dl shears = tools.NFWShear(r_mpc, 4.0, 0.5, 0.3, dl, Omega_m=om, Omega_l=1 - om) kappa = tools.NFWKappa(r_mpc, 4.0, 0.5, 0.3, dl, Omega_m=om, Omega_l=1 - om) g = betas * shears / (1 - betas * kappa) scale_radii = beta_method(cat['r_pix'], r_mpc, g, np.mean(betas), np.mean(betas**2), 4, 0.3, Omega_m=om, Omega_l=1 - om) mass = nfwutils.massInsideR(scale_radii, 4.0, 0.3, 1, cosmology) return mass
def multibinresidual(binbase, fig = None): matplotlib.rcParams['figure.figsize'] = [16,16] if fig is None: fig = pylab.figure() curplot = 1 for curm in range(4): for curc in range(4): pylab.subplot(4,4,curplot) colori = 0 # for curz in range(3): for curz in [0]: mass, concen, redshift = readtxtfile.readtxtfile('%s_%d_%d_%d.dat' % (binbase, curz, curm, curc))[0] cat = ldac.openObjectFile('%s_%d_%d_%d.cat' % (binbase, curz, curm, curc)) zlens = cat.hdu.header['ZLENS'] rscale = nfwutils.rscaleConstM(mass/nfwutils.global_cosmology.h, concen, zlens, 200) gamma = nfwmodeltools.NFWShear(cat['r_mpc'], concen, rscale, zlens) kappa = nfwmodeltools.NFWKappa(cat['r_mpc'], concen, rscale, zlens) gpred = cat['beta_s']*gamma / (1 - (cat['beta_s2']*kappa/cat['beta_s'])) pylab.errorbar(cat['r_mpc']*0.72, cat['ghat'], cat['ghatdistrosigma']/(np.sqrt(cat['ndat'])), linestyle='None', marker='o', color=c[colori], label='BCC z=%1.1f' % redshift) pylab.plot(cat['r_mpc']*0.72, gpred, 'k-', linewidth=2) ax = pylab.gca() ax.set_xscale('log') pylab.axhline(0.0, c='k', linewidth=2) pylab.legend(loc='lower center', fontsize=10) pylab.axis([0.05, 10, -.55, 0.35]) # pylab.axis([0.05, 10, -.10, 0.05]) colori+= 1 pylab.title('M=%1.1fx10^14 C=%1.1f' % ( mass/1e14, concen)) curplot += 1 for i in range(4): pylab.subplot(4,4,13+i) pylab.xlabel('Radius [Mpc/h]') pylab.subplot(4,4,4*i+1) # pylab.ylabel('<g_m-g_p>/g_p(<M>,<c>)') # pylab.ylabel('<g_m/g_p - 1>') pylab.tight_layout() # pylab.savefig('%s_multibin_fracresid.png' % binbase) pylab.savefig('%s_multibin_resid.png' % binbase) return fig
def __init__(self, filebase): print 'Loading %s' % filebase #the file in this case is a configuration file with information about mass, concentration, redshift, etc super(AnalyticSim, self).__init__() with open(filebase) as input: config = yaml.load(input) max_dist = config['max_dist'] gridlength = config['gridlength'] zcluster = config['zcluster'] m200 = config['m200'] c200 = config['c200'] rscale = nfwutils.rscaleConstM(m200, c200, zcluster, 200.) xs = np.linspace(-max_dist, max_dist, gridlength) ys = np.linspace(-max_dist, max_dist, gridlength) x_mpc, y_mpc = [grid.flatten() for grid in np.meshgrid(xs, ys, indexing='ij')] r_mpc = np.sqrt(x_mpc**2 + y_mpc**2) Dl = nfwutils.global_cosmology.angulardist(zcluster) x_arcmin = (x_mpc/Dl)*(180./np.pi)*60. y_arcmin = (y_mpc/Dl)*(180./np.pi)*60. rho_c_over_sigma_c = 1.5 * nfwutils.global_cosmology.angulardist(zcluster) * nfwutils.global_cosmology.beta([1e6], zcluster)[0] * nfwutils.global_cosmology.hubble2(zcluster) / nfwutils.global_cosmology.v_c**2 gamma_t_inf = nfwmodeltools.NFWShear(r_mpc, c200, rscale, rho_c_over_sigma_c) kappa_inf = nfwmodeltools.NFWKappa(r_mpc, c200, rscale, rho_c_over_sigma_c) posangle = np.arctan2(y_mpc, x_mpc) cos2phi = np.cos(2*posangle) sin2phi = np.sin(2*posangle) gamma1_inf = -gamma_t_inf*cos2phi gamma2_inf = -gamma_t_inf*sin2phi self.zcluster = zcluster self.x_mpc = x_mpc self.y_mpc = y_mpc self.x_arcmin = x_arcmin self.y_arcmin = y_arcmin self.gamma1_inf = gamma1_inf self.gamma2_inf = gamma2_inf self.kappa_inf = kappa_inf
def BK11multibinresidual(dirbase): setBK11() matplotlib.rcParams['figure.figsize'] = [16,16] fig = pylab.figure() curplot = 1 for curm in range(4): for curc in range(4): pylab.subplot(4,4,curplot) colori = 1 for snap in [124,141]: try: mass, concen, redshift = readtxtfile.readtxtfile('%s_%d/bk11stack_%d_%d.dat' % (dirbase, snap, curm, curc))[0] cat = ldac.openObjectFile('%s_%d/bk11stack_%d_%d.cat' % (dirbase, snap, curm, curc)) zlens = cat.hdu.header['ZLENS'] rscale = nfwutils.rscaleConstM(mass/nfwutils.global_cosmology.h, concen, zlens, 200) gamma = nfwmodeltools.NFWShear(cat['r_mpc'], concen, rscale, zlens) kappa = nfwmodeltools.NFWKappa(cat['r_mpc'], concen, rscale, zlens) gpred = cat['beta_s']*gamma / (1 - (cat['beta_s2']*kappa/cat['beta_s'])) pylab.errorbar(cat['r_mpc']*nfwutils.global_cosmology.h, cat['ghat'], cat['ghatdistrosigma']/(np.sqrt(cat['ndat'])), linestyle='None', marker='o', color=c[colori], label='M=%1.1fx10^14' % (mass/1e14)) pylab.plot(cat['r_mpc']*nfwutils.global_cosmology.h, gpred, 'k-', linewidth=2) ax = pylab.gca() ax.set_xscale('log') pylab.axhline(0.0, c='k', linewidth=2) pylab.axis([0.05, 10, -0.03, 0.4]) ax = pylab.gca() ax.set_xscale('log') pylab.axhline(0.0, c='k', linewidth=2) # pylab.legend(loc='lower center', fontsize=10) # pylab.title('M=%1.1fx10^14 C=%1.1f' % ( mass/1e14, concen)) except: pass colori+= 1 curplot += 1 for i in range(4): pylab.subplot(4,4,13+i) pylab.xlabel('Radius [Mpc/h]') pylab.subplot(4,4,4*i+1) pylab.ylabel('<g_m/g_p - 1>') pylab.tight_layout() pylab.savefig('%s_multibin_shearprofile.png' % dirbase) # pylab.savefig('%s_multibin_resid.png' % binbase) return fig
def MXXLmultibinresidualoverplot(binbase, fig = None): setMXXL() if fig is None: matplotlib.rcParams['figure.figsize'] = [16,8] fig = pylab.figure() curplot = 5 for curc in range(4): pylab.subplot(2,4,curplot) colori = 0 for curm in range(2): try: mass, concen = readtxtfile.readtxtfile('%s_%d_%d.dat' % (binbase, curm, curc))[0] cat = ldac.openObjectFile('%s_%d_%d.cat' % (binbase, curm, curc)) zlens = cat.hdu.header['ZLENS'] rscale = nfwutils.rscaleConstM(mass/nfwutils.global_cosmology.h, concen, zlens, 200) gamma = nfwmodeltools.NFWShear(cat['r_mpc'], concen, rscale, zlens) kappa = nfwmodeltools.NFWKappa(cat['r_mpc'], concen, rscale, zlens) gpred = cat['beta_s']*gamma / (1 - (cat['beta_s2']*kappa/cat['beta_s'])) pylab.errorbar(cat['r_mpc']*nfwutils.global_cosmology.h, cat['ghat'], cat['ghatdistrosigma']/(np.sqrt(cat['ndat'])), linestyle='None', marker='o', color=c[colori], label='M=%1.1fx10^14' % (mass/1e14)) pylab.plot(cat['r_mpc']*nfwutils.global_cosmology.h, gpred, 'k-', linewidth=2) ax = pylab.gca() ax.set_xscale('log') pylab.axhline(0.0, c='k', linewidth=2) pylab.axis([0.05, 10, -0.03, 0.4]) except: pass colori+= 1 pylab.title('C=%1.1f' % (concen)) curplot += 1 for i in range(4): pylab.subplot(2,4,4+i+1) pylab.xlabel('Radius [Mpc/h]') pylab.text(0.1, 0.03, 'MXXL') pylab.minorticks_on() pylab.subplot(2,4,5) pylab.ylabel('<g_m/g_p-1>') pylab.subplot(2,4,8) pylab.legend(loc='upper right') pylab.tight_layout() pylab.savefig('%s_shearstack.png' % binbase) return fig