BaryonForge.utils.Tabulate module
- class BaryonForge.utils.Tabulate.TabulatedProfile(self, model, cosmo)[source]
Bases:
HaloProfileA class for creating tabulated halo profiles from a given model.
The TabulatedProfile class takes a profile model and generates tabulated profiles using the given cosmology and mass definition. It provides methods to set up interpolators for efficient profile evaluation across a range of redshifts, masses, and radii. This class is designed to handle both real-space and projected-space profiles.
- Parameters:
- raw_input_3D
The raw 3D profile data used for setting up the interpolator.
- Type:
ndarray
- raw_input_2D
The raw 2D (projected) profile data used for setting up the interpolator.
- Type:
ndarray
- raw_input_z_range
The redshift range used in the interpolation, stored in log(1+z).
- Type:
ndarray
- raw_input_M_range
The mass range used in the interpolation, stored in log(M).
- Type:
ndarray
- raw_input_r_range
The radius range used in the interpolation, stored in log(r).
- Type:
ndarray
- interp3D
The interpolator for the 3D (real-space) profile.
- Type:
RegularGridInterpolator
- interp2D
The interpolator for the 2D (projected-space) profile.
- Type:
RegularGridInterpolator
- setup_interpolator(z_min=1e-2, z_max=5, N_samples_z=30, z_linear_sampling=False,
M_min=1e12, M_max=1e16, N_samples_Mass=30, R_min=1e-3, R_max=1e2, N_samples_R=100, other_params={}, verbose=True)
Sets up the interpolators for the 3D and 2D profiles based on the specified parameter ranges.
- _readout(r, M, a, table)[source]
Evaluates the profile from the interpolation table for given radii, masses, and scale factors.
- _projected(cosmo, r, M, a)[source]
Computes the projected-space profile using the tabulated interpolator.
Examples
>>> model = SomeProfileModel() >>> cosmo = ccl.Cosmology(...) >>> profile = TabulatedProfile(model, cosmo) >>> profile.setup_interpolator() >>> real_profile = profile.real(cosmo, r, M, a) >>> projected_profile = profile.projected(cosmo, r, M, a)
Notes
The setup_interpolator() method must be called before using real() and projected() methods to initialize the interpolation tables.
The interpolators are set up using log-scaled grids for mass, radius, and redshift to efficiently handle a wide range of scales.
This class inherits from ccl.halos.profiles.HaloProfile and can be used in contexts where a halo profile is required.
- setup_interpolator(z_min=0.01, z_max=5, N_samples_z=30, z_linear_sampling=False, M_min=1000000000000.0, M_max=1e+16, N_samples_Mass=30, R_min=0.001, R_max=100.0, N_samples_R=100, other_params={}, verbose=True)[source]
Sets up the interpolators for the 3D and 2D profiles based on the specified parameter ranges.
This method generates tabulated profiles over specified ranges of redshift, mass, and radius. The profiles are stored in 3D and 2D interpolators for efficient profile evaluation. Can be read out using either the _readout() helper class, or the real() and projected() functions.
- Parameters:
z_min (float, optional) – The minimum redshift value for the tabulation. Default is 1e-2.
z_max (float, optional) – The maximum redshift value for the tabulation. Default is 5.
N_samples_z (int, optional) – The number of redshift samples. Default is 30.
z_linear_sampling (bool, optional) – If True, use linear sampling for redshift; otherwise, use logarithmic sampling. Default is False.
M_min (float, optional) – The minimum mass value for the tabulation. Default is 1e12.
M_max (float, optional) – The maximum mass value for the tabulation. Default is 1e16.
N_samples_Mass (int, optional) – The number of mass samples. Default is 30.
R_min (float, optional) – The minimum radius value for the tabulation. Default is 1e-3.
R_max (float, optional) – The maximum radius value for the tabulation. Default is 1e2.
N_samples_R (int, optional) – The number of radius samples. Default is 100.
other_params (dict, optional) – Additional parameters for the profile model. Default is an empty dictionary.
verbose (bool, optional) – If True, display a progress bar during the tabulation process. Default is True.
- class BaryonForge.utils.Tabulate.ParamTabulatedProfile(model, cosmo)[source]
Bases:
objectA class for creating tabulated halo profiles that depend on additional parameters.
The ParamTabulatedProfile class takes a profile model and tabulates its output as a function of halo mass, redshift, and additional parameters specified during initialization. This allows for flexible interpolation of profiles based on various physical properties of halos.
- Parameters:
model (object) – A profile model object that defines the real and projected halo profiles. This object should have real() and projected() methods for evaluating profiles.
cosmo (object) – A ccl.Cosmology object representing the cosmological parameters.
mass_def (object, optional) – A ccl.halos.massdef.MassDef object that defines the mass definition. Default is MassDef(200, ‘critical’).
- raw_input_3D
The raw 3D profile data used for setting up the interpolator.
- Type:
ndarray
- raw_input_2D
The raw 2D (projected) profile data used for setting up the interpolator.
- Type:
ndarray
- interp3D
The interpolator for the 3D (real-space) profile.
- Type:
RegularGridInterpolator
- interp2D
The interpolator for the 2D (projected-space) profile.
- Type:
RegularGridInterpolator
- setup_interpolator(z_min=1e-2, z_max=5, N_samples_z=30, z_linear_sampling=False,
M_min=1e12, M_max=1e16, N_samples_Mass=30, R_min=1e-3, R_max=1e2, N_samples_R=100, other_params={}, verbose=True)
Sets up the interpolators for the 3D and 2D profiles based on the specified parameter ranges.
- _readout(r, M, a, table, \*\*kwargs)[source]
Evaluates the profile from the interpolation table for given radii, masses, scale factors, and other parameters.
- real(cosmo, r, M, a, \*\*kwargs)[source]
Computes the real-space profile using the tabulated interpolator.
- projected(cosmo, r, M, a, \*\*kwargs)[source]
Computes the projected-space profile using the tabulated interpolator.
Examples
>>> model = SomeProfileModel() >>> cosmo = ccl.Cosmology(...) >>> profile = ParamTabulatedProfile(model, cosmo) >>> profile.setup_interpolator(other_params={'param1': np.array([0.1, 0.2, 0.3])}) >>> real_profile = profile.real(cosmo, r, M, a, param1=0.2) >>> projected_profile = profile.projected(cosmo, r, M, a, param1=0.2)
Notes
The setup_interpolator() method must be called before using real() and projected() methods to initialize the interpolation tables.
The class allows for parameterizing profiles over additional user-defined parameters (other_params).
This class is not compatible with TabulatedProfile objects; ensure that the input model is not an instance of TabulatedProfile.
- setup_interpolator(z_min=0.01, z_max=5, N_samples_z=30, z_linear_sampling=False, M_min=1000000000000.0, M_max=1e+16, N_samples_Mass=30, R_min=0.001, R_max=100.0, N_samples_R=100, other_params={}, verbose=True)[source]
Sets up the interpolators for the 3D and 2D profiles based on the specified parameter ranges.
This method generates tabulated profiles over specified ranges of redshift, mass, radius, and additional user-defined parameters. The profiles are stored in 3D and 2D interpolators for efficient profile evaluation.
- Parameters:
z_min (float, optional) – The minimum redshift value for the tabulation. Default is 1e-2.
z_max (float, optional) – The maximum redshift value for the tabulation. Default is 5.
N_samples_z (int, optional) – The number of redshift samples. Default is 30.
z_linear_sampling (bool, optional) – If True, use linear sampling for redshift; otherwise, use logarithmic sampling. Default is False.
M_min (float, optional) – The minimum mass value for the tabulation. Default is 1e12.
M_max (float, optional) – The maximum mass value for the tabulation. Default is 1e16.
N_samples_Mass (int, optional) – The number of mass samples. Default is 30.
R_min (float, optional) – The minimum radius value for the tabulation. Default is 1e-3.
R_max (float, optional) – The maximum radius value for the tabulation. Default is 1e2.
N_samples_R (int, optional) – The number of radius samples. Default is 100.
other_params (dict, optional) – A dictionary of other parameters to be tabulated. The keys are parameter names, and the values are arrays of parameter values. Default is an empty dictionary.
verbose (bool, optional) – If True, display a progress bar during the tabulation process. Default is True.
- real(cosmo, r, M, a, **kwargs)[source]
Computes the real-space profile using the tabulated interpolator.
- Parameters:
cosmo (object) – A ccl.Cosmology object representing the cosmological parameters. It’s not actually used, but we allow it as input to have consistent API with the CCL profile methods.
r (array_like) – The radii at which to compute the profile.
M (float or array_like) – The mass of the halo.
a (float or array_like) – The scale factor at which to compute the profile.
**kwargs – Additional parameters required for the profile evaluation.
- Returns:
prof – The real-space profile values evaluated at the given radii, masses, and scale factors.
- Return type:
ndarray
- projected(cosmo, r, M, a, **kwargs)[source]
Computes the projected-space profile using the tabulated interpolator.
- Parameters:
cosmo (object) – A ccl.Cosmology object representing the cosmological parameters. It’s not actually used, but we allow it as input to have consistent API with the CCL profile methods.
r (array_like) – The radii at which to compute the profile.
M (float or array_like) – The mass of the halo.
a (float or array_like) – The scale factor at which to compute the profile.
**kwargs – Additional parameters required for the profile evaluation.
- Returns:
prof – The projected-space profile values evaluated at the given radii, masses, and scale factors.
- Return type:
ndarray