コード例 #1
0
ファイル: xcorrReal.py プロジェクト: sudeepdas/SpecKPack-
def estimateErrorFromRandoms(randomsDir, tag=''):
    """
    @brief estimate the errors on a given bin from correlations
    with random maps
    
    @param randomsDir: the directory storing the results of the random correlations
    """   
    corr_total = []

    for f in os.listdir(randomsDir):

        # consider only the pickle files
        if "pkl" not in f:
            continue

        # consider only those files containing 'tag'
        if tag not in f:
            continue

        fig, theta, corr, corr_errs = xcorrUtils.plot1DRealCorr("%s/%s" %(randomsDir, f))

    corr_total = np.array(corr_total)

    corr_mean = np.mean(corr_total, axis=0)
    corr_err = np.std(corr_total, axis = 0)
    
    return corr_err
    
コード例 #2
0
ファイル: xcorrReal.py プロジェクト: sudeepdas/SpecKPack-
def plot(params):
    """
    @brief plot a real space correlation measured from data and the corresponding theory
    prediction

    @param params: dictionary containing the following:
           powerSpectrum: name of file containing spectrum to use for theory curve (str)
           dataCorr: name of pickle file containing 2D correlation from data (str)
           filter1_path: path of file containing filter #1 (str)
           filter1FromFunction: tuple containing ('function_name', functionKWArgs)
           filter2_path: path of file containing filter #2 (str)
           filter2FromFunction: tuple containing ('function_name', functionKWArgs)       
    """

    # load the data spectrum to plot
    ell, cl = np.loadtxt(params['powerSpectrum'], usecols=[0,1], unpack=True)

    # make the first filter, if provided
    F1 = np.ones(len(ell))

    # first, read from a path, if given 
    if params['filter1_path'] is not None:
            x, F1 = np.loadtxt(params['filter1_path'], unpack=True)
            f = InterpolatedUnivariateSpline(x, F1)
            F1 = f(ell)
    # then try to make the filter from a function  
    elif params['filter1FromFunction'] is not None:

        func = xcorrUtils.__stringToFunction(params['filter1FromFunction'][0])
        F1 = func(ell, **params['filter1FromFunction'][1])

    # make the second filter, if provided
    F2 = np.ones(len(ell))

     # first, read from a path, if given 
    if params['filter2_path'] is not None:

        x, F2 = np.loadtxt(params['filter2_path'], unpack=True)
        f = InterpolatedUnivariateSpline(x, F2)
        F2 = f(ell)
    # then try to make the filter from a function   
    elif params['filter2FromFunction'] is not None:
        func = xcorrUtils.__stringToFunction(params['filter2FromFunction'][0])
        F1 = func(ell, **params['filter2FromFunction'][1])

    # compute the expected correlation given the filter and power spectrum
    theta_th, corr_th = xcorrTheory.realSpaceCorrFromTheory(ell, cl, Fell_1=F1, Fell_2=F2)

    # plot the binned 1D correlation from the 2D data
    fig, theta, corr, corr_errs = xcorrUtils.plot1DRealCorr(params['dataCorr'])

    # also plot the expected curve from theory
    curr_ax = fig_gca()
    curr_ax.plot(theta_th*60, corr_th, ls='--')

    # add a horizontal axis line
    plt.axhline(y=0, c='k')
    plt.show()

    return 0