Utils#
- pyexshalos.utils.Compute_Correlation(k: ndarray, P: ndarray, direction: str = 'pk2xi', verbose: bool = False) dict #
Compute the correlation function given the power spectrum or the power spectrum given the correlation function.
- Parameters:
k (numpy.ndarray) – Wavenumbers of the power spectrum or the distance of the correlation function.
P (numpy.ndarray) – Power spectrum or the correlation function.
direction (str) – Direction to compute the fftlog (“pk2xi” or “xi2pk”). Fiducial value: “pk2xi”
verbose (bool) – Whether to output information in the C code. Fiducial value: False
- Returns:
Dictionary with keys:
”R” or “k”: Ndarray with k or r
”Xi” or “Pk”: Ndarray with Xi(r) or P(k)
- Return type:
dict
- pyexshalos.utils.Compute_High_Order_Operators(grid: ndarray, order: int = 2, nl_order: int = 0, Galileons: bool = False, Renormalized: bool = False, Lc: float = 2.0, verbose: bool = False, nthreads: int = 1) Dict[str, ndarray] #
Compute the higher order operators up to a given order.
- Parameters:
grid (numpy.ndarray) – Lagrangian density grid.
order (int) – Order to be used to compute the local operators. Fiducial value: 2
nl_order (int) – Order to be used to compute the non-local operators. Fiducial value: 0
Galileons (bool) – Whether to use the Galileons operators. Fiducial value: False
Renormalized (bool) – Whether to use renormalized operators. Fiducial value: False
Lc (float) – Size of each cell in Mpc/h. Fiducial value: 2.0
verbose (bool) – Whether to output information in the C code. Fiducial value: False
nthreads (int) – Number of threads used by OpenMP. Fiducial value: 1
- Returns:
Dictionary with keys:
”delta2”: Ndarray with delta^2
”K2”: Ndarray with K^2 or G_2
”delta3”: Ndarray with delta^3
”K3”: Ndarray with K^3 or G_3
”deltaK2”: Ndarray with delta*K^2 or delta*G_2
”laplacian”: Ndarray with Laplacian(delta)
- Return type:
dict
- pyexshalos.utils.Displace_LPT(grid: ndarray, Lc: float = 2.0, Om0: float = 0.31, z: float = 0.0, k_smooth: float = 10000.0, DO_2LPT: bool = False, OUT_VEL: bool = False, Input_k: bool = False, OUT_POS: bool = True, verbose: bool = False) Dict[str, ndarray] #
Compute the displacement of particles using Lagrangian Perturbation Theory (LPT).
- Parameters:
grid (numpy.ndarray) – Density grid where the halos will be found.
Lc (float) – Size of each cell in Mpc/h. Fiducial value: 2.0
Om0 (float) – Value of the matter overdensity today. Fiducial value: 0.31
z (float) – Redshift of the density grid and final halo catalogue. Fiducial value: 0.0
k_smooth (float) – Scale used to smooth the displacements. Fiducial value: 10000.0
DO_2LPT (bool) – Whether to use the second-order LPT. Fiducial value: False
OUT_VEL (bool) – Whether to output the velocities of the particles. Fiducial value: False
Input_k (bool) – Whether the input density grid is in real space (or Fourier). Fiducial value: False
OUT_POS (bool) – Whether to output the positions or just the displacements. Fiducial value: True
verbose (bool) – Whether to output information in the C code. Fiducial value: False
- Returns:
Dictionary with keys:
”pos”: Ndarray with particle positions (displacements)
”vel”: Ndarray with particle velocities (if OUT_VEL is True)
- Return type:
dict
- pyexshalos.utils.Find_Halos_from_Grid(grid: ndarray, k: ndarray, P: ndarray, Lc: float = 2.0, Om0: float = 0.31, z: float = 0.0, delta_c: float | None = None, Nmin: int = 10, a: float = 1.0, beta: float = 0.0, alpha: float = 0.0, OUT_FLAG: bool = False, verbose: bool = False) Dict[str, ndarray] #
Generate a halo catalogue (in Lagrangian space) given an initial density grid.
- Parameters:
grid (numpy.ndarray) – Density grid where the halos will be found.
k (numpy.ndarray) – Wavenumbers of the power spectrum.
P (numpy.ndarray) – Power spectrum.
Lc (float) – Size of each cell in Mpc/h. Fiducial value: 2.0
Om0 (float) – Value of the matter overdensity today. Fiducial value: 0.31
z (float) – Redshift of the density grid and final halo catalogue. Fiducial value: 0.0
delta_c (Optional[float]) – Critical density of the halo formation linearly extrapolated to z. Fiducial value: None
Nmin (int) – Minimum number of particles in each halo. Fiducial value: 10
a (float) – Parameter a of the ellipsoidal barrier. Fiducial value: 1.0
beta (float) – Parameter beta of the ellipsoidal barrier. Fiducial value: 0.0
alpha (float) – Parameter alpha of the ellipsoidal barrier. Fiducial value: 0.0
OUT_FLAG (bool) – Whether to output flag with the information if a cell belongs to a halo. Fiducial value: False
verbose (bool) – Whether to output information in the C code. Fiducial value: False
- Returns:
Dictionay with keys:
”posh”: Ndarray with halo positions
”Mh”: Ndarray with halo masses
”flag”: Ndarray with flags for each cell
- Return type:
dict
- pyexshalos.utils.Fit_Barrier(k: ndarray, P: ndarray, M: ndarray, dndlnM: ndarray, dn_err: ndarray | None = None, grid: ndarray | None = None, R_max: float = 100000.0, Mmin: float | None = None, Mmax: float | None = None, Nm: int = 25, nd: int = 256, Lc: float = 2.0, Om0: float = 0.31, z: float = 0.0, delta_c: float | None = None, Nmin: int = 10, seed: int = 12345, x0: ndarray | None = None, verbose: bool = False, nthreads: int = 1, Max_iter: int = 100, tol: float | None = None) ndarray #
Fit the parameters of the barrier given a mass function.
- Parameters:
k (numpy.ndarray) – Wavenumbers of the power spectrum
P (numpy.ndarray) – Power spectrum
M (numpy.ndarray) – Mass of the mass function to be approximated.
dndlnM (numpy.ndarray) – Differential mass function to be approximated.
dn_err (Optional[numpy.ndarray]) – Errors on the mass function. Fiducial value: None
grid (Optional[numpy.ndarray]) – Pre-computed Gaussian density grid. Fiducial value: None
R_max (float) – Maximum size used to compute the correlation function in Mpc/h. Fiducial value: 100000.0
Mmin (Optional[float]) – Minimum mass used to construct the mass bins. Fiducial value: None
Mmax (Optional[float]) – Maximum mass used to construct the mass bins. Fiducial value: None
Nm (int) – Number of mass bins. Fiducial value: 25
nd (int) – Number of cells in each direction. Fiducial value: 256
Lc (float) – Size of each cell in Mpc/h. Fiducial value: 2.0
Om0 (float) – Value of the matter overdensity today. Fiducial value: 0.31
z (float) – Redshift of the density grid and final halo catalogue. Fiducial value: 0.0
delta_c (Optional[float]) – Critical density, for the halo formation, linearly extrapolated to z. Fiducial value: None
Nmin (int) – Minimum number of particles in each halo. Fiducial value: 10
seed (int) – Seed used to generate the random numbers. Fiducial value: 12345
x0 (Optional[numpy.ndarray]) – Initial guess for the parameters of the barrier. Fiducial value: None
verbose (bool) – Whether to output information in the C code. Fiducial value: False
nthreads (int) – Number of threads used by OpenMP. Fiducial value: 1
Max_iter (int) – Maximum number of iterations used in the minimization. Fiducial value: 100
tol (Optional[float]) – Tolerance for the minimization. Fiducial value: None
- Returns:
Best fit of the values of the parameters of the ellipsoidal barrier.
- Return type:
numpy.ndarray
- pyexshalos.utils.Fit_HOD(k: ndarray, P: ndarray, nbar: float | None = None, posh: ndarray | None = None, Mh: ndarray | None = None, velh: ndarray | None = None, Ch: ndarray | None = None, nd: int = 256, ndx: int | None = None, ndy: int | None = None, ndz: int | None = None, Lc: float = 2.0, Om0: float = 0.31, z: float = 0.0, x0: ndarray | None = None, sigma: float = 0.5, Deltah: float = -1.0, seed: int = 12345, USE_VEL: bool = False, l_max: int = 0, direction: str = 'z', window: str | int = 'cic', R: float = 4.0, R_times: float = 5.0, interlacing: bool = True, Nk: int = 25, k_min: float | None = None, k_max: float | None = None, verbose: bool = False, nthreads: int = 1, Max_inter: int = 100, tol: float | None = None) ndarray #
Fit the parameters of the Halo Occupation Distribution (HOD).
- Parameters:
k (numpy.ndarray) – Wavenumbers of the galaxy power spectrum.
P (numpy.ndarray) – Galaxy power spectrum.
nbar (Optional[float]) – Mean number density of galaxies. Fiducial value: None
posh (Optional[numpy.ndarray]) – Positions of the halos. Fiducial value: None
Mh (Optional[numpy.ndarray]) – Mass of the halos. Fiducial value: None
velh (Optional[numpy.ndarray]) – Velocities of the halos. Fiducial value: None
Ch (Optional[numpy.ndarray]) – Concentration of the halos. Fiducial value: None
nd (int) – Number of cells in each direction. Fiducial value: 256
ndx (Optional[int]) – Number of cells in the x direction. Fiducial value: None
ndy (Optional[int]) – Number of cells in the y direction. Fiducial value: None
ndz (Optional[int]) – Number of cells in the z direction. Fiducial value: None
Lc (float) – Size of each cell in Mpc/h. Fiducial value: 2.0
Om0 (float) – Value of the matter overdensity today. Fiducial value: 0.31
z (float) – Redshift of the density grid and final halo catalogue. Fiducial value: 0.0
x0 (Optional[numpy.ndarray]) – Initial guess for the best fit parameters of the HOD. Fiducial value: None
sigma (float) – Parameter of the exclusion term of the halo density profile. Fiducial value: 0.5
Deltah (Optional[float]) – Overdensity of the halos. Fiducial value: None
seed (int) – Seed used to generate the density field. Fiducial value: 12345
USE_VEL (bool) – Whether to use the power spectrum in redshift space. Fiducial value: False
l_max (int) – Maximum multipole to consider. Fiducial value: 0
direction (str) – Direction for redshift space distortions. Fiducial value: “z”
window (Union[str, int]) – Type of window function to use. Fiducial value: “cic”
R (float) – Smoothing radius. Fiducial value: 4.0
R_times (float) – Smoothing factor for the radius. Fiducial value: 5.0
interlacing (bool) – Whether to use interlacing to reduce aliasing effects. Fiducial value: True
Nk (int) – Number of bins in k for the power spectrum. Fiducial value: 25
k_min (Optional[float]) – Minimum wavenumber for the power spectrum. Fiducial value: None
k_max (Optional[float]) – Maximum wavenumber for the power spectrum. Fiducial value: None
verbose (bool) – Whether to output information in the C code. Fiducial value: False
nthreads (int) – Number of threads used by OpenMP. Fiducial value: 1
Max_inter (int) – Maximum number of iterations used in the minimization. Fiducial value: 100
tol (Optional[float]) – Tolerance for the minimization. Fiducial value: None
- Returns:
The best fit parameters of the HOD.
- Return type:
numpy.ndarray
- pyexshalos.utils.Generate_Density_Grid(k: ndarray, P: ndarray, R_max: float = 100000.0, nd: int = 256, ndx: int | None = None, ndy: int | None = None, ndz: int | None = None, Lc: float = 2.0, outk: bool = False, seed: int = 12345, fixed: bool = False, phase: float = 0.0, k_smooth: float = 100000.0, verbose: bool = False, nthreads: int = 1) ndarray #
Compute the Gaussian density grid given the power spectrum.
- Parameters:
k (numpy.ndarray) – Wavenumbers of the power spectrum.
P (numpy.ndarray) – Power spectrum.
R_max (float) – Maximum size used to compute the correlation function in Mpc/h. Fiducial value: 100000.0
nd (int) – Number of cells per dimension. Fiducial value: 256
ndx (Optional[int]) – Number of cells in the x direction. Fiducial value: None
ndy (Optional[int]) – Number of cells in the y direction. Fiducial value: None
ndz (Optional[int]) – Number of cells in the z direction. Fiducial value: None
Lc (float) – Size of each cell in Mpc/h. Fiducial value: 2.0
outk (bool) – Whether to return the density field in Fourier space. Fiducial value: False
seed (int) – Seed used to generate the random numbers. Fiducial value: 12345
fixed (bool) – Whether to use fixed amplitudes. Fiducial value: False
phase (float) – Phase of the density field. Fiducial value: 0.0
k_smooth (float) – Smoothing scale in k-space. Fiducial value: 100000.0
verbose (bool) – Whether to output information in the C code. Fiducial value: False
nthreads (int) – Number of threads used by OpenMP. Fiducial value: 1
- Returns:
The 3D density grid in real space (and in Fourier space if outk is True).
- Return type:
numpy.ndarray
- pyexshalos.utils.Smooth_Fields(grid: ndarray, Lc: float = 2.0, k_smooth: float = 10000.0, Input_k: bool = False, Nfields: int = 1, verbose: bool = False, nthreads: int = 1) ndarray #
Smooth a given field (or fields) on a given scale.
- Parameters:
grid (numpy.ndarray) – Lagrangian density grid.
Lc (float) – Size of each cell in Mpc/h. Fiducial value: 2.0
k_smooth (float) – Scale used to smooth the fields. Fiducial value: 10000.0
Input_k (bool) – Whether the density grid is in real or Fourier space. Fiducial value: False
Nfields (int) – Number of fields. Fiducial value: 1
verbose (bool) – Whether to output information in the C code. Fiducial value: False
nthreads (int) – Number of threads used by OpenMP. Fiducial value: 1
- Returns:
A dictionary with all fields (excluding the linear) up to the given order or a single smoothed field.
- Return type:
np.ndarray
- pyexshalos.utils.Smooth_and_Reduce_Fields(grid: ndarray, Lc: float = 2.0, k_smooth: float = 10000.0, Input_k: bool = False, Nfields: int = 1, verbose: bool = False, nthreads: int = 1) ndarray #
Smooth a given field (or fields) on a given scale and reduce it.
- Parameters:
grid (numpy.ndarray) – Lagrangian density grid.
Lc (float) – Size of each cell in Mpc/h. Fiducial value: 2.0
k_smooth (float) – Scale used to smooth the fields. Fiducial value: 10000.0
Input_k (bool) – Whether the density grid is in real or Fourier space. Fiducial value: False
Nfields (int) – Number of fields. Fiducial value: 1
verbose (bool) – Whether to output information in the C code. Fiducial value: False
nthreads (int) – Number of threads used by OpenMP. Fiducial value: 1
- Returns:
Smoothed and reduced fields.
- Return type:
numpy.ndarray