nbodykit.algorithms.
FFTPower
(first, mode, Nmesh=None, BoxSize=None, second=None, los=[0, 0, 1], Nmu=5, dk=None, kmin=0.0, kmax=None, poles=[])[source]¶Algorithm to compute the 1d or 2d power spectrum and/or multipoles in a periodic box, using a Fast Fourier Transform (FFT).
This computes the power spectrum as the square of the Fourier modes of the density field, which are computed via a FFT.
Results are computed when the object is inititalized. See the documenation
of run()
for the attributes storing the results.
Note
A full tutorial on the class is available in the documentation here.
Parameters: 


Methods
load (output[, comm]) 
Load a saved result. 
run () 
Compute the power spectrum in a periodic box, using FFTs. 
save (output) 
Save the result to disk. 
load
(output, comm=None)¶Load a saved result. The result has been saved to disk with save()
.
run
()[source]¶Compute the power spectrum in a periodic box, using FFTs.
Returns: 


save
(output)¶Save the result to disk. The format is currently JSON.
nbodykit.algorithms.
ProjectedFFTPower
(first, Nmesh=None, BoxSize=None, second=None, axes=(0, 1), dk=None, kmin=0.0)[source]¶The power spectrum of a field in a periodic box, projected over certain axes.
This is not really always physically meaningful, but convenient for making sense of LymanAlpha forest or lensing maps.
This is usually called the 1d power spectrum or 2d power spectrum.
Results are computed when the object is inititalized. See the documenation
of run()
for the attributes storing the results.
Parameters: 


Methods
load (output[, comm]) 
Load a saved result. 
run () 
Run the algorithm. 
save (output) 
Save the result to disk. 
load
(output, comm=None)¶Load a saved result. The result has been saved to disk with save()
.
run
()[source]¶Run the algorithm. This attaches the following attributes to the class:
edges
¶the edges of the wavenumber bins
Type:  array_like 

power
¶a BinnedStatistic object that holds the projected power. It stores the following variables:
k
binType:  BinnedStatistic 

save
(output)¶Save the result to disk. The format is currently JSON.
nbodykit.algorithms.
FFTCorr
(first, mode, Nmesh=None, BoxSize=None, second=None, los=[0, 0, 1], Nmu=5, dr=None, rmin=0.0, rmax=None, poles=[])[source]¶Algorithm to compute the 1d or 2d correlation and/or multipoles in a periodic box, using a Fast Fourier Transform (FFT).
This computes the power spectrum as the square of the Fourier modes of the density field, which are computed via a FFT. Then it is transformed back to obtain the correlation function.
Results are computed when the object is inititalized. See the documenation
of run()
for the attributes storing the results.
Note
This is very similar to FFTPower
.
Parameters: 


Methods
load (output[, comm]) 
Load a saved result. 
run () 
Compute the correlation function in a periodic box, using FFTs. 
save (output) 
Save the result to disk. 
load
(output, comm=None)¶Load a saved result. The result has been saved to disk with save()
.
run
()[source]¶Compute the correlation function in a periodic box, using FFTs.
Returns: 


save
(output)¶Save the result to disk. The format is currently JSON.
nbodykit.algorithms.
ConvolvedFFTPower
(first, poles, second=None, Nmesh=None, kmin=0.0, kmax=None, dk=None, use_fkp_weights=None, P0_FKP=None)[source]¶Algorithm to compute power spectrum multipoles using FFTs for a data survey with nontrivial geometry.
Due to the geometry, the estimator computes the true power spectrum convolved with the window function (FFT of the geometry).
This estimator implemented in this class is described in detail in Hand et al. 2017 (arxiv:1704.02357). It uses the spherical harmonic addition theorem such that only \(2\ell+1\) FFTs are required to compute each multipole. This differs from the implementation in Bianchi et al. and Scoccimarro et al., which requires \((\ell+1)(\ell+2)/2\) FFTs.
Results are computed when the object is inititalized, and the result is
stored in the poles
attribute. Important metadata computed
during algorithm execution is stored in the attrs
dict. See the
documenation of run()
.
Note
A full tutorial on the class is available in the documentation here.
Note
Cross correlations are only supported when the FKP weight column
differs between the two mesh objects, i.e., the underlying data
and randoms
must be the same. This allows users to compute
the cross power spectrum of the same density field, weighted
differently.
Parameters: 


