Centering methods

class pNbody._centering_mixin._CenteringNbodyMixin

Bases: object

Mixin class providing sophisticated centering algorithms for N-body models.

This mixin extends the Nbody class with methods to identify and shift the coordinate system based on various physical centers, such as the center of mass, potential minima, or density peaks.

The methods are divided into ‘get’ methods (which return coordinates) and ‘action’ methods (which apply a translation to the object).

Notes

The centering algorithms supported include:

  • Center of Mass (CM): Standard mass-weighted average.

  • Potential Minimum: Identifies the “bottom” of the potential well using a tree-code calculation.

  • Shrinking Sphere: An iterative approach that converges on the densest region (Power et al. 2003).

  • Histogram (1D/3D): Identifies density peaks by binning particles into grids or Cloud-In-Cell maps.

  • Velocity Center: Centers the frame of reference on the bulk motion of the system.

See also

pNbody.main.Nbody

The main class that consumes this mixin.

center(ptype=None, method='potcenter', r_max=None, center=array([0., 0., 0.]), **kwargs)

Center the model according to the chosen algorithm.

Calculates the center using get_center and translates the entire N-body system so that this point becomes the new origin (0, 0, 0).

The following centring modes are available:

  • potential: potential minimim

  • cm: center of mass

  • shrinking_sphere: shrinking sphere method

  • hist1D: density maximum using 3 independent 1D histogram in the x,y

    and z axes

  • hist3D: density maximum with a 3D histogram

  • velocity: centers the velocity on the XXX

Parameters
  • ptype (int or list, optional) – Particle type(s) used to identify the center.

  • method ({'potcenter', 'cm', 'shrinking_sphere'}, default 'potcenter') – The algorithm used to find the center.

  • r_max (float, optional) – Maximum radius to consider for the calculation.

  • center (array_like, optional) – The reference point used if r_max is specified. Defaults to [0, 0, 0].

See also

cmcenter

Center on the center of mass.

potcenter

Center on the potential minimum.

histocenter

Center on the maximal density center using 1D histograms.

histocenter3D

center on the maximal density center using a 3D histogram.

cvcenter

Center the velocities on the velocity center of mass.

cmcenter(ptype=None, r_max=None, center=array([0., 0., 0.]))

Center the model based on the center of mass.

Translates the entire N-body object so that the center of mass (calculated within r_max if provided) is moved to the origin (0, 0, 0).

Parameters
  • ptype (int or list, optional) – Particle type(s) used to identify the center of mass minimum.

  • r_max (float, optional) – Maximum radius to consider for the center of mass calculation.

  • center (array_like, optional) – The reference point used for the r_max selection. Defaults to [0, 0, 0].

See also

potcenter

Center on the potential minimum.

histocenter

Center on the maximal density center using 1D histograms.

histocenter3D

center on the maximal density center using a 3D histogram.

cvcenter

Center the velocities on the velocity center of mass.

cvcenter(ptype=None, r_max=None, center=array([0., 0., 0.]))

Center the velocities on the velocity center of mass.

Parameters
  • ptype (int or list, optional) – Particle type(s) used to identify the center of mass minimum.

  • r_max (float, optional) – Maximum radius, in positions space, from the provided center to consider for the calculation.

  • center (array_like, optional) – The reference point (x, y, z) used if r_max is specified. Defaults to [0, 0, 0].

Returns

A 3D array [x, y, z] representing the velocity center of mass coordinates.

Return type

ndarray

See also

cm

Get the center of mass.

get_potcenter

Get the potential minimum.

get_histocenter

Get the maximal density center using 1D histograms.

get_histocenter3D

Get the maximal density center using 3D histogram.

get_center_shrinking_sphere

Get the center using shrinking sphere.

cv

Get the center of mass velocity.

get_center(ptype=None, method='potential', r_max=None, center=array([0., 0., 0.]), **kwargs)

Calculate the center of the model using a specified centering method.

The following centring modes are available:

  • potential: potential minimim

  • cm: center of mass

  • shrinking_sphere: shrinking sphere method

  • hist1D: density maximum using 3 independent 1D histogram in the x,y

    and z axes

  • hist3D: density maximum with a 3D histogram

  • velocity: centers the velocity on the XXX

