In [4]:
import pylab
import numpy as np
%pylab inline
from halotools.empirical_models import Zheng07 , model_defaults
from astropy.table import Table
import plotting
from plotting import prettyplot
prettyplot()


WARNING: pylab import has clobbered these variables: ['pylab']
`%matplotlib` prevents importing * from pylab and numpy
/home/mj/.local/lib/python2.7/site-packages/IPython/kernel/__init__.py:13: ShimWarning: The `IPython.kernel` package has been deprecated. You should import from ipykernel or jupyter_client instead.
  "You should import from ipykernel or jupyter_client instead.", ShimWarning)
Populating the interactive namespace from numpy and matplotlib
igraph package not installed.  Some functions will not be available.

In [587]:
model = Zheng07(threshold = -21)
data = np.loadtxt("richness.dat")
model.param_dict


Out[587]:
{'alpha': 1.15,
 'logM0': 11.92,
 'logM1': 13.94,
 'logMmin': 12.79,
 'sigma_logM': 0.39}

In [5]:
def richness(group_id):
    gals = Table()
    gals['groupid'] = group_id
    gals['dummy'] = 1
    grouped_table = gals.group_by('groupid')
    grp_richness = grouped_table['dummy'].groups.aggregate(np.sum)
    return grp_richness

In [232]:
model2 = Zheng07(threshold=-21)
model2.param_dict["logM0"] = 12.1

In [233]:
model.populate_mock()
model2.populate_mock()

In [234]:
g2 = model2.mock.compute_fof_group_ids()
g1 = model.mock.compute_fof_group_ids()

In [589]:
bins = np.arange(1,61,1)

In [590]:
np.histogram(data,bins)


Out[590]:
(array([5830, 1542,  560,  253,  135,   73,   44,   37,   18,   18,   13,
           9,    3,    4,    4,    3,    3,    2,    1,    2,    2,    1,
           1,    0,    0,    0,    1,    1,    0,    0,    0,    0,    0,
           0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
           0,    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
           0,    0,    0,    0]),
 array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17,
        18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
        35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
        52, 53, 54, 55, 56, 57, 58, 59, 60]))

In [221]:
x = plt.hist(data , bins , normed="True")[0]



In [269]:
y = np.histogram(richness(g2),bins , normed="True")[0]
yy = plt.hist(richness(g2),bins , normed="True")[0]
print yy.shape
z = plt.hist(richness(g1),bins , normed="True" , color = "r" , alpha = .5)[0]
np.histogram(data,bins,normed="True")


(59,)
Out[269]:
(array([  6.81074766e-01,   1.80140187e-01,   6.54205607e-02,
          2.95560748e-02,   1.57710280e-02,   8.52803738e-03,
          5.14018692e-03,   4.32242991e-03,   2.10280374e-03,
          2.10280374e-03,   1.51869159e-03,   1.05140187e-03,
          3.50467290e-04,   4.67289720e-04,   4.67289720e-04,
          3.50467290e-04,   3.50467290e-04,   2.33644860e-04,
          1.16822430e-04,   2.33644860e-04,   2.33644860e-04,
          1.16822430e-04,   1.16822430e-04,   0.00000000e+00,
          0.00000000e+00,   0.00000000e+00,   1.16822430e-04,
          1.16822430e-04,   0.00000000e+00,   0.00000000e+00,
          0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
          0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
          0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
          0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
          0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
          0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
          0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
          0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
          0.00000000e+00,   0.00000000e+00,   0.00000000e+00,
          0.00000000e+00,   0.00000000e+00]),
 array([ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16, 17,
        18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
        35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
        52, 53, 54, 55, 56, 57, 58, 59, 60]))

In [ ]:


In [264]:
list_r = []
model = Zheng07(threshold = -21)
for i in xrange(100):
    model.populate_mock()
    gid = model.mock.compute_fof_group_ids()
    x = np.histogram(richness(gid),bins , normed="True")[0]
    list_r.append(x)

In [270]:
d_r = np.array(list_r)
print d_r.shape
plt.pcolor(d_r)
plt.colorbar()


(100, 59)
Out[270]:
<matplotlib.colorbar.Colorbar instance at 0x7fb6fd3df1b8>

In [ ]:


In [591]:
plt.imshow(np.cov(d_r.T), interpolation = "None" , origin = "lower")
plt.colorbar()


Out[591]:
<matplotlib.colorbar.Colorbar instance at 0x7fb6e779d950>

