Correlation function of DR72 SDSS VAGC 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 aptestmetricdt import *
from aptestmetricdz import *
from scipy.spatial import distance as d
from apcat import *
from progressbar import *
from tqdm import *
from functools import partial
import pymangle
from apdz import *
from apdt import *
from scipy.optimize import curve_fit
#from astroML.datasets import fetch_sdss_specgals
#from astroML.correlation import bootstrap_two_point_angular
%matplotlib inline

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


Out[2]:
array([[ 0.160002,  5.964543,  0.235823],
       [ 0.160018,  3.089162,  0.28616 ],
       [ 0.16002 ,  4.085181,  0.284492],
       ..., 
       [ 0.469989,  3.059253,  0.349895],
       [ 0.469994,  3.506603,  1.073682],
       [ 0.469996,  2.217024,  0.108364]])

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 [3]:
# Getting back the objects:
with open('../output/rdatzAP.pkl') as f:  # Python 3: open(..., 'rb')
    datR = pickle.load(f)
datR


Out[3]:
array([[ 0.160002,  5.9527  ,  0.007988],
       [ 0.160004,  3.420454,  0.123662],
       [ 0.160007,  3.876158,  0.295957],
       ..., 
       [ 0.469993,  2.683356,  0.525876],
       [ 0.469994,  5.75026 ,  0.212152],
       [ 0.469996,  2.732208,  0.523037]])

In [4]:
rr2d=np.zeros((20,20))

In [5]:
rng = np.array([[0, 0.02], [0, 0.02]])

In [6]:
rrbt=BallTree(datR,metric='pyfunc',func=APdz)

In [7]:
rng


Out[7]:
array([[ 0.  ,  0.02],
       [ 0.  ,  0.02]])

In [8]:
bins=np.arange(0.0,0.02001,0.001)

In [9]:
bins


Out[9]:
array([ 0.   ,  0.001,  0.002,  0.003,  0.004,  0.005,  0.006,  0.007,
        0.008,  0.009,  0.01 ,  0.011,  0.012,  0.013,  0.014,  0.015,
        0.016,  0.017,  0.018,  0.019,  0.02 ])

In [ ]:
%%time
for i in tqdm(xrange(len(datR))):
    ind=rrbt.query_radius(datR[i].reshape(1,-1),0.021)
    for j in ind:
        dist0=d.cdist([datR[i],],datR[j],APdz)[0]
        dist1=d.cdist([datR[i],],datR[j],APzdth)[0]
        rr2d+=np.histogram2d(dist0, dist1,range=rng,bins=(bins,bins))[0]
print rr2d


  0%|          | 26/211661 [00:05<12:22:25,  4.75it/s]/Users/rohin/anaconda/lib/python2.7/site-packages/numpy/lib/function_base.py:973: RuntimeWarning: invalid value encountered in greater_equal
  not_smaller_than_edge = (sample[:, i] >= edges[i][-1])
 35%|███▌      | 74595/211661 [8:50:21<14:55:11,  2.55it/s]

In [ ]:
with open('rr2ddr72v06cdist200kopt.pkl','w') as f:
    pickle.dump(rr2d,f)    
rr2d

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [37]:
%%time
ind=ddbt.query_radius(dat[0].reshape(1,-1),bins[0])
ind1=ind.reshape(1,0)


---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-37-2abeeb5bf42c> in <module>()
----> 1 get_ipython().run_cell_magic(u'time', u'', u'ind=ddbt.query_radius(dat[0].reshape(1,-1),bins[0])\nind1=ind.reshape(1,0)')

/Users/rohin/anaconda/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_cell_magic(self, magic_name, line, cell)
   2113             magic_arg_s = self.var_expand(line, stack_depth)
   2114             with self.builtin_trap:
-> 2115                 result = fn(magic_arg_s, cell)
   2116             return result
   2117 

<decorator-gen-59> in time(self, line, cell, local_ns)

/Users/rohin/anaconda/lib/python2.7/site-packages/IPython/core/magic.pyc in <lambda>(f, *a, **k)
    186     # but it's overkill for just that one bit of state.
    187     def magic_deco(arg):
--> 188         call = lambda f, *a, **k: f(*a, **k)
    189 
    190         if callable(arg):

/Users/rohin/anaconda/lib/python2.7/site-packages/IPython/core/magics/execution.pyc in time(self, line, cell, local_ns)
   1178         else:
   1179             st = clock2()
-> 1180             exec(code, glob, local_ns)
   1181             end = clock2()
   1182             out = None

<timed exec> in <module>()

ValueError: cannot reshape array of size 1 into shape (1,0)

In [35]:
ind1


Out[35]:
array([ array([ 78,  65,  54, 102,  97,   9,  27, 156, 116, 190, 161,  55,  69,
       170,  77,  30, 125, 144,  47,  71,  46,  98,  14, 182,  70,  40,
       191, 101,  50,  86,  74,  31, 175, 189, 122,  63,  20,  53,  37,
        32,  93, 177, 173, 140, 151, 183,  44,  72, 112,  66, 143,  85,
        34, 163, 147,  45, 103, 168, 131, 149,  76, 105, 124,  59,  99,
         1,  11, 155,  15,   8, 186,  57,  39, 176, 154,  10,   5,  26,
       181, 185,  29,  51, 106, 137, 178,  49,  95,  23, 108, 159,  56,
         7, 160, 132,  82, 107,  19,  21, 164,   4, 187, 141,  58, 153,
       110, 152,   3, 167, 136, 117, 138,  13, 172,  87,  60, 119, 150,
        24, 166,  43,  67,  35, 146, 120, 179, 192, 104,  89, 111,  33,
       128, 169,  79,   6,  90,  92, 118,  73,  12, 129, 134, 162, 174,
       126,  16, 133,  22, 158,  48,   2, 115,  62, 157, 139,  81, 114,
       109,  68,  36,  38,  52, 100, 121,  28,  17, 188,  18, 113, 142,
       180, 184,  91,  88,  25, 127,  83,  41, 171,  94,  75,  61, 145,
       148,  96, 123,  64,  80, 165,   0,  42,  84, 130, 135])], dtype=object)

