Skip to content

Commit 98aa11f

Browse files
committed
Added checks for negative RRR counts
following from the multipole decomposition
1 parent 558be43 commit 98aa11f

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

RascalC/correction_function_3pcf.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,19 @@ def compute_inv_phi_aperiodic_3pcf(n: int, m: int, n_multipoles: int, r_bins: np
3131
for ell in range(n_multipoles):
3232
# (NB: we've absorbed a factor of delta_mu into RRR_true here)
3333
leg_triple[:, :, ell] += (2.*ell+1.) * np.sum(legendre(ell)(mu_cen)[None, None, :] * RRR_true, axis=-1)
34+
35+
# as a precaution, check for negative counts, which should be problematic
36+
n_mu_check = 2001
37+
triple_counts_check = np.zeros([n, n, n_mu_check])
38+
mu_values_check = np.linspace(-1, 1, n_mu_check)
39+
for ell in range(n_multipoles):
40+
triple_counts_check += leg_triple[:, :, ell][:, :, None] * legendre(ell)(mu_values_check)[None, None, :]
41+
problem_indices = np.argwhere(triple_counts_check <= 0)
42+
if len(problem_indices) > 0:
43+
rbins, mu_counts = np.unique(problem_indices[:, :2], axis=0, return_counts=True)
44+
for ((rbin1, rbin2), mu_count) in zip(rbins, mu_counts):
45+
if rbin1 > rbin2: continue # this case can be skipped by symmetry
46+
print_function(f"WARNING: counts are not positive for radial bin pair {rbin1}, {rbin2} for {mu_count} mu values of {n_mu_check} checked")
3447

3548
vol_r = 4 * np.pi / 3 * (r_bins[:, 1] **3 - r_bins[:, 0] ** 3)
3649

@@ -155,7 +168,20 @@ def compute_3pcf_correction_function_from_encore(randoms_pos: np.ndarray[float],
155168
# fill the edge/corner diagonal elements which are more tricky
156169
leg_triple[0, 0] = (2 * (2 * leg_triple[1, 0] - leg_triple[2, 0]) + (2 * leg_triple[1, 1] - leg_triple[2, 2])) / 3
157170
leg_triple[-1, -1] = (2 * (2 * leg_triple[-2, -1] - leg_triple[-3, -1]) + (2 * leg_triple[-2, -2] - leg_triple[-3, -3])) / 3
158-
# hopefully this leads to no negative bin counts, worth checking later
171+
172+
# check for negative counts, which should be problematic
173+
n_mu_check = 2001
174+
triple_counts_check = np.zeros([n, n, n_mu_check])
175+
mu_values_check = np.linspace(-1, 1, n_mu_check)
176+
for ell in range(n_multipoles):
177+
triple_counts_check += leg_triple[:, :, ell][:, :, None] * legendre(ell)(mu_values_check)[None, None, :]
178+
problem_indices = np.argwhere(triple_counts_check <= 0)
179+
if len(problem_indices) > 0:
180+
rbins, mu_counts = np.unique(problem_indices[:, :2], axis=0, return_counts=True)
181+
for ((rbin1, rbin2), mu_count) in zip(rbins, mu_counts):
182+
if rbin1 > rbin2: continue # this case can be skipped by symmetry
183+
print_function(("INFO" if rbin1 == rbin2 else "WARNING") + f": counts are not positive for radial bin pair {rbin1}, {rbin2} for {mu_count} mu values of {n_mu_check} checked")
184+
# the problem for same-bin pairs is less critical (and seems more likely), for different-bin pairs it is more critical
159185

160186
vol_r = 4 * np.pi / 3 * (r_bins[:, 1] ** 3 - r_bins[:, 0] ** 3) # volume of radial/separation bins as 1D array
161187

0 commit comments

Comments
 (0)