cosmax.tools package
Submodules
cosmax.tools.fit_field module
- cosmax.tools.fit_field.fit_field(key: Array, elements: int, field: Array, total_mass: float, size: float = 1.0, iterations: float = 400, learning_rate: float = 0.005) Tuple[Array, Array, Array]
Given a 3D density field, fit the particle positions and masses such that the density field is well represented by the particles.
- Parameters:
key – random key
elements – cubic root of the number of particles
field – 3D density field
total_mass – total mass of the field
size – size of the box in real space
iterations – number of iterations
learning_rate – learning rate
- Returns:
initial particle positions, fitted particle positions, particle masses
- cosmax.tools.fit_field.loss(pos: Array, mass: Array, field_truth: Array, size: float = 1.0) Array
Loss function for fitting a 3D density field with particles
- Parameters:
pos – particle positions
mass – particle masses
field_truth – 3D density field
- Returns:
mean squared error
- Return type:
loss
cosmax.tools.gradient module
- cosmax.tools.gradient.central_difference(field: Array, axis: int, delta: float) Array
Compute the central difference of a field along a given axis. Periodic boundary conditions are used.
- Parameters:
field – field to differentiate
axis – axis along which to differentiate
delta – grid spacing
- Returns:
The central difference of the field
- cosmax.tools.gradient.gradient(field: Array, delta: float) Array
Compute the gradient of a field using central differences. Periodic boundary conditions are used.
- Parameters:
field – field to differentiate
delta – grid spacing
- Returns:
The gradient of the field
cosmax.tools.helpers module
- cosmax.tools.helpers.compute_overdensity(rho: Array) Array
Overdensity (delta) of a density field (rho) as defined in cosmology
- Parameters:
rho – density field
- Returns:
overdensity field
- Return type:
overdensity
- cosmax.tools.helpers.compute_overdensity_mean(rho: Array) Tuple[Array, float]
Overdensity (delta) of a density field (rho) as defined in cosmology
- Parameters:
rho – density field
- Returns:
overdensity field and mean density
- cosmax.tools.helpers.compute_rho(overdensity: Array, mean: float) Array
Get density (rho) from overdensity (delta)
- Parameters:
overdensity – overdensity field
mean – mean density
- Returns:
density field
- Return type:
rho
- cosmax.tools.helpers.growth_factor_approx(a: float, Omega_M: float, Omega_L: float)
Approximation of the growth factor in cosmology
- Parameters:
a – scale factor
Omega_M – matter density parameter
Omega_L – dark energy density parameter
- Returns:
growth factor
- Return type:
growth_factor