Parameters
  • ptype (int or list, optional) – Particle type(s) to consider for the selection. If None, all particles are used.

  • method ({'potential', 'cm', 'shrinking_sphere'}, default 'potcenter') – The algorithm used to find the center.

  • r_max (float, optional) – Maximum radius from the provided center to consider.

  • center (array_like, optional) – The reference point used if r_max is specified. Defaults to [0, 0, 0].

Returns

The 3D coordinates (x, y, z) of the calculated center.

Return type

ndarray

Raises

ValueError – If the requested method is not recognized.

See also

cm

Get the center of mass.

get_potcenter

Get the potential minimum.

get_histocenter

Get the maximal density center using 1D histograms.

get_histocenter3D

Get the maximal density center using 3D histogram.

get_center_shrinking_sphere

Get the center using shrinking sphere.

cv

Get the center of mass velocity.

get_center_shrinking_sphere(ptype=None, r_max=None, center=array([0., 0., 0.]), shrink_factor=0.95, min_particles=100, r_min=0.01)

Calculate the center of the system using the shrinking sphere method of Power et al (2003).

Parameters
  • ptype (int or list, optional) – Particle type(s) used to identify the center of mass minimum.

  • r_max (float, optional) – The initial radius to consider. If None, uses the maximum distance from the current origin.

  • shrink_factor (float, optional) – The factor by which the radius is reduced at each step (0.95 = 5% shrink).

  • min_particles (int, optional) – The iteration stops if the number of particles falls below this value.

  • r_min (float, optional) – The iteration stops if the radius becomes smaller than this value.

Returns

center – The 3D coordinates (x, y, z) of the calculated center.

Return type

ndarray

See also

cm

Get the center of mass.

get_potcenter

Get the potential minimum.

get_histocenter

Get the maximal density center using 1D histograms.

get_histocenter3D

Get the maximal density center using 3D histogram.

cv

Get the center of mass velocity.

get_histocenter(ptype=None, r_max=None, center=None, rbox=50, nb=500, fromBoxSize=False)

Identify the highest density region using 1D density histograms.

Parameters
  • ptype (int or list, optional) – Particle type(s) used to identify the density maximum.

  • r_max (float, optional) – Maximum radius from the input center to search.

  • center (array_like, optional) – Reference coordinates for the search. Defaults to [0, 0, 0].

  • rbox (float, default 50) – Physical size of the search box.

  • nb (int, default 500) – Number of bins in each dimension.

  • fromBoxSize (bool, default False) – If True, use the global boxsize for histogram limits.

Returns

center_coords – The [x, y, z] coordinates of the density peak.

Return type

numpy.ndarray

See also

cm

Get the center of mass.

get_potcenter

Get the potential minimum.

get_histocenter3D

Get the maximal density center using 3D histogram.

get_center_shrinking_sphere

Get the center using shrinking sphere.

cv

Get the velocity center of mass.

get_histocenter2(rbox=50, nb=64)

Return the position of the higher density region in x,y,z (not good) found by the function “histocenter”.

rbox : size of the box nb : number of bins in each dimension

get_histocenter3D(ptype=None, r_max=None, center=None, rbox=50, nb=256, fromBoxSize=False)

Identify the highest density region in 3D using Cloud-In-Cell mapping.

Note this method is computationnaly more expensive than get_histocenter() as it requires a 3D grid with nb bins.

Parameters
  • ptype (int or list, optional) – Particle type(s) used to build the density map.

  • r_max (float, optional) – Maximum radius from the input center to consider particles.

  • center (array_like, optional) – Reference coordinates for the search and box center. Defaults to [0, 0, 0].

  • rbox (float, default 50) – Physical side length of the cubic 3D grid.

  • nb (int, default 256) – Number of grid cells in each dimension.

  • fromBoxSize (bool, default False) – If True, center on the simulation box and set rbox to the box size.

Returns

center_coords – The [x, y, z] coordinates of the 3D density peak.

Return type

numpy.ndarray

See also

cm

Get the center of mass.

get_potcenter

Get the potential minimum.

get_histocenter3D

Get the maximal density center using 3D histogram.

get_center_shrinking_sphere

Get the center using shrinking sphere.

cv

Get the velocity center of mass.

