def beta_method(r_pix, r_mpc, ghat, beta_s, beta_s2, concentration, zcluster, pixscale=__DEFAULT_PIXSCALE__, fitrange=(0.5, 3.), Omega_m=0.3, Omega_l=0.7): cosmology = nfwutils.Cosmology(Omega_m, Omega_l) comovingdist = nfwutils.ComovingDistMemoization(cosmology=cosmology) def NFWModel(r, r_scale): nfw_shear = beta_s * tools.NFWShear(r, concentration, r_scale, zcluster, comovingdist) nfw_kappa = beta_s * tools.NFWKappa(r, concentration, r_scale, zcluster, comovingdist) g = (1 + (beta_s2 / beta_s**2 - 1) * nfw_kappa) * nfw_shear / (1 - nfw_kappa) return g minPix = fitrange[0] * 3600. * (180. / np.pi) / (pixscale * D_lens) maxPix = fitrange[1] * 3600. * (180. / np.pi) / (pixscale * D_lens) profile = sp.shearprofile(np.zeros_like(r_pix), r_pix, ghat, np.zeros_like(ghat), sigma2=None, range=(minPix, maxPix), bins=15, center=(0, 0), logbin=True) profile_r_mpc = profile.r * pixscale * (1. / 3600.) * (np.pi / 180.) * D_lens keepBins = np.logical_and(np.isfinite(profile.E), np.isfinite(profile.Eerr)) rs, isCon = leastsq.leastsq(NFWModel, [0.4], profile_r_mpc[keepBins], profile.E[keepBins], profile.Eerr[keepBins], fullOutput=False) if not isCon: return None return rs
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 getCosmology(self): return nfwutils.Cosmology(omega_m=0.27, omega_l=0.73, h=0.7)
mean_ghat, covar = sr.calcCovariance(medians) return mean_ghat, covar ################################# if __name__ == '__main__': # bootstrap = int(sys.argv[1]) # outdir = sys.argv[2] # # data = calcBootstrapCovar(bootstrap) # # output = open('%s/scan_%d.pkl' % (outdir, bootstrap), 'wb') # cPickle.dump(data, output) # output.close() # omega_l = float(sys.argv[1]) outdir = sys.argv[2] cosmology = nfwutils.Cosmology(1-omega_l, omega_l) data = stackClusters(doPlot = False, cosmology = cosmology) output = open('%s/scan_%4.3f.pkl' % (outdir, omega_l), 'wb') cPickle.dump(data, output) output.close()
import nfwutils omega_ms = np.arange(0.15, 0.39, 0.005) ws = np.arange(-1.76, -0.2, 0.005) zclusters = [0.25, 1.0] zsource = 1.5 c = [(.9, .6, 0), (.35, .7, .9), (0, .6, .5), (0.95, 0.9, 0.25)] scalings = [] for zcluster in zclusters: scaling = np.zeros_like(omega_ms) for i, omega_m in enumerate(omega_ms): cosmo = nfwutils.Cosmology(omega_m=omega_m, omega_l=1. - omega_m) dl = cosmo.angulardist(zcluster) ds = cosmo.angulardist(zsource) dls = cosmo.angulardist(zcluster, zsource) scaling[i] = dl * ds / dls scalings.append(scaling) hydro_scalings = [] mgas_scalings = [] for zcluster in zclusters: hydro_scaling = np.zeros_like(omega_ms) mgas_scaling = np.zeros_like(omega_ms) for i, omega_m in enumerate(omega_ms): cosmo = nfwutils.Cosmology(omega_m=omega_m, omega_l=1. - omega_m) dl = cosmo.angulardist(zcluster) hydro_scaling[i] = dl mgas_scaling[i] = dl**(5 / 2) hydro_scalings.append(hydro_scaling) mgas_scalings.append(mgas_scaling)
def publicationStack(data = None): if data is None: data = {} if 'standard' not in data: stddata = {} stdfig, stddata = stackClusters(data = stddata) data['standard'] = stddata else: stddata = data['standard'] if 'eds' not in data: edsdata = {} edsfig, edsdata = stackClusters(data = edsdata, cosmology = nfwutils.Cosmology(omega_m = 1.0, omega_l = 0.0), outdir = '/u/ki/dapple/subaru/doug/publication/eds_cosmos_2012-05-17') data['eds'] = edsdata else: edsdata = data['eds'] stdzbins = stddata['zbins'] stdbincenters = (stdzbins[1:] + stdzbins[:-1])/2. edszbins = edsdata['zbins'] edsbincenters = (edszbins[1:] + edszbins[:-1])/2. stdmaxlike = stddata['maxlike'] stdsig1 = stddata['sig1'] stdsig2 = stddata['sig2'] edsmaxlike = edsdata['maxlike'] edssig1 = edsdata['sig1'] edssig2 = edsdata['sig2'] fig = pylab.figure() ax = fig.add_axes([0.125, 0.12, 0.95 - 0.125, 0.95 - 0.12]) xplot = np.arange(0.01, np.max(np.hstack([stdzbins, edszbins])), 0.01) ax.axhline(0.0, linestyle=':', linewidth=1.25, color='k') ax.plot(xplot, sr.shearScaling(xplot), 'k-', linewidth=1.5, label='Expected Scaling') ax.errorbar(edsbincenters, edsmaxlike, edssig1, fmt='rs', mfc = 'None',label='$\mathbf{\Omega_{\Lambda} = 0.0}$', elinewidth=1.5, markeredgewidth=1.5, markeredgecolor='r', marker='None') ax.plot(edsbincenters, edsmaxlike, 'rs', markerfacecolor='None', markeredgecolor='r', markeredgewidth=1.5) ax.errorbar(stdbincenters, stdmaxlike, stdsig1, fmt='bo', label='$\mathbf{\Omega_{\Lambda} = 0.7}$', elinewidth=1.5, markeredgewidth=1.5, markeredgecolor='b', marker='None') ax.plot(stdbincenters, stdmaxlike, 'bo') thexrange = (0., 5.0) theyrange = (-0.15, 1.75) ax.legend(loc='upper left', numpoints=1) ax.set_xlabel('$x = \omega_s/\omega_l$', size='x-large') ax.set_ylabel('$\gamma_t(x)/\gamma_t(x=\infty)$', size='x-large') fig.savefig('publication/pubstack.pdf') ###### fig2 = pylab.figure() ax = fig2.add_axes([0.125, 0.12, 0.95 - 0.125, 0.95 - 0.12]) ax.axhline(0.0, linestyle=':', linewidth=1.25, color='k') ax.plot(xplot, sr.shearScaling(xplot), 'k-', linewidth=1.5, label='Expected Scaling') ax.errorbar(stdbincenters, stdmaxlike, stdsig1, fmt='bo', label='$\mathbf{\Omega_{\Lambda} = 0.7}$', elinewidth=1.5, markeredgewidth=1.5, markeredgecolor='b', marker='None') ax.plot(stdbincenters, stdmaxlike, 'bo') ax.set_xlim(*thexrange) ax.set_ylim(*theyrange) ax.text(0.3, 1.5, '$\mathbf{\Omega_{\Lambda} = 0.7}$', size='xx-large', weight='bold') ax.set_xlabel('$x = \omega_s/\omega_l$ ', size='x-large') ax.set_ylabel('$\gamma_t(x)/\gamma_t(x=\infty)$', size='x-large') fig2.savefig('publication/pubstack_lcdm.pdf') ################### fig3 = pylab.figure() ax = fig3.add_axes([0.125, 0.12, 0.95 - 0.125, 0.95 - 0.12]) ax.axhline(0.0, linestyle=':', linewidth=1.25, color='k') ax.plot(xplot, sr.shearScaling(xplot), 'k-', linewidth=1.5, label='Expected Scaling') ax.errorbar(edsbincenters, edsmaxlike, edssig1, fmt='bo', label='$\mathbf{\Omega_{\Lambda} = 0.0}$', elinewidth=1.5, markeredgewidth=1.5, markeredgecolor='b', marker='None') ax.plot(edsbincenters, edsmaxlike, 'bo') ax.set_xlim(*thexrange) ax.set_ylim(*theyrange) ax.text(0.3, 1.5, '$\mathbf{\Omega_{\Lambda} = 0.0}$', size='xx-large', weight='bold') ax.set_xlabel('$x = \omega_s/\omega_l$', size='x-large') ax.set_ylabel('$\gamma_t(x)/\gamma_t(x=\infty)$', size='x-large') fig3.savefig('publication/pubstack_eds.pdf') return fig, fig2, fig3, data
# Utility to parse Stefan's 2D and 3D mass profiles ################## import numpy as np import readtxtfile import varcontainer import re, os.path import nfwutils import scipy.interpolate as interp ################# h = .73 #m_p = 7.18*8.60657e8/h #M_sol m_p = 8.456e9 cosmo = nfwutils.Cosmology(omega_m=0.25, omega_l=0.75, h=0.73) ################ profile_start_template = re.compile('r_lo') class MXXLProfile(object): def __init__(self, filename): self.parseFile(filename) self._massEnclosed = None self._overdensitymass = None self._overdensityradius = None ###
def setBK11(): nfwutils.global_cosmology.set_cosmology(nfwutils.Cosmology(omega_m = 0.27, omega_l = 0.73, h = 0.7))
def setBCC(): nfwutils.global_cosmology.set_cosmology(nfwutils.Cosmology(omega_m = 0.23, omega_l = 0.77, h=.72))
def setMXXL(): nfwutils.global_cosmology.set_cosmology(nfwutils.Cosmology(omega_m = 0.25, omega_l = 0.75, h=0.73))