nbodykit.algorithms.pair_counters¶
- class nbodykit.algorithms.pair_counters.SimulationBoxPairCount(mode, first, edges, BoxSize=None, periodic=True, second=None, los='z', Nmu=None, pimax=None, weight='Weight', position='Position', 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
, andz
vectors. To compute pair counts on survey data, using right ascension, declination, and redshift, seeSurveyDataPairCount
.- 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+1BoxSize (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, ifpimax=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
position (str, optional) – name of the column of the position of particles
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
- 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,)
whenmode
is ‘1d’, ‘2d’, ‘projected’, ‘angular’, respectively.The BinnedStatistic stores the following variables:
r
,rp
, ortheta
: the mean separation value in the binnpairs
: the number of pairs in the binwnpairs
: the average weight value in the bin; each pair contributes the product of the individual weight values
- Type
- save(output)¶
Save result as a JSON file with name
output
- class nbodykit.algorithms.pair_counters.SurveyDataPairCount(mode, first, edges, cosmo=None, second=None, Nmu=None, pimax=None, ra='RA', dec='DEC', redshift='Redshift', weight='Weight', show_progress=False, domain_factor=4, **config)[source]¶
Count (weighted) pairs of objects from a survey data catalog 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 class is inititalized. See the documenation of
run()
for the attributes storing the results.Note
The algorithm expects the positions of particles from a survey catalog be the sky coordinates, right ascension and declination, and redshift. To compute pair counts in a simulation box using Cartesian coordinates, see
SimulationBoxPairCount
.Warning
The right ascension and declination columns should be specified in degrees.
- 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+1cosmo (
Cosmology
, optional) – the cosmology instance used to convert redshift into comoving distance; this is required for all cases exceptmode='angular'
second (CatalogSource, optional) – the second source of particles to cross-correlate
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, ifpimax=40
, then 40 bins will be created along the \(\pi\) direction.ra (str, optional) – the name of the column in the source specifying the right ascension coordinates in units of degrees; default is ‘RA’
dec (str, optional) – the name of the column in the source specifying the declination coordinates; default is ‘DEC’
redshift (str, optional) – the name of the column in the source specifying the redshift coordinates; default is ‘Redshift’
weight (str, optional) – the name of the column in the source specifying the object 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 codedomain_factor (int, optional) – the integer value by which to oversubscribe the domain decomposition mesh before balancing loads; this number can affect the distribution of loads on the ranks – an optimal value will lead to balanced loads
**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\)
Methods
load
(output[, comm])Load a result has been saved to disk with
save()
.run
()Calculate the pair counts of a survey data catalog.
save
(output)Save result as a JSON file with name
output
- run()[source]¶
Calculate the pair counts of a survey data catalog. This adds the following attribute:
self.pairs.attrs[‘total_wnpairs’]: The total of wnpairs.
- pairs¶
a BinnedStatistic object holding the pair count results. The coordinate grid will be
(r,)
,(r,mu)
,(rp, pi)
, or(theta,)
whenmode
is ‘1d’, ‘2d’, ‘projected’, ‘angular’, respectively.The BinnedStatistic stores the following variables:
r
,rp
, ortheta
: the mean separation value in the binnpairs
: the number of pairs in the binwnpairs
: the weighted npairs in the bin; each pair contributes the product of the individual weight values
- Type
- save(output)¶
Save result as a JSON file with name
output