py21cmfast.wrapper.run_lightcone(*, redshift: float = None, max_redshift: float = None, lightcone_quantities=('brightness_temp',), lightconer: py21cmfast.lightcones.Lightconer | None = None, user_params=None, cosmo_params=None, astro_params=None, flag_options=None, regenerate=None, write=None, global_quantities=('brightness_temp', 'xH_box'), direc=None, init_box=None, perturb=None, random_seed=None, coeval_callback=None, coeval_callback_redshifts=1, use_interp_perturb_field=False, cleanup=True, hooks=None, always_purge: bool = False, lightcone_filename: str | pathlib.Path = None, return_at_z: float = 0.0, **global_kwargs)[source]

Evaluate a full lightcone ending at a given redshift.

This is generally the easiest and most efficient way to generate a lightcone, though it can be done manually by using the lower-level functions which are called by this function.

  • redshift (float) – The minimum redshift of the lightcone.

  • max_redshift (float, optional) – The maximum redshift at which to keep lightcone information. By default, this is equal to z_heat_max. Note that this is not exact, but will be typically slightly exceeded.

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

  • astro_params (AstroParams, optional) – Defines the astrophysical parameters of the run.

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

  • flag_options (FlagOptions, optional) – Options concerning how the reionization process is run, eg. if spin temperature fluctuations are required.

  • lightcone_quantities (tuple of str, optional) – The quantities to form into a lightcone. By default, just the brightness temperature. Note that these quantities must exist in one of the output structures:

    • InitialConditions

    • PerturbField

    • TsBox

    • IonizedBox

    • BrightnessTemp

    To get a full list of possible quantities, run get_all_fieldnames().

  • global_quantities (tuple of str, optional) – The quantities to save as globally-averaged redshift-dependent functions. These may be any of the quantities that can be used in lightcone_quantities. The mean is taken over the full 3D cube at each redshift, rather than a 2D slice.

  • init_box (InitialConditions, optional) – If given, the user and cosmo params will be set from this object, and it will not be re-calculated.

  • perturb (list of PerturbedField, optional) – If given, must be compatible with init_box. It will merely negate the necessity of re-calculating the perturb fields. It will also be used to set the redshift if given.

  • coeval_callback (callable, optional) – User-defined arbitrary function computed on Coeval, at redshifts defined in coeval_callback_redshifts. If given, the function returns LightCone and the list of coeval_callback outputs.

  • coeval_callback_redshifts (list or int, optional) – Redshifts for coeval_callback computation. If list, computes the function on node_redshifts closest to the specified ones. If positive integer, computes the function on every n-th redshift in node_redshifts. Ignored in the case coeval_callback is None.

  • use_interp_perturb_field (bool, optional) – Whether to use a single perturb field, at the lowest redshift of the lightcone, to determine all spin temperature fields. If so, this field is interpolated in the underlying C-code to the correct redshift. This is less accurate (and no more efficient), but provides compatibility with older versions of 21cmFAST.

  • cleanup (bool, optional) – A flag to specify whether the C routine cleans up its memory before returning. Typically, if spin_temperature is called directly, you will want this to be true, as if the next box to be calculate has different shape, errors will occur if memory is not cleaned. Note that internally, this is set to False until the last iteration.

  • minimize_memory_usage – If switched on, the routine will do all it can to minimize peak memory usage. This will be at the cost of disk I/O and CPU time. Recommended to only set this if you are running particularly large boxes, or have low RAM.

  • lightcone_filename – The filename to which to save the lightcone. The lightcone is returned in memory, and can be saved manually later, but including this filename will save the lightcone on each iteration, which can be helpful for checkpointing.

  • return_at_z – If given, evaluation of the lightcone will be stopped at the given redshift, and the partial lightcone object will be returned. Lightcone evaluation can continue if the returned lightcone is saved to file, and this file is passed as lightcone_filename.

  • **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.


  • lightcone (LightCone) – The lightcone object.

  • coeval_callback_output (list) – Only if coeval_callback in not None.

Other Parameters:

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