In [273]:
C_diag =  np.diag(np.cov(d_r.T))+1.e-11

In [292]:
np.sum(((np.mean(d_r,axis=0)-y)**2./C_diag)[10:])


Out[292]:
54.85047045868302

In [291]:
np.sum(((np.mean(d_r,axis=0)-z)**2./C_diag)[10:])


Out[291]:
48.568792671390725

In [276]:
data_richness = np.mean(d_r,axis=0)

In [277]:
variance = C_diag
variance.shape , data_richness.shape


Out[277]:
((59,), (59,))

In [278]:
covariance = np.cov(d_r.T)

In [279]:
np.savetxt("data_richness.dat" , data_richness)

In [280]:
np.savetxt("covariance_richness.dat" , covariance)

In [281]:
np.savetxt("variance_richness.dat" , variance)

In [ ]:


In [ ]:


In [293]:


In [ ]:


In [ ]:


In [301]:
zhengerror = np.array([3.46285183e+03, 1.64749125e+03, 7.80527281e+02,
                      3.30492728e+02, 1.38927882e+02, 5.91026616e+01,
                      2.45091664e+01, 1.10830722e+01, 5.76577829e+00,
                      3.14415063e+00, 1.88664838e+00, 1.07786531e+00,
                      5.54622962e-01, 2.87849970e-01])

In [508]:
covariance = np.cov(xr.T)
pylab.pcolor(covariance)
pylab.colorbar()
pylab.show()

icov = np.linalg.inv(covariance)
icov2 = np.linalg.solve(covariance , np.eye(14))
pylab.savetxt("inverse_clustering_covariance.dat" , icov2)
pylab.pcolor(icov)
pylab.colorbar()
pylab.show()
err = (np.diag(icov2))**-.5
print np.diag(covariance)
print err


[  7.77902050e+04   1.22017943e+04   2.10972985e+03   3.01345792e+02
   5.46276177e+01   9.68773060e+00   1.36126685e+00   1.96206242e-01
   2.70759896e-02   5.22624299e-03   1.51568697e-03   5.11665528e-04
   1.44225424e-04   5.85306759e-05]
[  2.75083456e+02   1.07295323e+02   4.31948728e+01   1.54787874e+01
   6.42202598e+00   2.57068025e+00   9.41583585e-01   3.68480210e-01
   1.46869395e-01   6.39425303e-02   3.39863300e-02   1.89939479e-02
   9.52064833e-03   6.48109302e-03]

In [316]:
m = Zheng07(threshold = -21)

In [319]:
m.param_dict["alpha"] = 2.

In [320]:
m.populate_mock()

In [321]:
r , x = m.mock.compute_galaxy_clustering()
rr , xx = model.mock.compute_galaxy_clustering()

In [609]:
print rr
pylab.figure(figsize(10,10))
pylab.errorbar(rr , xx , yerr = 2. * err , fmt="-ok", ms=1,
            capsize=2, alpha=1.)

pylab.yscale("log")
pylab.xscale("log")
pylab.xlabel("$r$")
pylab.ylabel("$\\xi (r)$")
#pylab.xlim((,16))


[  0.12239095   0.17719995   0.25655347   0.37144299   0.53778224
   0.77861137   1.12728837   1.63210958   2.36299934   3.42119545
   4.95327193   7.17144145  10.38294952  15.03263208]
Out[609]:
<matplotlib.text.Text at 0x7fb6fea818d0>

In [315]:
model.param_dict


Out[315]:
{'alpha': 1.15,
 'logM0': 11.92,
 'logM1': 13.94,
 'logMmin': 12.79,
 'sigma_logM': 0.39}

In [362]:
m = np.logspace(11,16, 100)
from scipy.special import erf

In [363]:
def mean_central(M):
    logMmin = model.param_dict["logMmin"]
    sigma = model.param_dict["sigma_logM"]
    return .5 * (1. + erf((np.log10(M) - logMmin)/(sigma)))

In [ ]:


In [364]:
def mean_satelite(M):
    ncen  = mean_central(M)
    M0 = 10. ** model.param_dict["logM0"]
    M1 = 10. ** model.param_dict["logM1"]
    alpha = model.param_dict["alpha"]
    return ncen * ((M - M0)/(M1)) ** alpha