In [38]:
for i in ind1:
    print dat[i]


[[  1.60442000e-01   1.18390000e-01   1.28770000e-02]
 [  1.60358000e-01   3.70501000e-01  -1.78040000e-01]
 [  1.60296000e-01   3.90689000e-01  -1.63910000e-02]
 [  1.60565000e-01   4.01300000e-01  -1.31940000e-02]
 [  1.60521000e-01   4.49435000e-01  -1.70570000e-01]
 [  1.60058000e-01   4.86250000e-01  -1.65317000e-01]
 [  1.60162000e-01   4.76180000e-01   2.32323000e-01]
 [  1.60774000e-01   6.15974000e-01  -1.64328000e-01]
 [  1.60644000e-01   2.04400200e+00   5.12437000e-01]
 [  1.60976000e-01   2.06564200e+00   5.12409000e-01]
 [  1.60792000e-01   2.06544700e+00   5.26077000e-01]
 [  1.60299000e-01   2.04005000e+00   5.33478000e-01]
 [  1.60389000e-01   2.05441200e+00   7.03576000e-01]
 [  1.60867000e-01   2.05407700e+00   7.04991000e-01]
 [  1.60441000e-01   2.18745700e+00   4.62760000e-01]
 [  1.60178000e-01   2.11351300e+00   5.15975000e-01]
 [  1.60668000e-01   2.12222000e+00   5.47658000e-01]
 [  1.60743000e-01   2.11776500e+00   5.36898000e-01]
 [  1.60268000e-01   2.21548200e+00   6.07208000e-01]
 [  1.60406000e-01   2.26746800e+00   6.22283000e-01]
 [  1.60266000e-01   2.17119300e+00   8.72532000e-01]
 [  1.60532000e-01   2.11250800e+00   8.51319000e-01]
 [  1.60083000e-01   2.20344600e+00   8.66432000e-01]
 [  1.60920000e-01   2.21828800e+00   8.51988000e-01]
 [  1.60404000e-01   2.17430400e+00   1.00295300e+00]
 [  1.60241000e-01   2.34819800e+00   4.06600000e-02]
 [  1.60978000e-01   2.30891000e+00   1.27447000e-01]
 [  1.60562000e-01   2.39786600e+00   1.61690000e-01]
 [  1.60276000e-01   2.50837300e+00   2.20870000e-02]
 [  1.60474000e-01   2.51767900e+00   7.70600000e-03]
 [  1.60415000e-01   2.54390200e+00   3.05970000e-02]
 [  1.60183000e-01   2.57648500e+00   8.19840000e-02]
 [  1.60884000e-01   2.53475600e+00   1.90217000e-01]
 [  1.60976000e-01   2.30349600e+00   2.62213000e-01]
 [  1.60666000e-01   2.30642400e+00   3.61519000e-01]
 [  1.60351000e-01   2.56403700e+00   2.69466000e-01]
 [  1.60116000e-01   2.54575400e+00   2.94491000e-01]
 [  1.60292000e-01   2.49658900e+00   5.51961000e-01]
 [  1.60227000e-01   2.46100000e+00   7.08299000e-01]
 [  1.60185000e-01   2.57263700e+00   5.84215000e-01]
 [  1.60504000e-01   2.34436600e+00   7.34716000e-01]
 [  1.60893000e-01   2.34257600e+00   7.51282000e-01]
 [  1.60880000e-01   2.55744200e+00   7.68823000e-01]
 [  1.60729000e-01   2.65985000e+00   8.10720000e-02]
 [  1.60765000e-01   2.72383400e+00   7.58010000e-02]
 [  1.60924000e-01   2.75199200e+00   7.51540000e-02]
 [  1.60256000e-01   2.71593000e+00   7.67780000e-02]
 [  1.60410000e-01   2.72024800e+00   8.30040000e-02]
 [  1.60600000e-01   2.62315400e+00   1.75893000e-01]
 [  1.60374000e-01   2.63993200e+00   1.90957000e-01]
 [  1.60743000e-01   2.76445600e+00   1.76570000e-02]
 [  1.60473000e-01   2.83277900e+00   4.30400000e-03]
 [  1.60214000e-01   2.83356300e+00  -1.87700000e-03]
 [  1.60805000e-01   2.60258100e+00   3.23189000e-01]
 [  1.60751000e-01   2.61194100e+00   3.30729000e-01]
 [  1.60265000e-01   2.67113700e+00   3.69434000e-01]
 [  1.60565000e-01   2.76838800e+00   2.69632000e-01]
 [  1.60854000e-01   2.78800800e+00   2.32986000e-01]
 [  1.60692000e-01   2.84203600e+00   4.59446000e-01]
 [  1.60755000e-01   2.95022600e+00   4.28480000e-02]
 [  1.60432000e-01   3.07422800e+00  -5.84920000e-02]
 [  1.60568000e-01   3.17889200e+00   4.18940000e-02]
 [  1.60668000e-01   2.97794400e+00   2.70958000e-01]
 [  1.60315000e-01   3.06936100e+00   4.10091000e-01]
 [  1.60544000e-01   3.01109700e+00   4.51782000e-01]
 [  1.60018000e-01   3.08916200e+00   2.86160000e-01]
 [  1.60078000e-01   3.14752500e+00   2.58412000e-01]
 [  1.60774000e-01   2.69835100e+00   6.94235000e-01]
 [  1.60086000e-01   2.70046900e+00   6.87017000e-01]
 [  1.60048000e-01   2.71326800e+00   7.13375000e-01]
 [  1.60945000e-01   2.75059000e+00   7.00823000e-01]
 [  1.60309000e-01   2.89654900e+00   5.23679000e-01]
 [  1.60237000e-01   2.89256100e+00   5.95641000e-01]
 [  1.60886000e-01   2.88454000e+00   7.17592000e-01]
 [  1.60771000e-01   2.95015700e+00   5.98659000e-01]
 [  1.60068000e-01   3.04979600e+00   6.54096000e-01]
 [  1.60039000e-01   3.10823700e+00   5.78983000e-01]
 [  1.60146000e-01   3.10801500e+00   5.79045000e-01]
 [  1.60918000e-01   2.67988800e+00   7.98889000e-01]
 [  1.60939000e-01   2.76307800e+00   8.81138000e-01]
 [  1.60163000e-01   2.91464200e+00   7.57777000e-01]
 [  1.60278000e-01   2.80580200e+00   8.23979000e-01]
 [  1.60575000e-01   2.97542300e+00   8.79430000e-01]
 [  1.60712000e-01   3.16402500e+00   7.44529000e-01]
 [  1.60896000e-01   3.14207900e+00   8.58702000e-01]
 [  1.60271000e-01   3.23847400e+00   1.43086000e-01]
 [  1.60516000e-01   3.26771500e+00   3.39149000e-01]
 [  1.60140000e-01   3.29096800e+00   3.39444000e-01]
 [  1.60590000e-01   3.28230800e+00   3.84141000e-01]
 [  1.60789000e-01   3.38646400e+00   2.33326000e-01]
 [  1.60305000e-01   3.49018100e+00   2.13899000e-01]
 [  1.60043000e-01   3.49099200e+00   2.86227000e-01]
 [  1.60790000e-01   3.48795000e+00   2.96686000e-01]
 [  1.60694000e-01   3.44997100e+00   3.33809000e-01]
 [  1.60461000e-01   3.45093700e+00   3.29212000e-01]
 [  1.60588000e-01   3.51720700e+00   3.67491000e-01]
 [  1.60115000e-01   3.47340200e+00   4.26715000e-01]
 [  1.60126000e-01   3.56515600e+00   1.82094000e-01]
 [  1.60815000e-01   3.71982500e+00  -3.94730000e-02]
 [  1.60037000e-01   3.69857500e+00  -1.59620000e-02]
 [  1.60952000e-01   3.74350500e+00   4.43260000e-02]
 [  1.60733000e-01   3.75659700e+00   1.67635000e-01]
 [  1.60311000e-01   3.76096800e+00   1.59528000e-01]
 [  1.60770000e-01   3.66409400e+00   3.95963000e-01]
 [  1.60593000e-01   3.71848000e+00   2.87606000e-01]
 [  1.60770000e-01   3.69310200e+00   3.03870000e-01]
 [  1.60033000e-01   3.79545500e+00   2.05735000e-01]
 [  1.60847000e-01   3.80445300e+00   2.07804000e-01]
 [  1.60705000e-01   3.82666500e+00   2.07953000e-01]
 [  1.60647000e-01   3.81008200e+00   2.20867000e-01]
 [  1.60715000e-01   3.83610500e+00   2.26191000e-01]
 [  1.60082000e-01   3.81192400e+00   2.48460000e-01]
 [  1.60879000e-01   3.83959600e+00   4.41995000e-01]
 [  1.60477000e-01   3.83567400e+00   4.17240000e-01]
 [  1.60335000e-01   3.34248000e+00   5.95731000e-01]
 [  1.60652000e-01   3.35949500e+00   6.33086000e-01]
 [  1.60765000e-01   3.36006500e+00   6.39900000e-01]
 [  1.60145000e-01   3.49299300e+00   4.99928000e-01]
 [  1.60833000e-01   3.60721300e+00   4.86124000e-01]
 [  1.60256000e-01   3.75797800e+00   7.03292000e-01]
 [  1.60375000e-01   3.77437900e+00   6.90626000e-01]
 [  1.60221000e-01   3.78045400e+00   6.84915000e-01]
 [  1.60747000e-01   3.25272000e+00   7.61084000e-01]
 [  1.60656000e-01   3.39779800e+00   1.06290900e+00]
 [  1.60904000e-01   3.49659700e+00   1.16833100e+00]
 [  1.60978000e-01   3.61966000e+00   8.23500000e-01]
 [  1.60565000e-01   3.65736800e+00   8.29584000e-01]
 [  1.60487000e-01   3.79400700e+00   7.60107000e-01]
 [  1.60597000e-01   3.62662600e+00   1.02487400e+00]
 [  1.60204000e-01   3.71821000e+00   9.99537000e-01]
 [  1.60681000e-01   3.79858400e+00   1.02125900e+00]
 [  1.60860000e-01   3.76638600e+00   1.03603200e+00]
 [  1.60451000e-01   3.97202500e+00  -4.40290000e-02]
 [  1.60041000e-01   3.87986100e+00   1.01975000e-01]
 [  1.60491000e-01   3.88558400e+00   9.25790000e-02]
 [  1.60504000e-01   3.88919000e+00   1.12721000e-01]
 [  1.60648000e-01   4.08663400e+00   1.64610000e-02]
 [  1.60414000e-01   4.04839500e+00   1.74674000e-01]
 [  1.60081000e-01   4.05508900e+00   1.77667000e-01]
 [  1.60688000e-01   4.04623900e+00   1.76442000e-01]
 [  1.60699000e-01   4.06680800e+00   1.95643000e-01]
 [  1.60799000e-01   4.04204100e+00   1.74528000e-01]
 [  1.60881000e-01   4.04211600e+00   1.74027000e-01]
 [  1.60672000e-01   4.13669000e+00   1.36578000e-01]
 [  1.60091000e-01   3.86404500e+00   2.40823000e-01]
 [  1.60695000e-01   3.90191600e+00   2.57042000e-01]
 [  1.60132000e-01   3.88958500e+00   2.92928000e-01]
 [  1.60786000e-01   3.96964000e+00   2.26226000e-01]
 [  1.60271000e-01   4.07838400e+00   2.84384000e-01]
 [  1.60020000e-01   4.08518100e+00   2.84492000e-01]
 [  1.60644000e-01   4.06079700e+00   3.33115000e-01]
 [  1.60351000e-01   3.85863300e+00   4.15064000e-01]
 [  1.60785000e-01   3.94719000e+00   4.18301000e-01]
 [  1.60724000e-01   3.98340100e+00   6.27588000e-01]
 [  1.60461000e-01   3.98586100e+00   6.29676000e-01]
 [  1.60632000e-01   4.05872500e+00   6.48528000e-01]
 [  1.60593000e-01   3.84156000e+00   6.75805000e-01]
 [  1.60386000e-01   3.86370100e+00   6.73753000e-01]
 [  1.60223000e-01   4.02552100e+00   7.39549000e-01]
 [  1.60231000e-01   4.08254400e+00   9.12077000e-01]
 [  1.60279000e-01   4.05575200e+00   9.81174000e-01]
 [  1.60545000e-01   4.19623900e+00   8.75690000e-02]
 [  1.60659000e-01   4.22575500e+00   3.68920000e-01]
 [  1.60163000e-01   4.27150700e+00   4.30567000e-01]
 [  1.60113000e-01   4.28761700e+00   4.27315000e-01]
 [  1.60969000e-01   4.26482700e+00   4.78107000e-01]
 [  1.60113000e-01   4.17642900e+00   6.23417000e-01]
 [  1.60609000e-01   4.36403400e+00   5.67614000e-01]
 [  1.60742000e-01   4.39095600e+00   5.80688000e-01]
 [  1.60908000e-01   4.25156700e+00   7.59569000e-01]
 [  1.60936000e-01   4.37557800e+00   6.61733000e-01]
 [  1.60499000e-01   4.37547700e+00   6.92598000e-01]
 [  1.60480000e-01   4.41103800e+00   4.02009000e-01]
 [  1.60145000e-01   4.53858600e+00   4.64704000e-01]
 [  1.60674000e-01   4.54088300e+00   4.66905000e-01]
 [  1.60464000e-01   5.53281900e+00  -1.34216000e-01]
 [  1.60250000e-01   5.63569300e+00  -1.19451000e-01]
 [  1.60868000e-01   5.48322800e+00   1.56710000e-02]
 [  1.60512000e-01   4.52818200e+00   5.27379000e-01]
 [  1.60416000e-01   4.54742600e+00   4.88898000e-01]
 [  1.60349000e-01   4.40960800e+00   5.76832000e-01]
 [  1.60744000e-01   4.48355200e+00   6.22055000e-01]
 [  1.60751000e-01   5.67213200e+00  -1.35287000e-01]
 [  1.60519000e-01   5.67937100e+00  -1.28753000e-01]
 [  1.60667000e-01   5.69617900e+00  -1.36130000e-02]
 [  1.60357000e-01   5.64316800e+00  -1.15791000e-01]
 [  1.60456000e-01   5.80115000e+00   1.51800000e-02]
 [  1.60825000e-01   5.96638800e+00   2.44394000e-01]
 [  1.60002000e-01   5.96454300e+00   2.35823000e-01]
 [  1.60251000e-01   6.08264500e+00  -1.51931000e-01]
 [  1.60465000e-01   5.98505300e+00   2.23334000e-01]
 [  1.60691000e-01   5.98427300e+00   2.28815000e-01]
 [  1.60705000e-01   5.98280300e+00   2.34411000e-01]]

