From 0dabb7a5ac4273de8c005806fa62057869afb411 Mon Sep 17 00:00:00 2001 From: Christopher Bradshaw Date: Wed, 16 Oct 2019 00:45:39 -0700 Subject: [PATCH 1/3] Correctly convert counts to cf when doing an autocorr --- Corrfunc/utils.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/Corrfunc/utils.py b/Corrfunc/utils.py index d6191f59..0227805f 100644 --- a/Corrfunc/utils.py +++ b/Corrfunc/utils.py @@ -23,7 +23,7 @@ def convert_3d_counts_to_cf(ND1, ND2, NR1, NR2, D1D2, D1R2, D2R1, R1R2, - estimator='LS'): + estimator='LS', autocorr=False): """ Converts raw pair counts to a correlation function. @@ -138,14 +138,22 @@ def convert_3d_counts_to_cf(ND1, ND2, NR1, NR2, nonzero = pair_counts['R1R2'] > 0 if 'LS' in estimator or 'Landy' in estimator: - fN1 = np.float(NR1) / np.float(ND1) - fN2 = np.float(NR2) / np.float(ND2) cf = np.zeros(nbins) cf[:] = np.nan - cf[nonzero] = (fN1 * fN2 * pair_counts['D1D2'][nonzero] - - fN1 * pair_counts['D1R2'][nonzero] - - fN2 * pair_counts['D2R1'][nonzero] + - pair_counts['R1R2'][nonzero]) / pair_counts['R1R2'][nonzero] + if autocorr: + fN1 = np.float(NR1) / np.float(ND1) + fN2 = (np.float(NR1) - 1) / (np.float(ND1) - 1) + fN3 = (np.float(NR1) - 1) / np.float(ND1) + cf[nonzero] = (fN1 * fN2 * pair_counts['D1D2'][nonzero] - + 2 * fN3 * pair_counts['D1R2'][nonzero] + + pair_counts['R1R2'][nonzero]) / pair_counts['R1R2'][nonzero] + else: + fN1 = np.float(NR1) / np.float(ND1) + fN2 = np.float(NR2) / np.float(ND2) + cf[nonzero] = (fN1 * fN2 * pair_counts['D1D2'][nonzero] - + fN1 * pair_counts['D1R2'][nonzero] - + fN2 * pair_counts['D2R1'][nonzero] + + pair_counts['R1R2'][nonzero]) / pair_counts['R1R2'][nonzero] if len(cf) != nbins: msg = 'Bug in code. Calculated correlation function does not '\ 'have the same number of bins as input arrays. Input bins '\ From 73ce9200b2db11eec53b55c67b99aad6194dd2bf Mon Sep 17 00:00:00 2001 From: Christopher Bradshaw Date: Fri, 18 Oct 2019 13:11:37 -0700 Subject: [PATCH 2/3] add docs + autocorr option convert_rp_pi_counts_to_wp --- Corrfunc/utils.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Corrfunc/utils.py b/Corrfunc/utils.py index 0227805f..9a50aedc 100644 --- a/Corrfunc/utils.py +++ b/Corrfunc/utils.py @@ -61,6 +61,9 @@ def convert_3d_counts_to_cf(ND1, ND2, NR1, NR2, The kind of estimator to use for computing the correlation function. Currently, only supports Landy-Szalay + autocorr: bool, default=False + Whether the counts are from an autocorrelation + Returns --------- @@ -171,7 +174,7 @@ def convert_3d_counts_to_cf(ND1, ND2, NR1, NR2, def convert_rp_pi_counts_to_wp(ND1, ND2, NR1, NR2, D1D2, D1R2, D2R1, R1R2, nrpbins, pimax, dpi=1.0, - estimator='LS'): + estimator='LS', autocorr=False): """ Converts raw pair counts to a correlation function. @@ -218,6 +221,10 @@ def convert_rp_pi_counts_to_wp(ND1, ND2, NR1, NR2, The kind of estimator to use for computing the correlation function. Currently, only supports Landy-Szalay + autocorr: bool, default=False + Whether the counts are from an autocorrelation + + Returns --------- @@ -297,7 +304,7 @@ def convert_rp_pi_counts_to_wp(ND1, ND2, NR1, NR2, xirppi = convert_3d_counts_to_cf(ND1, ND2, NR1, NR2, D1D2, D1R2, D2R1, R1R2, - estimator=estimator) + estimator=estimator, autocorr=autocorr) wp = np.empty(nrpbins) npibins = len(xirppi) // nrpbins if ((npibins * nrpbins) != len(xirppi)): From 4db04f7798d19872b899dc22e60fc9002dabf691 Mon Sep 17 00:00:00 2001 From: Christopher Bradshaw Date: Fri, 18 Oct 2019 13:37:44 -0700 Subject: [PATCH 3/3] fix line lengths --- Corrfunc/utils.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Corrfunc/utils.py b/Corrfunc/utils.py index 9a50aedc..06b60c05 100644 --- a/Corrfunc/utils.py +++ b/Corrfunc/utils.py @@ -149,14 +149,16 @@ def convert_3d_counts_to_cf(ND1, ND2, NR1, NR2, fN3 = (np.float(NR1) - 1) / np.float(ND1) cf[nonzero] = (fN1 * fN2 * pair_counts['D1D2'][nonzero] - 2 * fN3 * pair_counts['D1R2'][nonzero] + - pair_counts['R1R2'][nonzero]) / pair_counts['R1R2'][nonzero] + pair_counts['R1R2'][nonzero] + ) / pair_counts['R1R2'][nonzero] else: fN1 = np.float(NR1) / np.float(ND1) fN2 = np.float(NR2) / np.float(ND2) cf[nonzero] = (fN1 * fN2 * pair_counts['D1D2'][nonzero] - fN1 * pair_counts['D1R2'][nonzero] - fN2 * pair_counts['D2R1'][nonzero] + - pair_counts['R1R2'][nonzero]) / pair_counts['R1R2'][nonzero] + pair_counts['R1R2'][nonzero] + ) / pair_counts['R1R2'][nonzero] if len(cf) != nbins: msg = 'Bug in code. Calculated correlation function does not '\ 'have the same number of bins as input arrays. Input bins '\