nbodykit.algorithms.fof.
DistributedArray
(local, comm)[source]¶Bases: object
Distributed Array Object
A distributed array is striped along ranks
comm
¶mpi4py.MPI.Comm
– the communicator
local
¶array_like – the local data
Methods
bincount ([local]) |
Assign count numbers from sorted local data. |
sort ([orderby]) |
Sort array globally by key orderby. |
unique_labels () |
Assign unique labels to sorted local. |
bincount
(local=False)[source]¶Assign count numbers from sorted local data.
Warning
local data must be sorted, and of integer type. (numpy.bincount)
Parameters: | local (boolean) – if local is True, only count the local array. |
---|---|
Returns: | N – distributed counts array. If items of the same value spans other chunks of array, they are added to N as well. |
Return type: | DistributedArray |
Examples
if the local array is [ (0, 0), (0, 1)], Then the counts array is [ (3, ), (3, 1)]
sort
(orderby=None)[source]¶Sort array globally by key orderby.
Due to a limitation of mpsort, self[orderby] must be u8.
unique_labels
()[source]¶Assign unique labels to sorted local.
Warning
local data must be sorted, and of simple type. (numpy.unique)
Returns: | label – the new labels, starting from 0 |
---|---|
Return type: | DistributedArray |
nbodykit.algorithms.fof.
FOF
(source, linking_length, nmin, absolute=False)[source]¶Bases: object
A friends-of-friends halo finder that computes the label for each particle, denoting which halo it belongs to.
Friends-of-friends 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 center-of-mass CMPosition , CMVelocity , and Length of each feature. |
run () |
Run the FOF algorithm. |
to_halos (particle_mass, cosmo, redshift[, …]) |
Return a HaloCatalog , holding the center-of-mass 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 center-of-mass 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 |
logger
= <logging.Logger object>¶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
¶array_like, length: size
– an array the label that specifies which FOF halo each particle
belongs to
max_label
¶int – the maximum label across all ranks; this represents the total number of FOF halos found
to_halos
(particle_mass, cosmo, redshift, mdef='vir', posdef='cm', peakcolumn='Density')[source]¶Return a HaloCatalog
, holding
the center-of-mass 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.
LinearTopology
(local, comm)[source]¶Bases: object
Helper object for the topology of a distributed array
Methods
heads () |
The first items on each rank. |
next () |
The item after the local data. |
prev () |
The item before the local data. |
tails () |
The last items on each rank. |
heads
()[source]¶The first items on each rank.
Returns: | heads – a list of first items, EmptyRank is used for empty ranks |
---|---|
Return type: | list |
next
()[source]¶The item after the local data.
This method the first item after the local data. If the rank after current rank is empty, item after that rank is used.
If no item is after local data, EmptyRank is returned.
Returns: | next – Item after local data, or EmptyRank if all ranks after this rank is empty. |
---|---|
Return type: | scalar |
prev
()[source]¶The item before the local data.
This method fetches the last item before the local data. If the rank before is empty, the rank before is used.
If no item is before this rank, EmptyRank is returned
Returns: | prev – Item before local data, or EmptyRank if all ranks before this rank is empty. |
---|---|
Return type: | scalar |
nbodykit.algorithms.fof.
centerofmass
(label, pos, boxsize=1.0, 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: |
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)[source]¶Run Friends-of-friends halo finder.
Friends-of-friends 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)[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 center-of-mass position and velocity in the same
units as the corresponding columns source
Parameters: |
|
---|---|
Returns: | catalog – A 1-d 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]