pycosmommf package

Copyright (c) 2024 James Sunseri. All rights reserved.

pycosmommf: A package for identifying structures in the cosmic web.

Submodules

pycosmommf.filter module

pycosmommf.filter.kspace_gaussian_filter(R_S, kv)

create a Gaussian filter in k-space.

Parameters:
  • R_S (float) – The smoothing scale.

  • kv (tuple) – The wavevectors in each dimension, each a 1D float np.ndarray.

Returns:

The filter in k-space.

Return type:

(3D float np.ndarray)

pycosmommf.filter.kspace_top_hat_filter(R_S, kv)

create a top-hat filter in k-space.

Parameters:
  • R_S (float) – The smoothing scale.

  • kv (tuple) – The wavevectors in each dimension.

Returns:

The filter in k-space.

Return type:

(3D float np.ndarray)

pycosmommf.filter.smooth_gauss(f, R_S, kv)

apply a Gaussian filter to a field f.

Parameters:
  • f (3D float np.ndarray) – The field to be smoothed.

  • R_S (float) – The smoothing scale in units of voxels.

  • kv (tuple) – The wavevectors in each dimension.

Returns:

The smoothed field.

Return type:

(3D float np.ndarray)

pycosmommf.filter.smooth_loggauss(f, R_S, kv)

apply a Gaussian filter to the log of a field f.

Parameters:
  • f (3D float np.ndarray) – The field to be smoothed.

  • R_S (float) – The smoothing scale in units of voxels.

  • kv (tuple) – The wavevectors in each dimension.

Returns:

The smoothed field.

Return type:

(3D float np.ndarray)

pycosmommf.filter.smooth_top_hat(f, R_S, kv)

apply a top-hat filter to a field f.

Parameters:
  • f (3D float np.ndarray) – The field to be smoothed.

  • R_S (float) – The smoothing scale in units of voxels.

  • kv (tuple) – The wavevectors in each dimension.

Returns:

The smoothed field.

Return type:

(3D float np.ndarray)

pycosmommf.filter.wavevectors3D(dims, box_size=(6.283185307179586, 6.283185307179586, 6.283185307179586))

Returns the wavevectors for a 3D grid of dimensions dims and box size box_size.

Parameters:
  • dims (tuple) – The dimensions of the grid (nx, ny, nz).

  • box_size (tuple, optional) – The size of the box in each dimension (Lx, Ly, Lz). Defaults to (2π, 2π, 2π).

Returns:

a tuple containing:
  • kx (np.ndarray): The wavevector in the x-direction.

  • ky (np.ndarray): The wavevector in the y-direction.

  • kz (np.ndarray): The wavevector in the z-direction.

Return type:

(tuple)

pycosmommf.hessian module

pycosmommf.hessian.fast_hessian_from_smoothed(f_Rn, R_S, kv)

Compute the hessian matrix of the smoothed field f_Rn.

Parameters:
  • f_Rn (3D float np.ndarray) – The smoothed field in real space.

  • R_S (float) – The smoothing scale in units of voxels.

  • kv (tuple) – The wavevectors in each dimension.

Returns:

The hessian matrix of the smoothed field. The shape is (nx, ny, nz, 6), where nx, ny, nz are the dimensions of f_Rn.

Return type:

(4D float np.ndarray)

pycosmommf.signatures module

pycosmommf.signatures.maximum_signature(Rs, density_cube, algorithm='NEXUSPLUS', eps=1e-16)

Compute the maximum signatures across all scales Rs.

Parameters:
  • Rs (list of float) – List of smoothing scales in units of voxels.

  • density_cube (3D float np.ndarray) – The 3D density field to analyze.

  • algorithm (str, optional) – The algorithm to use for smoothing. Can be either “NEXUS” or “NEXUSPLUS”. Defaults to “NEXUSPLUS”.

  • eps (float, optional) – Small value to avoid division by zero. Defaults to 1e-16.

Returns:

An array of signatures with shape (nx, ny, nz, 3), where nx, ny, nz are the dimensions of the input density_cube. The last dimension contains the signatures for clusters, filaments, and walls respectively.

Return type:

(4D float np.ndarray)

pycosmommf.signatures.signatures_from_hessian(hessian)

Function to calculate the signatures from a given hessian.

Parameters:

hessian (4D float np.ndarray) – The hessian matrix of the smoothed field, with shape (nx, ny, nz, 6).

Returns:

The signatures array with shape (nx, ny, nz, 3). Each signature corresponds to a different type of structure:
  • sigs[..., 0]: Cluster signature

  • sigs[..., 1]: Filament signature

  • sigs[..., 2]: Wall signature

Return type:

(4D float np.ndarray)

pycosmommf.tagging module

pycosmommf.tagging.calc_mass_change(sig_vec, density_vec, Smin, Smax)

Calculate the mass change curve for a given structure type.

Parameters:
  • sig_vec (1D float np.ndarray) – the signature values for a given structure type

  • density_vec (1D float np.ndarray) – the density values for a given structure type

  • Smin (float) – the minimum signature value

  • Smax (float) – the maximum signature value