In [45]:
%%time
for i in ind:
    dist0=d.cdist([dat[0],],dat[i],APdz)[0]
    dist1=d.cdist([dat[0],],dat[i],APzdth)[0]
    print np.histogram2d(dist0, dist1,range=rng)
    dd2d+=np.histogram2d(dist0, dist1,range=rng,bins=(bins,bins))[0]
print dd2d


(array([[ 2.,  3.,  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.,  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.,  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.,  0.,  0.,  0.,  0.,  0.]]), array([ 0.   ,  0.002,  0.004,  0.006,  0.008,  0.01 ,  0.012,  0.014,
        0.016,  0.018,  0.02 ]), array([ 0.   ,  0.002,  0.004,  0.006,  0.008,  0.01 ,  0.012,  0.014,
        0.016,  0.018,  0.02 ]))
[[ 2.  2.  2.  4.  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.  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.  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.  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.  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.  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.  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.  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.  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.  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.  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.  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.  0.  0.
   0.  0.]
 [ 0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.
   0.  0.]]
CPU times: user 18.1 ms, sys: 4.82 ms, total: 22.9 ms
Wall time: 19.6 ms

In [40]:
help(np.histogram2d)


Help on function histogram2d in module numpy.lib.twodim_base:

histogram2d(x, y, bins=10, range=None, normed=False, weights=None)
    Compute the bi-dimensional histogram of two data samples.
    
    Parameters
    ----------
    x : array_like, shape (N,)
        An array containing the x coordinates of the points to be
        histogrammed.
    y : array_like, shape (N,)
        An array containing the y coordinates of the points to be
        histogrammed.
    bins : int or array_like or [int, int] or [array, array], optional
        The bin specification:
    
          * If int, the number of bins for the two dimensions (nx=ny=bins).
          * If array_like, the bin edges for the two dimensions
            (x_edges=y_edges=bins).
          * If [int, int], the number of bins in each dimension
            (nx, ny = bins).
          * If [array, array], the bin edges in each dimension
            (x_edges, y_edges = bins).
          * A combination [int, array] or [array, int], where int
            is the number of bins and array is the bin edges.
    
    range : array_like, shape(2,2), optional
        The leftmost and rightmost edges of the bins along each dimension
        (if not specified explicitly in the `bins` parameters):
        ``[[xmin, xmax], [ymin, ymax]]``. All values outside of this range
        will be considered outliers and not tallied in the histogram.
    normed : bool, optional
        If False, returns the number of samples in each bin. If True,
        returns the bin density ``bin_count / sample_count / bin_area``.
    weights : array_like, shape(N,), optional
        An array of values ``w_i`` weighing each sample ``(x_i, y_i)``.
        Weights are normalized to 1 if `normed` is True. If `normed` is
        False, the values of the returned histogram are equal to the sum of
        the weights belonging to the samples falling into each bin.
    
    Returns
    -------
    H : ndarray, shape(nx, ny)
        The bi-dimensional histogram of samples `x` and `y`. Values in `x`
        are histogrammed along the first dimension and values in `y` are
        histogrammed along the second dimension.
    xedges : ndarray, shape(nx+1,)
        The bin edges along the first dimension.
    yedges : ndarray, shape(ny+1,)
        The bin edges along the second dimension.
    
    See Also
    --------
    histogram : 1D histogram
    histogramdd : Multidimensional histogram
    
    Notes
    -----
    When `normed` is True, then the returned histogram is the sample
    density, defined such that the sum over bins of the product
    ``bin_value * bin_area`` is 1.
    
    Please note that the histogram does not follow the Cartesian convention
    where `x` values are on the abscissa and `y` values on the ordinate
    axis.  Rather, `x` is histogrammed along the first dimension of the
    array (vertical), and `y` along the second dimension of the array
    (horizontal).  This ensures compatibility with `histogramdd`.
    
    Examples
    --------
    >>> import matplotlib as mpl
    >>> import matplotlib.pyplot as plt
    
    Construct a 2-D histogram with variable bin width. First define the bin
    edges:
    
    >>> xedges = [0, 1, 3, 5]
    >>> yedges = [0, 2, 3, 4, 6]
    
    Next we create a histogram H with random bin content:
    
    >>> x = np.random.normal(2, 1, 100)
    >>> y = np.random.normal(1, 1, 100)
    >>> H, xedges, yedges = np.histogram2d(x, y, bins=(xedges, yedges))
    >>> H = H.T  # Let each row list bins with common y range.
    
    :func:`imshow <matplotlib.pyplot.imshow>` can only display square bins:
    
    >>> fig = plt.figure(figsize=(7, 3))
    >>> ax = fig.add_subplot(131, title='imshow: square bins')
    >>> plt.imshow(H, interpolation='nearest', origin='low',
    ...         extent=[xedges[0], xedges[-1], yedges[0], yedges[-1]])
    
    :func:`pcolormesh <matplotlib.pyplot.pcolormesh>` can display actual edges:
    
    >>> ax = fig.add_subplot(132, title='pcolormesh: actual edges',
    ...         aspect='equal')
    >>> X, Y = np.meshgrid(xedges, yedges)
    >>> ax.pcolormesh(X, Y, H)
    
    :class:`NonUniformImage <matplotlib.image.NonUniformImage>` can be used to
    display actual bin edges with interpolation:
    
    >>> ax = fig.add_subplot(133, title='NonUniformImage: interpolated',
    ...         aspect='equal', xlim=xedges[[0, -1]], ylim=yedges[[0, -1]])
    >>> im = mpl.image.NonUniformImage(ax, interpolation='bilinear')
    >>> xcenters = (xedges[:-1] + xedges[1:]) / 2
    >>> ycenters = (yedges[:-1] + yedges[1:]) / 2
    >>> im.set_data(xcenters, ycenters, H)
    >>> ax.images.append(im)
    >>> plt.show()