In [713]:
pylab.loglog(m , mean_central(m) , "r" , alpha = .1 , lw = 4.)
pylab.loglog(m , mean_satelite(m) , "b" , alpha = .1 , lw = 4.)
pylab.loglog(m , mean_central(m) + mean_satelite(m) , "g" , alpha = 1.)
pylab.ylabel("$N(M)$")
pylab.ylim((10**-6 , 10**10))


Out[713]:
(1e-06, 10000000000)

In [351]:
print model.param_dict["logM0"]


11.92

In [451]:
model = Zheng07(threshold = -21)

In [453]:
model.populate_mock()

In [556]:
nbar = []
for i in xrange(500):
     model.populate_mock()
     nbar.append(model.mock.number_density)

In [557]:
nbar = np.array(nbar)
np.savetxt("mock_nbar.dat" , nbar)

In [558]:
print np.mean(nbar)


0.000923547392

In [560]:
print np.var(nbar)


2.89344914063e-11

In [464]:
print model.param_dict
print model2.param_dict


{'logM0': 11.92, 'sigma_logM': 0.39, 'logMmin': 12.79, 'alpha': 1.15, 'logM1': 13.94}
{'logM0': 12.1, 'sigma_logM': 0.39, 'logMmin': 12.79, 'alpha': 1.15, 'logM1': 13.94}

In [ ]:


In [ ]:


In [515]:
np.diag(covariance)**.5


Out[515]:
array([  2.78908955e+02,   1.10461732e+02,   4.59317956e+01,
         1.73593143e+01,   7.39104984e+00,   3.11251194e+00,
         1.16673341e+00,   4.42951738e-01,   1.64547834e-01,
         7.22927589e-02,   3.89318246e-02,   2.26200249e-02,
         1.20093890e-02,   7.65053435e-03])

In [516]:
np.savetxt("clustering_covariance.dat" , covariance)

In [518]:
model.mock.number_density


Out[518]:
0.000929408

In [526]:
np.logspace(np.log10(1e12),np.log10(10) , 30)


Out[526]:
array([  1.00000000e+12,   4.17531894e+11,   1.74332882e+11,
         7.27895384e+10,   3.03919538e+10,   1.26896100e+10,
         5.29831691e+09,   2.21221629e+09,   9.23670857e+08,
         3.85662042e+08,   1.61026203e+08,   6.72335754e+07,
         2.80721620e+07,   1.17210230e+07,   4.89390092e+06,
         2.04335972e+06,   8.53167852e+05,   3.56224789e+05,
         1.48735211e+05,   6.21016942e+04,   2.59294380e+04,
         1.08263673e+04,   4.52035366e+03,   1.88739182e+03,
         7.88046282e+02,   3.29034456e+02,   1.37382380e+02,
         5.73615251e+01,   2.39502662e+01,   1.00000000e+01])

In [ ]:


In [551]:
dist= [[  9.34611722e+30 ,  1.19139184e+03],
 [  4.40717814e+32 ,  3.16556027e+03],
 [  6.97969451e+31 ,  3.61021871e+02],
 [  6.23476568e+28 ,  1.97302236e+04],
 [  3.05209675e+31 ,  1.10247217e+03]]
eps= [  1.00000000e+41 ,  1.00000000e+12]
dist = np.array(dist)

In [553]:
[(dist[i]<eps).all() for i in range(dist.shape[0])]


Out[553]:
[True, True, True, True, True]

In [592]:
mean = np.mean(nbar)
var = np.var(nbar)

In [ ]:


In [568]:


In [570]:



0.978275918821

In [571]:
mocks_xir = np.loadtxt("xir.dat")
data_xir = np.mean(mocks_xir , axis = 0)
covariance = np.loadtxt("clustering_covariance.dat")
cii = np.diag(covariance)

In [576]:
for i in range(200):
    model.populate_mock()
    n = model.mock.number_density
    chi1.append((n - mean)**2. / var)
    
    r , x = model.mock.compute_galaxy_clustering()
    chi2.append(np.sum((data_xir - x)**2. / cii))

In [585]:
np.median(np.array(chi1))


Out[585]:
0.42059392849736243

In [584]:
np.median(np.array(chi2))


Out[584]:
12.831631385845437

In [582]:
plt.hist(np.array(chi2))


Out[582]:
(array([  55.,  118.,   66.,   34.,   16.,    7.,    2.,    1.,    0.,    1.]),
 array([  3.1745792 ,   8.51949181,  13.86440442,  19.20931703,
         24.55422964,  29.89914225,  35.24405486,  40.58896747,
         45.93388008,  51.27879269,  56.6237053 ]),
 <a list of 10 Patch objects>)