References
Methods
load (output[, comm, format]) 
Load a saved ConvolvedFFTPower result, which has been saved to disk with ConvolvedFFTPower.save() . 
normalization (name, alpha) 
Compute the power spectrum normalization, using either the data or randoms source. 
run () 
Compute the power spectrum multipoles. 
save (output) 
Save the ConvolvedFFTPower result to disk. 
shotnoise (alpha) 
Compute the power spectrum shot noise, using either the data or randoms source. 
to_pkmu (mu_edges, max_ell) 
Invert the measured multipoles \(P_\ell(k)\) into power spectrum wedges, \(P(k,\mu)\). 
__setstate_pre000305__
(state)[source]¶compatible version of setstate for files generated before 0.3.5
load
(output, comm=None, format='current')[source]¶Load a saved ConvolvedFFTPower result, which has been saved to
disk with ConvolvedFFTPower.save()
.
The current MPI communicator is automatically used
if the comm
keyword is None
format can be ‘current’, or ‘pre000305’ for files generated before 0.3.5.
normalization
(name, alpha)[source]¶Compute the power spectrum normalization, using either the
data
or randoms
source.
The normalization is given by:
The mean densities are assumed to be the same, so this can be converted to a summation over objects in the source, as
References
see Eqs. 13,14 of Beutler et al. 2014, “The clustering of galaxies in the SDSSIII Baryon Oscillation Spectroscopic Survey: testing gravity with redshift space distortions using the power spectrum multipoles”
run
()[source]¶Compute the power spectrum multipoles. This function does not return anything, but adds several attributes (see below).
edges
¶the edges of the wavenumber bins
Type:  array_like 

poles
¶a BinnedStatistic object that behaves similar to a structured array, with
fancy slicing and reindexing; it holds the measured multipole
results, as well as the number of modes (modes
) and average
wavenumbers values in each bin (k
)
Type:  BinnedStatistic 

attrs
¶dictionary holding input parameters and several important quantites computed during execution:
data.W
to randoms.W
data.shotnoise
+ randoms.shotnoise
; this should be subtracted from
the monopole.For further details on the metadata, see the documentation.
Type:  dict 

save
(output)[source]¶Save the ConvolvedFFTPower result to disk.
The format is currently json.
Parameters:  output (str) – the name of the file to dump the JSON results to 

shotnoise
(alpha)[source]¶Compute the power spectrum shot noise, using either the
data
or randoms
source.
This computes:
References
see Eq. 15 of Beutler et al. 2014, “The clustering of galaxies in the SDSSIII Baryon Oscillation Spectroscopic Survey: testing gravity with redshift space distortions using the power spectrum multipoles”
to_pkmu
(mu_edges, max_ell)[source]¶Invert the measured multipoles \(P_\ell(k)\) into power spectrum wedges, \(P(k,\mu)\).
Parameters: 


Returns:  pkmu – a data set holding the \(P(k,\mu)\) wedges 
Return type: 
nbodykit.algorithms.
FKPPower
¶alias of nbodykit.algorithms.convpower.fkp.ConvolvedFFTPower
nbodykit.algorithms.
FKPCatalog
(data, randoms, BoxSize=None, BoxPad=0.02, P0=None, nbar='NZ')[source]¶An interface for simultaneous modeling of a data
CatalogSource and a
randoms
CatalogSource, in the spirit of
Feldman, Kaiser, and Peacock, 1994.
This main functionality of this class is:
data
CatalogSource and randoms
CatalogSource, using
column names prefixed with “data/” or “randoms/”BoxSize
of the source, by
finding the maximum Cartesian extent of the randoms
data
and randoms
Parameters: 


References
Attributes: 


