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 [46]:
dd2d=np.zeros((20,20))

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

In [6]:
ddbt=BallTree(dat,metric='pyfunc',func=APdz)

In [7]:
rng


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

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

In [43]:
bins


Out[43]:
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 [47]:
%%time
for i in tqdm(xrange(len(dat))):
    ind=ddbt.query_radius(dat[i].reshape(1,-1),0.021)
    for j in ind:
        dist0=d.cdist([dat[i],],dat[j],APdz)[0]
        dist1=d.cdist([dat[i],],dat[j],APzdth)[0]
        dd2d+=np.histogram2d(dist0, dist1,range=rng,bins=(bins,bins))[0]
print dd2d


  0%|          | 82/105830 [00:09<3:29:38,  8.41it/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])
100%|██████████| 105830/105830 [8:17:57<00:00,  6.26it/s] 
[[ 116475.   20430.   20444.   19608.   19982.   20242.   21130.   22540.
    23048.   24036.   25810.   26690.   27352.   29306.   30394.   32510.
    34092.   35408.   37064.   39042.]
 [  10098.   14470.   16368.   17616.   18594.   19684.   20690.   21646.
    22626.   24146.   25352.   26908.   27444.   29408.   30810.   33000.
    34558.   36016.   37138.   39260.]
 [   6416.    9538.   12504.   15334.   17168.   18368.   19906.   21126.
    22190.   23610.   25328.   26120.   28036.   29542.   31228.   32204.
    34352.   35682.   37694.   38946.]
 [   4304.    7012.    9840.   12684.   14876.   16694.   18284.   19986.
    21308.   23528.   24174.   25852.   27424.   29272.   30604.   32524.
    33986.   35416.   37146.   39062.]
 [   3100.    5528.    8502.   10852.   13462.   15830.   17078.   18966.
    20768.   22674.   24442.   25372.   26950.   28796.   30068.   32146.
    34118.   35482.   37698.   38638.]
 [   2214.    4774.    7496.   10024.   12352.   14640.   16664.   18838.
    20460.   22172.   23620.   25604.   27478.   28472.   30218.   31998.
    32912.   35502.   37404.   38868.]
 [   1922.    4248.    6728.    9626.   11898.   13386.   15934.   17778.
    19400.   21718.   23140.   25044.   26800.   28630.   30208.   31986.
    33452.   35388.   36746.   38862.]
 [   1616.    3778.    6454.    8858.   10714.   13304.   15394.   17176.
    19274.   21336.   22418.   24568.   26532.   28544.   29946.   31624.
    33174.   35422.   36696.   38716.]
 [   1548.    3618.    6092.    8240.   10748.   12686.   15034.   16706.
    18672.   20916.   22762.   24074.   25986.   27604.   29712.   31244.
    32954.   34748.   36582.   37976.]
 [   1238.    3678.    5722.    7856.   10388.   12500.   14458.   16916.
    18154.   19850.   22478.   23490.   26060.   27454.   29588.   30872.
    32932.   34240.   36132.   38120.]
 [   1158.    3432.    5748.    7910.    9982.   12120.   13976.   16070.
    17966.   20302.   21678.   23584.   25774.   27352.   29546.   31014.
    32260.   33870.   35912.   37228.]
 [   1260.    3318.    5498.    7686.    9862.   11646.   14054.   15976.
    17486.   19506.   21866.   23284.   25498.   26526.   29098.   30562.
    32158.   34212.   35778.   37570.]
 [   1126.    3292.    5508.    7688.    9556.   11650.   13794.   15638.
    17186.   19334.   21410.   23650.   24982.   26444.   28424.   29870.
    31934.   33898.   35184.   37008.]
 [   1112.    3336.    5400.    7434.    9374.   11434.   13406.   15262.
    17548.   19366.   21284.   23014.   24756.   26526.   28430.   30298.
    30998.   33650.   35522.   37470.]
 [   1032.    3276.    5260.    7356.    9100.   11246.   13298.   15312.
    17150.   19138.   20672.   22788.   24540.   26438.   28184.   29744.
    31760.   33408.   35396.   37126.]
 [   1014.    3252.    5334.    7102.    9360.   11068.   13196.   15328.
    17064.   18834.   20996.   22386.   24240.   26644.   28052.   29842.
    31686.   33062.   34934.   36206.]
 [   1058.    3050.    5298.    7002.    9318.   10864.   13476.   15096.
    16700.   18896.   20904.   22762.   24592.   25748.   27592.   29044.
    31210.   33026.   34566.   36238.]
 [    986.    3092.    5024.    6986.    8940.   10986.   13312.   14884.
    16888.   18562.   20528.   22736.   24186.   25796.   27624.   29330.
    31178.   32710.   34534.   36012.]
 [   1026.    3020.    5050.    6900.    8754.   10864.   12814.   14802.
    16708.   18376.   20762.   22174.   23944.   26166.   27716.   29360.
    30898.   32820.   34036.   36144.]
 [   1134.    3160.    4922.    6958.    8852.   10802.   12820.   14756.
    16680.   18634.   20256.   22290.   23466.   25564.   27894.   28902.
    30814.   32246.   33912.   36194.]]
