nbodykit.algorithms.pair_counters.simbox

Functions

shift_to_box_center(pos, BoxSize, comm) Find the bounds of the input position array, and if needed, shift the position to an observer at the box center.

Classes

SimulationBoxPairCount(mode, first, edges[, …]) Count (weighted) pairs of objects in a simulation box as a function of \(r\), \((r,\mu)\), \((r_p, \pi)\), or \(\theta\) using the Corrfunc package.
class nbodykit.algorithms.pair_counters.simbox.SimulationBoxPairCount(mode, first, edges, BoxSize=None, periodic=True, second=None, los='z', Nmu=None, pimax=None, weight='Weight', show_progress=False, **config)[source]

Count (weighted) pairs of objects in a simulation box as a function of \(r\), \((r,\mu)\), \((r_p, \pi)\), or \(\theta\) using the Corrfunc package.

See the Notes below for the allowed coordinate dimensions.

The default weighting scheme uses the product of the weights for each object in a pair.

Results are computed when the object is inititalized. See the documenation of run() for the attributes storing the results.

Note

The algorithm expects the positions of particles in a simulation box to be the Cartesian x, y, and z vectors. To compute pair counts on survey data, using right ascension, declination, and redshift, see SurveyDataPairCount.

Parameters:
  • mode ('1d', '2d', 'projected', 'angular') – compute pair counts as a function of the specified coordinate basis; see the Notes section below for specifics
  • first (CatalogSource) – the first source of particles, providing the ‘Position’ column
  • edges (array_like) – the separation bin edges along the first coordinate dimension; depending on mode, the options are \(r\), \(r_p\), or \(\theta\). Expected units for distances are \(\mathrm{Mpc}/h\) and degrees for angles. Length of nbins+1
  • BoxSize (float, 3-vector, optional) – the size of the box; if ‘BoxSize’ is not provided in the source ‘attrs’, it must be provided here
  • periodic (bool, optional) – whether to use periodic boundary conditions
  • second (CatalogSource, optional) – the second source of particles to cross-correlate
  • los ({'x', 'y', 'z'}, int, optional) – the axis of the simulation box to treat as the line-of-sight direction; this can be provided as string identifying one of ‘x’, ‘y’, ‘z’ or the equivalent integer number of the axis
  • Nmu (int, optional) – the number of \(\mu\) bins, ranging from 0 to 1; requred if mode='2d'
  • pimax (float, optional) – The maximum separation along the line-of-sight when mode='projected'. Distances along the \(\pi\) direction are binned with unit depth. For instance, if pimax=40, then 40 bins will be created along the \(\pi\) direction.
  • weight (str, optional) – the name of the column in the source specifying the particle weights
  • show_progress (bool, optional) – if True, perform the pair counting calculation in 10 iterations, logging the progress after each iteration; this is useful for understanding the scaling of the code
  • **config (key/value pairs) – additional keywords to pass to the Corrfunc function

Notes

This class can compute pair counts using several different coordinate choices, based on the value of the input argument mode. The choices are:

  • mode='1d' : compute pairs as a function of the 3D separation \(r\)
  • mode='2d' : compute pairs as a function of the 3D separation \(r\) and the cosine of the angle to the line-of-sight, \(\mu\)
  • mode='projected' : compute pairs as a function of distance perpendicular and parallel to the line-of-sight, \(r_p\) and \(\pi\)
  • mode='angular' : compute pairs as a function of angle on the sky, \(\theta\)

For angular pair counts, the observer is placed at the center of the box when converting Cartesian coordinates to angular coordinates on the unit sphere.

Methods

load(output[, comm]) Load a result has been saved to disk with save().
run() Calculate the pair counts in a simulation box.
save(output) Save result as a JSON file with name output
classmethod load(output, comm=None)

Load a result has been saved to disk with save().

run()[source]

Calculate the pair counts in a simulation box. This adds the following attributes to the class:

pairs

a BinnedStatistic object holding the pair count results. The coordinate grid will be (r,), (r,mu), (rp, pi), or (theta,) when mode is ‘1d’, ‘2d’, ‘projected’, ‘angular’, respectively.

The BinnedStatistic stores the following variables:

  • r, rp, or theta : the mean separation value in the bin
  • npairs: the number of pairs in the bin
  • wnpairs: the average weight value in the bin; each pair contributes the product of the individual weight values
Type:BinnedStatistic
save(output)

Save result as a JSON file with name output

nbodykit.algorithms.pair_counters.simbox.shift_to_box_center(pos, BoxSize, comm)[source]

Find the bounds of the input position array, and if needed, shift the position to an observer at the box center.

Position should be bounded by [0, BoxSize] or [-BoxSize/2, BoxSize/2]; if not, an exception will be raised.

Parameters:
  • pos (dask array) – the dask array holding the Position
  • BoxSize (array_like) – the size of the box
  • comm – the MPI communicator
Returns:

pos – the position array, shifted such that observer is in the box center

Return type:

dask array