Methods
compute (*args, **kwargs) 
Our version of dask.compute() that computes multiple delayed dask collections at once. 
copy () 
Return a shallow copy of the object, where each column is a reference of the corresponding column in self . 
get_hardcolumn (col) 
Construct and return a hardcoded column. 
make_column (array) 
Utility function to convert an arraylike object to a dask.array.Array . 
read (columns) 
Return the requested columns as dask arrays. 
save (output, columns[, dataset, datasets, …]) 
Save the CatalogSource to a bigfile.BigFile . 
to_mesh ([Nmesh, BoxSize, BoxCenter, dtype, …]) 
Convert the FKPCatalog to a mesh, which knows how to “paint” the FKP density field. 
to_subvolumes ([domain, position, columns]) 
Domain Decompose a catalog, sending items to the ranks according to the supplied domain object. 
view ([type]) 
Return a “view” of the CatalogSource object, with the returned type set by type . 
create_instance 
__delitem__
(col)¶Delete a column of the form species/column
__finalize__
(other)¶Finalize the creation of a CatalogSource object by copying over any additional attributes from a second CatalogSource.
The idea here is to only copy over attributes that are similar
to metadata, so we do not copy some of the core attributes of the
CatalogSource
object.
Parameters:  other – the second object to copy over attributes from; it needs to be a subclass of CatalogSourcBase for attributes to be copied 

Returns:  return self , with the added attributes 
Return type:  CatalogSource 
__getitem__
(key)¶This provides access to the underlying data in two ways:
key
is a species name.species/column
.__setitem__
(col, value)¶Add columns to any of the species catalogs.
Note
New column names should be prefixed by ‘species/’ where
‘species’ is a name in the species
attribute.
attrs
¶A dictionary storing relevant metadata about the CatalogSource.
columns
¶Columns for individual species can be accessed using a species/
prefix and the column name, i.e., data/Position
.
compute
(*args, **kwargs)¶Our version of dask.compute()
that computes
multiple delayed dask collections at once.
This should be called on the return value of read()
to converts any dask arrays to numpy arrays.
base
attribute is set, compute()
will called using base
instead of self
.Parameters:  args (object) – Any number of objects. If the object is a dask collection, it’s computed and the result is returned. Otherwise it’s passed through unchanged. 

copy
()¶Return a shallow copy of the object, where each column is a reference
of the corresponding column in self
.
Note
No copy of data is made.
Note
This is different from view in that the attributes dictionary
of the copy no longer related to self
.
Returns:  a new CatalogSource that holds all of the data columns of self 

Return type:  CatalogSource 
get_hardcolumn
(col)¶Construct and return a hardcoded column.
These are usually produced by calling member functions marked by the
@column
decorator.
Subclasses may override this method and the hardcolumns attribute to bypass the decorator logic.
Note
If the base
attribute is set, get_hardcolumn()
will called using base
instead of self
.
hardcolumns
¶Hardcolumn of the form species/name
make_column
(array)¶Utility function to convert an arraylike object to a
dask.array.Array
.
Note
The dask array chunk size is controlled via the dask_chunk_size
global option. See set_options
.
Parameters:  array (array_like) – an arraylike object; can be a dask array, numpy array, ColumnAccessor, or other nonscalar arraylike object 

Returns:  a dask array initialized from array 
Return type:  dask.array.Array 
read
(columns)¶Return the requested columns as dask arrays.
Parameters:  columns (list of str) – the names of the requested columns 

Returns:  the list of column data, in the form of dask arrays 
Return type:  list of dask.array.Array 
save
(output, columns, dataset=None, datasets=None, header='Header')¶Save the CatalogSource to a bigfile.BigFile
.
Only the selected columns are saved and attrs
are saved in
header
. The attrs of columns are stored in the datasets.
Parameters: 


species
¶List of species names
to_mesh
(Nmesh=None, BoxSize=None, BoxCenter=None, dtype='f4', interlaced=False, compensated=False, resampler='cic', fkp_weight='FKPWeight', comp_weight='Weight', selection='Selection', position='Position', bbox_from_species=None, window=None, nbar=None)[source]¶Convert the FKPCatalog to a mesh, which knows how to “paint” the FKP density field.
Additional keywords to the to_mesh()
function include the
FKP weight column, completeness weight column, and the column
specifying the number density as a function of redshift.
Parameters: 


