BaryonForge.Runners.SnapshotRunner module

class BaryonForge.Runners.SnapshotRunner.DefaultRunnerSnapshot(HaloNDCatalog, ParticleSnapshot, epsilon_max, model, mass_def=MassDef(Delta=200, rho_type=critical), verbose=True, KDTree_kwargs={})[source]

Bases: object

A utility class for handling input/output operations related to HaloNDCatalogs and particle snapshots.

The DefaultRunnerSnapshot class provides methods to manage and process data associated with halo ND catalogs and particle snapshots, including distance calculations with periodic boundary conditions. It uses a KDTree for efficient nearest-neighbor searches within the particle snapshot.

The initialization of this class builds a scipy.spatial.KDTree object to use in querying particles around a given halo. This step takes some considerable time.

Parameters:
  • HaloNDCatalog (object) – An instance of a HaloNDCatalog, containing data about halos and their properties. It must have a cosmology attribute to specify the cosmological parameters.

  • ParticleSnapshot (object) – An instance representing a ParticleSnapshot containing the positions of particles in the simulation.

  • epsilon_max (float) – A parameter specifying the maximum size, in units of halo radius, of cutouts made around each halo during painting/baryonification.

  • model (object, optional) – An object that generates profiles or displacements. For example, see Baryonification2D or Pressure

  • mass_def (object, optional) – An instance of a mass definition object from the CCL (Core Cosmology Library), specifying the mass definition to be used. Default is ccl.halos.massdef.MassDef(200, ‘critical’).

  • verbose (bool, optional) – A flag to enable verbose output for logging or debugging purposes. Default is True.

HaloNDCatalog

The halo ND catalog instance.

Type:

object

ParticleSnapshot

The particle snapshot instance.

Type:

object

cosmo

The cosmology object extracted from HaloNDCatalog.

Type:

object

model

The model used for baryonification or profile painting.

Type:

object

epsilon_max

The maximum radius, in halo radius units, of cutouts around halos.

Type:

float

mass_def

The mass definition object.

Type:

object

verbose

Whether verbose output is enabled.

Type:

bool

tree

A KDTree built from the particle coordinates for efficient nearest-neighbor searches.

Type:

KDTree

compute_distance(*args)[source]

Helper function that computes the Euclidean distance between points, accounting for periodic boundary conditions.

enforce_periodicity(dx)[source]

Helper function that adjusts distances to enforce periodic boundary conditions, ensuring distances are within the box size.

compute_distance(*args)[source]

Computes the Euclidean distance between points, accounting for periodic boundary conditions.

This method calculates the distance between points, ensuring that the computed distance takes into account the periodicity of the simulation box. It is designed to handle cases where distances might wrap around the edges of the box.

Parameters:

*args (list of ndarrays) – Arrays representing differences in each dimension (e.g., dx, dy, dz) between the points.

Returns:

d – An array of distances computed for each pair of points, with periodicity accounted for.

Return type:

ndarray

enforce_periodicity(dx)[source]

Adjusts distances to enforce periodic boundary conditions.

This method adjusts the input distances to ensure that they are within the box size, effectively enforcing periodic boundary conditions. It modifies the distances in place.

Parameters:

dx (ndarray) – An array of distances to be adjusted for periodic boundary conditions.

Returns:

dx – The adjusted distances, with values wrapped around the box size if necessary.

Return type:

ndarray

class BaryonForge.Runners.SnapshotRunner.BaryonifySnapshot(HaloNDCatalog, ParticleSnapshot, epsilon_max, model, mass_def=MassDef(Delta=200, rho_type=critical), verbose=True, KDTree_kwargs={})[source]

Bases: DefaultRunnerSnapshot

A class to apply baryonification to a particle snapshot using a halo catalog.

The BaryonifySnapshot class inherits from DefaultRunnerSnapshot and is designed to process a particle snapshot by applying baryonification techniques to adjust particle positions. It uses a halo catalog to determine the necessary adjustments based on halo properties, cosmological parameters, and a specified model.

process()[source]

Processes the particle snapshot by applying baryonification and returns the modified particle catalog.

process()[source]

Applies baryonification to the particle snapshot using the halo catalog.

This method iterates over each halo in the HaloNDCatalog, calculating the necessary displacements for particles within a certain radius of each halo. The displacements are computed based on the halo’s mass, position, and scale factor. The resulting offsets are applied to the particle positions, and the modified particle catalog is returned.

Returns:

new_cat – A structured array representing the modified particle catalog after baryonification.

Return type:

ndarray

Notes

  • This method supports both 2D and 3D particle snapshots.

  • The KDTree is used for efficient querying of particles within the radius of influence of each halo.

  • Periodic boundary conditions are enforced to ensure particles remain within the simulation box.

  • The method assumes that the input catalog provides particle coordinates as ‘x’, ‘y’, and optionally ‘z’.