CPU times: user 8h 13min 44s, sys: 8min 44s, total: 8h 22min 29s
Wall time: 8h 17min 57s


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


Out[48]:
array([[ 116475.,   20430.,   20444.,   19608.,   19982.,   20242.,
          21130.,   22540.,   23048.,   24036.,   25810.,   26690.,
          27352.,   29306.,   30394.,   32510.,   34092.,   35408.,
          37064.,   39042.],
       [  10098.,   14470.,   16368.,   17616.,   18594.,   19684.,
          20690.,   21646.,   22626.,   24146.,   25352.,   26908.,
          27444.,   29408.,   30810.,   33000.,   34558.,   36016.,
          37138.,   39260.],
       [   6416.,    9538.,   12504.,   15334.,   17168.,   18368.,
          19906.,   21126.,   22190.,   23610.,   25328.,   26120.,
          28036.,   29542.,   31228.,   32204.,   34352.,   35682.,
          37694.,   38946.],
       [   4304.,    7012.,    9840.,   12684.,   14876.,   16694.,
          18284.,   19986.,   21308.,   23528.,   24174.,   25852.,
          27424.,   29272.,   30604.,   32524.,   33986.,   35416.,
          37146.,   39062.],
       [   3100.,    5528.,    8502.,   10852.,   13462.,   15830.,
          17078.,   18966.,   20768.,   22674.,   24442.,   25372.,
          26950.,   28796.,   30068.,   32146.,   34118.,   35482.,
          37698.,   38638.],
       [   2214.,    4774.,    7496.,   10024.,   12352.,   14640.,
          16664.,   18838.,   20460.,   22172.,   23620.,   25604.,
          27478.,   28472.,   30218.,   31998.,   32912.,   35502.,
          37404.,   38868.],
       [   1922.,    4248.,    6728.,    9626.,   11898.,   13386.,
          15934.,   17778.,   19400.,   21718.,   23140.,   25044.,
          26800.,   28630.,   30208.,   31986.,   33452.,   35388.,
          36746.,   38862.],
       [   1616.,    3778.,    6454.,    8858.,   10714.,   13304.,
          15394.,   17176.,   19274.,   21336.,   22418.,   24568.,
          26532.,   28544.,   29946.,   31624.,   33174.,   35422.,
          36696.,   38716.],
       [   1548.,    3618.,    6092.,    8240.,   10748.,   12686.,
          15034.,   16706.,   18672.,   20916.,   22762.,   24074.,
          25986.,   27604.,   29712.,   31244.,   32954.,   34748.,
          36582.,   37976.],
       [   1238.,    3678.,    5722.,    7856.,   10388.,   12500.,
          14458.,   16916.,   18154.,   19850.,   22478.,   23490.,
          26060.,   27454.,   29588.,   30872.,   32932.,   34240.,
          36132.,   38120.],
       [   1158.,    3432.,    5748.,    7910.,    9982.,   12120.,
          13976.,   16070.,   17966.,   20302.,   21678.,   23584.,
          25774.,   27352.,   29546.,   31014.,   32260.,   33870.,
          35912.,   37228.],
       [   1260.,    3318.,    5498.,    7686.,    9862.,   11646.,
          14054.,   15976.,   17486.,   19506.,   21866.,   23284.,
          25498.,   26526.,   29098.,   30562.,   32158.,   34212.,
          35778.,   37570.],
       [   1126.,    3292.,    5508.,    7688.,    9556.,   11650.,
          13794.,   15638.,   17186.,   19334.,   21410.,   23650.,
          24982.,   26444.,   28424.,   29870.,   31934.,   33898.,
          35184.,   37008.],
       [   1112.,    3336.,    5400.,    7434.,    9374.,   11434.,
          13406.,   15262.,   17548.,   19366.,   21284.,   23014.,
          24756.,   26526.,   28430.,   30298.,   30998.,   33650.,
          35522.,   37470.],
       [   1032.,    3276.,    5260.,    7356.,    9100.,   11246.,
          13298.,   15312.,   17150.,   19138.,   20672.,   22788.,
          24540.,   26438.,   28184.,   29744.,   31760.,   33408.,
          35396.,   37126.],
       [   1014.,    3252.,    5334.,    7102.,    9360.,   11068.,
          13196.,   15328.,   17064.,   18834.,   20996.,   22386.,
          24240.,   26644.,   28052.,   29842.,   31686.,   33062.,
          34934.,   36206.],
       [   1058.,    3050.,    5298.,    7002.,    9318.,   10864.,
          13476.,   15096.,   16700.,   18896.,   20904.,   22762.,
          24592.,   25748.,   27592.,   29044.,   31210.,   33026.,
          34566.,   36238.],
       [    986.,    3092.,    5024.,    6986.,    8940.,   10986.,
          13312.,   14884.,   16888.,   18562.,   20528.,   22736.,
          24186.,   25796.,   27624.,   29330.,   31178.,   32710.,
          34534.,   36012.],
       [   1026.,    3020.,    5050.,    6900.,    8754.,   10864.,
          12814.,   14802.,   16708.,   18376.,   20762.,   22174.,
          23944.,   26166.,   27716.,   29360.,   30898.,   32820.,
          34036.,   36144.],
       [   1134.,    3160.,    4922.,    6958.,    8852.,   10802.,
          12820.,   14756.,   16680.,   18634.,   20256.,   22290.,
          23466.,   25564.,   27894.,   28902.,   30814.,   32246.,
          33912.,   36194.]])

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