to_subvolumes
(domain=None, position='Position', columns=None)¶Domain Decompose a catalog, sending items to the ranks according to the supplied domain object. Using the position column as the Position.
This will read in the full position array and all of the requested columns.
Parameters: 


Returns:  A decomposed catalog source, where each rank only contains objects belongs to the rank as claimed by the domain object. self.attrs are carried over as a shallow copy to the returned object. 
Return type: 
view
(type=None)¶Return a “view” of the CatalogSource object, with the returned
type set by type
.
This initializes a new empty class of type type
and attaches
attributes to it via the __finalize__()
mechanism.
Parameters:  type (Python type) – the desired class type of the returned object. 

nbodykit.algorithms.
FKPWeightFromNbar
(P0, nbar)[source]¶Create FKPWeight from nbar, the number density of objects per redshift.
Parameters: 


Returns: 

nbodykit.algorithms.
FOF
(source, linking_length, nmin, absolute=False, periodic=True, domain_factor=1)[source]¶A friendsoffriends halo finder that computes the label for each particle, denoting which halo it belongs to.
Friendsoffriends was first used by Davis et al 1985 to define halos in hierachical structure formation of cosmological simulations. The algorithm is also known as DBSCAN in computer science. The subroutine here implements a parallel version of the FOF.
The underlying local FOF algorithm is from kdcount.cluster
,
which is an adaptation of the implementation in Volker Springel’s
Gadget and Martin White’s PM.
Results are computed when the object is inititalized. See the documenation
of run()
for the attributes storing the results.
For returning a CatalogSource of the FOF halos, see find_features()
and for computing a halo catalog with added analytic information for
a specific redshift and cosmology, see to_halos()
.
Parameters: 


Methods
find_features ([peakcolumn]) 
Based on the particle labels, identify the groups, and return the centerofmass CMPosition , CMVelocity , and Length of each feature. 
run () 
Run the FOF algorithm. 
to_halos (particle_mass, cosmo, redshift[, …]) 
Return a HaloCatalog , holding the centerofmass position and velocity of each FOF halo, as well as the properly scaled mass, for a given cosmology and redshift. 
find_features
(peakcolumn=None)[source]¶Based on the particle labels, identify the groups, and return
the centerofmass CMPosition
, CMVelocity
, and Length of each
feature.
If a peakcolumn
is given, the PeakPosition
and PeakVelocity
is also calculated for the particle at the peak value of the column.
Data is scattered evenly across all ranks.
Returns:  a source holding the (‘CMPosition’, ‘CMVelocity’, ‘Length’)
of each feature; optionaly, PeakPosition , PeakVelocity are
also included if peakcolumn is not None 

Return type:  ArrayCatalog 
run
()[source]¶Run the FOF algorithm. This function returns nothing, but does attach several attributes to the class instance:
max_labels
Note
The labels
array is scattered evenly across all ranks.
labels
¶an array the label that specifies which FOF halo each particle belongs to
Type:  array_like, length: size 

to_halos
(particle_mass, cosmo, redshift, mdef='vir', posdef='cm', peakcolumn='Density')[source]¶Return a HaloCatalog
, holding
the centerofmass position and velocity of each FOF halo, as well as
the properly scaled mass, for a given cosmology and redshift.
The returned catalog also has default analytic prescriptions for halo radius and concentration.
The data is scattered evenly across all ranks.
Parameters: 


Returns:  a HaloCatalog at the specified cosmology and redshift 
Return type: 
nbodykit.algorithms.
FiberCollisions
(ra, dec, collision_radius=0.017222222222222226, seed=None, degrees=True, comm=None)[source]¶Run an angular FOF algorithm to determine fiber collision groups from an input catalog, and then assign fibers such that the maximum amount of object receive a fiber.
This amounts to determining the following population of objects:
Results are computed when the object is inititalized. See the documenation
of run()
for the attributes storing the results.
Parameters: 