Returns:

a tuple containing:
  • S (1D float np.ndarray): the signature values

  • ΔΜ_2 (1D float np.ndarray): the mass change curve

Return type:

(tuple)

pycosmommf.tagging.calc_structure_bools(density_cube, max_sigs, verbose_flag, clusbool=None, Smin=-3, Smax=2, overdensity_threshold=370)

Calculate the boolean filters for clusters, filaments, walls, and voids.

Parameters:
  • density_cube (3D float np.ndarray) – the (δ+1 = ρ/<ρ>) density_cube, this is NOT (δ = ρ/<ρ> - 1).

  • max_sigs (4D float np.ndarray) – the maximum signatures array from CosmoMMF.maximum_signature()

  • verbose_flag (bool) – a flag to allow the function to be more helpful and verbose.

  • clusbool (bool np.ndarray, optional) – the cluster boolean filter

  • Smin (float, optional) – the minimum signature value

  • Smax (float, optional) – the maximum signature value

  • overdensity_threshold (int, optional) – the overdensity parameter threshold for determining virialization

Returns:

a tuple containing:
  • clusbool (3D bool np.ndarray): the cluster boolean filter

  • filbool (3D bool np.ndarray): the filament boolean filter

  • wallbool (3D bool np.ndarray): the wall boolean filter

  • voidbool (3D bool np.ndarray): the void boolean filter

  • summary_data (dict): a dictionary returned only when verbose_flag = True, it contains the following keys:
    • S_clus (1D float np.ndarray): the signature values for clusters

    • f_vir_clus (1D float np.ndarray): the virialization fraction for clusters

    • S_fil (1D float np.ndarray): the signature values for filaments

    • dM2_fil (1D float np.ndarray): the mass change curve for filaments

    • S_fil_thresh (float): the threshold value for filaments

    • S_wall (1D float np.ndarray): the signature values for walls

    • dM2_wall (1D float np.ndarray): the mass change curve for walls

    • S_wall_thresh (float): the threshold value for walls

    • mass_fractions (1D float np.ndarray): a list of mass fractions for clusters, filaments, walls, and voids

    • volume_fractions (1D float np.ndarray): a list of volume fractions for clusters, filaments, walls, and voids

Return type:

(tuple)

pycosmommf.tagging.make_the_clusbool(delta, max_sigs, overdensity_threshold)

A function that creates a bool Filter which selects only the clusters in a given cosmological δ field. This function accomplishes this by finding a threshold value for 𝒮_cluster by looking at the change in virialization fraction as a function of 𝒮_cluster.

Parameters:
  • delta (3D float np.ndarray) – delta refers to the (δ = ρ / <ρ> - 1) field, this is NOT the (δ + 1 = ρ / <ρ>) field.

  • max_sigs (4D float np.ndarray) – the maximum signatures array from the maximum_signature() function.

  • verbose_flag (bool) – a flag to allow the function to be more helpful and verbose.

  • overdensity_threshold (float) – The overdensity parameter threshold for determining virialization. Commonly used values that are physically motivated can be 370, 200, or 500.

Returns:

a tuple containing:
  • clusbool (3D bool np.ndarray): a boolean filter that selects only the clusters in a given cosmological δ field.

  • S_th (float): the threshold value for 𝒮_cluster.

  • signature_thresholds (1D float np.ndarray): an array of threshold values for 𝒮_cluster.

  • virialized_fractions (1D float np.ndarray): an array of virialized fractions as a function of 𝒮_cluster.

Return type:

(tuple)

pycosmommf.utils module

pycosmommf.utils.cylinder(n, r)

Returns an nxnxn array with a cylinder in the center with radius r. All points within the radius are set to 10, the rest are set to 0.

Parameters:
  • n (int) – The size of the 3D array to create.

  • r (int) – The radius of the cylinder.

Returns:

An nxnxn array with a cylinder in the center.

Return type:

(3D float np.ndarray)

pycosmommf.utils.shrink(data, new_size)

A simple function to shrink a 3D array by summing over blocks of new_size.

Parameters:
  • data (3D float np.ndarray) – The input 3D array to be shrunk.

  • new_size (int) – The new size for each dimension after shrinking.

Returns:

The shrunk 3D array.

Return type:

(3D float np.ndarray)

pycosmommf.utils.sphere(n, r)

Returns an nxnxn array with a sphere in the center with radius r. All points within the radius are set to 10, the rest are set to 0.

Parameters:
  • n (int) – The size of the 3D array to create.

  • r (int) – The radius of the sphere.

Returns:

An nxnxn array with a sphere in the center.

Return type:

(3D float np.ndarray)

pycosmommf.utils.wall(n)

Builds a wall out of an nxnxn array. All values in the wall are set to 10. Other points are set to 0.

Parameters:

n (int) – The size of the 3D array to create.

Returns:

An nxnxn array with a wall in the center.

Return type:

(3D float np.ndarray)