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 xydistance r and zdistance z from each point insample1
, where r and z are defined by the inputproj_search_radius
andcylinder_half_length
, respectively.Parameters: sample1 : array_like
Npts1 x 3 numpy array 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, optional
Npts2 x 3 array containing 3D positions of points.
proj_search_radius : array_like
LengthNpts1 array defining the xydistance 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_length : array_like
LengthNpts1 array defining the zdistance 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.period : array_like, optional
Length3 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
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.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 insample1
.indexes : array_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 lowmass host halos are in cylinders of fixed length surrounding highmass 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 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
Now let’s drop a cylinder of radius 200 kpc/h and halflength 250 kpc/h around each highmass host halo, and for each highmass host we’ll count the number of lowmass 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 countsincells on a realistic galaxy catalog tutorial.