References
Methods
run () 
Run the fiber assignment algorithm. 
run
()[source]¶Run the fiber assignment algorithm. This attaches the following attribute to the object:
Note
The labels
attribute has a 1to1 correspondence with
the rows in the input source.
labels
¶a CatalogSource that has the following columns:
source
, else it is set to 1Type:  ArrayCatalog ; size: size 

nbodykit.algorithms.
CylindricalGroups
(source, rankby, rperp, rpar, flat_sky_los=None, periodic=False, BoxSize=None)[source]¶Compute groups of objects using a cylindrical grouping method. We identify all satellites within a given cylindrical volume around a central object.
Results are computed when the object is inititalized, and the result is
stored in the groups
attribute; see the documenation of
run()
.
Input parameters are stored in the attrs
attribute dictionary.
Parameters: 


References
Okumura, Teppei, et al. “Reconstruction of halo power spectrum from redshiftspace galaxy distribution: cylindergrouping method and halo exclusion effect”, arXiv:1611.04165, 2016.
Methods
run () 
Compute the cylindrical groups, saving the results to the groups attribute 
run
()[source]¶Compute the cylindrical groups, saving the results to the
groups
attribute
groups
¶a catalog holding the result of the grouping. The length of the
catalog is equal to the length of the input size, i.e., the length
is equal to the size
attribute. The relevant fields are:
Type:  ArrayCatalog 

nbodykit.algorithms.
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: 


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 lineofsight, \(\mu\)mode='projected'
: compute pairs as a function of distance perpendicular
and parallel to the lineofsight, \(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,)
when mode
is ‘1d’, ‘2d’, ‘projected’, ‘angular’,
respectively.
The BinnedStatistic stores the following variables:
r
, rp
, or theta
: 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 valuesType:  BinnedStatistic 

save
(output)¶Save result as a JSON file with name output
nbodykit.algorithms.
SurveyData2PCF
(mode, data1, randoms1, edges, cosmo=None, Nmu=None, pimax=None, data2=None, randoms2=None, R1R2=None, ra='RA', dec='DEC', redshift='Redshift', weight='Weight', show_progress=False, **config)[source]¶Compute the twopoint correlation function for observational survey data as a function of \(r\), \((r,\mu)\), \((r_p, \pi)\), or \(\theta\) using pair counting.
The LandySzalay estimator (DD/RR  2 DD/RR + 1) is used to transform pair counts in to the correlation function.
Parameters: 


Notes
This class can compute correlation functions 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 lineofsight, \(\mu\)mode='projected'
: compute pairs as a function of distance perpendicular
and parallel to the lineofsight, \(r_p\) and \(\pi\)mode='angular'
: compute pairs as a function of angle on the sky, \(\theta\)If mode='projected'
, the projected correlation function \(w_p(r_p)\)
is also computed, using the input \(\pi_\mathrm{max}\) value.
Methods
load (output[, comm]) 
Load a result has been saved to disk with save() . 
run () 
Run the twopoint correlation function algorithm. 
save (output) 
Save result as a JSON file with name output 
run
()[source]¶Run the twopoint correlation function algorithm. This attaches the following attributes:
SurveyData2PCF.D1D2
SurveyData2PCF.D1R2
SurveyData2PCF.D2R1
SurveyData2PCF.R1R2
SurveyData2PCF.corr
SurveyData2PCF.wp
(if mode='projected'
)D1D2
¶the data1  data2 pair counts
Type:  BinnedStatistic 

D1R2
¶the data1  randoms2 pair counts
Type:  BinnedStatistic 

D2R1
¶the data2  randoms1 pair counts
Type:  BinnedStatistic 

R1R2
¶the randoms1  randoms2 pair counts
Type:  BinnedStatistic 

corr
¶the correlation function values, stored as the corr
variable,
computed from the pair counts
Type:  BinnedStatistic 

wp
¶the projected correlation function, \(w_p(r_p)\), computed
if mode='projected'
; correlation is stored as the corr
variable
Type:  BinnedStatistic 