In [ ]:
d.

In [24]:
ind


Out[24]:
array([ array([ 78,  65,  54, 102,  97,   9,  27, 156, 116, 190, 161,  55,  69,
       170,  77,  30, 125, 144,  47,  71,  46,  98,  14, 182,  70,  40,
       191, 101,  50,  86,  74,  31, 175, 189, 122,  63,  20,  53,  37,
        32,  93, 177, 173, 140, 151, 183,  44,  72, 112,  66, 143,  85,
        34, 163, 147,  45, 103, 168, 131, 149,  76, 105, 124,  59,  99,
         1,  11, 155,  15,   8, 186,  57,  39, 176, 154,  10,   5,  26,
       181, 185,  29,  51, 106, 137, 178,  49,  95,  23, 108, 159,  56,
         7, 160, 132,  82, 107,  19,  21, 164,   4, 187, 141,  58, 153,
       110, 152,   3, 167, 136, 117, 138,  13, 172,  87,  60, 119, 150,
        24, 166,  43,  67,  35, 146, 120, 179, 192, 104,  89, 111,  33,
       128, 169,  79,   6,  90,  92, 118,  73,  12, 129, 134, 162, 174,
       126,  16, 133,  22, 158,  48,   2, 115,  62, 157, 139,  81, 114,
       109,  68,  36,  38,  52, 100, 121,  28,  17, 188,  18, 113, 142,
       180, 184,  91,  88,  25, 127,  83,  41, 171,  94,  75,  61, 145,
       148,  96, 123,  64,  80, 165,   0,  42,  84, 130, 135])], dtype=object)

