py21cmfast.wrapper.perturb_field

py21cmfast.wrapper.perturb_field(*, redshift, init_boxes=None, user_params=None, cosmo_params=None, random_seed=None, regenerate=None, write=None, direc=None, hooks: dict[Callable, dict[str, Any]] | None = None, **global_kwargs) PerturbedField[source]

Compute a perturbed field at a given redshift.

Parameters:
  • redshift (float) – The redshift at which to compute the perturbed field.

  • init_boxes (InitialConditions, optional) – If given, these initial conditions boxes will be used, otherwise initial conditions will be generated. If given, the user and cosmo params will be set from this object.

  • user_params (UserParams, optional) – Defines the overall options and parameters of the run.

  • cosmo_params (CosmoParams, optional) – Defines the cosmological parameters used to compute initial conditions.

  • **global_kwargs – Any attributes for GlobalParams. This will temporarily set global attributes for the duration of the function. Note that arguments will be treated as case-insensitive.

Returns:

PerturbedField

Other Parameters:

regenerate, write, direc, random_seed – See docs of initial_conditions() for more information.

Examples

The simplest method is just to give a redshift:

>>> field = perturb_field(7.0)
>>> print(field.density)

Doing so will internally call the initial_conditions() function. If initial conditions have already been calculated, this can be avoided by passing them:

>>> init_boxes = initial_conditions()
>>> field7 = perturb_field(7.0, init_boxes)
>>> field8 = perturb_field(8.0, init_boxes)

The user and cosmo parameter structures are by default inferred from the init_boxes, so that the following is consistent:

>>> init_boxes = initial_conditions(user_params= UserParams(HII_DIM=1000))
>>> field7 = perturb_field(7.0, init_boxes)

If init_boxes is not passed, then these parameters can be directly passed:

>>> field7 = perturb_field(7.0, user_params=UserParams(HII_DIM=1000))