Notes
The D1D2
, D1R2
, D2R1
, and R1R2
attributes are identical to the
pairs
attribute
of SurveyDataPairCount
.
save
(output)¶Save result as a JSON file with name output
nbodykit.algorithms.
SurveyData3PCF
(source, poles, edges, cosmo, domain_factor=4, ra='RA', dec='DEC', redshift='Redshift', weight='Weight')[source]¶Compute the multipoles of the isotropic, threepoint correlation function in configuration space for observational survey data.
This uses the algorithm of Slepian and Eisenstein, 2015 which scales as \(\mathcal{O}(N^2)\), where \(N\) is the number of objects.
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 objects from a survey catalog
be the sky coordinates, right ascension and declination, and redshift.
For simulation box data in Cartesian coordinates, see
SimulationBox3PCF
.
Warning
The right ascension and declination columns should be specified in degrees.
Parameters: 


References
Slepian and Eisenstein, MNRAS 454, 41424158 (2015)
Methods
load (filename[, comm]) 
Load a result from filename that has been saved to disk with save() . 
run () 
Compute the threepoint CF multipoles. 
save (output) 
Save the poles result to a JSON file with name output . 
load
(filename, comm=None)¶Load a result from filename
that has been saved to
disk with save()
.
run
()[source]¶Compute the threepoint CF multipoles. This attaches the following the attributes to the class:
poles
¶a BinnedStatistic object to hold the multipole results; the
binned statistics stores the multipoles as variables corr_0
,
corr_1
, etc for \(\ell=0,1,\) etc. The coordinates
of the binned statistic are r1
and r2
, which give the
separations between the three objects in CF.
Type:  BinnedStatistic 

nbodykit.algorithms.
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: 


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 lineofsight, \(\mu\)mode='projected'
: compute pairs as a function of distance perpendicular
and parallel to the lineofsight, \(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,)
when mode
is ‘1d’, ‘2d’, ‘projected’, ‘angular’,
respectively.
The BinnedStatistic stores the following variables:
r
, rp
, or theta
: 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 valuesType:  BinnedStatistic 

save
(output)¶Save result as a JSON file with name output
nbodykit.algorithms.
SimulationBox2PCF
(mode, data1, edges, Nmu=None, pimax=None, data2=None, randoms1=None, randoms2=None, R1R2=None, periodic=True, BoxSize=None, los='z', weight='Weight', show_progress=False, **config)[source]¶Compute the twopoint correlation function for data in a simulation box as a function of \(r\), \((r,\mu)\), \((r_p, \pi)\), or \(\theta\) using pair counting.
This uses analytic randoms when using periodic conditions, unless a randoms catalog is specified. The “natural” estimator (DD/RR1) is used in the former case, and the LandySzalay estimator (DD/RR  2DR/RR + 1) in the latter case.
Note
When using analytic randoms, the expected counts are assumed to be unweighted.
Parameters: 


Notes
This class can compute correlation functions 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 lineofsight, \(\mu\)mode='projected'
: compute pairs as a function of distance perpendicular
and parallel to the lineofsight, \(r_p\) and \(\pi\)mode='angular'
: compute pairs as a function of angle on the sky, \(\theta\)If mode='projected'
, the projected correlation function \(w_p(r_p)\)
is also computed, using the input \(\pi_\mathrm{max}\) value.
Methods
load (output[, comm]) 
Load a result has been saved to disk with save() . 
run () 
Run the twopoint correlation function algorithm. 
save (output) 
Save result as a JSON file with name output 
run
()[source]¶Run the twopoint correlation function algorithm. This attaches the following attributes:
SimulationBox2PCF.D1D2
SimulationBox2PCF.D1R2
SimulationBox2PCF.D2R1
SimulationBox2PCF.R1R2
SimulationBox2PCF.corr
SimulationBox2PCF.wp
(if mode='projected'
)D1D2
¶the data1  data2 pair counts
Type:  BinnedStatistic 

D1R2
¶the data1  randoms2 pair counts
Type:  BinnedStatistic 

