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)[source] [edit on github]

Function counts the number of points in sample2 separated by a xy-distance r and z-distance z from each point in sample1, where r and z are defined by the input proj_search_radius and cylinder_half_length, respectively.

Parameters:

sample1 : array_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 and sample2 arguments. Length units are comoving and assumed to be in Mpc/h, here and throughout Halotools.

sample2 : array_like, optional

Npts2 x 3 array containing 3-D positions of points.

proj_search_radius : array_like

Length-Npts1 array defining the xy-distance around each point in sample1 to search for points in sample2. Length units are comoving and assumed to be in Mpc/h, here and throughout Halotools.

cylinder_half_length : array_like

Length-Npts1 array defining the z-distance around each point in sample1 to search for points in sample2. Thus the total length of the cylinder placed around each point in sample1 will be twice the corresponding value stored in the input cylinder_half_length. Length units are comoving and assumed to be in Mpc/h, here and throughout Halotools.

period : array_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.

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

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_size : array_like, optional

Analogous to approx_cell1_size, but for sample2. See comments for approx_cell1_size for details.

return_indexes: bool, optional

If true, return both counts and the indexes of the pairs.

Returns:

num_pairs : array_like

Numpy array of length Npts1 storing the numbers of points in sample2 inside the cylinder surrounding each point in sample1.

indexes : array_like, optional

If return_indexes is true, return a structured array of length num_pairs with the indexes of the pairs. Column i1 is the index in sample1 at the center of the cylinder and column i2 is the index in sample2 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 the mock_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.