py21cmfast.wrapper.cfuncs ========================= .. py:module:: py21cmfast.wrapper.cfuncs .. autoapi-nested-parse:: Low-level python wrappers of C functions. .. !! processed by numpydoc !! Attributes ---------- .. autoapisummary:: py21cmfast.wrapper.cfuncs.logger Functions --------- .. autoapisummary:: py21cmfast.wrapper.cfuncs.compute_luminosity_function py21cmfast.wrapper.cfuncs.compute_mturns py21cmfast.wrapper.cfuncs.compute_tau py21cmfast.wrapper.cfuncs.convert_halo_properties py21cmfast.wrapper.cfuncs.evaluate_FgtrM_cond py21cmfast.wrapper.cfuncs.evaluate_Nion_cond py21cmfast.wrapper.cfuncs.evaluate_Nion_z py21cmfast.wrapper.cfuncs.evaluate_SFRD_cond py21cmfast.wrapper.cfuncs.evaluate_SFRD_z py21cmfast.wrapper.cfuncs.evaluate_Xray_cond py21cmfast.wrapper.cfuncs.evaluate_condition_integrals py21cmfast.wrapper.cfuncs.evaluate_inverse_table py21cmfast.wrapper.cfuncs.evaluate_sigma py21cmfast.wrapper.cfuncs.get_condition_mass py21cmfast.wrapper.cfuncs.get_delta_crit py21cmfast.wrapper.cfuncs.get_delta_crit_nu py21cmfast.wrapper.cfuncs.get_expected_nhalo py21cmfast.wrapper.cfuncs.get_growth_factor py21cmfast.wrapper.cfuncs.get_halo_catalog_buffer_size py21cmfast.wrapper.cfuncs.get_matter_power_values py21cmfast.wrapper.cfuncs.get_vcb_power_values py21cmfast.wrapper.cfuncs.integrate_chmf_interval py21cmfast.wrapper.cfuncs.return_chmf_value py21cmfast.wrapper.cfuncs.return_uhmf_value py21cmfast.wrapper.cfuncs.sample_halos_from_conditions Module Contents --------------- .. py:function:: compute_luminosity_function(*, redshifts: collections.abc.Sequence[float], inputs: py21cmfast.wrapper.inputs.InputParameters, nbins: int = 100, mturnovers: numpy.ndarray | None = None, mturnovers_mini: numpy.ndarray | None = None, lightcone: py21cmfast.drivers.lightcone.LightCone | None = None, global_evolution: py21cmfast.drivers.global_evolution.GlobalEvolution | None = None, component: Literal['both', 'acg', 'mcg'] = 'both') -> tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray] 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** (:class:`~InputParameters`) -- The input parameters defining the simulation run. * **nbins** (*int, optional*) -- The number of luminosity bins to produce for the luminosity function. * **lightcone** (:class:`~LightCone` or None, optional) -- The lightcone object to use for the computation. If None, the function will consider `global_evolution` for the global m_turnover values, otherwise they will be extracted from the given lightcone. * **global_evolution** (:class:`~GlobalEvolution` or None, optional) -- The global evolution object to use for the computation. If None, the function will run a global evolution to estimate the global m_turnover values, otherwise they will be extracted from the given global evolution. * **component** (*str, {'both', 'acg', 'mcg}*) -- The component of the LF to be calculated. Forced to be 'acg' if USE_MINI_HALOS is False. :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]. .. !! processed by numpydoc !! .. py:function:: compute_mturns(*, inputs: py21cmfast.wrapper.inputs.InputParameters, redshifts: float | collections.abc.Sequence[float], J_LW_21: float | collections.abc.Sequence[float], v_cb: float | collections.abc.Sequence[float], ionisation_rate_G12: float | collections.abc.Sequence[float], z_reion: float | collections.abc.Sequence[float]) -> tuple[float, float] Compute the turnover masses for both ACGs and MCGs at a given redshift. :Parameters: * **redshifts** (*array-like*) -- The redshifts at which to compute the turnover masses. * **J_LW_21** (*array-like*) -- The Lyman-Werner flux in units of 1e-21 erg/s/Hz/cm^2/sr at the given redshifts. * **v_cb** (*array-like*) -- The amplitude of the relative velocity between dark matter and baryons in units of km/s at the given redshifts. * **ionisation_rate_G12** (*array-like*) -- The ionisation rate in units of 1e-12 s^-1 at the given redshifts. * **z_reion** (*array-like*) -- The reionisation redshift at the given redshifts. :returns: * **M_turn_a** (*array-like*) -- The turnover mass for atomic cooling halos at the given redshifts. * **M_turn_m** (*array-like*) -- The turnover mass for molecular cooling halos at the given redshifts. :raises ValueError :: If the input arrays do not have the same shape. .. !! processed by numpydoc !! .. py:function:: compute_tau(*, redshifts: collections.abc.Sequence[float], global_xHI: collections.abc.Sequence[float], inputs: py21cmfast.wrapper.inputs.InputParameters, z_re_HeII: float = 3.0) -> float 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** (:class:`~InputParameters`) -- Defines the input parameters of the run * **z_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. .. !! processed by numpydoc !! .. py:function:: convert_halo_properties(*, redshift: float, inputs: py21cmfast.wrapper.inputs.InputParameters, halo_masses: numpy.typing.NDArray[numpy.floating], star_rng: numpy.typing.NDArray[numpy.floating], sfr_rng: numpy.typing.NDArray[numpy.floating], xray_rng: numpy.typing.NDArray[numpy.floating], halo_coords: numpy.typing.NDArray[numpy.floating] | None = None, vcb_grid: numpy.typing.NDArray[numpy.floating] | None = None, J_21_LW_grid: numpy.typing.NDArray[numpy.floating] | None = None, z_re_grid: numpy.typing.NDArray[numpy.floating] | None = None, Gamma12_grid: numpy.typing.NDArray[numpy.floating] | None = None) 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 .. !! processed by numpydoc !! .. py:function:: evaluate_FgtrM_cond(inputs: py21cmfast.wrapper.inputs.InputParameters, densities: numpy.typing.NDArray[numpy.floating], redshift: float, R: float) Get the collapsed fraction from the backend, given a density and condition sigma. .. !! processed by numpydoc !! .. py:function:: evaluate_Nion_cond(*, inputs: py21cmfast.wrapper.inputs.InputParameters, redshift: float, radius: float, densities: numpy.typing.NDArray[numpy.floating], l10mturns_acg: numpy.typing.NDArray[numpy.floating] | None = None, l10mturns_mcg: numpy.typing.NDArray[numpy.floating] | None = None, lightcone: py21cmfast.drivers.lightcone.LightCone | None = None, global_evolution: py21cmfast.drivers.global_evolution.GlobalEvolution | None = None) Evaluate the global number of ionising photons per baryon, expected at a range of densities. :Parameters: * **inputs** (:class:`~InputParameters`) -- The input parameters defining the simulation run. * **redshift** (*float*) -- The redshift at which to compute Nion. * **radius** (*float*) -- The radius of the region at which to compute the conditional Nion. * **densities** (*array-like*) -- The densities at which to compute the conditional Nion. * **lightcone** (:class:`~LightCone` or None, optional) -- The lightcone object to use for the computation. If None, the function will consider `global_evolution` for the global m_turnover values, otherwise they will be extracted from the given lightcone. * **global_evolution** (:class:`~GlobalEvolution` or None, optional) -- The global evolution object to use for the computation. If None, the function will run a global evolution to estimate the global m_turnover values, otherwise they will be extracted from the given global evolution. :returns: * **nion** (*np.ndarray*) -- The conditional number of ionising photons per baryon at the given redshift and radius for ACGs. * **nion_mini** (*np.ndarray or None*) -- The conditional number of ionising photons per baryon at the given redshift and radius for MCGs. Will be None if `USE_MINI_HALOS` is False. .. rubric:: Notes This function estimates the conditional N_ion by using the global turnover masses. In reality, these turnover masses do not depend solely on redshift, but also on the local density field, as well on its environment and history. Since it is impossible to well-define the conditional N_ion in given region by only providing redshift and density, we approximate the used turnover masses in this calculation to be the global ones. .. !! processed by numpydoc !! .. py:function:: evaluate_Nion_z(*, inputs: py21cmfast.wrapper.inputs.InputParameters, redshifts: numpy.typing.NDArray[numpy.floating], log10mturns: numpy.typing.NDArray[numpy.floating] | None = None, lightcone: py21cmfast.drivers.lightcone.LightCone | None = None, global_evolution: py21cmfast.drivers.global_evolution.GlobalEvolution | None = None) Evaluate the global number of ionising photons per baryon, expected at a range of redshifts. :Parameters: * **inputs** (:class:`~InputParameters`) -- The input parameters defining the simulation run. * **redshifts** (*array-like*) -- The redshifts at which to compute Nion. * **lightcone** (:class:`~LightCone` or None, optional) -- The lightcone object to use for the computation. If None, the function will consider `global_evolution` for the global m_turnover values, otherwise they will be extracted from the given lightcone. * **global_evolution** (:class:`~GlobalEvolution` or None, optional) -- The global evolution object to use for the computation. If None, the function will run a global evolution to estimate the global m_turnover values, otherwise they will be extracted from the given global evolution. :returns: * **nion** (*np.ndarray*) -- The global number of ionising photons per baryon at the given redshifts for ACGs. * **nion_mini** (*np.ndarray or None*) -- The global number of ionising photons per baryon at the given redshifts for MCGs. Will be None if `USE_MINI_HALOS` is False. .. !! processed by numpydoc !! .. py:function:: evaluate_SFRD_cond(*, inputs: py21cmfast.wrapper.inputs.InputParameters, redshift: float, radius: float, densities: numpy.typing.NDArray[numpy.floating], log10mturns: numpy.typing.NDArray[numpy.floating] | None = None, lightcone: py21cmfast.drivers.lightcone.LightCone | None = None, global_evolution: py21cmfast.drivers.global_evolution.GlobalEvolution | None = None) Evaluate the conditional star formation rate density (in units of M_sun/s/Mpc^3) expected at a range of densities. :Parameters: * **inputs** (:class:`~InputParameters`) -- The input parameters defining the simulation run. * **redshift** (*float*) -- The redshift at which to compute the SFRD. * **radius** (*float*) -- The radius of the region at which to compute the conditional SFRD. * **densities** (*array-like*) -- The densities at which to compute the conditional SFRD. * **lightcone** (:class:`~LightCone` or None, optional) -- The lightcone object to use for the computation. If None, the function will consider `global_evolution` for the global m_turnover values, otherwise they will be extracted from the given lightcone. * **global_evolution** (:class:`~GlobalEvolution` or None, optional) -- The global evolution object to use for the computation. If None, the function will run a global evolution to estimate the global m_turnover values, otherwise they will be extracted from the given global evolution. :returns: * **sfrd** (*np.ndarray*) -- The conditional star formation rate density at the given redshift and radius for ACGs. * **sfrd_mini** (*np.ndarray or None*) -- The conditional star formation rate density at the given redshift and radius for MCGs. Will be None if `USE_MINI_HALOS` is False. .. rubric:: Notes This function estimates the conditional SFRD by using the global turnover masses. In reality, these turnover masses do not depend solely on redshift, but also on the local density field, as well on its environment and history. Since it is impossible to well-define the conditional SFRD in given region by only providing redshift and density, we approximate the used turnover masses in this calculation to be the global ones. .. !! processed by numpydoc !! .. py:function:: evaluate_SFRD_z(*, inputs: py21cmfast.wrapper.inputs.InputParameters, redshifts: numpy.typing.NDArray[numpy.floating], log10mturns: numpy.typing.NDArray[numpy.floating] | None = None, lightcone: py21cmfast.drivers.lightcone.LightCone | None = None, global_evolution: py21cmfast.drivers.global_evolution.GlobalEvolution | None = None) Evaluate the global star formation rate density (in units of M_sun/s/Mpc^3) expected at a range of redshifts. :Parameters: * **inputs** (:class:`~InputParameters`) -- The input parameters defining the simulation run. * **redshifts** (*array-like*) -- The redshifts at which to compute the SFRD. * **lightcone** (:class:`~LightCone` or None, optional) -- The lightcone object to use for the computation. If None, the function will consider `global_evolution` for the global m_turnover values, otherwise they will be extracted from the given lightcone. * **global_evolution** (:class:`~GlobalEvolution` or None, optional) -- The global evolution object to use for the computation. If None, the function will run a global evolution to estimate the global m_turnover values, otherwise they will be extracted from the given global evolution. :returns: * **sfrd** (*np.ndarray*) -- The global star formation rate density at the given redshifts for ACGs. * **sfrd_mini** (*np.ndarray or None*) -- The global star formation rate density at the given redshifts for MCGs. Will be None if `USE_MINI_HALOS` is False. .. !! processed by numpydoc !! .. py:function:: evaluate_Xray_cond(*, inputs: py21cmfast.wrapper.inputs.InputParameters, redshift: float, radius: float, densities: numpy.typing.NDArray[numpy.floating], log10mturns: numpy.typing.NDArray[numpy.floating] | None = None, lightcone: py21cmfast.drivers.lightcone.LightCone | None = None, global_evolution: py21cmfast.drivers.global_evolution.GlobalEvolution | None = None) Evaluate the conditional X-ray emissivity (in units of erg/s/Mpc^3) expected at a range of densities. :Parameters: * **inputs** (:class:`~InputParameters`) -- The input parameters defining the simulation run. * **redshift** (*float*) -- The redshift at which to compute the conditional X-ray emissivity. * **radius** (*float*) -- The radius of the region at which to compute the conditional X-ray emissivity. * **densities** (*array-like*) -- The densities at which to compute the conditional X-ray emissivity. * **lightcone** (:class:`~LightCone` or None, optional) -- The lightcone object to use for the computation. If None, the function will consider `global_evolution` for the global m_turnover values, otherwise they will be extracted from the given lightcone. * **global_evolution** (:class:`~GlobalEvolution` or None, optional) -- The global evolution object to use for the computation. If None, the function will run a global evolution to estimate the global m_turnover values, otherwise they will be extracted from the given global evolution. :returns: **xray_emissivity** (*np.ndarray*) -- The conditional X-ray emissivity at the given redshift and radius for ACGs and MCGs combined. .. rubric:: Notes This function estimates the conditional X-ray emissivity by using the global turnover masses. In reality, these turnover masses do not depend solely on redshift, but also on the local density field, as well on its environment and history. Since it is impossible to well-define the conditional X-ray emissivity in given region by only providing redshift and density, we approximate the used turnover masses in this calculation to be the global ones. .. !! processed by numpydoc !! .. py:function:: evaluate_condition_integrals(inputs: py21cmfast.wrapper.inputs.InputParameters, cond_array: numpy.typing.NDArray[numpy.floating], redshift: float, redshift_prev: float | None = None) 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. .. !! processed by numpydoc !! .. py:function:: evaluate_inverse_table(inputs: py21cmfast.wrapper.inputs.InputParameters, cond_array: numpy.typing.NDArray[numpy.floating], probabilities: numpy.typing.NDArray[numpy.floating], redshift: float, redshift_prev: float | None = None) Get the expected number and mass of halos given a condition. .. !! processed by numpydoc !! .. py:function:: evaluate_sigma(*, inputs: py21cmfast.wrapper.inputs.InputParameters, masses: numpy.typing.NDArray[numpy.floating]) Evaluate the variance of a mass scale. Uses the 21cmfast backend .. !! processed by numpydoc !! .. py:function:: get_condition_mass(inputs: py21cmfast.wrapper.inputs.InputParameters, R: float) Determine condition masses for backend routines. Returns either mass contained within a radius, or mass of the Lagrangian cell on HII_DIM .. !! processed by numpydoc !! .. py:function:: get_delta_crit(*, inputs: py21cmfast.wrapper.inputs.InputParameters, mass: float, redshift: float) Get the critical collapse density given a mass, redshift and parameters. .. !! processed by numpydoc !! .. py:function:: get_delta_crit_nu(hmf_int_flag: int, sigma: float, growth: float) Get the critical density from sigma and growth factor. .. !! processed by numpydoc !! .. py:function:: get_expected_nhalo(*, redshift: float, inputs: py21cmfast.wrapper.inputs.InputParameters) -> int Get the expected number of halos in a given box. :Parameters: * **redshift** (*float*) -- The redshift at which to calculate the halo list. * **inputs** (:class:`~InputParameters`) -- The input parameters of the run :returns: **n_halo** (*float*) -- The expected number of halos in the box at the given redshift under the given model. :raises ValueError :: If the matter options do not have a discrete halo model. .. !! processed by numpydoc !! .. py:function:: get_growth_factor(*, inputs: py21cmfast.wrapper.inputs.InputParameters, redshift: float) Get the growth factor at a given redshift. .. !! processed by numpydoc !! .. py:function:: get_halo_catalog_buffer_size(*, redshift: float, inputs: py21cmfast.wrapper.inputs.InputParameters, min_size: int = 1000000) -> int 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** (:class:`~InputParameters`) -- The input parameters of the run * **min_size** (*int, optional*) -- A minimum size to be used as the buffer. .. !! processed by numpydoc !! .. py:function:: get_matter_power_values(*, inputs: py21cmfast.wrapper.inputs.InputParameters, k_values: collections.abc.Sequence[float]) Evaluate the matter density power spectrum (at z=0) at a certain scale from the 21cmFAST backend. .. !! processed by numpydoc !! .. py:function:: get_vcb_power_values(*, inputs: py21cmfast.wrapper.inputs.InputParameters, k_values: collections.abc.Sequence[float]) Evaluate the vcb power spectrum (at kinematic decoupling) at a certain scale from the 21cmFAST backend. .. !! processed by numpydoc !! .. py:function:: integrate_chmf_interval(inputs: py21cmfast.wrapper.inputs.InputParameters, redshift: float, lnm_lower: numpy.typing.NDArray[numpy.floating], lnm_upper: numpy.typing.NDArray[numpy.floating], cond_values: numpy.typing.NDArray[numpy.floating], redshift_prev: float | None = None) Evaluate conditional mass function integrals at a range of mass intervals. .. !! processed by numpydoc !! .. py:function:: return_chmf_value(*, inputs: py21cmfast.wrapper.inputs.InputParameters, redshift: float, mass_values: collections.abc.Sequence[float], delta_values: collections.abc.Sequence[float], condmass_values: collections.abc.Sequence[float]) 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. .. !! processed by numpydoc !! .. py:function:: return_uhmf_value(*, inputs: py21cmfast.wrapper.inputs.InputParameters, redshift: float, mass_values: collections.abc.Sequence[float]) 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. .. !! processed by numpydoc !! .. py:function:: sample_halos_from_conditions(*, inputs: py21cmfast.wrapper.inputs.InputParameters, redshift: float, cond_array, redshift_prev: float | None = None, buffer_size: int | None = None) Construct a halo sample given a descendant catalogue and redshifts. .. !! processed by numpydoc !! .. py:data:: logger