コード例 #1
0
ファイル: Correlations.py プロジェクト: steven-murray/PyGS
def _1d_correlation(pos, min_cut, max_cut, end_s=0.02, ns=15, n_randoms=1, n_cores=1):
    """
    Does a 1d correlation in either redshift or comoving distance space.
    """

    if pos.max() < 10.0:
        A, g, t = sf.fit_selection_simple_z(pos)
    else:
        A, g, t = sf.fit_selection_simple(pos)


    DD = _correlation_1d_DD_wrapper(pos1=pos, end_s=end_s, ns=ns, n_cores=n_cores)
    print "Done DD"
    RR = np.zeros((ns))
    DR = np.zeros((ns))
    print "made zeros"
    for i in range(n_randoms):
        rand_r = sf.create_radial_selection(A, g, t, min_cut, max_cut, len(pos))

        if i == 0:
            plt.hist(rand_r, normed=True)
            plt.hist(pos, normed=True)
            plt.show()

            go_ahead = str(raw_input("do you like what you see?? [Y/n]"))
            if go_ahead == 'n':
                raise ValueError("Okay we'll stop then")

        print len(rand_r)
        RR += _correlation_1d_DD_wrapper(pos1=rand_r, end_s=end_s, ns=ns, n_cores=n_cores)
        print "Done RR"
        DR += _correlation_1d_DR_wrapper(pos1=pos, pos2=rand_r, end_s=end_s, ns=ns, n_cores=n_cores)
        print "done DR"

    RR /= n_randoms
    DR /= n_randoms

    #Use the Landy-Szalay Estimator
    Corr = 1 + DD / RR - 2 * DR * (len(pos) - 1.0) / len(pos) / RR

    #Calculate the centre of bins
    s_bins = np.linspace(end_s / (2 * ns), end_s * (1 - 0.5 / ns), ns)

    print "got to the end..."
    print Corr
    return s_bins.copy(), Corr.copy()