counts_in_cylinders¶
- halotools.mock_observables.counts_in_cylinders(sample1, sample2, proj_search_radius, cylinder_half_length, period=None, verbose=False, num_threads=1, approx_cell1_size=None, approx_cell2_size=None, return_indexes=False, condition=None, condition_args=())[source]¶
Function counts the number of points in
sample2
separated by a xy-distance r and z-distance z from each point insample1
, where r and z are defined by the inputproj_search_radius
andcylinder_half_length
, respectively.- Parameters:
- sample1array_like
Npts1 x 3 numpy array containing 3-D 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.- sample2array_like
Npts2 x 3 array containing 3-D positions of points. If this is None, an autocorrelation on sample1 will be done instead.
- proj_search_radiusarray_like
Length-Npts1 array defining the xy-distance around each point in
sample1
to search for points insample2
. Length units are comoving and assumed to be in Mpc/h, here and throughout Halotools.- cylinder_half_lengtharray_like
Length-Npts1 array defining the z-distance around each point in
sample1
to search for points insample2
. Thus the total length of the cylinder placed around each point insample1
will be twice the corresponding value stored in the inputcylinder_half_length
. Length units are comoving and assumed to be in Mpc/h, here and throughout Halotools.- periodarray_like, optional
Length-3 array defining the periodic boundary conditions. If only one number is specified, the enclosing volume is assumed to be a periodic cube (by far the most common case). If period is set to None, the default option, PBCs are set to infinity.
- verboseBoolean, optional
If True, print out information and progress.
- num_threadsint, 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_sizearray_like, optional
Length-3 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 use-cases. Performance can vary sensitively with this parameter, so it is highly recommended that you experiment with this parameter when carrying out performance-critical calculations.
- approx_cell2_sizearray_like, optional
Analogous to
approx_cell1_size
, but for sample2. See comments forapprox_cell1_size
for details.- return_indexes: bool, optional
If true, return both counts and the indexes of the pairs.
- conditionstr, optional
Require a condition to be met for a pair to be counted. See options below: None | “always_true”: Count all pairs in cylinder
- “mass_frac”:
Only count pairs which satisfy lim[0] < mass2/mass1 < lim[1]
- condition_argstuple, optional
Arguments passed to the condition constructor None | “always_true”: condition_args will be ignored
- “mass_frac”:
-mass1 (array of mass of sample 1; required) -mass2 (array of mass of sample 2; required) -lim (tuple of min,max; required) -lower_equality (bool to use lim[0] <= m2/m1; optional) -upper_equality (bool to use m2/m1 <= lim[1]; optional)
- Returns:
- num_pairsarray_like
Numpy array of length Npts1 storing the numbers of points in
sample2
inside the cylinder surrounding each point insample1
.- indexesarray_like, optional
If
return_indexes
is true, return a structured array of length num_pairs with the indexes of the pairs. Columni1
is the index insample1
at the center of the cylinder and columni2
is the index insample2
that is contained in the cylinder.
Examples
For illustration purposes, we’ll create some fake data and call the pair counter.
>>> from halotools.sim_manager import FakeSim >>> halocat = FakeSim()
In this first example, we’ll demonstrate how to calculate the number of low-mass host halos are in cylinders of fixed length surrounding high-mass halos.
>>> host_halo_mask = halocat.halo_table['halo_upid'] == -1 >>> host_halos = halocat.halo_table[host_halo_mask] >>> high_mass_mask = host_halos['halo_mvir'] >= 5e13 >>> high_mass_hosts = host_halos[high_mass_mask] >>> low_mass_mask = host_halos['halo_mvir'] <= 1e12 >>> low_mass_hosts = host_halos[low_mass_mask]
>>> x1, y1, z1 = high_mass_hosts['halo_x'], high_mass_hosts['halo_y'], high_mass_hosts['halo_z'] >>> x2, y2, z2 = low_mass_hosts['halo_x'], low_mass_hosts['halo_y'], low_mass_hosts['halo_z']
We transform our x, y, z points into the array shape used by the pair-counter by taking the transpose of the result of
numpy.vstack
. This boilerplate transformation is used throughout themock_observables
sub-package:>>> sample1 = np.vstack([x1, y1, z1]).T >>> sample2 = np.vstack([x2, y2, z2]).T
Now let’s drop a cylinder of radius 200 kpc/h and half-length 250 kpc/h around each high-mass host halo, and for each high-mass host we’ll count the number of low-mass halos falling within that cylinder:
>>> period = halocat.Lbox >>> proj_search_radius, cylinder_half_length = 0.2, 0.25 >>> result = counts_in_cylinders(sample1, sample2, proj_search_radius, cylinder_half_length, period=period)
For example usage of the
counts_in_cylinders
function on a realistic galaxy catalog that makes use of the variable search length feature, see the Calculating counts-in-cells on a realistic galaxy catalog tutorial.