CosmoFit.model_from_expression

CosmoFit.model_from_expression(name, E, *, extra_params=None, label=None, w=None, dEdz=None, Omega_de=None, mu=None)[source]

Same as define_model(), but E/w/dEdz/ Omega_de/mu are given as Python expression strings (e.g. "sqrt(Omega_m*(1+z)**3 + (1-Omega_m)*(1+z)**(3*(1+w0)))") instead of callables – convenient for text-entry UIs (see the Streamlit app under app/), where asking for a Python function isn’t practical. E/w/dEdz/Omega_de expressions see z and every current parameter value (standard ones plus any extra_params) as plain names; mu instead sees a (scale factor) and k (wavenumber [h/Mpc], or None if not supplied by the caller) – see _compile_expression() for exactly what else is available.

Example

>>> MyModel = model_from_expression(
...     "MyModel",
...     E="sqrt(Omega_m*(1+z)**3 + (1-Omega_m)*(1+z)**(3*(1+w0))*(1+beta*z))",
...     extra_params={"beta": {"default": 0.0, "bounds": (-2.0, 2.0)}},
... )

A modified-gravity example (custom growth on top of an otherwise LCDM background, in the spirit of FRTLinear):

>>> MyMG = model_from_expression(
...     "MyMG",
...     E="sqrt(Omega_m*(1+z)**3 + (1-Omega_m))",
...     mu="1 + 3*beta",
...     extra_params={"beta": {"default": 0.0, "bounds": (-0.2, 0.2)}},
... )
Parameters:
  • name (str)

  • E (str)

  • extra_params (dict | None)

  • label (str | None)

  • w (str | None)

  • dEdz (str | None)

  • Omega_de (str | None)

  • mu (str | None)

Return type:

type