tpcf¶
- halotools.mock_observables.tpcf(sample1, rbins, sample2=None, randoms=None, period=None, do_auto=True, do_cross=True, estimator='Natural', num_threads=1, approx_cell1_size=None, approx_cell2_size=None, approx_cellran_size=None, RR_precomputed=None, NR_precomputed=None, seed=None)[source]¶
Calculate the real space two-point correlation function, \(\xi(r)\).
Example calls to this function appear in the documentation below. See the Formatting your xyz coordinates for Mock Observables calculations documentation page for instructions on how to transform your coordinate position arrays into the format accepted by the
sample1andsample2arguments.See also Galaxy Catalog Analysis Example: Calculating galaxy clustering in 3d for example usage on a mock galaxy catalog.
- 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
sample1andsample2arguments. Length units are comoving and assumed to be in Mpc/h, here and throughout Halotools.- rbinsarray_like
array of boundaries defining the real space radial bins in which pairs are counted. Length units are comoving and assumed to be in Mpc/h, here and throughout Halotools.
- sample2array_like, optional
Npts2 x 3 array containing 3-D positions of points. Passing
sample2as an input permits the calculation of the cross-correlation function. Default is None, in which case only the auto-correlation function will be calculated.- randomsarray_like, optional
Nran x 3 array containing 3-D positions of randomly distributed points. If no randoms are provided (the default option), calculation of the tpcf can proceed using analytical randoms (only valid for periodic boundary conditions).
- periodarray_like, optional
Length-3 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. If set to None (the default option), PBCs are set to infinity, in which case
randomsmust be provided. Length units are comoving and assumed to be in Mpc/h, here and throughout Halotools.- do_autoboolean, optional
Boolean determines whether the auto-correlation function will be calculated and returned. Default is True.
- do_crossboolean, optional
Boolean determines whether the cross-correlation function will be calculated and returned. Only relevant when
sample2is also provided. Default is True for the case wheresample2is provided, otherwise False.- estimatorstring, optional
Statistical estimator for the tpcf. Options are ‘Natural’, ‘Davis-Peebles’, ‘Hewett’ , ‘Hamilton’, ‘Landy-Szalay’ Default is
Natural.- num_threadsint, optional
Number of threads to use in calculation, where parallelization is performed using the python
multiprocessingmodule. 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_sizefor details.- approx_cellran_sizearray_like, optional
Analogous to
approx_cell1_size, but for randoms. See comments forapprox_cell1_sizefor details.- RR_precomputedarray_like, optional
Array storing the number of RR-counts calculated in advance during a pre-processing phase. Must have the same length as len(rbins). If the
RR_precomputedargument is provided, you must also provide theNR_precomputedargument. Default is None.- NR_precomputedint, optional
Number of points in the random sample used to calculate
RR_precomputed. If theNR_precomputedargument is provided, you must also provide theRR_precomputedargument. Default is None.- seedint, optional
Random number seed used to randomly downsample data, if applicable. Default is None, in which case downsampling will be stochastic.
- Returns:
- correlation_function(s)numpy.array
len(rbins)-1 length array containing the correlation function \(\xi(r)\) computed in each of the bins defined by input
rbins.\[1 + \xi(r) \equiv \mathrm{DD}(r) / \mathrm{RR}(r),\]If
estimatoris set to ‘Natural’. \(\mathrm{DD}(r)\) is the number of sample pairs with separations equal to \(r\), calculated by the pair counter. \(\mathrm{RR}(r)\) is the number of random pairs with separations equal to \(r\), and is counted internally using “analytic randoms” ifrandomsis set to None (see notes for an explanation), otherwise it is calculated using the pair counter.If
sample2is passed as input (and ifsample2is not exactly the same assample1), then three arrays of length len(rbins)-1 are returned:\[\xi_{11}(r), \xi_{12}(r), \xi_{22}(r),\]the autocorrelation of
sample1, the cross-correlation betweensample1andsample2, and the autocorrelation ofsample2, respectively. Ifdo_autoordo_crossis set to False, the appropriate sequence of results is returned.
Notes
For a higher-performance implementation of the tpcf function written in C, see the Corrfunc code written by Manodeep Sinha, available at https://github.com/manodeep/Corrfunc.
Examples
For demonstration purposes we calculate the
tpcffor halos in theFakeSim.>>> from halotools.sim_manager import FakeSim >>> halocat = FakeSim()
>>> x = halocat.halo_table['halo_x'] >>> y = halocat.halo_table['halo_y'] >>> z = halocat.halo_table['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_observablessub-package:>>> sample1 = np.vstack((x,y,z)).T
Alternatively, you may use the
return_xyz_formatted_arrayconvenience function for this same purpose, which provides additional wrapper behavior aroundnumpy.vstacksuch as placing points into redshift-space.>>> rbins = np.logspace(-1, 1, 10) >>> xi = tpcf(sample1, rbins, period=halocat.Lbox)