py21cmfast.wrapper.cfuncs¶
Low-level python wrappers of C functions.
Attributes¶
Functions¶
|
Broadcast the parameters to the C library. |
|
Broadcast the parameters to the C library before calling the function. |
|
Compute a the luminosity function over a given number of bins and redshifts. |
|
Compute the optical depth to reionization under the given model. |
|
Construct all necessary FFTW wisdoms. |
|
Convert a halo catalogue's mass and RNG fields to halo properties. |
|
Get the collapsed fraction from the backend, given a density and condition sigma. |
|
Evaluate the conditional ionising emissivity expected at a range of densities. |
|
Evaluate the global ionising emissivity expected at a range of redshifts. |
|
Evaluate the conditional star formation rate density expected at a range of densities. |
|
Evaluate the global star formation rate density expected at a range of redshifts. |
|
Evaluate the conditional star formation rate density expected at a range of densities. |
|
Get the expected number and mass of halos given a condition. |
|
Get the expected number and mass of halos given a condition. |
|
Evaluate the variance of a mass scale. |
Free the memory of cosmo_tables_global that was allocated at the C backend. |
|
|
Determine condition masses for backend routines. |
|
Get the critical collapse density given a mass, redshift and parameters. |
|
Get the critical density from sigma and growth factor. |
|
Get the expected number of halos in a given box. |
|
Get the growth factor at a given redshift. |
|
Compute the required size of the memory buffer to hold a halo list. |
|
Evaluate the power at a certain scale from the 21cmFAST backend. |
|
Initialise the backend power-spectrum before calling the function. |
|
Initialise the Gauss-Legendre integration if required before calling the function. |
|
Initialise the the sigma interpolation table before calling the function. |
|
Evaluate conditional mass function integrals at a range of mass intervals. |
|
Return the value of the conditional halo mass function at given parameters. |
|
Return the value of the unconditional halo mass function at given parameters. |
|
Construct a halo sample given a descendant catalogue and redshifts. |
Module Contents¶
- py21cmfast.wrapper.cfuncs.broadcast_input_struct(inputs)[source]¶
Broadcast the parameters to the C library.
- Parameters:
- py21cmfast.wrapper.cfuncs.broadcast_params(func)[source]¶
Broadcast the parameters to the C library before calling the function.
This should be added as a decorator to any function which accesses the 21cmFAST if it does not directly call broadcast_input_struct.
- Parameters:
func (collections.abc.Callable)
- Return type:
collections.abc.Callable
- py21cmfast.wrapper.cfuncs.compute_luminosity_function(*, redshifts, inputs, nbins=100, mturnovers=None, mturnovers_mini=None, component='both')[source]¶
Compute a the luminosity function over a given number of bins and redshifts.
- Parameters:
redshifts (array-like) – The redshifts at which to compute the luminosity function.
inputs (
InputParameters) – The input parameters defining the simulation run.nbins (int, optional) – The number of luminosity bins to produce for the luminosity function.
mturnovers (array-like, optional) – The turnover mass at each redshift for massive halos (ACGs). Only required when USE_MINI_HALOS is True.
mturnovers_mini (array-like, optional) – The turnover mass at each redshift for minihalos (MCGs). Only required when USE_MINI_HALOS is True.
component (str, {‘both’, ‘acg’, ‘mcg}) – The component of the LF to be calculated.
- Returns:
Muvfunc (np.ndarray) – Magnitude array (i.e. brightness). Shape [nredshifts, nbins]
Mhfunc (np.ndarray) – Halo mass array. Shape [nredshifts, nbins]
lfunc (np.ndarray) – Number density of haloes corresponding to each bin defined by Muvfunc. Shape [nredshifts, nbins].
- Parameters:
redshifts (collections.abc.Sequence[float])
nbins (int)
mturnovers (numpy.ndarray | None)
mturnovers_mini (numpy.ndarray | None)
component (Literal['both', 'acg', 'mcg'])
- Return type:
tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray]
- py21cmfast.wrapper.cfuncs.compute_tau(*, redshifts, global_xHI, inputs, z_re_HeII=3.0)[source]¶
Compute the optical depth to reionization under the given model.
- Parameters:
redshifts (array-like) – Redshifts defining an evolution of the neutral fraction.
global_xHI (array-like) – The mean neutral fraction at redshifts.
inputs (
InputParameters) – Defines the input parameters of the runz_re_HeII (float, optional) – The redshift at which helium reionization occurs.
- Returns:
tau (float) – The optical depth to reionization
- Raises:
ValueError : – If redshifts and global_xHI have inconsistent length or if redshifts are not in ascending order.
- Parameters:
redshifts (collections.abc.Sequence[float])
global_xHI (collections.abc.Sequence[float])
z_re_HeII (float)
- Return type:
float
- py21cmfast.wrapper.cfuncs.construct_fftw_wisdoms(*, use_fftw_wisdom)[source]¶
Construct all necessary FFTW wisdoms.
- Parameters:
USE_FFTW_WISDOM (bool) – Whether we are interested in having FFTW wisdoms.
- Parameters:
use_fftw_wisdom (bool)
- Return type:
int
- py21cmfast.wrapper.cfuncs.convert_halo_properties(*, redshift, inputs, halo_masses, star_rng, sfr_rng, xray_rng, halo_coords=None, vcb_grid=None, J_21_LW_grid=None, z_re_grid=None, Gamma12_grid=None)[source]¶
Convert a halo catalogue’s mass and RNG fields to halo properties.
Assumes no feedback (Lyman-Werner, reionization).
- Returns a dict of 12 properties per halo:
halo mass stellar mass (ACG) star formation rate (ACG) xray luminosity (combined) ionising emissivity (combined) escape-fraction weighted SFR (combined) stellar mass (MCG) star formation rate (MCG) ACG turnover mass MCG turnover mass Reionization turnover mass Metallicity
- Parameters:
redshift (float)
halo_masses (numpy.typing.NDArray[float])
star_rng (numpy.typing.NDArray[float])
sfr_rng (numpy.typing.NDArray[float])
xray_rng (numpy.typing.NDArray[float])
halo_coords (numpy.typing.NDArray[float] | None)
vcb_grid (numpy.typing.NDArray[float] | None)
J_21_LW_grid (numpy.typing.NDArray[float] | None)
z_re_grid (numpy.typing.NDArray[float] | None)
Gamma12_grid (numpy.typing.NDArray[float] | None)
- py21cmfast.wrapper.cfuncs.evaluate_FgtrM_cond(inputs, densities, redshift, R)[source]¶
Get the collapsed fraction from the backend, given a density and condition sigma.
- Parameters:
densities (numpy.typing.NDArray[float])
redshift (float)
R (float)
- py21cmfast.wrapper.cfuncs.evaluate_Nion_cond(*, inputs, redshift, radius, densities, l10mturns_acg, l10mturns_mcg)[source]¶
Evaluate the conditional ionising emissivity expected at a range of densities.
- Parameters:
redshift (float)
radius (float)
densities (numpy.typing.NDArray[float])
l10mturns_acg (numpy.typing.NDArray[float])
l10mturns_mcg (numpy.typing.NDArray[float])
- py21cmfast.wrapper.cfuncs.evaluate_Nion_z(*, inputs, redshifts, log10mturns)[source]¶
Evaluate the global ionising emissivity expected at a range of redshifts.
- Parameters:
redshifts (numpy.typing.NDArray[float])
log10mturns (numpy.typing.NDArray[float])
- py21cmfast.wrapper.cfuncs.evaluate_SFRD_cond(*, inputs, redshift, radius, densities, log10mturns)[source]¶
Evaluate the conditional star formation rate density expected at a range of densities.
- Parameters:
redshift (float)
radius (float)
densities (numpy.typing.NDArray[float])
log10mturns (numpy.typing.NDArray[float])
- py21cmfast.wrapper.cfuncs.evaluate_SFRD_z(*, inputs, redshifts, log10mturns)[source]¶
Evaluate the global star formation rate density expected at a range of redshifts.
- Parameters:
redshifts (numpy.typing.NDArray[float])
log10mturns (numpy.typing.NDArray[float])
- py21cmfast.wrapper.cfuncs.evaluate_Xray_cond(*, inputs, redshift, radius, densities, log10mturns)[source]¶
Evaluate the conditional star formation rate density expected at a range of densities.
- Parameters:
redshift (float)
radius (float)
densities (numpy.typing.NDArray[float])
log10mturns (numpy.typing.NDArray[float])
- py21cmfast.wrapper.cfuncs.evaluate_condition_integrals(inputs, cond_array, redshift, redshift_prev=None)[source]¶
Get the expected number and mass of halos given a condition.
If USE_INTERPOLATION_TABLES is set to ‘hmf-interpolation’: Will crash if the table has not been initialised, only cond_array is used, and the rest of the arguments are taken from when the table was initialised.
- Parameters:
cond_array (numpy.typing.NDArray[float])
redshift (float)
redshift_prev (float | None)
- py21cmfast.wrapper.cfuncs.evaluate_inverse_table(inputs, cond_array, probabilities, redshift, redshift_prev=None)[source]¶
Get the expected number and mass of halos given a condition.
- Parameters:
cond_array (numpy.typing.NDArray[float])
probabilities (numpy.typing.NDArray[float])
redshift (float)
redshift_prev (float | None)
- py21cmfast.wrapper.cfuncs.evaluate_sigma(*, inputs, masses)[source]¶
Evaluate the variance of a mass scale.
Uses the 21cmfast backend
- Parameters:
masses (numpy.typing.NDArray[float])
- py21cmfast.wrapper.cfuncs.free_cosmo_tables()[source]¶
Free the memory of cosmo_tables_global that was allocated at the C backend.
- py21cmfast.wrapper.cfuncs.get_condition_mass(inputs, R)[source]¶
Determine condition masses for backend routines.
Returns either mass contained within a radius, or mass of the Lagrangian cell on HII_DIM
- Parameters:
R (float)
- py21cmfast.wrapper.cfuncs.get_delta_crit(*, inputs, mass, redshift)[source]¶
Get the critical collapse density given a mass, redshift and parameters.
- Parameters:
mass (float)
redshift (float)
- py21cmfast.wrapper.cfuncs.get_delta_crit_nu(hmf_int_flag, sigma, growth)[source]¶
Get the critical density from sigma and growth factor.
- Parameters:
hmf_int_flag (int)
sigma (float)
growth (float)
- py21cmfast.wrapper.cfuncs.get_expected_nhalo(*, redshift, inputs, **kwargs)[source]¶
Get the expected number of halos in a given box.
- Parameters:
redshift (float) – The redshift at which to calculate the halo list.
inputs (
InputParameters) – The input parameters of the run
- Parameters:
redshift (float)
- Return type:
int
- py21cmfast.wrapper.cfuncs.get_growth_factor(*, inputs, redshift)[source]¶
Get the growth factor at a given redshift.
- Parameters:
redshift (float)
- py21cmfast.wrapper.cfuncs.get_halo_catalog_buffer_size(*, redshift, inputs, min_size=1000000, **kwargs)[source]¶
Compute the required size of the memory buffer to hold a halo list.
- Parameters:
redshift (float) – The redshift at which to calculate the halo list.
inputs (
InputParameters) – The input parameters of the runmin_size (int, optional) – A minimum size to be used as the buffer.
- Parameters:
redshift (float)
min_size (int)
- Return type:
int
- py21cmfast.wrapper.cfuncs.get_matter_power_values(*, inputs, k_values)[source]¶
Evaluate the power at a certain scale from the 21cmFAST backend.
- Parameters:
k_values (collections.abc.Sequence[float])
- py21cmfast.wrapper.cfuncs.init_backend_ps(func)[source]¶
Initialise the backend power-spectrum before calling the function.
This should be added as a decorator to any function which uses the cosmology from the 21cmFAST backend without passing through our regular functions.
- Parameters:
func (collections.abc.Callable)
- Return type:
collections.abc.Callable
- py21cmfast.wrapper.cfuncs.init_gl(func)[source]¶
Initialise the Gauss-Legendre integration if required before calling the function.
Calculates the abcissae weights and stores them as arrays in the backend when either of the HMF integrals is set to use Gauss-Legendre integration. This should be added as a decorator to any function which calls backend integrals directly.
- Parameters:
func (collections.abc.Callable)
- Return type:
collections.abc.Callable
- py21cmfast.wrapper.cfuncs.init_sigma_table(func)[source]¶
Initialise the the sigma interpolation table before calling the function.
This should be added as a decorator to any function which calls lib.EvaluateSigma or the sigma tables directly.
- Parameters:
func (collections.abc.Callable)
- Return type:
collections.abc.Callable
- py21cmfast.wrapper.cfuncs.integrate_chmf_interval(inputs, redshift, lnm_lower, lnm_upper, cond_values, redshift_prev=None)[source]¶
Evaluate conditional mass function integrals at a range of mass intervals.
- Parameters:
redshift (float)
lnm_lower (numpy.typing.NDArray[float])
lnm_upper (numpy.typing.NDArray[float])
cond_values (numpy.typing.NDArray[float])
redshift_prev (float | None)
- py21cmfast.wrapper.cfuncs.return_chmf_value(*, inputs, redshift, mass_values, delta_values, condmass_values)[source]¶
Return the value of the conditional halo mass function at given parameters.
- Parameters:
inputs (InputParameters) – The input parameters defining the simulation run.
redshift (float) – The redshift at which to evaluate the halo mass function.
mass_values (float) – The mass values at which to evaluate the halo mass function.
delta (float) – The overdensity at which to evaluate the halo mass function.
cond_mass (float) – The condition mass at which to evaluate the halo mass function.
- Parameters:
redshift (float)
mass_values (collections.abc.Sequence[float])
delta_values (collections.abc.Sequence[float])
condmass_values (collections.abc.Sequence[float])
- py21cmfast.wrapper.cfuncs.return_uhmf_value(*, inputs, redshift, mass_values)[source]¶
Return the value of the unconditional halo mass function at given parameters.
- Parameters:
inputs (InputParameters) – The input parameters defining the simulation run.
redshift (float) – The redshift at which to evaluate the halo mass function.
mass_values (float) – The mass values at which to evaluate the halo mass function.
- Parameters:
redshift (float)
mass_values (collections.abc.Sequence[float])