BaryonForge.utils.io module
- class BaryonForge.utils.io.HaloLightConeCatalog(ra, dec, M, z, cosmo, **arrays)[source]
Bases:
objectA class to read and store a halo catalog in a lightcone, along with cosmological parameters.
The HaloLightConeCatalog class is used in the baryonification pipeline to manage data related to halos observed in a lightcone, including their right ascension (RA), declination (Dec), mass (M), and redshift (z). The class also stores additional quantities as provided and ensures that necessary cosmological parameters are specified.
- Parameters:
ra (array-like) – The right ascension values of the halos. Can be a list, numpy array, or tuple.
dec (array-like) – The declination values of the halos. Can be a list, numpy array, or tuple. Declination values exactly at the poles (±90 degrees) are slightly offset (by 1e-5 arcsec) to avoid singularities.
M (array-like) – The mass values of the halos. Can be a list, numpy array, or tuple.
z (array-like) – The redshift values of the halos. Can be a list, numpy array, or tuple.
cosmo (dict) – A dictionary containing the cosmological parameters. Must include keys for ‘Omega_m’, ‘sigma8’, ‘h’, ‘Omega_b’, ‘n_s’, and ‘w0’.
**arrays (a kwargs dictionary) – Additional arrays to be included in the catalog. Each key-value pair corresponds to a name and an array of values of that parameter for the halos.
- cat
A structured numpy array containing the halo data, including RA, Dec, mass, redshift, and any additional quantities provided.
- Type:
structured ndarray
- Raises:
ValueError – If not all required cosmological parameters are provided.
- property data
Returns the structured array containing halo data.
- property cosmology
Returns the cosmology dictionary.
- class BaryonForge.utils.io.HaloNDCatalog(x, y, M, redshift, cosmo, z=None, **arrays)[source]
Bases:
objectA class to read and store a halo catalog in a 2D or 3D field, along with cosmological parameters.
The HaloNDCatalog class is used in the baryonification pipeline to manage data related to halos in either a 2D or 3D field. The catalog includes information about halos’ positions, masses, and any other provided attributes, as well as the cosmological parameters necessary for analysis.
- Parameters:
x (array-like) – The x-coordinates of the halos. Can be a list, numpy array, or tuple.
y (array-like) – The y-coordinates of the halos. Can be a list, numpy array, or tuple.
M (array-like) – The mass values of the halos. Can be a list, numpy array, or tuple.
redshift (float) – The redshift value associated with the halos.
cosmo (dict) – A dictionary containing the cosmological parameters. Must include keys for ‘Omega_m’, ‘sigma8’, ‘h’, ‘Omega_b’, ‘n_s’, and ‘w0’.
z (array-like, optional) – The z-coordinates of the halos. Default is None, which sets the z-coordinates to 0, indicating a 2D field.
**arrays (a kwargs dict) – Additional arrays to be included in the catalog. Each key-value pair corresponds to a name and an array of values of that parameter for the halos.
- cat
A structured numpy array containing the halo data, including x, y, z (if applicable), mass, and any additional quantities provided.
- Type:
structured ndarray
- data()
Returns the structured array containing halo data.
- cosmology()
Returns the dictionary of cosmological parameters.
- Raises:
ValueError – If not all required cosmological parameters are provided.
- property data
Returns the structured array containing halo data.
- property cosmology
Returns the dictionary of cosmological parameters.
- class BaryonForge.utils.io.LightconeShell(map=None, path=None, cosmo=None, redshift=None)[source]
Bases:
objectA class to read and store a lightcone shell (HEALPix map) along with cosmological parameters.
The LightconeShell class is used in the pipeline to manage data related to a lightcone shell, which is represented as a HEALPix map. This class facilitates the reading and storage of the map data, either directly from an array or by loading from a file, and ensures that necessary cosmological parameters are specified.
- Parameters:
map (ndarray, optional) – A numpy array containing the HEALPix map data. The map must be in ring configuration. If not provided, path must be specified.
path (str, optional) – A string representing the path to a file containing the HEALPix map data. If not provided, map must be specified.
cosmo (dict, optional) – A dictionary containing the cosmological parameters. Must include keys for ‘Omega_m’, ‘sigma8’, ‘h’, ‘Omega_b’, ‘n_s’, and ‘w0’.
redshift (float) – The redshift value associated with the map.
- map
A numpy array representing the HEALPix map data.
- Type:
ndarray
- data()
Returns the HEALPix map data.
- cosmology()
Returns the dictionary of cosmological parameters.
- Raises:
ValueError – If neither map nor path is provided, or if the required cosmological parameters are not included.
- property data
Returns the HEALPix map data.
- property cosmology
Returns the dictionary of cosmological parameters.
- class BaryonForge.utils.io.GriddedMap(map=None, redshift=None, bins=None, cosmo=None)[source]
Bases:
objectA class to read and store a gridded map (either 2D or 3D) along with cosmological parameters.
The GriddedMap class is used in the baryonification pipeline to manage data related to a gridded map, which can be either a 2D or 3D representation of a field. This class facilitates the storage of the map data, resolution, and bin information, and ensures that necessary cosmological parameters are specified.
- Parameters:
map (ndarray) – A numpy array containing the gridded map data. Can be either 2D or 3D.
redshift (float) – The redshift value associated with the map.
bins (ndarray) – A numpy array representing the coordinates of the map along a given axis, in physical Mpc. It determines the spacing and extent of the grid. This is the center of each pixel.
cosmo (dict) – A dictionary containing the cosmological parameters. Must include keys for ‘Omega_m’, ‘sigma8’, ‘h’, ‘Omega_b’, ‘n_s’, and ‘w0’.
- map
A numpy array representing the gridded map data.
- Type:
ndarray
- Npix
The number of pixels along one axis of the map (assuming the map is square for 2D or cubic for 3D).
- Type:
- res
The resolution of the grid, calculated as the difference between consecutive bin values.
- Type:
- bins
The bin coordinates of the map, in physical Mpc. This is the center of each pixel.
- Type:
ndarray
- grid
A list of numpy arrays representing the meshgrid of bin coordinates, useful for indexing.
- Type:
list of ndarrays
- inds
An array of indices corresponding to positions in the grid.
- Type:
ndarray
- data()
Returns the gridded map data.
- cosmology()
Returns the dictionary of cosmological parameters.
- Raises:
ValueError – If the map is not square or cubic, or if the required cosmological parameters are not included.
- property data
Returns the gridded map data.
- property cosmology
Returns the dictionary of cosmological parameters.
- class BaryonForge.utils.io.ParticleSnapshot(x=None, y=None, z=None, M=None, L=None, redshift=None, cosmo=None)[source]
Bases:
objectA class for handling particle snapshots used in the baryonification pipeline.
The ParticleSnapshot class manages data from a snapshot of particles in a simulation. It stores particle positions and masses, along with relevant cosmological information. The class provides functionality to generate 2D or 3D gridded maps of mass distribution from the particle data.
- Parameters:
x (array_like, optional) – The x-coordinates of the particles.
y (array_like, optional) – The y-coordinates of the particles.
z (array_like, optional) – The z-coordinates of the particles. If None, the snapshot is assumed to be 2D.
M (array_like, optional) – The masses of the particles.
L (float, optional) – The size of the simulation box in comoving Mpc. This determines the extent of the grid.
redshift (float, optional) – The redshift corresponding to the snapshot. This is used for associating the snapshot with a specific cosmological epoch.
cosmo (dict, optional) – A dictionary containing cosmological parameters required for baryonification. The required parameters are Omega_m, sigma8, h, Omega_b, n_s, and w0.
- cat
A structured NumPy array containing particle data, with columns for mass (‘M’) and coordinates (‘x’, ‘y’, ‘z’).
- Type:
ndarray
- data()
Returns the particle data as a structured array.
- cosmology()
Returns the dictionary of cosmological parameters.
- make_map(N_grid)[source]
Generates a 2D or 3D map from the snapshot data, based on the specified grid resolution.
Examples
>>> x = np.random.rand(1000) * 100 >>> y = np.random.rand(1000) * 100 >>> z = np.random.rand(1000) * 100 >>> M = np.random.rand(1000) * 1e10 >>> L = 100.0 >>> redshift = 0.5 >>> cosmo = { ... 'Omega_m': 0.3, ... 'sigma8': 0.8, ... 'h': 0.7, ... 'Omega_b': 0.045, ... 'n_s': 0.96, ... 'w0': -1.0 ... } >>> snapshot = ParticleSnapshot(x=x, y=y, z=z, M=M, L=L, redshift=redshift, cosmo=cosmo) >>> map_2d = snapshot.make_map(N_grid=100)
Notes
The input cosmo dictionary must contain all the required cosmological parameters: Omega_m, sigma8, h, Omega_b, n_s, and w0. Otherwise, a ValueError is raised.
If z is not provided, the snapshot is assumed to be 2D, and is2D is set to True.
The make_map function uses the np.histogramdd function to bin particle positions into a grid, weighting by their mass to create the map.
- property data
Returns the gridded map data.
- property cosmology
Returns the dictionary of cosmological parameters.
- make_map(N_grid)[source]
Generates a 2D or 3D map from the snapshot data.
The make_map function creates a gridded map (2D or 3D) from the halo catalog by binning halo positions into a grid of specified resolution. The halos are weighted by their mass to produce the final map. This function is useful for visualizing the mass distribution in a simulated field or analyzing the density field for further baryonification processing.
- Parameters:
N_grid (int) – The number of grid cells along each axis. This determines the resolution of the resulting map.
- Returns:
Map – A 2D or 3D numpy array representing the gridded map of mass distribution. The dimensionality of the map corresponds to the dimensionality of the input catalog (2D or 3D).
- Return type:
ndarray
- Raises:
AssertionError – If the mass values (‘M’) in the catalog contain NaNs, indicating that the particle mass is not provided.
Notes
The function assumes that the cat attribute contains ‘x’, ‘y’, and optionally ‘z’ positions of halos,
as well as their masses (‘M’). - The size of the simulation box is assumed to be self.L. - The resulting map will have shape (N_grid, N_grid) for 2D maps or (N_grid, N_grid, N_grid) for 3D maps.