get_potcenter(ptype=None, eps=0.1, force=False, r_max=None, center=array([0., 0., 0.]))

Return the center defined as the position of the particle with the minimum potential.

Parameters
  • ptype (int or list, optional) – Particle type(s) to consider for the selection. If None, all particles are used.

  • eps (float, default 0.1) – Softening length used for the potential calculation in the tree code.

  • force (bool, default False) – If True, recalculate the potential even if it already exists in the object.

  • r_max (float, optional) – Maximum radius from the provided center to consider for the calculation.

  • center (array_like, default [0, 0, 0]) – The origin point (x, y, z) used for the r_max selection. Defaults to [0, 0, 0].

Returns

The 3D coordinates (x, y, z) of the particle with the minimum potential within the selection.

Return type

ndarray

See also

cm

Get the center of mass.

get_histocenter

Get the maximal density center using 1D histograms.

get_histocenter3D

Get the maximal density center using 3D histogram.

get_center_shrinking_sphere

Get the center using shrinking sphere.

cv

Get the center of mass velocity.

hdcenter()

Move the N-body object in order to center the higher density region found.

histocenter(ptype=None, r_max=None, center=array([0., 0., 0.]), rbox=50, nb=500, fromBoxSize=False)

Translate the N-body object to center on the highest density region.

This method using 1D density histograms in the x,y and z axes.

Parameters
  • ptype (int or list, optional) – Particle type(s) used to identify the density maximum.

  • r_max (float, optional) – Maximum radius from the input center to search.

  • center (array_like, optional) – Reference coordinates for the search. Defaults to [0, 0, 0].

  • rbox (float, default 50) – Physical size of the search box.

  • nb (int, default 500) – Number of bins in each dimension.

  • fromBoxSize (bool, default False) – If True, use the global boxsize for histogram limits.

Returns

center_coords – The [x, y, z] coordinates of the density peak.

Return type

numpy.ndarray

See also

cmcenter

Center on the center of mass.

potcenter

Center on the potential minimum.

histocenter3D

center on the maximal density center using a 3D histogram.

cvcenter

Center the velocities on the velocity center of mass.

histocenter2(rbox=50, nb=64)

Move the N-body object in order to center the higher density region found near the mass center. The higher density region is determined whith density histograms.

rbox : box dimension, where to compute the histograms nb : number of bins for the histograms

histocenter3D(ptype=None, r_max=None, center=array([0., 0., 0.]), rbox=50, nb=500, fromBoxSize=False)

Translate the N-body object to center on the highest density region.

This method using 1D density histograms in the x,y and z axes.

Parameters
  • ptype (int or list, optional) – Particle type(s) used to identify the density maximum.

  • r_max (float, optional) – Maximum radius from the input center to search.

  • center (array_like, optional) – Reference coordinates for the search. Defaults to [0, 0, 0].

  • rbox (float, default 50) – Physical size of the search box.

  • nb (int, default 500) – Number of bins in each dimension.

  • fromBoxSize (bool, default False) – If True, use the global boxsize for histogram limits.

Returns

center_coords – The [x, y, z] coordinates of the density peak.

Return type

numpy.ndarray

See also

cmcenter

Center on the center of mass.

potcenter

Center on the potential minimum.

histocenter

Center on the maximal density center using 1D histograms.

cvcenter

Center the velocities on the velocity center of mass.

potcenter(ptype=None, eps=0.1, r_max=None, center=array([0., 0., 0.]))

Center the model based on the position of the minimum potential.

This method calculates the center of the potential well (optionally within a restricted radius) and translates all particles so that this point becomes the new origin (0, 0, 0).

Parameters
  • ptype (int or list, optional) – Particle type(s) used to identify the potential minimum.

  • eps (float, default 0.1) – Gravitational softening length for the potential calculation.

  • r_max (float, optional) – Maximum radius from the current center to search for the potential minimum.

  • center (array_like, default [0, 0, 0]) – The reference coordinates used if r_max is specified. Defaults to [0, 0, 0].

See also

cmcenter

Center on the center of mass.

histocenter

Center on the maximal density center using 1D histograms.

histocenter3D

center on the maximal density center using a 3D histogram.

cvcenter

Center the velocities on the velocity center of mass.