D2R1
¶the data2  randoms1 pair counts
Type:  BinnedStatistic 

R1R2
¶the randoms1  randoms2 pair counts
Type:  BinnedStatistic 

corr
¶the correlation function values, stored as the corr
variable,
computed from the pair counts
Type:  BinnedStatistic 

wp
¶the projected correlation function, \(w_p(r_p)\), computed
if mode='projected'
; correlation is stored as the corr
variable
Type:  BinnedStatistic 

Notes
The D1D2
, D1R2
, D2R1
, and R1R2
attributes are identical to the
pairs
attribute
of SimulationBoxPairCount
.
save
(output)¶Save result as a JSON file with name output
nbodykit.algorithms.
SimulationBox3PCF
(source, poles, edges, BoxSize=None, periodic=True, weight='Weight')[source]¶Compute the multipoles of the isotropic, threepoint correlation function in configuration space for data in a simulation box.
This uses the algorithm of Slepian and Eisenstein, 2015 which scales as \(\mathcal{O}(N^2)\), where \(N\) is the number of objects.
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 objects in a simulation box to
be the Cartesian x
, y
, and z
vectors. For survey data,
in the form of right ascension, declination, and
redshift, see SurveyData3PCF
.
Parameters: 


References
Slepian and Eisenstein, MNRAS 454, 41424158 (2015)
Methods
load (filename[, comm]) 
Load a result from filename that has been saved to disk with save() . 
run ([pedantic]) 
Compute the threepoint CF multipoles. 
save (output) 
Save the poles result to a JSON file with name output . 
load
(filename, comm=None)¶Load a result from filename
that has been saved to
disk with save()
.
run
(pedantic=False)[source]¶Compute the threepoint CF multipoles. This attaches the following the attributes to the class:
poles
¶a BinnedStatistic object to hold the multipole results; the
binned statistics stores the multipoles as variables corr_0
,
corr_1
, etc for \(\ell=0,1,\) etc. The coordinates
of the binned statistic are r1
and r2
, which give the
separations between the three objects in CF.
Type:  BinnedStatistic 

nbodykit.algorithms.
KDDensity
(source, margin=1.0)[source]¶Estimate a proxy density based on the distance to the nearest neighbor. The result is proportional to the density but the scale is unspecified.
Results are computed when the object is inititalized. See the documenation
of run()
for the attributes storing the results.
Parameters: 


Methods
run () 
Compute the density proxy. 
nbodykit.algorithms.
RedshiftHistogram
(source, fsky, cosmo, bins=None, redshift='Redshift', weight=None)[source]¶Compute the mean number density as a function of redshift \(n(z)\) from an input CatalogSource of particles.
Results are computed when the object is inititalized. See the documenation
of run()
for the attributes storing the results.
Note
The units of the number density are \((\mathrm{Mpc}/h)^{3}\)
Parameters: 


Methods
interpolate (z) 
Interpoalte dndz as a function of redshift. 
load (output[, comm]) 
Load a saved RedshiftHistogram result. 
run () 
Run the algorithm, which computes the histogram. 
save (output) 
Save the RedshiftHistogram result to disk. 
interpolate
(z)[source]¶Interpoalte dndz as a function of redshift.
The interpolation acts as a band pass filter, removing small scale fluctuations in the estimator.
Returns:  n 

Return type:  n(z) 
load
(output, comm=None)[source]¶Load a saved RedshiftHistogram result.
The result has been saved to disk with RedshiftHistogram.save()
.
run
()[source]¶Run the algorithm, which computes the histogram. This function does not return anything, but adds the following attributes to the class:
Note
All ranks store the same result attributes.
bin_edges
¶the edges of the redshift bins
Type:  array_like 

bin_centers
¶the center values of each redshift bin
Type:  array_like 

dV
¶the volume of each redshift shell in units of \((\mathrm{Mpc}/h)^3\)
Type:  array_like 

nbar
¶the values of the redshift histogram, normalized to number density (in units of \((\mathrm{Mpc}/h)^{3}\))
Type:  array_like 