In [19]:
np.random.seed(0)
X = np.random.random((10, 3))  # 10 points in 3 dimensions
tree = BallTree(X, leaf_size=2)     # doctest: +SKIP
#print(tree.query_radius(X[0], r=0.3, count_only=True))
ind = tree.query_radius(X[0].reshape(1,-1), r=0.3)  # doctest: +SKIP
print(ind)  # indices of neighbors within distance 0.3


[array([3, 0, 1])]

In [11]:
help(ddbt.query_radius)


Help on built-in function query_radius:

query_radius(...)
    query_radius(self, X, r, count_only = False):
    
    query the tree for neighbors within a radius r
    
    Parameters
    ----------
    X : array-like, last dimension self.dim
        An array of points to query
    r : distance within which neighbors are returned
        r can be a single value, or an array of values of shape
        x.shape[:-1] if different radii are desired for each point.
    return_distance : boolean (default = False)
        if True,  return distances to neighbors of each point
        if False, return only neighbors
        Note that unlike the query() method, setting return_distance=True
        here adds to the computation time.  Not all distances need to be
        calculated explicitly for return_distance=False.  Results are
        not sorted by default: see ``sort_results`` keyword.
    count_only : boolean (default = False)
        if True,  return only the count of points within distance r
        if False, return the indices of all points within distance r
        If return_distance==True, setting count_only=True will
        result in an error.
    sort_results : boolean (default = False)
        if True, the distances and indices will be sorted before being
        returned.  If False, the results will not be sorted.  If
        return_distance == False, setting sort_results = True will
        result in an error.
    
    Returns
    -------
    count       : if count_only == True
    ind         : if count_only == False and return_distance == False
    (ind, dist) : if count_only == False and return_distance == True
    
    count : array of integers, shape = X.shape[:-1]
        each entry gives the number of neighbors within
        a distance r of the corresponding point.
    
    ind : array of objects, shape = X.shape[:-1]
        each element is a numpy integer array listing the indices of
        neighbors of the corresponding point.  Note that unlike
        the results of a k-neighbors query, the returned neighbors
        are not sorted by distance by default.
    
    dist : array of objects, shape = X.shape[:-1]
        each element is a numpy double array
        listing the distances corresponding to indices in i.
    
    Examples
    --------
    Query for neighbors in a given radius
    
    >>> import numpy as np
    >>> np.random.seed(0)
    >>> X = np.random.random((10, 3))  # 10 points in 3 dimensions
    >>> tree = BinaryTree(X, leaf_size=2)     # doctest: +SKIP
    >>> print(tree.query_radius(X[0], r=0.3, count_only=True))
    3
    >>> ind = tree.query_radius(X[0], r=0.3)  # doctest: +SKIP
    >>> print(ind)  # indices of neighbors within distance 0.3
    [3 0 1]


