tpcf_jackknife¶

halotools.mock_observables.
tpcf_jackknife
(sample1, randoms, rbins, Nsub=[5, 5, 5], sample2=None, period=None, do_auto=True, do_cross=True, estimator=u'Natural', num_threads=1, seed=None)[source] [edit on github]¶ Calculate the twopoint correlation function, \(\xi(r)\) and the covariance matrix, \({C}_{ij}\), between ith and jth radial bin.
The covariance matrix is calculated using spatial jackknife sampling of the data volume. The spatial samples are defined by splitting the box along each dimension, N times, set by the
Nsub
argument.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
sample1
andsample2
arguments.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.randoms : array_like
Nran x 3 array containing 3D positions of randomly distributed points.
rbins : array_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.
Nsub : array_like, optional
Lenght3 numpy array of number of divisions along each dimension defining jackknife sample subvolumes. If single integer is given, it is assumed to be equivalent for each dimension. The total number of samples used is then given by numpy.prod(Nsub). Default is 5 divisions per dimension.
sample2 : array_like, optional
Npts2 x 3 array containing 3D positions of points. Passing
sample2
as an input permits the calculation of the crosscorrelation function. Default is None, in which case only the autocorrelation function will be calculated.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. If set to None (the default option), PBCs are set to infinity. Length units are comoving and assumed to be in Mpc/h, here and throughout Halotools.
do_auto : boolean, optional
Boolean determines whether the autocorrelation function will be calculated and returned. Default is True.
do_cross : boolean, optional
Boolean determines whether the crosscorrelation function will be calculated and returned. Only relevant when
sample2
is also provided. Default is True for the case wheresample2
is provided, otherwise False.estimator : string, optional
Statistical estimator for the tpcf. Options are ‘Natural’, ‘DavisPeebles’, ‘Hewett’ , ‘Hamilton’, ‘LandySzalay’ Default is ‘Natural’.
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.approx_cellran_size : array_like, optional
Analogous to
approx_cell1_size
, but for randoms. See comments forapprox_cell1_size
for details.seed : int, 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 correlation function \(\xi(r)\) computed in each of the radial bins defined by input
rbins
.If
sample2
is passed as input, three arrays of length len(rbins)1 are returned:\[\xi_{11}(r), \xi_{12}(r), \xi_{22}(r)\]The autocorrelation of
sample1
, the crosscorrelation betweensample1
andsample2
, and the autocorrelation ofsample2
. Ifdo_auto
ordo_cross
is set to False, the appropriate result(s) is not returned.cov_matrix(ices) : numpy.ndarray
len(rbins)1 by len(rbins)1 ndarray containing the covariance matrix \(C_{ij}\)
If
sample2
is passed as input three ndarrays of shape len(rbins)1 by len(rbins)1 are returned:\[C^{11}_{ij}, C^{12}_{ij}, C^{22}_{ij},\]the associated covariance matrices of \(\xi_{11}(r), \xi_{12}(r), \xi_{22}(r)\). If
do_auto
ordo_cross
is set to False, the appropriate result(s) is not returned.Notes
The jackknife sampling of pair counts is done internally in
npairs_jackknife_3d
.Pairs are counted such that when ‘removing’ subvolume \(k\), and counting a pair in subvolumes \(i\) and \(j\):
\[\begin{split}D_i D_j += \left \{ \begin{array}{ll} 1.0 & : i \neq k, j \neq k \\ 0.5 & : i \neq k, j=k \\ 0.5 & : i = k, j \neq k \\ 0.0 & : i=j=k \\ \end{array} \right.\end{split}\]Examples
For demonstration purposes we create a randomly distributed set of points within a periodic cube of box length Lbox = 250 Mpc/h.
>>> Npts = 1000 >>> Lbox = 100.
>>> x = np.random.uniform(0, Lbox, Npts) >>> y = np.random.uniform(0, Lbox, Npts) >>> z = np.random.uniform(0, Lbox, Npts)
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:>>> coords = np.vstack((x,y,z)).T
Create some ‘randoms’ in the same way:
>>> Nran = Npts*500 >>> xran = np.random.uniform(0, Lbox, Nran) >>> yran = np.random.uniform(0, Lbox, Nran) >>> zran = np.random.uniform(0, Lbox, Nran) >>> randoms = np.vstack((xran,yran,zran)).T
Calculate the jackknife covariance matrix by dividing the simulation box into 3 samples per dimension (for a total of 3^3 total jackknife samples):
>>> rbins = np.logspace(0.5, 1.5, 8) >>> xi, xi_cov = tpcf_jackknife(coords, randoms, rbins, Nsub=3, period=Lbox)