nbodykit.algorithms.
FFTRecon
(data, ran, Nmesh, bias=1.0, f=0.0, los=[0, 0, 1], R=20, position='Position', revert_rsd_random=False, scheme='LGS', BoxSize=None)[source]¶FFT based Lagrangian reconstruction algorithm in a periodic box.
References
Eisenstein et al, 2007 http://adsabs.harvard.edu/abs/2007ApJ…664..675E Section 3, paragraph starting with ‘Restoring in full the …’
We follow a cleaner description in Schmitfull et al 2015,
Table I, and text below. Schemes are LGS, LF2 and LRR.
A slight difference against the paper is that Redshift distortion and bias are corrected in the linear order. The Random shifting followed Martin White’s suggestion to exclude the RSD by default. (with default revert_rsd_random=False.)
Parameters: 


Attributes: 
Methods
apply (func[, kind, mode]) 
Return a view of the mesh, with actions updated to apply the specified function, either in Fourier space or configuration space, based on mode 
compute ([mode, Nmesh]) 
Compute / Fetch the mesh object into memory as a RealField or ComplexField object. 
preview ([axes, Nmesh, root]) 
Gather the mesh into as a numpy array, with (reduced) resolution. 
save (output[, dataset, mode]) 
Save the mesh as a BigFileMesh on disk, either in real or complex space. 
to_complex_field ([out]) 
Convert the mesh source to the Fourierspace field, returning a pmesh.pm.ComplexField object. 
to_field ([mode, out]) 
Return the mesh as a pmesh Field object, either in Fourier space or configuration space, based on mode . 
to_real_field () 
Convert the mesh source to the configurationspace field, returning a pmesh.pm.RealField object. 
view () 
Return a “view” of the MeshSource, in the spirit of numpy’s ndarray view. 
paint  
run  
work_with 
__finalize__
(other)¶Finalize the creation of a MeshSource object by copying over attributes from a second MeshSource.
Parameters:  other (MeshSource) – the second MeshSource to copy over attributes from 

__len__
()¶Length of a mesh source is zero
actions
¶A list of actions to apply to the density field when interpolating to the mesh.
This stores tuples of (mode, func, kind)
; see apply()
for more details.
apply
(func, kind='wavenumber', mode='complex')¶Return a view of the mesh, with actions
updated to
apply the specified function, either in Fourier space or
configuration space, based on mode
Parameters: 


Returns:  a view of the mesh object with the 
Return type: 
attrs
¶A dictionary storing relevant metadata about the CatalogSource.
compute
(mode='real', Nmesh=None)¶Compute / Fetch the mesh object into memory as a RealField or ComplexField object.
preview
(axes=None, Nmesh=None, root=0)¶Gather the mesh into as a numpy array, with (reduced) resolution. The result is broadcast to all ranks, so this uses \(\mathrm{Nmesh}^3\) per rank.
Parameters:  

Returns:  out – An numpy array holding the real density field. 
Return type:  array_like 
save
(output, dataset='Field', mode='real')¶Save the mesh as a BigFileMesh
on disk, either in real or complex space.
Parameters: 

to_complex_field
(out=None)¶Convert the mesh source to the Fourierspace field,
returning a pmesh.pm.ComplexField
object.
Not implemented in the base class, unless object is a view.
to_field
(mode='real', out=None)¶Return the mesh as a pmesh
Field object, either in Fourier
space or configuration space, based on mode
.
This will call to_real_field()
or to_complex_field()
based on mode
.
Parameters:  mode ('real' or 'complex') – the return type of the field 

Returns:  either a RealField of ComplexField, storing the value of the field on the mesh 
Return type:  RealField , ComplexField 
to_real_field
()[source]¶Convert the mesh source to the configurationspace field,
returning a pmesh.pm.RealField
object.
Not implemented in the base class, unless object is a view.
view
()¶Return a “view” of the MeshSource, in the spirit of numpy’s ndarray view.
This returns a new MeshSource whose memory is owned by self
.
Note that for CatalogMesh objects, this is overidden by the
CatalogSource.view
function.