In [ ]:
dr2d=np.zeros((20,20))

In [ ]:
rng = np.array([[0, 0.02], [0, 0.02]])

In [ ]:
%%time
dist0=d.cdist([dat[0],],datR,APdz)[0]
dist1=d.cdist([dat[0],],datR,APzdth)[0]
print np.histogram2d(dist0, dist1,range=rng)

In [ ]:
%%time
for i in tqdm(xrange(len(dat))):
    dist0=d.cdist([dat[i],],datR,APdz)[0]
    dist1=d.cdist([dat[i],],datR,APzdth)[0]
    dr2d+=np.histogram2d(dist0, dist1,range=rng)[0]
print dr2d

In [ ]:
with open('dr2ddr72v06cdist200k.pkl','w') as f:
    pickle.dump(dr2d,f)    
dr2d

In [ ]:

%%time dist0=d.cdist(dat[0:10],dat,APdz) dist1=d.cdist(dat[0:10],dat,APzdtheta) #print np.histogram2d(dist0, dist1,range=rng) #print dd2d

In [ ]:
dist0

In [ ]:
len(dist0)

In [ ]:
dist0.size

In [ ]:
dist0.flatten
print dist0

In [ ]:
len(dist0)

In [ ]:
%%time
dist0=d.cdist([dat[0],],dat,APdz)[0]
dist1=d.cdist([dat[0],],dat,APzdtheta)[0]
print np.histogram2d(dist0, dist1,range=rng)
#print dd2d

In [ ]:


In [ ]:
dist0

In [ ]:


In [ ]:
dist0=dist0[0]

In [ ]:
dist0[1]

In [ ]:
dist0[1:len(dist0)]

In [ ]:
len(dist0)

In [ ]:
dist0.size

In [ ]:
help(dist0.flatten)

In [ ]:
dist0[0]

In [ ]:
np.array.flatten(dist0)

In [ ]:
len(dist0)

In [ ]:


In [ ]:


In [ ]:
%%time
while len(dat)>0:
    i=len(dat)-1
    while i>0:
        dist[i]=APcat(dat[0],dat[i])
        i-=1
    dd2d+=np.histogram2d(dist[:,0], dist[:,1],range=rng)[0]
    dat=np.delete(dat,0,axis=0)