In [593]:
plt.hist(np.array(chi1))


Out[593]:
(array([ 191.,   46.,   23.,   18.,    9.,    4.,    5.,    2.,    0.,    2.]),
 array([  4.63165447e-05,   7.59171743e-01,   1.51829717e+00,
          2.27742260e+00,   3.03654802e+00,   3.79567345e+00,
          4.55479888e+00,   5.31392430e+00,   6.07304973e+00,
          6.83217516e+00,   7.59130058e+00]),
 <a list of 10 Patch objects>)

In [594]:
print "the mean of clustering distances with the correct HOD = " , np.array(chi2).mean()
print "the mean of number density distances with the correct HOD = " , np.array(chi1).mean()


the mean of clustering distances with the correct HOD =  14.3684511307
the mean of number density distances with the correct HOD =  0.930518398615

In [ ]:


In [ ]:


In [605]:
model.populate_mock()
r , x = model.mock.compute_galaxy_clustering()
res = data_xir - x
%timeit np.dot(res , np.linalg.solve(covariance , res))
%timeit np.sum(res**2 / cii)


The slowest run took 4.02 times longer than the fastest. This could mean that an intermediate result is being cached 
10000 loops, best of 3: 26.9 µs per loop
The slowest run took 4.80 times longer than the fastest. This could mean that an intermediate result is being cached 
100000 loops, best of 3: 8.94 µs per loop

In [9]:
from halotools.mock_observables import wp

In [10]:
from halotools.mock_observables.clustering import tpcf

In [11]:
from halotools import mock_observables

In [ ]:


In [12]:
from halotools.empirical_models.mock_helpers import (three_dim_pos_bundle,
                                                     infer_mask_from_kwargs)
from halotools.mock_observables.clustering import wp

In [13]:
rbins = model_defaults.default_rbins

In [14]:
rbin_centers = (rbins[1:] + rbins[0:-1])/2.

In [15]:
print rbins


[  0.1          0.1447819    0.209618     0.30348893   0.43939706
   0.63616743   0.92105532   1.33352143   1.93069773   2.79530095
   4.04708995   5.85945392   8.48342898  12.28247006  17.7827941 ]

In [16]:
from halotools.sim_manager import supported_sims

In [17]:
cat = supported_sims.HaloCatalog()

In [18]:
L = cat.Lbox
mask = infer_mask_from_kwargs(model.mock.galaxy_table)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-18-17d06fa52b53> in <module>()
      1 L = cat.Lbox
----> 2 mask = infer_mask_from_kwargs(model.mock.galaxy_table)

NameError: name 'model' is not defined

In [638]:
pos = three_dim_pos_bundle(table=model.mock.galaxy_table,
                               key1='x', key2='y', key3='z', mask=mask,
                               return_complement=False)

In [690]:
clustering = wp(pos, rbins, p_bins , period = L)

In [687]:
print clustering.shape
print rbin_centers.shape
print L


(14,)
(14,)
250.0

In [691]:
plot(rbin_centers , clustering)
plt.xscale("Log")
plt.yscale("Log")



In [689]:
p_bins = np.linspace(0,L/2,10)

In [694]:
pi_max  = np.linspace(2, L/2 , 10)
cl = []
for pi in pi_max:
    p_bins = np.linspace(0,pi,100)
    clustering = wp(pos, rbins, p_bins , period = L)
    cl.append(clustering)

In [750]:
figure = plt.figure(figsize = (10,10))
for i in range(0,10):
    plot(rbin_centers , cl[i] , label = "$\pi_{max}$="+str(round(pi_max[i])))
    #plot(rbin_centers , cl[i] , label = "$\pi_{max}$={0:.2f}".format(pi_max[i]))
    
    plt.ylabel("$w_p$")
    plt.xlabel("$r_p$")
    plt.xscale("Log")
    plt.yscale("Log")
    plt.legend()



In [732]:
binsize = np.logspace(1,3,20)
cl2 = []
for bsize in binsize:
    p_bins = np.linspace(0,125,bsize)
    clustering = wp(pos, rbins, p_bins , period = L)
    cl2.append(clustering)

