Functions
centerofmass (label, pos, boxsize[, comm]) 
Calulate the center of mass of particles of the same label. 
count (label[, comm]) 
Count the number of particles of the same label. 
equiv_class (labels, values, op[, …]) 
apply operation to equivalent classes by label, on values 
fof (source, linking_length, comm, periodic, …) 
Run Friendsoffriends halo finder. 
fof_catalog (source, label, comm[, position, …]) 
Catalog of FOF groups based on label from a parent source 
fof_find_peaks (source, label, comm[, …]) 
Find position of the peak (maximum) from a given column for a fof result. 
replacesorted (arr, sorted, b[, out]) 
replace a with corresponding b in arr 
Classes
FOF (source, linking_length, nmin[, …]) 
A friendsoffriends halo finder that computes the label for each particle, denoting which halo it belongs to. 
nbodykit.algorithms.fof.
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.fof.
centerofmass
(label, pos, boxsize, comm=<mpi4py.MPI.Intracomm object>)[source]¶Calulate the center of mass of particles of the same label.
The center of mass is defined as the mean of positions of particles, but care has to be taken regarding to the periodic boundary.
This is a collective operation, and after the call, all ranks will have the position of halos.
Parameters:  

Returns:  hpos – the center of mass position of the halos. 
Return type:  array_like (float, 3) 
nbodykit.algorithms.fof.
count
(label, comm=<mpi4py.MPI.Intracomm object>)[source]¶Count the number of particles of the same label.
This is a collective operation, and after the call, all ranks will have the particle count.
Parameters: 


Returns:  count – the count of number of particles in each halo 
Return type:  array_like 
nbodykit.algorithms.fof.
equiv_class
(labels, values, op, dense_labels=False, identity=None, minlength=None)[source]¶apply operation to equivalent classes by label, on values
Parameters: 


Returns:  the value of each equivalent class 
Return type:  result 
Examples
>>> x = numpy.arange(10)
>>> print equiv_class(x, x, numpy.fmin, dense_labels=True)
[0 1 2 3 4 5 6 7 8 9]
>>> x = numpy.arange(10)
>>> v = numpy.arange(20).reshape(10, 2)
>>> x[1] = 0
>>> print equiv_class(x, 1.0 * v, numpy.fmin, dense_labels=True, identity=numpy.inf)
[[ 0. 1.]
[ inf inf]
[ 4. 5.]
[ 6. 7.]
[ 8. 9.]
[ 10. 11.]
[ 12. 13.]
[ 14. 15.]
[ 16. 17.]
[ 18. 19.]]
nbodykit.algorithms.fof.
fof
(source, linking_length, comm, periodic, domain_factor, logger)[source]¶Run Friendsoffriends halo finder.
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. It could have been done faster.
Parameters: 


Returns:  minid – A unique label of each position. The label is not ranged from 0. 
Return type:  array_like 
nbodykit.algorithms.fof.
fof_catalog
(source, label, comm, position='Position', velocity='Velocity', initposition='InitialPosition', peakcolumn=None, periodic=True)[source]¶Catalog of FOF groups based on label from a parent source
This is a collective operation – the returned halo catalog will be equally distributed across all ranks
Notes
This computes the centerofmass position and velocity in the same
units as the corresponding columns source
Parameters: 


Returns:  catalog – A 1d array of type ‘Position’, ‘Velocity’, ‘Length’.
The center mass position and velocity of the FOF halo, and
Length is the number of particles in a halo. The catalog is
sorted such that the most massive halo is first. 
Return type:  array_like 
nbodykit.algorithms.fof.
fof_find_peaks
(source, label, comm, position='Position', column='Density')[source]¶Find position of the peak (maximum) from a given column for a fof result.
nbodykit.algorithms.fof.
replacesorted
(arr, sorted, b, out=None)[source]¶replace a with corresponding b in arr
Parameters: 


Examples
>>> print replacesorted(numpy.arange(10), numpy.arange(5), numpy.ones(5))
[1 1 1 1 1 5 6 7 8 9]