In [49]:
ddbtzdth=BallTree(dat,metric='pyfunc',func=APzdth)

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



  0%|          | 0/105830 [00:00<?, ?it/s]

  0%|          | 6/105830 [00:00<33:12, 53.12it/s]

  0%|          | 11/105830 [00:00<34:13, 51.52it/s]

  0%|          | 16/105830 [00:00<35:23, 49.84it/s]

  0%|          | 21/105830 [00:00<37:14, 47.35it/s]

  0%|          | 26/105830 [00:00<37:15, 47.33it/s]

  0%|          | 32/105830 [00:00<36:46, 47.95it/s]

  0%|          | 37/105830 [00:00<36:50, 47.86it/s]

  0%|          | 44/105830 [00:00<34:24, 51.23it/s]

  0%|          | 49/105830 [00:01<36:32, 48.24it/s]

  0%|          | 54/105830 [00:01<36:20, 48.52it/s]

  0%|          | 60/105830 [00:01<35:14, 50.03it/s]

  0%|          | 65/105830 [00:01<36:30, 48.28it/s]

  0%|          | 71/105830 [00:01<36:17, 48.56it/s]

  0%|          | 76/105830 [00:01<36:12, 48.68it/s]

  0%|          | 83/105830 [00:01<34:22, 51.27it/s]

  0%|          | 90/105830 [00:01<33:14, 53.00it/s]

  0%|          | 96/105830 [00:01<36:04, 48.84it/s]

  0%|          | 101/105830 [00:02<35:55, 49.04it/s]

  0%|          | 106/105830 [00:02<37:51, 46.54it/s]

  0%|          | 111/105830 [00:02<40:09, 43.88it/s]

  0%|          | 116/105830 [00:02<42:24, 41.55it/s]

  0%|          | 121/105830 [00:02<41:47, 42.16it/s]

  0%|          | 126/105830 [00:02<40:21, 43.65it/s]

  0%|          | 132/105830 [00:02<38:09, 46.16it/s]

  0%|          | 137/105830 [00:02<38:12, 46.10it/s]

  0%|          | 142/105830 [00:03<40:59, 42.97it/s]

  0%|          | 147/105830 [00:03<40:33, 43.42it/s]

  0%|          | 153/105830 [00:03<39:20, 44.77it/s]

  0%|          | 158/105830 [00:03<39:24, 44.68it/s]

  0%|          | 163/105830 [00:03<41:15, 42.69it/s]

  0%|          | 169/105830 [00:03<39:36, 44.45it/s]

  0%|          | 174/105830 [00:03<38:28, 45.76it/s]

  0%|          | 179/105830 [00:03<45:27, 38.74it/s]

  0%|          | 184/105830 [00:04<49:36, 35.49it/s]

  0%|          | 188/105830 [00:04<54:22, 32.39it/s]

  0%|          | 192/105830 [00:04<56:23, 31.22it/s]

  0%|          | 196/105830 [00:04<1:00:33, 29.07it/s]

  0%|          | 200/105830 [00:04<1:03:07, 27.89it/s]

  0%|          | 204/105830 [00:04<1:01:12, 28.76it/s]

  0%|          | 208/105830 [00:04<57:13, 30.77it/s]  

  0%|          | 214/105830 [00:05<50:38, 34.76it/s]

  0%|          | 219/105830 [00:05<46:17, 38.02it/s]

  0%|          | 225/105830 [00:05<42:03, 41.85it/s]

  0%|          | 231/105830 [00:05<40:27, 43.50it/s]

  0%|          | 236/105830 [00:05<39:53, 44.12it/s]

  0%|          | 242/105830 [00:05<38:25, 45.79it/s]

  0%|          | 248/105830 [00:05<37:15, 47.24it/s]

  0%|          | 253/105830 [00:05<38:49, 45.32it/s]

  0%|          | 258/105830 [00:05<39:57, 44.04it/s]

  0%|          | 263/105830 [00:06<40:45, 43.17it/s]

  0%|          | 268/105830 [00:06<41:28, 42.42it/s]

  0%|          | 273/105830 [00:06<40:06, 43.86it/s]

  0%|          | 278/105830 [00:06<41:56, 41.95it/s]

  0%|          | 283/105830 [00:06<42:54, 41.00it/s]

  0%|          | 289/105830 [00:06<39:29, 44.54it/s]

  0%|          | 294/105830 [00:06<40:07, 43.83it/s]

  0%|          | 299/105830 [00:06<39:31, 44.49it/s]

  0%|          | 304/105830 [00:07<42:00, 41.87it/s]

  0%|          | 309/105830 [00:07<42:39, 41.23it/s]

  0%|          | 314/105830 [00:07<43:40, 40.26it/s]

  0%|          | 319/105830 [00:07<43:45, 40.19it/s]

  0%|          | 324/105830 [00:07<45:50, 38.35it/s]

  0%|          | 328/105830 [00:07<47:16, 37.19it/s]

  0%|          | 332/105830 [00:07<46:22, 37.92it/s]

  0%|          | 336/105830 [00:07<47:15, 37.20it/s]

  0%|          | 341/105830 [00:07<45:12, 38.89it/s]

  0%|          | 346/105830 [00:08<42:42, 41.16it/s]


  0%|          | 351/105830 [00:08<41:38, 42.23it/s]

  0%|          | 356/105830 [00:08<43:06, 40.78it/s]

  0%|          | 362/105830 [00:08<40:36, 43.29it/s]

  0%|          | 367/105830 [00:08<40:42, 43.19it/s]

  0%|          | 372/105830 [00:08<41:25, 42.44it/s]

  0%|          | 377/105830 [00:08<43:14, 40.64it/s]

  0%|          | 382/105830 [00:08<45:41, 38.46it/s]

  0%|          | 386/105830 [00:09<46:34, 37.73it/s]

  0%|          | 390/105830 [00:09<46:00, 38.20it/s]

  0%|          | 394/105830 [00:09<45:45, 38.40it/s]

  0%|          | 398/105830 [00:09<46:20, 37.92it/s]

  0%|          | 403/105830 [00:09<45:06, 38.96it/s]

  0%|          | 408/105830 [00:09<42:28, 41.37it/s]

  0%|          | 413/105830 [00:09<44:12, 39.74it/s]

  0%|          | 418/105830 [00:09<43:21, 40.52it/s]

  0%|          | 424/105830 [00:10<41:18, 42.53it/s]

  0%|          | 429/105830 [00:10<40:16, 43.62it/s]

  0%|          | 434/105830 [00:10<41:21, 42.47it/s]

  0%|          | 440/105830 [00:10<39:52, 44.05it/s]

  0%|          | 445/105830 [00:10<43:04, 40.77it/s]

  0%|          | 450/105830 [00:10<44:08, 39.78it/s]

  0%|          | 455/105830 [00:10<44:45, 39.24it/s]

  0%|          | 459/105830 [00:10<45:36, 38.50it/s]

  0%|          | 463/105830 [00:10<46:46, 37.55it/s]

  0%|          | 468/105830 [00:11<45:23, 38.69it/s]

  0%|          | 472/105830 [00:11<46:26, 37.80it/s]

  0%|          | 476/105830 [00:11<48:37, 36.11it/s]

  0%|          | 480/105830 [00:11<49:04, 35.78it/s]

  0%|          | 485/105830 [00:11<46:53, 37.44it/s]

  0%|          | 491/105830 [00:11<43:11, 40.64it/s]

  0%|          | 496/105830 [00:11<44:01, 39.88it/s]

  0%|          | 501/105830 [00:11<45:32, 38.54it/s]

  0%|          | 505/105830 [00:12<45:32, 38.55it/s]

  0%|          | 511/105830 [00:12<42:30, 41.29it/s]

  0%|          | 516/105830 [00:12<44:31, 39.42it/s]

  0%|          | 521/105830 [00:12<46:09, 38.03it/s]

  0%|          | 525/105830 [00:12<46:56, 37.39it/s]

  1%|          | 532/105830 [00:12<41:03, 42.74it/s]

  1%|          | 537/105830 [00:12<42:19, 41.46it/s]

  1%|          | 542/105830 [00:12<43:29, 40.35it/s]

  1%|          | 547/105830 [00:13<44:12, 39.70it/s]

  1%|          | 552/105830 [00:13<44:27, 39.46it/s]

  1%|          | 557/105830 [00:13<42:54, 40.90it/s]

  1%|          | 562/105830 [00:13<43:27, 40.37it/s]

  1%|          | 568/105830 [00:13<41:00, 42.78it/s]

  1%|          | 573/105830 [00:13<39:34, 44.33it/s]
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-55-d911ee1eea21> in <module>()
----> 1 get_ipython().run_cell_magic(u'time', u'', u'for i in tqdm(xrange(len(dat))):\n    ind=ddbtzdth.query_radius(dat[i].reshape(1,-1),0.021)\n    for j in ind:\n        dist0=d.cdist([dat[i],],dat[j],APdz)[0]\n        dist1=d.cdist([dat[i],],dat[j],APzdth)[0]\n        dd2d+=np.histogram2d(dist0, dist1,range=rng,bins=(bins,bins))[0]\nprint dd2d')