In [754]:
figure = plt.figure(figsize = (10,10))
for i in range(0,10):
    plot(rbin_centers , cl2[i] , label = "Bin size="+str(round(125/binsize[i]))+" Mpc")
    #plot(rbin_centers , cl[i] , label = "$\pi_{max}$={0:.2f}".format(pi_max[i]))
    plt.title("$\pi_{max}=$"+str(125)+" Mpc")

    plt.ylabel("$w_p$")
    plt.xlabel("$r_p$")
    plt.xscale("Log")
    plt.yscale("Log")
    plt.legend()



In [739]:
binsize = np.logspace(1,3,20)
cl3 = []
for bsize in binsize:
    p_bins = np.linspace(0,50,bsize)
    clustering = wp(pos, rbins, p_bins , period = L)
    cl3.append(clustering)

In [772]:
figure = plt.figure(figsize = (10,10))
for i in range(0,10):
    plot(rbin_centers , cl3[i] ,label = "Bin size="+str(round(50/binsize[i]))+" Mpc")
    #plot(rbin_centers , cl[i] , label = "$\pi_{max}$={0:.2f}".format(pi_max[i]))
    plt.title("$\pi_{max}=$"+str(50)+" Mpc")
    plt.ylabel("$w_p$")
    plt.xlabel("$r_p$")
    plt.xscale("Log")
    plt.yscale("Log")
    plt.legend()



In [786]:
model.populate_mock()
pos = three_dim_pos_bundle(table=model.mock.galaxy_table,
                               key1='x', key2='y', key3='z', mask=mask,
                               return_complement=False)
pbins = np.linspace(0 , 125 , 50)
clustering = wp(pos, rbins, p_bins , period = L)


---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-786-d63864255082> in <module>()
      2 pos = three_dim_pos_bundle(table=model.mock.galaxy_table,
      3                                key1='x', key2='y', key3='z', mask=mask,
----> 4                                return_complement=False)
      5 pbins = np.linspace(0 , 125 , 50)
      6 clustering = wp(pos, rbins, p_bins , period = L)

/home/mj/halotools/halotools/empirical_models/mock_helpers.pyc in three_dim_pos_bundle(table, key1, key2, key3, return_complement, **kwargs)
     35     if 'mask' in kwargs.keys():
     36         mask = kwargs['mask']
---> 37         x, y, z = table[key1][mask], table[key2][mask], table[key3][mask]
     38         if return_complement is True:
     39             x2, y2, z2 = table[key1][np.invert(mask)], table[key2][np.invert(mask)], table[key3][np.invert(mask)]

/export/bbq2/rfadely/anaconda/lib/python2.7/site-packages/astropy/table/column.pyc in __getitem__(self, item)
    328             return self.data[item]  # Return as plain ndarray or ma.MaskedArray
    329         else:
--> 330             return super(BaseColumn, self).__getitem__(item)
    331 
    332     # avoid == and != to be done based on type of subclass

IndexError: index 14330 is out of bounds for axis 1 with size 14330

In [770]:
from halotools.mock_observables import s_mu_tpcf

In [769]:
#s_bins = np.logspace(-2,-1,10)
#mu_bins = np.linspace(0,1,50)
#xis = s_mu_tpcf(pos, s_bins, mu_bins, period=L)

In [927]:
wp_list = []
p_bins = np.linspace(0,125,100)
for i in range(500):
    model.populate_mock()
    pos = three_dim_pos_bundle(table=model.mock.galaxy_table,
                               key1='x', key2='y', key3='z')
    wp_list.append(wp(pos, rbins, p_bins , period = np.array([L,L,L])))

In [926]:
import time
a = time.time()
#pos = three_dim_pos_bundle(table=model.mock.galaxy_table,key1='x', key2='y', key3='z' ,return_complement=False)
#wp(pos, rbins, pi_bins , period = np.array([L,L,L]))
model.mock.compute_galaxy_clustering()
print time.time() - a


1.4071688652

In [921]:
pi_bins = np.linspace(0,125,200)
d1 = wp(pos, rbins, pi_bins , period = np.array([L,L,L]))

In [922]:
pi_bins = np.linspace(0,125,100)
%timeit d2 = wp(pos, rbins, pi_bins , period = np.array([L,L,L]))


1 loops, best of 3: 903 ms per loop

In [929]:
wps = np.array(wp_list)

In [931]:
wp_cov = np.cov(wps.T)

In [937]:
imshow(wp_cov , interpolation = "None" , origin = "lower")
colorbar()


Out[937]:
<matplotlib.colorbar.Colorbar instance at 0x7fb6f43e9e60>