In [ ]:
dd2d

In [ ]:


In [ ]:


In [ ]:
%%time
while len(dat)>0:
    i=len(dat)-1
    while i>0:
        dist=500*APcat(dat[0],dat[i])
        dd2d+=np.histogram2d(dist[0], dist[1], bins = 10, range = rng)
        i-=1
    dat=np.delete(dat,0,axis=0)

In [ ]:
def binDists2d(dat, dz = lambda u, v: abs(u[0]-v[0]), zdth = lambda u, v: 0.5*(u[0]+v[0])*np.arccos(np.sin(u[2])*np.sin(v[2])+np.cos(u[2])*np.cos(v[2])*np.cos(u[1]-v[1]))):
    i, j = np.triu_indices(dat.shape[0], 1)
    dist0 = dz(dat[i], dat[j])
    dist1 = zdth(dat[i], dat[j])
    rng = np.array([[0, 0.02], [0, 0.02]])
    return np.histogram2d(dist0, dist1, bins = 10, range = rng)

In [ ]:
td=np.random.rand(1000,3)

In [ ]:
binDists2d(td)

In [ ]:
%%time
binDists2d(dat)

In [ ]:


In [ ]:


In [ ]:
def binDists2d(dat, f1 = 'euclidean', f2 = 'cosine'):
    dist0 = APcat(dat, f1)
    dist1 = d.pdist(dat, f2)
    return np.histogram2d(dist0, dist1, bins = 10)

In [ ]:
dd2d

In [ ]:
plt.contour(dd2d)

In [ ]:
with open('DR72DD2DMI.pkl', 'w') as f:
    pickle.dump(dd2d,f)

In [ ]:
with open('DR72DD2DMI.pkl') as f:
    DD2D = pickle.load(f)
    
DD2D

In [ ]:
dzbin=zdthbin=np.arange(0.002,0.022,0.002)

In [ ]:
plt.contour(dzbin,zdthbin,dd2d)

In [ ]:
dzbin

In [ ]:
plt.contour(dzbin,zdthbin,dd2d,levels=[  5041.,  13955.,  23161.,  31557.,  38796.,  46402.,  53552.,
         60708.,  67437.,  74549.])

In [ ]:


In [ ]:
for i in range(len(dat)-1):
    for j in range(len(dat)-1):
        dist=APcat(dat[0],dat[i])
        ind0=int(dist[0]/0.002)
        ind1=int(dist[1]/0.002)
        if ind0>9 or ind1>9:
            pass
        else:
            dd2d[ind0,ind1]+=1
    dat=np.delete(dat,0,0)
    print len(dat)
    print dd2d

In [ ]:
for i in range(len(dat)):

In [ ]:
bins=np.arange(0,0.022,0.002)
print bins

In [ ]:
%%time
from apmetric6 import *
BTdat6 = BallTree(dat,metric='pyfunc',func=APmetric6,leaf_size=5)

In [ ]:
BTdat6

In [ ]:
%%time
per6=BTdat6.two_point_correlation(dat,bins)

In [ ]:
print per6

One has to change if condition in the metric definition of dz<=0.002 to 0.002<dz<=0.004 and so on


In [ ]:
%%time
from apmetric4 import *
BTdat4 = BallTree(dat,metric='pyfunc',func=APmetric4,leaf_size=5)

In [ ]:
BTdat4

In [ ]:
%%time
per4=BTdat4.two_point_correlation(dat,bins)

In [ ]:
print per4

In [ ]:


In [ ]:
%%time
from apmetric3 import *
BTdat3 = BallTree(dat,metric='pyfunc',func=APmetric3,leaf_size=5) 

BTdat3

%%time
per3=BTdat3.two_point_correlation(dat,bins)

print per3print bins

In [ ]:
Nbins=len(bins)

In [ ]:
Nbins

In [ ]:
LCfmetric=LCDMmetric

In [ ]:
LCfmetric(dat[0],dat[1])

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

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

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

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

In [ ]:
DD

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

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


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

In [ ]:
dataR

In [ ]:
len(dataR)

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

In [ ]:
dataR

In [ ]:
dataR.remove_column('z')
dataR.remove_column('ra')
dataR.remove_column('dec')

In [ ]:
dataR

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

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

In [ ]:
datR

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

In [ ]:
datR=datR.transpose()

In [ ]:
datR

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

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

In [ ]:
%%time
BT_RLC = BallTree(datR,metric='pyfunc',func=LCfmetric,leaf_size=5) 

with open('BTR200kdatsLCf.pkl', 'w') as f:
    pickle.dump(BT_RLC,f)

In [ ]:
with open('BTR200kdatsLCf.pkl') as f:
    BTRLC = pickle.load(f)
    
BTRLC

In [ ]:
%%time
start_time=time.time()
counts_RR=BTRLC.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('BTR200kcRRLCf.pkl', 'w') as f:
    pickle.dump(counts_RR,f)

with open('BTR200kcRRLCf.pkl') as f:
    counts_RR = pickle.load(f)
    
counts_RR

In [ ]:
counts_RR

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

In [ ]:
RR

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

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

In [ ]:
%%time
start_time=time.time()
counts_DR=BTRLC.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('BTR200kcDRLCf.pkl', 'w') as f:
    pickle.dump(counts_DR,f)

In [ ]:
with open('BTR200kcDRLCf.pkl') as f:
    counts_DR = pickle.load(f)
    
counts_DR

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

In [ ]:
DR

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

In [ ]:
corrells

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

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

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

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

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

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

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

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

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

In [ ]:


In [ ]:


In [ ]:
from functools import partial