/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>()

KeyboardInterrupt: 

  1%|          | 573/105830 [00:28<1:26:06, 20.37it/s]

In [51]:
dd2d


Out[51]:
array([[ 127059.,   23004.,   23163.,   22401.,   22666.,   22895.,
          24001.,   25466.,   26323.,   27367.,   29361.,   30323.,
          31171.,   33406.,   34623.,   37039.,   38781.,   40233.,
          42330.,   44419.],
       [  11322.,   16330.,   18480.,   19976.,   21067.,   22266.,
          23384.,   24647.,   25629.,   27367.,   28684.,   30609.,
          31215.,   33356.,   34927.,   37513.,   39341.,   41005.,
          42143.,   44654.],
       [   7192.,   10611.,   14113.,   17336.,   19358.,   20806.,
          22434.,   23971.,   25107.,   26804.,   28853.,   29682.,
          31771.,   33463.,   35534.,   36469.,   39060.,   40544.,
          42607.,   44270.],
       [   4788.,    7828.,   11146.,   14256.,   16862.,   18903.,
          20614.,   22573.,   24161.,   26702.,   27482.,   29351.,
          31054.,   33202.,   34900.,   37060.,   38493.,   40073.,
          42199.,   44400.],
       [   3445.,    6124.,    9567.,   12198.,   15144.,   17811.,
          19189.,   21520.,   23655.,   25789.,   27724.,   28795.,
          30411.,   32671.,   34016.,   36296.,   38517.,   40221.,
          42557.,   43710.],
       [   2465.,    5371.,    8397.,   11204.,   13944.,   16429.,
          18799.,   21279.,   23228.,   25089.,   26800.,   29028.,
          31052.,   32290.,   34293.,   36245.,   37197.,   40196.,
          42156.,   43883.],
       [   2134.,    4755.,    7551.,   10806.,   13387.,   15155.,
          17885.,   20005.,   21743.,   24516.,   26068.,   28287.,
          30256.,   32402.,   34235.,   36220.,   37821.,   39949.,
          41438.,   43838.],
       [   1794.,    4280.,    7190.,    9905.,   11972.,   14984.,
          17358.,   19309.,   21693.,   23953.,   25256.,   27691.,
          30008.,   32176.,   33960.,   35647.,   37340.,   39759.,
          41506.,   43558.],
       [   1694.,    4084.,    6866.,    9243.,   12109.,   14314.,
          16913.,   18683.,   21015.,   23523.,   25634.,   27084.,
          29290.,   31166.,   33613.,   35254.,   37238.,   39135.,
          41229.,   42621.],
       [   1394.,    4132.,    6447.,    8761.,   11584.,   14008.,
          16209.,   18985.,   20349.,   22298.,   25251.,   26358.,
          29288.,   31025.,   33464.,   34895.,   37188.,   38557.,
          40709.,   42927.],
       [   1298.,    3855.,    6378.,    8882.,   11132.,   13573.,
          15664.,   18009.,   20059.,   22908.,   24423.,   26470.,
          29100.,   30844.,   33331.,   34938.,   36183.,   38120.,
          40343.,   41995.],
       [   1432.,    3721.,    6157.,    8595.,   11042.,   12942.,
          15621.,   17849.,   19559.,   21879.,   24536.,   26121.,
          28704.,   29831.,   32664.,   34412.,   36181.,   38343.,
          40104.,   42284.],
       [   1261.,    3708.,    6123.,    8605.,   10652.,   13047.,
          15387.,   17519.,   19207.,   21668.,   23983.,   26517.,
          28048.,   29592.,   31880.,   33483.,   35825.,   38171.,
          39435.,   41548.],
       [   1230.,    3718.,    6011.,    8281.,   10451.,   12690.,
          15030.,   16993.,   19589.,   21605.,   23711.,   25721.,
          27641.,   29712.,   31890.,   33917.,   34641.,   37571.,
          39927.,   41963.],
       [   1148.,    3678.,    5856.,    8227.,   10160.,   12611.,
          14915.,   17018.,   19023.,   21212.,   22957.,   25527.,
          27423.,   29487.,   31490.,   33294.,   35492.,   37421.,
          39558.,   41611.],
       [   1106.,    3656.,    5983.,    7922.,   10403.,   12327.,
          14750.,   17067.,   19002.,   20945.,   23378.,   24945.,
          27053.,   29725.,   31201.,   33272.,   35252.,   36867.,
          38937.,   40330.],
       [   1185.,    3420.,    5893.,    7768.,   10416.,   12040.,
          14959.,   16722.,   18626.,   21032.,   23153.,   25332.,
          27528.,   28794.,   30661.,   32347.,   34583.,   36872.,
          38527.,   40356.],
       [   1099.,    3448.,    5615.,    7753.,    9925.,   12198.,
          14793.,   16541.,   18700.,   20632.,   22815.,   25275.,
          26801.,   28668.,   30712.,   32584.,   34642.,   36431.,
          38441.,   39995.],
       [   1133.,    3334.,    5615.,    7693.,    9712.,   12059.,
          14262.,   16459.,   18542.,   20366.,   22971.,   24625.,
          26582.,   29108.,   30845.,   32621.,   34280.,   36365.,
          37770.,   40099.],
       [   1256.,    3553.,    5484.,    7758.,    9897.,   11922.,
          14216.,   16463.,   18498.,   20529.,   22379.,   24684.,
          25982.,   28223.,   31066.,   32150.,   34120.,   35733.,
          37680.,   40062.]])
  9%|▊         | 9005/105830 [03:00<32:16, 50.01it/s]

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

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)