In [938]:
np.savetxt("wps.dat" , wps)
np.savetxt("wp_covariance.dat" , wp_cov)

In [946]:
data_wp = np.mean(wps , axis = 0) 
cii = np.diag(wp_cov)
chi3 = []
for i in range(500):
    #model.populate_mock()
    #pos = three_dim_pos_bundle(table=model.mock.galaxy_table,
    #                           key1='x', key2='y', key3='z')
    #wp_list.append(wp(pos, rbins, p_bins , period = np.array([L,L,L])))
    
    #r , x = model.mock.compute_galaxy_clustering()
    chi3.append(np.sum((data_wp - wps[i])**2. / cii))

In [947]:
np.array(chi3).mean()


Out[947]:
13.972000000000003

In [957]:
model = Zheng07(threshold = -21)
model.populate_mock()

In [958]:
g = model.mock.compute_fof_group_ids()

In [959]:
r = richness(g)

In [979]:
print r.min()


1

In [980]:
bins = np.arange(1,46)

In [1017]:
histogram = plt.hist(r , bins)
plt.close()
number = histogram[0]
print histogram[1]
print number.shape
gmp = number/250**3.
figure = plt.figure(figsize = (10,10))
plt.semilogx(bins[:-1] , np.log10(gmp) , "bo-")
plt.xlabel("N")
plt.ylabel(r"$\log\, n_{grp}(N) \, [h^{3}Mpc^{-3}]$")
plt.show()
plt.close()

figure = plt.figure(figsize = (10,10))
plt.plot(bins[:-1] , np.log10(number) , "bo-")
plt.xlabel("N")
plt.ylabel(r"$\log\, Abundance(N)$")
plt.xlim((0,30))
plt.show()
plt.close()


[ 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45]
(44,)

In [1012]:
n_mocks = 20
grp_list = []

In [1305]:
print model.param_dict
#for k in range(n_mocks):
#    model.populate_mock()
#    gids = model.mock.compute_fof_group_ids()
#    grp_list.append(richness(gids))
%timeit model.mock.compute_fof_group_ids(Nthreads = 4)


{'logM0': 11.92, 'sigma_logM': 0.39, 'logMmin': 12.79, 'alpha': 1.15, 'logM1': 13.94}
1 loops, best of 3: 1.03 s per loop

In [1070]:
#fig1, ax1 = plt.subplots()
print model.mock.number_density


0.00092928

In [1318]:
bins = [10,14,20,30]#[10,12,14,16,18,20,24,28]
gmps = []
for i in range(20): 
    r = grp_list[i]
    histogram = plt.hist(r , bins)
    #plt.show()
    plt.close()
    number = histogram[0]
    print number
    #print histogram[1]
    #print number.shape
    gmp = number/250**3.
    #print np.sum(gmp) , gmp
    gmps.append(gmp)
    """
    #figure = plt.figure(figsize = (10,10))
    fig1, ax1 = plt.subplots()
    ax1.semilogx(bins[:-1] , number , "o-")
    xticks = np.arange(10, 50, 10)
    plt.xticks(xticks)
    ax1.set_xscale('log')
    ax1.set_xticks(xticks)
    ax1.get_xaxis().set_major_formatter(matplotlib.ticker.ScalarFormatter())
    
    ax1.set_xlim((10,50))
    ax1.set_ylim((0,20))
    ax1.set_xlabel("N")
    ax1.set_ylabel("Abundance(N)")
    ax1.set_title("Group multiplicity of mock "+str(i))
    plt.show()
    plt.close()"""
gmps = np.array(gmps)
print np.mean(gmps , axis = 0) , np.std(gmps , axis = 0)


[ 45.  17.   4.]
[ 31.  26.   3.]
[ 41.  21.   5.]
[ 39.  14.   4.]
[ 50.  16.   3.]
[ 56.  20.   2.]
[ 40.  24.   3.]
[ 50.  22.   4.]
[ 40.  21.   5.]
[ 56.  16.   4.]
[ 39.  16.   6.]
[ 47.  16.   8.]
[ 35.  15.   6.]
[ 47.  15.   4.]
[ 37.  10.   9.]
[ 39.  16.   3.]
[ 43.  14.   6.]
[ 54.  16.   4.]
[ 40.  14.   6.]
[ 47.  20.   7.]
[  2.80320000e-06   1.11680000e-06   3.07200000e-07] [  4.33880352e-07   2.44103585e-07   1.13768889e-07]

In [ ]:


In [ ]:


