Skip to content

Commit 75c930f

Browse files
committed
Implemented analytical counts with rp cut
1 parent 868ba4e commit 75c930f

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

pycorr/correlation_function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def is_same(array1, array2):
364364
size2 = counts['D1D2'].size2
365365
if boxsize is None:
366366
raise ValueError('boxsize must be provided for analytic two-point counts {}.'.format(label12))
367-
counts[label12] = AnalyticTwoPointCounter(mode, edges, boxsize, size1=size1, size2=size2)
367+
counts[label12] = AnalyticTwoPointCounter(mode, edges, boxsize, size1=size1, size2=size2, selection_attrs=selection_attrs)
368368
continue
369369
if log: logger.info('Computing two-point counts {}.'.format(label12))
370370
twopoint_kwargs = {'twopoint_weights': twopoint_weights[label12], 'weight_type': weight_type[label12], 'selection_attrs': selection_attrs[label12]}

pycorr/twopoint_counter.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ class AnalyticTwoPointCounter(BaseTwoPointCounter):
14291429
"""
14301430
name = 'analytic'
14311431

1432-
def __init__(self, mode, edges, boxsize, size1=10, size2=None, los='z'):
1432+
def __init__(self, mode, edges, boxsize, size1=10, size2=None, los='z', selection_attrs=None):
14331433
r"""
14341434
Initialize :class:`AnalyticTwoPointCounter`, and set :attr:`wcounts` and :attr:`sep`.
14351435
@@ -1474,17 +1474,42 @@ def __init__(self, mode, edges, boxsize, size1=10, size2=None, los='z'):
14741474
self._set_default_seps()
14751475
self._set_reversible()
14761476
self.wnorm = self.normalization()
1477+
self._set_selection(selection_attrs)
14771478
self.run()
14781479

14791480
def run(self):
14801481
"""Set analytical two-point counts."""
1482+
if any(name != "rp" for name in self.selection_attrs.keys()):
1483+
raise TwoPointCounterError("Analytic random counts not implemented for selections other than rp")
1484+
rp_selection = self.selection_attrs.get("rp", None)
1485+
if rp_selection is not None and self.mode not in ['s', 'smu']:
1486+
raise TwoPointCounterError("Analytic random counts not implemented for rp selection with mode {}".format(self.mode))
14811487
if self.mode == 's':
14821488
v = 4. / 3. * np.pi * self.edges[0]**3
14831489
dv = np.diff(v, axis=0)
1490+
if rp_selection:
1491+
v_rpcut = [4. / 3. * np.pi * (self.edges[0]**3 - (self.edges[0]**2 - np.fmin(rp_cut, self.edges[0])**1.5)) for rp_cut in rp_selection]
1492+
v_rpcut = v_rpcut[1] - v_rpcut[0]
1493+
dv_rpcut = np.diff(v_rpcut, axis=0) # volume in each bin removed by rp selection
1494+
dv_total = dv - dv_rpcut
1495+
dv = np.where(dv_total >= 1e-8 * dv, dv_total, 0) # ensure that the volume is not negative and further remove small positive values that may arise due to rounding errors; assumes that dv is accurate
14841496
elif self.mode == 'smu':
14851497
# we bin in mu
14861498
v = 2. / 3. * np.pi * self.edges[0][:, None]**3 * self.edges[1]
14871499
dv = np.diff(np.diff(v, axis=0), axis=-1)
1500+
if rp_selection:
1501+
s, mu = self.edges[0][:, None], self.edges[1][None, :]
1502+
sin_theta = np.sqrt(1 - mu**2) * np.ones_like(s)
1503+
v_rpcut = []
1504+
for rp_cut in rp_selection:
1505+
ss = s * np.ones_like(mu); c = ss * sin_theta > rp_cut; ss[c] = rp_cut / sin_theta[c] # this prevents division by zero
1506+
r = ss * sin_theta
1507+
h = ss * mu
1508+
v_rpcut.append(2. / 3. * np.pi * (s**3 - (s**2 - r**2)**1.5 + r**2 * h))
1509+
v_rpcut = v_rpcut[1] - v_rpcut[0]
1510+
dv_rpcut = np.diff(np.diff(v_rpcut, axis=0), axis=-1) # volume in each bin removed by rp selection
1511+
dv_total = dv - dv_rpcut
1512+
dv = np.where(dv_total >= 1e-8 * dv, dv_total, 0) # ensure that the volume is not negative and further remove small positive values that may arise due to rounding errors; assumes that dv is accurate
14881513
elif self.mode == 'rppi':
14891514
v = np.pi * self.edges[0][:, None]**2 * self.edges[1]
14901515
dv = np.diff(np.diff(v, axis=0), axis=1)

0 commit comments

Comments
 (0)