def harvester(text, case):
    X = case[0]
    return text + str(X)


partial_harvester = partial(harvester, case=RAW_DATASET)

partial_qr=partial(BTD.query_radius,count_only=True)

if __name__ == '__main__':
    pool = multiprocessing.Pool(processes=6)
    case_data = RAW_DATASET
    pool.map(partial_harvester, case_data, 1)
    pool.close()
    pool.join()

mapfunc = partial(BTD.query_radius, count_only=True)
map(mapfunc, volume_ids)

In [ ]:


In [ ]:
#ascii.write("DR72DDbinned.dat",(bins[1:len(bins)],DDresult))
start_time=time.time()
@pickle_results("DR72DDmp1.pkl")
def ddcal(BTD,dat,bins,Nbins):
    counts_DD=np.zeros(Nbins)
    for i in tqdm(range(Nbins)):
        counts_DD[i]=np.sum(BTD.query_radius(dat, bins[i],count_only=True))
    DD = np.diff(counts_DD)
    print counts_DD
    print DD
    return DD

def mf_wrap(args):
    return ddcal(*args)

pool=mp.Pool(8)

arg=[(BTD,dat,bins,Nbins)]
%timeit DDresult=pool.map(mf_wrap,arg) 
#DDresult = ddcal(BTD,dat,bins,Nbins)
end_time=time.time()
tottime=end_time-start_time
print "Total run time:"
print tottime

In [ ]:
%timeit dat

In [ ]:
DDresult[0]

In [ ]:
DDresult[1]

In [ ]:
plt.plot(bins[1:len(bins)],DDresult[0],'ro')

In [ ]:


In [ ]:


In [ ]:
def myfun(a,b):
  print a + b
  return a+b

def mf_wrap(args):
  return myfun(*args)

p = mp.Pool(4)

fl = [(a,b) for a in range(3) for b in range(2)]

p.map(mf_wrap, fl)

In [ ]:


In [ ]:


In [ ]:


In [ ]:
counts_DD=np.zeros(Nbins)

for i in range(Nbins):
    counts_DD[i]=np.sum(BTD.query_radius(dat, bins[i],count_only=True))
DD = np.diff(counts_DD)

In [ ]:
print counts_DD
print DD

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

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:
dataR=fits.open("/Users/rohin/Downloads/random-DR7-Full.fits")

In [ ]:
dataR=dataR[1].data

In [ ]:
len(dataR)

In [ ]:


In [ ]:
tdata=np.array(data)

In [ ]:
type(tdata[4])

In [ ]:
tdata.shape

In [ ]:


In [ ]:
tdata.shape

In [ ]:
tdata=np.atleast_d(tdata)

In [ ]:
tdata.shape

In [ ]:
tdata.reshape(len(tdata),3)

In [ ]:
tdata=np.asarray(data)
tdata=tdata.transpose()

In [ ]:


In [ ]:


In [ ]:
tdata

In [ ]:
len(tdata)

In [ ]:


In [ ]:
BTD.two_point_correlationpoint_correlationpoint_correlationpoint_correlationtime
stime=time.time()
tpcf=BTD.two_point_correlation(dat,bins)
print time.time()-stime
print tpcf
plt.plot(bins,tpcf)

In [ ]:
stime=time.time()
tpcfd=BTD.two_point_correlation(dat,bins,dualtree=True)
print time.time()-stime
print tpcfd
plt.plot(bins,tpcfd)

In [ ]:


In [ ]:


In [ ]:


In [ ]:
X

In [ ]:


In [ ]:
np.random.seed(0)
X = np.random.random((30,3))
r = np.linspace(0, 1, 10)
tree = BallTree(X,metric='pyfunc',func=LCDMmetric)                
s = pickle.dumps(tree)                     
treedump = pickle.loads(s) 
treedump.two_point_correlation(X,r)

In [ ]:
BT_D = BallTree(data)
        BT_R = BallTree(data_R)

        counts_DD = np.zeros(Nbins + 1)
        counts_RR = np.zeros(Nbins + 1)

        for i in range(Nbins + 1):
            counts_DD[i] = np.sum(BT_D.query_radius(data, bins[i],
                                                    count_only=True))
            counts_RR[i] = np.sum(BT_R.query_radius(data_R, bins[i],
                                                    count_only=True))

    DD = np.diff(counts_DD)
    RR = np.diff(counts_RR)

    # check for zero in the denominator
    RR_zero = (RR == 0)
    RR[RR_zero] = 1

    if method == 'standard':
        corr = factor ** 2 * DD / RR - 1
    elif method == 'landy-szalay':
        if sklearn_has_two_point:
            counts_DR = KDT_R.two_point_correlation(data, bins)
        else:
            counts_DR = np.zeros(Nbins + 1)
            for i in range(Nbins + 1):
                counts_DR[i] = np.sum(BT_R.query_radius(data, bins[i],
                                                        count_only=True))
        DR = np.diff(counts_DR)

        corr = (factor ** 2 * DD - 2 * factor * DR + RR) / RR

    corr[RR_zero] = np.nan

    return corr

In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:
dr7fdat=np.array([data['s'][0:300] data['rar'][0:300] data['decr'][0:300]])
dr7fdat

In [ ]:
dr7fdat[2]

In [ ]:


In [ ]:
def LCDMmetric(p1,p2):
    costheta=m.sin(dec1)*m.sin(dec2)+m.cos(dec1)*m.cos(dec2)*m.cos(ra1-ra2)
    s1=DC_LCDM(z1)
    s2=DC_LCDM(z2)
    return np.sqrt(s1**2+s2**2-2.0*s1*s2*costheta)