In [1097]:


In [1099]:


In [1137]:


In [1108]:



[  2.88000000e-06   5.76000000e-07   5.12000000e-07   2.56000000e-07]

In [1319]:
gmp_mean = gmps[0]
gmp_std  = np.std(gmps , axis = 0)

In [1320]:
def distance(x):
    return ((x - gmps[0])**2.) / gmp_std**2.

In [1321]:
for i in range(4):
    model2 = Zheng07(threshold = -21)
    model2.param_dict["alpha"] = 1.15
    model2.populate_mock()
    id2 = model2.mock.compute_fof_group_ids()
    r2 = richness(id2)
    n2 = plt.hist(r2 , bins)[0]/250.**3
    plt.close()
    print distance(n2) , np.sum(distance(n2))


[ 0.0870322   0.618663    1.26582278] 1.97151798724
[ 3.67711053  0.06874033  5.06329114] 8.80914200353
[ 0.0870322   1.09984533  0.3164557 ] 1.50333323237
[ 0.19582245  0.618663    0.        ] 0.814485454824

In [1322]:
for i in range(4):
    model2 = Zheng07(threshold = -21)
    model2.param_dict["alpha"] = 1.3
    model2.populate_mock()
    id2 = model2.mock.compute_fof_group_ids()
    r2 = richness(id2)
    n2 = plt.hist(r2 , bins)[0]/250.**3
    plt.close()
    print distance(n2) , np.sum(distance(n2))


[ 0.02175805  1.09984533  7.91139241] 9.03299578979
[ 0.78328982  0.618663    1.26582278] 2.66777560256
[ 0.0870322   0.06874033  1.26582278] 1.42159532012
[ 0.         0.         0.3164557] 0.316455696203

In [1323]:
for i in range(4):
    model2 = Zheng07(threshold = -21)
    model2.param_dict["alpha"] = 0.9
    model2.populate_mock()
    id2 = model2.mock.compute_fof_group_ids()
    r2 = richness(id2)
    n2 = plt.hist(r2 , bins)[0]/250**3
    plt.close()
    print distance(n2) , np.sum(distance(n2))


[ 0.54395126  0.618663    0.3164557 ] 1.47906995869
[ 0.78328982  5.567967    5.06329114] 11.4145479611
[ 1.39251523  0.06874033  2.84810127] 4.30935682985
[ 0.54395126  1.71850833  1.26582278] 3.52828238154

In [1293]:
for i in range(4):
    model2 = Zheng07(threshold = -21)
    model2.param_dict["alpha"] = 1.25
    model2.populate_mock()
    id2 = model2.mock.compute_fof_group_ids()
    r2 = richness(id2)
    n2 = plt.hist(r2 , bins)[0]/250**3
    plt.close()
    print distance(n2)


[ 0.63730801  1.04317589  1.69491525  1.35338346]
[ 0.10196928  1.85453492  0.75329567  5.41353383]
[ 0.10196928  4.17270356  1.69491525  1.35338346]
[ 0.10196928  0.46363373  4.70809793  0.60150376]

In [1324]:
m = Zheng07()

In [1325]:
m.param_dict


Out[1325]:
{'alpha': 1.06,
 'logM0': 11.38,
 'logM1': 13.31,
 'logMmin': 12.02,
 'sigma_logM': 0.26}

In [1326]:
m.populate_mock()

In [1327]:
m.threshold


Out[1327]:
-20

In [1338]:
%timeit m.mock.compute_fof_group_ids()


1 loops, best of 3: 2.81 s per loop

In [1332]:
t = richness(g)

In [1340]:
plt.hist(t , np.arange(10,60 , 4))


Out[1340]:
(array([ 283.,  119.,   57.,   33.,   33.,   20.,    8.,   10.,   11.,
           2.,    2.,    2.]),
 array([10, 14, 18, 22, 26, 30, 34, 38, 42, 46, 50, 54, 58]),
 <a list of 12 Patch objects>)

In [1347]:
rich20 = []
for i in range(50):
    m = Zheng07()
    m.populate_mock()
    gid = m.mock.compute_fof_group_ids()
    rich = richness(gid)
    rich20.append(rich)
    #plt.hist(rich , np.arange(10,100))
    #plt.xlim((10,100))
    #plt.show()

In [1348]:
bins = np.arange(10,60,1)
gmp = []
for i in range(50):
    gmp.append(plt.hist(rich20[i] , bins)[0]/250.**3.)



