weighted_npairs_s_mu¶

halotools.mock_observables.pair_counters.
weighted_npairs_s_mu
(sample1, sample2, weights1, weights2, s_bins, mu_bins, period=None, verbose=False, num_threads=1, approx_cell1_size=None, approx_cell2_size=None)[source] [edit on github]¶ Function performs a weighted count of the number of pairs of points separated by less than radial separation, \(s\), given by
s_bins
and angular distance, \(\mu\equiv\cos(\theta_{\rm los})\), given bymu_bins
, where \(\theta_{\rm los}\) is the angle between \(\vec{s}\) and the lineofsight (LOS).The first two dimensions (x, y) define the plane for perpendicular distances. The third dimension (z) defines the LOS. i.e. x,y positions are on the plane of the sky, and z is the radial distance coordinate. This is the ‘distant observer’ approximation.
A common variation of paircounting calculations is to count pairs with separations between two different distances, e.g. [s1 ,s2] and [mu1, mu2]. You can retrieve this information from
weighted_npairs_s_mu
by takingnumpy.diff
of the returned array along each axis.See Notes section for further clarification.
Parameters: sample1 : array_like
Numpy array of shape (Npts1, 3) containing 3D positions of points. See the Formatting your xyz coordinates for Mock Observables calculations documentation page, or the Examples section below, for instructions on how to transform your coordinate position arrays into the format accepted by the
sample1
andsample2
arguments. Length units are comoving and assumed to be in Mpc/h, here and throughout Halotools.sample2 : array_like
Numpy array of shape (Npts2, 3) containing 3D positions of points. Should be identical to sample1 for cases of autosample pair counts. Length units are comoving and assumed to be in Mpc/h, here and throughout Halotools.
weights1 : array_like
Numpy array of shape (Npts1, ) containing weights used to weight the pair counts.
weights2 : array_like
Numpy array of shape (Npts2, ) containing weights used to weight the pair counts.
s_bins : array_like
numpy array of shape (num_s_bin_edges, ) storing the \(s\) boundaries defining the bins in which pairs are counted.
mu_bins : array_like
numpy array of shape (num_mu_bin_edges, ) storing the \(\cos(\theta_{\rm LOS})\) boundaries defining the bins in which pairs are counted. All values must be between [0,1].
period : array_like, optional
Length3 sequence defining the periodic boundary conditions in each dimension. If you instead provide a single scalar, Lbox, period is assumed to be the same in all Cartesian directions. Length units are comoving and assumed to be in Mpc/h, here and throughout Halotools.
verbose : Boolean, optional
If True, print out information and progress.
num_threads : int, optional
Number of threads to use in calculation, where parallelization is performed using the python
multiprocessing
module. Default is 1 for a purely serial calculation, in which case a multiprocessing Pool object will never be instantiated. A string ‘max’ may be used to indicate that the pair counters should use all available cores on the machine.approx_cell1_size : array_like, optional
Length3 array serving as a guess for the optimal manner by how points will be apportioned into subvolumes of the simulation box. The optimum choice unavoidably depends on the specs of your machine. Default choice is to use Lbox/10 in each dimension, which will return reasonable result performance for most usecases. Performance can vary sensitively with this parameter, so it is highly recommended that you experiment with this parameter when carrying out performancecritical calculations.
approx_cell2_size : array_like, optional
Analogous to
approx_cell1_size
, but for sample2. See comments forapprox_cell1_size
for details.Returns: num_pairs : array of shape (num_s_bin_edges, num_mu_bin_edges) storing the
number of pairs separated by less than (s, mu)
weighted_num_pairs : array of shape (num_s_bin_edges, num_mu_bin_edges) storing the
weighted number of pairs separated by less than (s, mu). Each pair is weighted by
w1*w2
.Notes
Let \(\vec{s}\) be the radial vector connnecting two points. The magnitude, \(s\), is:
\[s = \sqrt{r_{\parallel}^2+r_{\perp}^2},\]where \(r_{\parallel}\) is the separation parallel to the LOS and \(r_{\perp}\) is the separation perpednicular to the LOS. \(\mu\) is the cosine of the angle, \(\theta_{\rm LOS}\), between the LOS and \(\vec{s}\):
\[\mu = \cos(\theta_{\rm LOS}) \equiv r_{\parallel}/s.\]Along the first dimension of
num_pairs
, \(s\) increases. Along the second dimension, \(\mu\) decreases, i.e. \(\theta_{\rm LOS}\) increases.If sample1 == sample2 that the
weighted_npairs_s_mu
function doublecounts pairs. If your science application requires sample1==sample2 inputs and also pairs to not be doublecounted, simply divide the final counts by 2.One final point of clarification concerning doublecounting may be in order. Suppose sample1==sample2 and s_bins[0]==0. Then the returned value for this bin will be len(sample1), since each sample1 point has distance 0 from itself.
Examples
For demonstration purposes we create randomly distributed sets of points within a periodic unit cube.
>>> Npts1, Npts2, Lbox = 1000, 1000, 200. >>> period = [Lbox, Lbox, Lbox] >>> s_bins = np.logspace(1, 1.25, 15) >>> mu_bins = np.linspace(0, 1)
>>> x1 = np.random.uniform(0, Lbox, Npts1) >>> y1 = np.random.uniform(0, Lbox, Npts1) >>> z1 = np.random.uniform(0, Lbox, Npts1) >>> x2 = np.random.uniform(0, Lbox, Npts2) >>> y2 = np.random.uniform(0, Lbox, Npts2) >>> z2 = np.random.uniform(0, Lbox, Npts2)
We transform our x, y, z points into the array shape used by the paircounter by taking the transpose of the result of
numpy.vstack
. This boilerplate transformation is used throughout themock_observables
subpackage:>>> sample1 = np.vstack([x1, y1, z1]).T >>> sample2 = np.vstack([x2, y2, z2]).T >>> weights1 = np.random.rand(Npts1) >>> weights2 = np.random.rand(Npts2)
>>> from halotools.mock_observables.pair_counters import weighted_npairs_s_mu >>> counts, weighted_counts = weighted_npairs_s_mu(sample1, sample2, weights1, weights2, s_bins, mu_bins, period=period)