enbid_ananke package#
enbid_ananke#
Provides a set of utilities to run the kernel density estimator EnBiD (Sharma & Steinmetz 2011 <http://ascl.net/1109.012>).
How to use#
enbid_ananke comes with the function enbid, please refer to its documentation for further help.
- enbid_ananke.write_gadget_file(filename: Path, pos: ndarray[Any, dtype[_ScalarType_co]], mass: ndarray[Any, dtype[_ScalarType_co]], vel: ndarray[Any, dtype[_ScalarType_co]] | None = None, boxsize: float = 0.0, time: float = 0.0, redshift: float = 0.0, omega0: float = 0.0, omegalambda: float = 0.0, hubble: float = 0.7, particle_type: int = 1) None[source]#
Write a GADGET-1 format snapshot file to serve as input for EnBiD (3D or 6D).
- Parameters:
filename (pathlib.Path) – Output file path.
pos (ndarray, shape (N, 3)) – Particle positions (float32).
mass (ndarray, shape (N,)) – Particle masses (float32).
vel (ndarray, shape (N, 3), optional) – Particle velocities. If None, zero velocities are written.
boxsize (float, optional) – Size of periodic box.
time, redshift, omega0, omegalambda, hubble (float, optional) – Cosmological parameters (ignored by EnBiD but part of header).
particle_type (int, optional) – Particle type index (0-5).
- enbid_ananke.write_for_enbid(points: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], velocities: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None = None, mass: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None = None, name: str | Path | None = None, caching: bool = False) Path[source]#
Writes the input files for EnBiD from 3D positions (and optional 3D velocities). If velocities are given, the combined input represents 6D phase-space data. The position frame is automatically centred on the most clustered structure to improve numerical stability; velocities are left unchanged.
Call signature:
path = write_for_enbid(points, velocities=None, mass=None, name=None, caching=False)
- Parameters:
points (array_like) – Contains 3D coordinates of the input particles, must be of shape (N,3) for any given N integer.
velocities (array_like, optional) – Particle velocities, shape (N, 3). If provided, EnBiD will run in 6D phase-space mode.
mass (array_like, optional) – Contains the mass of each particle. Must be a 1D array of length N. If provided, a GADGET binary input file is written and EnBiD will compute mass-weighted densities. If None (default), an ASCII file is written and unit masses are assumed.
name (string, optional) – Name of folder where to place EnBiD input files. Default to None.
caching (bool, optional) – If True, check if EnBiD input file already exists and ignore writing if it does. Default to False.
- Returns:
path – Path of folder where EnBiD input files are located.
- Return type:
pathlib.Path
- enbid_ananke.run_enbid(points: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], velocities: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None = None, mass: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None = None, name: str | Path | None = None, ngb: int = 64, verbose: bool = True, caching: bool = False, **kwargs: Dict[str, Any]) Path[source]#
Run the EnBiD kernel density estimator on the supplied particle data. The appropriate pre-compiled EnBiD binary (3D or 6D) is selected automatically based on whether
velocitiesare provided.Call signature:
path = run_enbid(points, velocities=None, mass=None, name=None, ngb=64, verbose=True, caching=False, **kwargs)
- Parameters:
points (array_like) – Contains 3D coordinates of the input particles, must be of shape (N,3) for any given N integer.
velocities (array_like, optional) – Particle velocities, shape (N, 3). If provided, EnBiD runs in 6D mode.
mass (array_like, optional) – Contains the mass of each particle. Must be a 1D array of length N. If provided, a GADGET binary input file is written and EnBiD will compute mass-weighted densities. If None (default), an ASCII file is written and unit masses are assumed.
name (string, optional) – Name of folder where EnBiD input files are located. Default to None.
ngb (int, optional) – Number of neighbouring particles EnBiD should consider in the smoothing for the density estimation. Default to 64.
verbose (bool, optional) – Verbose boolean flag to allow EnBiD to print what it’s doing to stdout. Default to True.
caching (bool, optional) – If True, the input data is hashed and compared to a cached hash. If the data (points, velocities, masses) are unchanged, the existing parameter file and density estimates are reused. Default to False.
spatial_scale (float, optional) – Scaling between position and velocity space where the scaling goes as velocity = position/spatial_scale if spatial_scale is set strictly positive, or velocity = position/std(position) if spatial_scale is set to 0 (with std representing the standard deviation for each coordinate). Default to 1 - TODO currently not implemented.
part_boundary (int, optional) – Minimum number of particles which a node must contain to have a boundary correction applied to its surfaces during tree generation. Optimum choice should be the larger of 7 or d+1, where d is the dimensionality of the space considered. Default to 7.
node_splitting_criterion (int (0, 1), optional) – Flag to allow for the node splitting to always split in priority the dimension with lowest Shannon entropy. If set to 0, the criteria splits each dimension alternately. Default to 1.
cubic_cells (int (0, 1), optional) – Flag to allow the node splitting to use position or velocity subspaces rather than individual dimensions when generating cells. Only work for 3 & 6 dimensional spaces. Default to 0 - TODO currently not implemented.
median_splitting_on (int (0, 1), optional) – Flag to allow for cell splitting to happen at the mean of data points when building the tree for faster estimates. Default to 1 (requires EnBiD compiled with -DMEDIAN TODO).
type_of_smoothing (int (0, 1, 2, 3, 4, 5), optional) –
- Type of smoothing used:
None
FiEstAS
Normal isotropic spherical kernel
Adaptive metric spherical kernel
Normal isotropic product form kernel
Adaptive metric product form kernel
Default to 3.
vol_corr (int (0, 1), optional) – Flag to enable a correction that avoid underestimating density when the smoothing box extends outside the boundary. Default to 1.
type_of_kernel (int (0, 1, 2, 3, 4, 5), optional) –
- Type of the kernel profile used:
B-spline
Top hat
Bi-weight (1-x^2)^2
Epanechikov
Cloud in cell
Triangular shaped cloud
Default to 3.
kernel_bias_correction (int (0, 1), optional) – Flag to enable corrections that displace central data points when computing densities, and reduce bias caused by irregularly distributed data. Default to 1.
anisotropy_kernel (int (0, 1), optional) – Flag to enable the use of anisotropic kernels which can have both shear and rotation. Kerels become then rotated ellipsoids in the density computation. With it on, type_of_smoothing should be either 2 or 3. Default to 0.
anisotropy (float, optional) – Minimum allowable minor to major axis ratio of the kernel smoothing lengths for computational management. Default to 0.
ngb_a (int, optional) – Number of neighbouring particles EnBiD should consider when computing the anisotropic kernel. Default to ngb.
type_list_on (int (0, 1), optional) – Flag to extend the number of particle types on which EnBiD can run independent density estimations from the default 6 types of GADGET formated data. Default to 0 - TODO currently not implemented.
periodic_boundary_on (int (0, 1), optional) – Flag to allow periodic boundary conditions. Default to 0 - TODO currently not implemented.
- Returns:
path – Path of folder where EnBiD output files are located.
- Return type:
pathlib.Path
- enbid_ananke.read_enbid_binary(filename: Path) ndarray[Any, dtype[_ScalarType_co]][source]#
Read a binary EnBiD density file (GADGET-style output).
The file contains a 256-byte header followed by a block of single-precision floats (density for each particle). Each record is preceded and followed by a 4-byte integer indicating the block size (Fortran unformatted).
- Parameters:
filename (pathlib.Path) – Path to the .est file.
- Returns:
density – Array of density values (float32).
- Return type:
ndarray
- enbid_ananke.return_enbid(name: str | Path | None = None) ndarray[Any, dtype[_ScalarType_co]][source]#
Read EnBiD output file and returns the associated kernel density estimates after running the EnBiD estimator.
Automatically detects whether the output is ASCII or binary based on the ICFormat used in the run.
Call signature:
rho = return_enbid(name=None)
- Parameters:
name (string) – Name of folder where EnBiD saved its output files. Default to None.
- Returns:
rho – Array representing the kernel density estimates output by EnBiD
- Return type:
array_like
- enbid_ananke.enbid(points: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], velocities: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None = None, mass: _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes] | None = None, **kwargs: Dict[str, Any]) ndarray[Any, dtype[_ScalarType_co]][source]#
Returns kernel density estimates for a set of particles.
If only 3D positions are given, the result is a 3D spatial density. If 3D velocities are also provided, the estimate becomes a 6D phase-space density. When a mass array is given, the densities are mass-weighted (mass density); otherwise they are number densities.
Call signature:
rho = enbid(points, velocities=None, mass=None, name=None, **kwargs)
- Parameters:
points (array_like) – Contains 3D coordinates of the input particles, must be of shape (N,3) for any given N integer.
velocities (array_like, optional) – Particle velocities, shape (N, 3). If provided, EnBiD runs in 6D phase-space mode.
mass (array_like, optional) – Contains the mass of each particle. Must be a 1D array of length N. If provided, a GADGET binary input file is written and EnBiD will compute mass-weighted densities (i.e., mass density). If None (default), an ASCII file is written and unit masses are assumed (number density).
name (string, optional) – Name of folder where to save the input/output files for the EnBiD estimator. Default to None.
caching (bool, optional) – Only to be used with a given folder under argument name. If True, check if EnBiD had already been used to produce the kernel density estimates. If it hasn’t, compute the estimates, otherwise, load the existing data that had previously been cached. Default to False.
**kwargs (dict) – Refer to function run_enbid documentation for additional keyword arguments.
- Returns:
rho – Array of density values. Units: mass density if mass is given, number density otherwise.
- Return type:
array_like