In [1351]:
plt.imshow(gmp , interpolation = "None")
plt.colorbar()


Out[1351]:
<matplotlib.colorbar.Colorbar instance at 0x7fb6f24db998>

In [1357]:
for i in range(50):
    plt.semilogx(bins[:-1] , np.log10(gmp[i]))



In [1440]:
sdss_bins = np.array([3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,22,25,29,31,35,43,61])
sdss_bins = np.array([10,11,12,13,14,15,16,17,18,19,20,22,25,29,31,35,43,61])

In [1441]:
sdss_gmp = []
sdss_counts = []
for i in range(50):
    sdss_gmp.append(plt.hist(rich20[i] , sdss_bins)[0]/250.**3.)
    sdss_counts.append(plt.hist(rich20[i] , sdss_bins)[0])
    plt.close()

In [1442]:
sdss_mean = np.mean(sdss_gmp , axis = 0)
sdss_count_mean = np.mean(sdss_counts  ,axis = 0)
sdss_poisson = np.sqrt(sdss_count_mean) / 250. ** 3.

In [1443]:
sdss_sigma = np.std(sdss_gmp , axis =0)
print sdss_sigma , sdss_poisson


[  5.91498512e-07   5.28533064e-07   5.09705258e-07   4.93338303e-07
   3.75214703e-07   3.60562618e-07   3.27429905e-07   2.54922533e-07
   3.04252527e-07   2.11417101e-07   3.12333114e-07   2.71712978e-07
   2.53892122e-07   1.99125384e-07   2.40844169e-07   1.93381695e-07
   1.87177845e-07] [  6.47381433e-07   5.68844443e-07   4.92342645e-07   4.52457821e-07
   4.00805589e-07   3.67540583e-07   3.33537644e-07   3.06131475e-07
   2.78969532e-07   2.69560828e-07   3.32184045e-07   3.60110205e-07
   3.40585848e-07   2.03797547e-07   2.53750113e-07   2.61540054e-07
   2.38780904e-07]

In [1445]:
plt.figure(figsize(10,10))
plt.errorbar(0.5*(sdss_bins[:-1]+sdss_bins[1:]) , sdss_mean, yerr = np.sqrt(sdss_poisson**2.+sdss_sigma**2.)
             ,fmt="ok", capsize=2.0)
plt.plot(0.5*(sdss_bins[:-1]+sdss_bins[1:])  , sdss_gmp[10] , alpha = .5)
plt.plot(0.5*(sdss_bins[:-1]+sdss_bins[1:])  , sdss_gmp[40] , alpha = .5)
plt.plot(0.5*(sdss_bins[:-1]+sdss_bins[1:])  , sdss_gmp[30] , alpha = .5)
plt.plot(0.5*(sdss_bins[:-1]+sdss_bins[1:])  , sdss_gmp[20] , alpha = .5)
plt.ylabel(r"Group Multiplicity Function [$h^{3}Mpc^{-3}$]")
plt.xlabel("Group Richness")
plt.xscale("log")
plt.yscale("log")
plt.xlim((10,60))
plt.title("Multiplicity function of the mock data with the true HOD")
plt.savefig("/home/mj/public_html/Multiplicity_function")



In [1449]:
def distance(model):
    model.populate_mock()
    group_ids = model.mock.compute_fof_group_ids()
    R = richness(group_ids)
    binned_R = plt.hist(R , sdss_bins)[0] / 250**3.
    return np.sum((binned_R - sdss_mean)**2. / (sdss_sigma**2. + sdss_poisson**2.))

In [1463]:
q = Zheng07()
q.param_dict["alpha"] = 1.0
print distance(q)


6.8320228062

Saving the multiplicity function summary statistics and its corresponding noise


In [1465]:
sdss_stdev = (sdss_sigma**2. + sdss_poisson**2.)**.5
sdss_bins = sdss_bins
sdss_mean = sdss_mean

np.savetxt("gmf_Mr20.dat"       , sdss_mean)
np.savetxt("gmf_bins_Mr20.dat"  , sdss_bins)
np.savetxt("gmf_noise_Mr20.dat" , sdss_stdev)

In [8]:
m = Zheng07()
print m.param_dict


{'logM0': 11.38, 'sigma_logM': 0.26, 'logMmin': 12.02, 'alpha': 1.06, 'logM1': 13.31}

In [ ]:
def ptpcf(tpcf , pbins , rbins):

In [ ]: