Correlation function of DR12Q SDSS Catalog

First import all the modules such as healpy and astropy needed for analyzing the structure


In [1]:
import healpix_util as hu
import astropy as ap
import numpy as np
from astropy.io import fits
from astropy.table import Table
import astropy.io.ascii as ascii
from astropy.io import fits
from astropy.constants import c
import matplotlib.pyplot as plt
import math as m
from math import pi
#from scipy.constants import c
import scipy.special as sp
from astroML.decorators import pickle_results
from scipy import integrate
import warnings
from sklearn.neighbors import BallTree
import pickle
import multiprocessing as mp
import time
from lcdmmetric import *
from progressbar import *
from tqdm import *
from functools import partial
import pymangle
from scipy.optimize import curve_fit
#from astroML.datasets import fetch_sdss_specgals
#from astroML.correlation import bootstrap_two_point_angular
%matplotlib inline

In [4]:
dr12q=fits.open("./input/DR12Q.fits")

In [5]:
dr12q


Out[5]:
[<astropy.io.fits.hdu.image.PrimaryHDU object at 0x107efa750>, <astropy.io.fits.hdu.table.BinTableHDU object at 0x10d50ee90>]

In [6]:
dr12qdat=dr12q[1].data

In [7]:
dr12qdat.columns


Out[7]:
ColDefs(
    name = 'SDSS_NAME'; format = '18A'; unit = '-'
    name = 'RA'; format = 'D'; unit = 'deg'
    name = 'DEC'; format = 'D'; unit = 'deg'
    name = 'THING_ID'; format = 'J'; unit = '-'
    name = 'PLATE'; format = 'J'; unit = '-'
    name = 'MJD'; format = 'J'; unit = '-'
    name = 'FIBERID'; format = 'J'; unit = '-'
    name = 'Z_VI'; format = 'D'; unit = '-'
    name = 'Z_PIPE'; format = 'E'; unit = '-'
    name = 'ERR_ZPIPE'; format = 'E'; unit = '-'
    name = 'ZWARNING'; format = 'J'; unit = '-'
    name = 'Z_PCA'; format = 'D'; unit = '-'
    name = 'ERR_ZPCA'; format = 'D'; unit = '-'
    name = 'PCA_QUAL'; format = 'D'; unit = '-'
    name = 'Z_CIV'; format = 'D'; unit = '-'
    name = 'Z_CIII'; format = 'D'; unit = '-'
    name = 'Z_MGII'; format = 'D'; unit = '-'
    name = 'SDSS_MORPHO'; format = 'I'; unit = '-'
    name = 'BOSS_TARGET1'; format = 'K'; unit = '-'
    name = 'ANCILLARY_TARGET1'; format = 'K'; unit = '-'
    name = 'ANCILLARY_TARGET2'; format = 'K'; unit = '-'
    name = 'EBOSS_TARGET0'; format = 'K'; unit = '-'
    name = 'NSPEC_BOSS'; format = 'J'; unit = '-'
    name = 'PLATE_DUPLICATE'; format = '32J'; unit = '-'
    name = 'MJD_DUPLICATE'; format = '32J'; unit = '-'
    name = 'FIBERID_DUPLICATE'; format = '32J'; unit = '-'
    name = 'SDSS_DR7'; format = 'J'; unit = '-'
    name = 'PLATE_DR7'; format = 'J'; unit = '-'
    name = 'MJD_DR7'; format = 'J'; unit = '-'
    name = 'FIBERID_DR7'; format = 'J'; unit = '-'
    name = 'UNIFORM'; format = 'I'; unit = '-'
    name = 'ALPHA_NU'; format = 'D'; unit = '-'
    name = 'SNR_SPEC'; format = 'D'; unit = '-'
    name = 'SNR_DUPLICATE'; format = '32D'; unit = '-'
    name = 'SNR_1700'; format = 'D'; unit = '-'
    name = 'SNR_3000'; format = 'D'; unit = '-'
    name = 'SNR_5150'; format = 'D'; unit = '-'
    name = 'FWHM_CIV'; format = 'D'; unit = 'km s-1'
    name = 'BHWHM_CIV'; format = 'D'; unit = 'km s-1'
    name = 'RHWHM_CIV'; format = 'D'; unit = 'km s-1'
    name = 'AMP_CIV'; format = 'D'; unit = '-'
    name = 'REWE_CIV'; format = 'D'; unit = '0.1nm'
    name = 'ERR_REWE_CIV'; format = 'D'; unit = '0.1nm'
    name = 'FWHM_CIII'; format = 'D'; unit = 'km s-1'
    name = 'BHWHM_CIII'; format = 'D'; unit = 'km s-1'
    name = 'RHWHM_CIII'; format = 'D'; unit = 'km s-1'
    name = 'AMP_CIII'; format = 'D'; unit = '-'
    name = 'REWE_CIII'; format = 'D'; unit = '0.1nm'
    name = 'ERR_REWE_CIII'; format = 'D'; unit = '0.1nm'
    name = 'FWHM_MGII'; format = 'D'; unit = 'km s-1'
    name = 'BHWHM_MGII'; format = 'D'; unit = 'km s-1'
    name = 'RHWHM_MGII'; format = 'D'; unit = 'km s-1'
    name = 'AMP_MGII'; format = 'D'; unit = '-'
    name = 'REWE_MGII'; format = 'D'; unit = '0.1nm'
    name = 'ERR_REWE_MGII'; format = 'D'; unit = '0.1nm'
    name = 'BAL_FLAG_VI'; format = 'I'; unit = '-'
    name = 'BI_CIV'; format = 'D'; unit = 'km s-1'
    name = 'ERR_BI_CIV'; format = 'D'; unit = 'km s-1'
    name = 'AI_CIV'; format = 'D'; unit = 'km s-1'
    name = 'ERR_AI_CIV'; format = 'D'; unit = 'km s-1'
    name = 'CHI2TROUGH'; format = 'D'; unit = '-'
    name = 'NCIV_2000'; format = 'J'; unit = '-'
    name = 'VMIN_CIV_2000'; format = 'D'; unit = '-'
    name = 'VMAX_CIV_2000'; format = 'D'; unit = '-'
    name = 'NCIV_450'; format = 'J'; unit = '-'
    name = 'VMIN_CIV_450'; format = 'D'; unit = '-'
    name = 'VMAX_CIV_450'; format = 'D'; unit = '-'
    name = 'REW_SIIV'; format = 'D'; unit = '0.1nm'
    name = 'REW_CIV'; format = 'D'; unit = '0.1nm'
    name = 'REW_ALIII'; format = 'D'; unit = '0.1nm'
    name = 'RUN_NUMBER'; format = 'I'; unit = '-'
    name = 'PHOTO_MJD'; format = 'J'; unit = '-'
    name = 'RERUN_NUMBER'; format = '3A'; unit = '-'
    name = 'COL_NUMBER'; format = 'I'; unit = '-'
    name = 'FIELD_NUMBER'; format = 'I'; unit = '-'
    name = 'OBJ_ID'; format = '19A'; unit = '-'
    name = 'PSFFLUX'; format = '5E'; unit = 'nanomaggies'
    name = 'IVAR_PSFFLUX'; format = '5E'; unit = '-'
    name = 'PSFMAG'; format = '5E'; unit = '-'
    name = 'ERR_PSFMAG'; format = '5E'; unit = '-'
    name = 'TARGET_FLUX'; format = '5D'; unit = 'nanomaggies'
    name = 'MI'; format = 'D'; unit = '-'
    name = 'DGMI'; format = 'D'; unit = '-'
    name = 'EXTINCTION'; format = '5E'; unit = '-'
    name = 'EXTINCTION_RECAL'; format = '5E'; unit = '-'
    name = 'HI_GAL'; format = 'D'; unit = '-'
    name = 'VAR_MATCHED'; format = 'I'; unit = '-'
    name = 'VAR_CHI2'; format = 'D'; unit = '-'
    name = 'VAR_A'; format = 'D'; unit = '-'
    name = 'VAR_GAMMA'; format = 'D'; unit = '-'
    name = 'RASS_COUNTS'; format = 'D'; unit = 'counts s-1'
    name = 'RASS_COUNTS_SNR'; format = 'D'; unit = '-'
    name = 'SDSS2ROSAT_SEP'; format = 'D'; unit = 'arcsec'
    name = 'N_DETECTION_XMM'; format = 'I'; unit = '-'
    name = 'FLUX02_12KEV_SGL'; format = 'D'; unit = 'erg cm-2 s-1'
    name = 'ERR_FLUX02_12KEV_SGL'; format = 'D'; unit = 'erg cm-2 s-1'
    name = 'FLUX02_2KEV'; format = 'D'; unit = 'erg cm-2 s-1'
    name = 'ERR_FLUX02_2KEV'; format = 'D'; unit = 'erg cm-2 s-1'
    name = 'FLUX2_12KEV'; format = 'D'; unit = 'erg cm-2 s-1'
    name = 'ERR_FLUX2_12KEV'; format = 'D'; unit = 'erg cm-2 s-1'
    name = 'FLUX02_12KEV'; format = 'D'; unit = 'erg cm-2 s-1'
    name = 'ERR_FLUX02_12KEV'; format = 'D'; unit = 'erg cm-2 s-1'
    name = 'LUM02_2KEV_SGL'; format = 'D'; unit = 'erg s-1'
    name = 'LUM05_2KEV'; format = 'D'; unit = 'erg s-1'
    name = 'LUM2_12KEV'; format = 'D'; unit = 'erg s-1'
    name = 'LUM02_2KEV'; format = 'D'; unit = 'erg s-1'
    name = 'LUMX2_10_UPPER'; format = 'I'; unit = '-'
    name = 'SDSS2XMM_SEP'; format = 'D'; unit = 'arcsec'
    name = 'GALEX_MATCHED'; format = 'I'; unit = '-'
    name = 'FUV'; format = 'D'; unit = 'nanomaggies'
    name = 'FUV_IVAR'; format = 'D'; unit = 'nanomaggies-2'
    name = 'NUV'; format = 'D'; unit = 'nanomaggies'
    name = 'NUV_IVAR'; format = 'D'; unit = 'nanomaggies-2'
    name = 'JMAG'; format = 'D'; unit = 'mag Vega'
    name = 'ERR_JMAG'; format = 'D'; unit = 'mag Vega'
    name = 'JSNR'; format = 'D'; unit = '-'
    name = 'JRDFLAG'; format = 'J'; unit = '-'
    name = 'HMAG'; format = 'D'; unit = 'mag Vega'
    name = 'ERR_HMAG'; format = 'D'; unit = 'mag Vega'
    name = 'HSNR'; format = 'D'; unit = '-'
    name = 'HRDFLAG'; format = 'J'; unit = '-'
    name = 'KMAG'; format = 'D'; unit = 'mag Vega'
    name = 'ERR_KMAG'; format = 'D'; unit = 'mag Vega'
    name = 'KSNR'; format = 'D'; unit = '-'
    name = 'KRDFLAG'; format = 'J'; unit = '-'
    name = 'SDSS2MASS_SEP'; format = 'D'; unit = 'arcsec'
    name = 'W1MAG'; format = 'D'; unit = 'mag Vega'
    name = 'ERR_W1MAG'; format = 'D'; unit = 'mag Vega'
    name = 'W1SNR'; format = 'D'; unit = '-'
    name = 'W1CHI2'; format = 'D'; unit = '-'
    name = 'W2MAG'; format = 'D'; unit = 'mag Vega'
    name = 'ERR_W2MAG'; format = 'D'; unit = 'mag Vega'
    name = 'W2SNR'; format = 'D'; unit = '-'
    name = 'W2CHI2'; format = 'D'; unit = '-'
    name = 'W3MAG'; format = 'D'; unit = 'mag Vega'
    name = 'ERR_W3MAG'; format = 'D'; unit = 'mag Vega'
    name = 'W3SNR'; format = 'D'; unit = '-'
    name = 'W3CHI2'; format = 'D'; unit = '-'
    name = 'W4MAG'; format = 'D'; unit = 'mag Vega'
    name = 'ERR_W4MAG'; format = 'D'; unit = 'mag Vega'
    name = 'W4SNR'; format = 'D'; unit = '-'
    name = 'W4CHI2'; format = 'D'; unit = '-'
    name = 'CC_FLAGS'; format = '4A'; unit = '-'
    name = 'PH_FLAG'; format = '4A'; unit = '-'
    name = 'SDSS2WISE_SEP'; format = 'D'; unit = 'arcsec'
    name = 'UKIDSS_MATCHED'; format = 'I'; unit = '-'
    name = 'YFLUX'; format = 'E'; unit = 'nanomaggies'
    name = 'YFLUX_ERR'; format = 'E'; unit = 'nanomaggies'
    name = 'JFLUX'; format = 'E'; unit = 'nanomaggies'
    name = 'JFLUX_ERR'; format = 'E'; unit = 'nanomaggies'
    name = 'HFLUX'; format = 'E'; unit = 'nanomaggies'
    name = 'HFLUX_ERR'; format = 'E'; unit = 'nanomaggies'
    name = 'KFLUX'; format = 'E'; unit = 'nanomaggies'
    name = 'KFLUX_ERR'; format = 'E'; unit = 'nanomaggies'
    name = 'FIRST_MATCHED'; format = 'I'; unit = '-'
    name = 'FIRST_FLUX'; format = 'D'; unit = 'mJy'
    name = 'FIRST_SNR'; format = 'D'; unit = '-'
    name = 'SDSS2FIRST_SEP'; format = 'D'; unit = 'arcsec'
)

In [8]:
z=dr12qdat['Z_PIPE']

In [9]:
ra=dr12qdat['RA']

In [10]:
dec=dr12qdat['DEC']

In [ ]:
fdata = open("./output/DR12Q.dat",'w')
fdata.write("z\t ra\t dec \n")
for i in range(0,len(ra)-1):
    fdata.write("%f\t" %z[i])
    fdata.write("%f\t" %ra[i])
    fdata.write("%f\n" %dec[i])
fdata.close()

In [ ]:
z

In [ ]:
ra,dec

In [ ]:
dat=np.array([z,ra,dec])

In [ ]:
dat

In [ ]:
dat=dat.transpose()

In [ ]:
dat

Read the data file (taken from http://cosmo.nyu.edu/~eak306/SDSS-LRG.html ) converted to ascii with comoving distance etc. in V01 reading from pkl files for faster read


In [ ]:
# Saving the objects:
with open('datDR12Q.pkl', 'w') as f:  # Python 3: open(..., 'wb')
    pickle.dump(dat, f)

In [2]:
# Getting back the objects:
with open('datDR12Q.pkl') as f:  # Python 3: open(..., 'rb')
    dat = pickle.load(f)
dat


Out[2]:
array([[  2.30909729e+00,   1.89828518e-03,   1.77737391e+01],
       [  2.49794078e+00,   2.75643009e-03,   1.49746755e+01],
       [  1.61884606e+00,   4.05238854e-03,   4.82978057e+00],
       ..., 
       [  2.45101476e+00,   3.59999118e+02,   2.89547342e+01],
       [  3.11339068e+00,   3.59999293e+02,   3.47208385e+01],
       [  2.39766693e+00,   3.59999942e+02,   3.47471272e+01]])

In [ ]:


In [3]:
Ez = lambda x: 1/m.sqrt(0.3*(1+x)**3+0.7)

np.vectorize(Ez)
#Calculate comoving distance of a data point using the Redshift - This definition is based on the cosmology model we take. Here the distance for E-dS universe is considered. Also note that c/H0 ratio is cancelled in the equations and hence not taken.

def DC_LCDM(z):
  return integrate.quad(Ez, 0, z)[0]
DC_LCDM=np.vectorize(DC_LCDM)

In [ ]:


In [11]:
dr12f = open("./output/DR12Qsrarf.dat",'w')
dr12f.write("z\t ra\t dec\t s\t rar\t decr \n")

for i in range(0,len(z)):
    dr12f.write("%f\t " %z[i])
    dr12f.write("%f\t %f\t " %(ra[i],dec[i]))
    dr12f.write("%f\t " %DC_LCDM(z[i]))
    dr12f.write("%f\t %f\n " %(ra[i]*pi/180.0,dec[i]*pi/180.0))
dr12f.close()

In [12]:
dr12Qdat=ascii.read("./output/DR12Qsrarf.dat")

In [13]:
s=dr12Qdat['s']
rar=dr12Qdat['ra']
decr=dr12Qdat['dec']

In [15]:
dat=np.array([s,rar,decr])

In [16]:
dat


Out[16]:
array([[  1.30676600e+00,   1.36014200e+00,   1.06859900e+00, ...,
          1.34726600e+00,   1.50892800e+00,   1.33232300e+00],
       [  1.89800000e-03,   2.75600000e-03,   4.05200000e-03, ...,
          3.59999118e+02,   3.59999293e+02,   3.59999942e+02],
       [  1.77737390e+01,   1.49746750e+01,   4.82978100e+00, ...,
          2.89547340e+01,   3.47208380e+01,   3.47471270e+01]])

In [17]:
dat=dat.transpose()

In [18]:
dat


Out[18]:
array([[  1.30676600e+00,   1.89800000e-03,   1.77737390e+01],
       [  1.36014200e+00,   2.75600000e-03,   1.49746750e+01],
       [  1.06859900e+00,   4.05200000e-03,   4.82978100e+00],
       ..., 
       [  1.34726600e+00,   3.59999118e+02,   2.89547340e+01],
       [  1.50892800e+00,   3.59999293e+02,   3.47208380e+01],
       [  1.33232300e+00,   3.59999942e+02,   3.47471270e+01]])

Read the data file (taken from http://cosmo.nyu.edu/~eak306/SDSS-LRG.html ) converted to ascii with comoving distance etc. in V01 reading from pkl files for faster read


In [19]:
# Saving the objects:
with open('datDR12Q.pkl', 'w') as f:  # Python 3: open(..., 'wb')
    pickle.dump(dat, f)

In [20]:
# Getting back the objects:
with open('datDR12Q.pkl') as f:  # Python 3: open(..., 'rb')
    dat = pickle.load(f)
dat


Out[20]:
array([[  1.30676600e+00,   1.89800000e-03,   1.77737390e+01],
       [  1.36014200e+00,   2.75600000e-03,   1.49746750e+01],
       [  1.06859900e+00,   4.05200000e-03,   4.82978100e+00],
       ..., 
       [  1.34726600e+00,   3.59999118e+02,   2.89547340e+01],
       [  1.50892800e+00,   3.59999293e+02,   3.47208380e+01],
       [  1.33232300e+00,   3.59999942e+02,   3.47471270e+01]])

In [21]:
bins=np.arange(0.,0.08,0.005)

In [22]:
print bins


[ 0.     0.005  0.01   0.015  0.02   0.025  0.03   0.035  0.04   0.045
  0.05   0.055  0.06   0.065  0.07   0.075]

In [23]:
binsq=bins**2

In [24]:
binsq


Out[24]:
array([  0.00000000e+00,   2.50000000e-05,   1.00000000e-04,
         2.25000000e-04,   4.00000000e-04,   6.25000000e-04,
         9.00000000e-04,   1.22500000e-03,   1.60000000e-03,
         2.02500000e-03,   2.50000000e-03,   3.02500000e-03,
         3.60000000e-03,   4.22500000e-03,   4.90000000e-03,
         5.62500000e-03])

In [ ]:
len(dat)

In [27]:
LCDMmetricsq(dat[0],dat[1])


Out[27]:
6.905895197702932

In [28]:
%%time
BTD = BallTree(dat,metric='pyfunc',func=LCDMmetricsq,leaf_size=5) 

with open('BTDDR12QLCDM.pkl', 'w') as f:
    pickle.dump(BTD,f)


CPU times: user 2min 49s, sys: 572 ms, total: 2min 49s
Wall time: 2min 50s

In [29]:
with open('BTDDR12QLCDM.pkl') as f:
    BTD = pickle.load(f)
    
BTD


Out[29]:
<sklearn.neighbors.ball_tree.BinaryTree at 0x7fbd3f8baab0>

In [30]:
%%time
start_time=time.time()
counts_DD=BTD.two_point_correlation(dat,binsq)
print counts_DD
end_time=time.time()
tottime=end_time-start_time
print "Total run time:"
print tottime

with open('BTD12QcDDLCDM.pkl', 'w') as f:
    pickle.dump(counts_DD,f)


[  242337   323953   400258   588348   934675  1483312  2268653  3328592
  4694027  6395412  8457547 10907804 13770242 17073543 20832319 25061700]
Total run time:
32082.7158611
CPU times: user 8h 52min 40s, sys: 1min 11s, total: 8h 53min 52s
Wall time: 8h 54min 42s

In [31]:
with open('BTD12QcDDLCDM.pkl') as f:
    counts_DD = pickle.load(f)
    
counts_DD


Out[31]:
array([  242337,   323953,   400258,   588348,   934675,  1483312,
        2268653,  3328592,  4694027,  6395412,  8457547, 10907804,
       13770242, 17073543, 20832319, 25061700])

In [32]:
DD=np.diff(counts_DD)

In [33]:
DD


Out[33]:
array([  81616,   76305,  188090,  346327,  548637,  785341, 1059939,
       1365435, 1701385, 2062135, 2450257, 2862438, 3303301, 3758776,
       4229381])

In [34]:
plt.plot(bins[1:len(bins)],DD,'ro-')


Out[34]:
[<matplotlib.lines.Line2D at 0x1342455d0>]

BallTree.two_point_correlation works almost 10 times faster! with leaf_size=5 Going with it to the random catalog


In [35]:
dataR=ascii.read("./output/rand200kDR12Q.dat")

In [36]:
dataR


Out[36]:
<Table length=594601>
zradec
float64float64float64
2.309097210.1848776.552465
2.497941181.01424840.013558
1.618846247.25752114.374272
1.360358341.52188426.037932
2.332655351.3196091.766683
3.088839241.44642745.933919
2.373299218.52105458.39641
2.542303194.51349.700852
3.711993190.11343833.289223
2.164559252.66828226.513047
.........
5.602488127.5615057.41027
4.054103197.34675312.703398
4.537804245.10534913.690674
3.269235165.26342429.143887
5.538107252.61045549.082342
0.27639918.50778721.238333
2.937095213.64190618.062931
6.490495148.41090833.08761
1.359045207.05091121.052432
3.828378248.12947921.816691

In [37]:
len(dataR)


Out[37]:
594601

In [38]:
len(dat)


Out[38]:
297301

In [39]:
rdr12f = open("./output/DR12Qsrarf.dat",'w')
rdr12f.write("z\t ra\t dec\t s\t rar\t decr \n")

for i in range(0,len(dataR)):
    rdr12f.write("%f\t " %dataR['z'][i])
    rdr12f.write("%f\t %f\t " %(dataR['ra'][i],dataR['dec'][i]))
    rdr12f.write("%f\t " %DC_LCDM(dataR['z'][i]))
    rdr12f.write("%f\t %f\n " %((dataR['ra'][i]*pi)/180.0,(dataR['dec'][i]*pi)/180.0))
rdr12f.close()

In [40]:
datR=ascii.read("./output/DR12Qsrarf.dat")

In [41]:
datR


Out[41]:
<Table length=594601>
zradecsrardecr
float64float64float64float64float64float64
2.309097210.1848776.5524651.3067663.6684180.114362
2.497941181.01424840.0135581.3601423.1592950.698368
1.618846247.25752114.3742721.0685994.3154580.250878
1.360358341.52188426.0379320.9565025.9606810.454448
2.332655351.3196091.7666831.3136576.1316840.030834
3.088839241.44642745.9339191.503624.2140350.801698
2.373299218.52105458.396411.3253863.8139121.01921
2.542303194.51349.7008521.372093.3948990.169312
3.711993190.11343833.2892231.6255733.3181050.581007
2.164559252.66828226.5130471.2629234.4098930.46274
..................
5.602488127.5615057.410271.8848262.2263680.129334
4.054103197.34675312.7033981.6829283.4443510.221716
4.537804245.10534913.6906741.7549164.2778950.238947
3.269235165.26342429.1438871.5415812.8843910.508657
5.538107252.61045549.0823421.8778754.4088840.856648
0.27639918.50778721.2383330.2585070.3230220.370679
2.937095213.64190618.0629311.4697563.7287550.315258
6.490495148.41090833.087611.9714252.5902590.577488
1.359045207.05091121.0524320.9558933.613720.367434
3.828378248.12947921.8166911.6457544.3306760.380773

In [42]:
rs=np.array(datR['s'])
rrar=np.array(datR['rar'])
rdecr=np.array(datR['decr'])

In [43]:
datR=np.array([rs,rrar,rdecr])

In [44]:
datR


Out[44]:
array([[ 1.306766,  1.360142,  1.068599, ...,  1.971425,  0.955893,
         1.645754],
       [ 3.668418,  3.159295,  4.315458, ...,  2.590259,  3.61372 ,
         4.330676],
       [ 0.114362,  0.698368,  0.250878, ...,  0.577488,  0.367434,
         0.380773]])

In [45]:
datR.reshape(3,len(dataR))


Out[45]:
array([[ 1.306766,  1.360142,  1.068599, ...,  1.971425,  0.955893,
         1.645754],
       [ 3.668418,  3.159295,  4.315458, ...,  2.590259,  3.61372 ,
         4.330676],
       [ 0.114362,  0.698368,  0.250878, ...,  0.577488,  0.367434,
         0.380773]])

In [46]:
datR=datR.transpose()

In [47]:
datR


Out[47]:
array([[ 1.306766,  3.668418,  0.114362],
       [ 1.360142,  3.159295,  0.698368],
       [ 1.068599,  4.315458,  0.250878],
       ..., 
       [ 1.971425,  2.590259,  0.577488],
       [ 0.955893,  3.61372 ,  0.367434],
       [ 1.645754,  4.330676,  0.380773]])

In [48]:
# Saving the objects:
with open('./output/rDR12Qsrarf.pkl', 'w') as f:  # Python 3: open(..., 'wb')
    pickle.dump(datR, f)

In [49]:
# Getting back the objects:
with open('./output/rDR12Qsrarf.pkl') as f:  # Python 3: open(..., 'rb')
    datR = pickle.load(f)
datR


Out[49]:
array([[ 1.306766,  3.668418,  0.114362],
       [ 1.360142,  3.159295,  0.698368],
       [ 1.068599,  4.315458,  0.250878],
       ..., 
       [ 1.971425,  2.590259,  0.577488],
       [ 0.955893,  3.61372 ,  0.367434],
       [ 1.645754,  4.330676,  0.380773]])

In [50]:
%%time
BT_R2 = BallTree(datR,metric='pyfunc',func=LCDMmetricsq,leaf_size=5) 

with open('./output/BTRDR12QLCDM.pkl', 'w') as f:
    pickle.dump(BT_R2,f)


CPU times: user 35.2 s, sys: 268 ms, total: 35.4 s
Wall time: 36.3 s

In [51]:
with open('./output/BTRDR12QLCDM.pkl') as f:
    BTR = pickle.load(f)
BTR


Out[51]:
<sklearn.neighbors.ball_tree.BinaryTree at 0x7fbd405bdca0>

In [52]:
%%time
start_time=time.time()
counts_RR=BTR.two_point_correlation(datR,bins)
print counts_RR
end_time=time.time()
tottime=end_time-start_time
print "Total run time:"
print tottime

with open('./output/BTRDR12QcRRLCDM.pkl', 'w') as f:
    pickle.dump(counts_RR,f)


[    480876   90521217  232985334  408026325  608257635  826290051
 1059640862 1307306243 1568500502 1841642191 2125602861 2419930980
 2723910487 3036569112 3356826807 3683764722]
Total run time:
2038.76613498
CPU times: user 33min 53s, sys: 3.05 s, total: 33min 56s
Wall time: 33min 58s

In [53]:
with open('./output/BTRDR12QcRRLCDM.pkl') as f:
    counts_RR = pickle.load(f)
    
counts_RR


Out[53]:
array([    480876,   90521217,  232985334,  408026325,  608257635,
        826290051, 1059640862, 1307306243, 1568500502, 1841642191,
       2125602861, 2419930980, 2723910487, 3036569112, 3356826807,
       3683764722])

In [54]:
counts_RR


Out[54]:
array([    480876,   90521217,  232985334,  408026325,  608257635,
        826290051, 1059640862, 1307306243, 1568500502, 1841642191,
       2125602861, 2419930980, 2723910487, 3036569112, 3356826807,
       3683764722])

In [55]:
RR=np.diff(counts_RR)

In [56]:
RR


Out[56]:
array([ 90040341, 142464117, 175040991, 200231310, 218032416, 233350811,
       247665381, 261194259, 273141689, 283960670, 294328119, 303979507,
       312658625, 320257695, 326937915])

In [57]:
plt.plot(bins[1:len(bins)],RR,'bo-')


Out[57]:
[<matplotlib.lines.Line2D at 0x150d9a4d0>]

In [58]:
RR_zero = (RR == 0)
RR[RR_zero] = 1

In [59]:
%%time
start_time=time.time()
counts_DR=BTR.two_point_correlation(dat,bins)
print counts_DR
end_time=time.time()
tottime=end_time-start_time
print "Total run time:"
print tottime

with open('./output/BTRDR12QcDRLCDM.pkl', 'w') as f:
    pickle.dump(counts_DR,f)


[     1369  10203169  27575044  49464879  75186580 103735887 134687673
 168002916 203520026 240850552 280135583 321097455 363631078 407963871
 453866559 501114126]
Total run time:
264.940030098
CPU times: user 4min 24s, sys: 383 ms, total: 4min 24s
Wall time: 4min 24s

In [60]:
with open('./output/BTRDR12QcDRLCDM.pkl') as f:
    counts_DR = pickle.load(f)
    
counts_DR


Out[60]:
array([     1369,  10203169,  27575044,  49464879,  75186580, 103735887,
       134687673, 168002916, 203520026, 240850552, 280135583, 321097455,
       363631078, 407963871, 453866559, 501114126])

In [61]:
DR=np.diff(counts_DR)

In [62]:
corrells=(4.0 * DD - 4.0 * DR + RR) / RR

In [63]:
DR


Out[63]:
array([10201800, 17371875, 21889835, 25721701, 28549307, 30951786,
       33315243, 35517110, 37330526, 39285031, 40961872, 42533623,
       44332793, 45902688, 47247567])

In [64]:
corrells


Out[64]:
array([ 0.55041556,  0.51438803,  0.50407628,  0.4930788 ,  0.48630262,
        0.48289968,  0.47905026,  0.47699195,  0.47823211,  0.47566125,
        0.47661657,  0.47797553,  0.47508895,  0.47362499,  0.47368373])

In [65]:
plt.plot(bins[1:len(bins)],corrells,'go-')


Out[65]:
[<matplotlib.lines.Line2D at 0x149e41a10>]

In [66]:
plt.plot(bins[1:len(bins)],bins[1:len(bins)]*bins[1:len(bins)]*corrells*(c*1e-5)**2,'go-')


Out[66]:
[<matplotlib.lines.Line2D at 0x13d4d5210>]

In [67]:
plt.plot(bins[2:len(bins)],bins[2:len(bins)]*bins[2:len(bins)]*corrells[1:len(bins)]*(c*1e-5)**2,'go-')


Out[67]:
[<matplotlib.lines.Line2D at 0x158cab350>]

In [68]:
plt.plot(bins[2:len(bins)],corrells[1:len(bins)],'go-')


Out[68]:
[<matplotlib.lines.Line2D at 0x158d9aa50>]

In [69]:
plt.plot(bins[2:len(bins)],corrells[1:len(bins)],'go-')
plt.savefig("correlDR12Qls.pdf")



In [70]:
plt.plot(bins[2:len(bins)]*c/1e5,corrells[1:len(bins)],'bo-')
plt.savefig("correl12Q1ls.pdf")



In [71]:
plt.yscale('log')
plt.plot(bins[1:len(bins)]*c/1e5,corrells,'bo-')
plt.savefig("correllsfiglogDR12Q.pdf")



In [72]:
plt.yscale('log')
plt.plot(bins[2:len(bins)]*c/1e5,corrells[1:len(bins)],'ro-')
plt.savefig("correllslog2xDR12Q.pdf")



In [73]:
plt.yscale('log')
plt.xscale('log')
plt.plot(bins[1:len(bins)]*c/1e5,corrells,'bo-')
plt.savefig("correllsloglogDR12Q.pdf")



In [ ]: