py21cmfast.InputParameters

class py21cmfast.InputParameters

A class defining a collection of InputStruct instances.

This class simplifies combining different InputStruct instances together, performing validation checks between them, and being able to cross-check compatibility between different sets of instances.

Parameters:
  • random_seed (float) – The seed that determines the realization produced by a 21cmFAST run.

  • node_redshifts (list[float]) – The redshifts at which coeval boxes will be computed. By default, empty if no evolution is required, and logarithmically spaced in (1+z) between z=5.5 and SimulationOptions.Z_HEAT_MAX if evolution is required.

  • cosmo_params (CosmoParams) – Cosmological parameters of a 21cmFAST run.

  • simulation_options (SimulationOptions) – Parameters controlling the simulation as a whole, e.g. the box size and dimensionality.

  • matter_options (MatterOptions) – Parameters controlling the matter field generated by 21cmFAST.

  • astro_options (AstroOptions) – Options for which physical processes to include in the simulation.

  • astro_params (AstroParams) – Astrophysical parameter values.

asdict(only_structs: bool = False, camel: bool = False, remove_base_cosmo: bool = True, only_cstruct_params: bool = True, use_aliases: bool = True, include_cosmo_tables: Literal['always', 'if_cached', 'never'] = 'always') dict[str, dict[str, Any]]

Convert the instance to a recursive dictionary.

Parameters:
  • only_structs – If True, only include parameter-struct-like fields (including cosmo_tables when included).

  • camel – If True, convert top-level input struct keys to CamelCase.

  • remove_base_cosmo – If True, remove the non-serializable _base_cosmo object from cosmo_params.

  • only_cstruct_params – If True, keep only fields that are required by each C struct.

  • use_aliases – If True, use constructor aliases for InputStruct fields (e.g. DIM instead of _DIM).

  • include_cosmo_tables – Controls whether cached cosmology tables are emitted in the dictionary.

    • "always": force materialization of cosmo_tables and include it in the output. This is the default for in-memory conversions.

    • "if_cached": include tables only if they were already materialized, which avoids triggering CLASS work during serialization.

    • "never": omit tables entirely, useful for portable templates.

Parameters:
  • only_structs (bool)

  • camel (bool)

  • remove_base_cosmo (bool)

  • only_cstruct_params (bool)

  • use_aliases (bool)

  • include_cosmo_tables (Literal['always', 'if_cached', 'never'])

Return type:

dict[str, dict[str, Any]]

clone(**kwargs) Self

Generate a copy of the InputParameter structure with specified changes.

Return type:

Self

evolve_input_structs(**kwargs) Self

Return an altered clone of the InputParameters structs.

Unlike clone(), this function takes fields from the constituent InputStruct classes and only overwrites those sub-fields instead of the entire field

Return type:

Self

classmethod from_template(name: str | pathlib.Path | collections.abc.Sequence[str | pathlib.Path], random_seed: int | None = None, node_redshifts: tuple[float] | None = None, **kwargs) Self

Construct full InputParameters instance from native or TOML file template.

Parameters:
  • name – Either a name of a built-in template, or a path to a parameter TOML, or a list of such names/paths. If a list, the final parameters will be built from left-to-right so that the parameters at the end of the list will have precedence.

  • random_seed – A random seed to use for the run.

  • node_redshifts – The redshifts at which to evolve the simulation (if applicable). Default detects whether evolution is required and sets the node redshifts according to the simulation parameters.

Other Parameters:
  • All other parameters are interpreted as elements of :class:`InputStruct`

  • subclasses (e.g. :class:`SimulationOptions`) and will over-ride what is in

  • the template.

Parameters:
  • name (str | pathlib.Path | collections.abc.Sequence[str | pathlib.Path])

  • random_seed (int | None)

  • node_redshifts (tuple[float] | None)

Return type:

Self

is_compatible_with(other: Self) bool

Check if this object is compatible with another parameter struct.

Compatibility is slightly different from strict equality. Compatibility requires that if a parameter struct exists on the other object, then it must be equal to this one. That is, if astro_params is None on the other InputParameter object, then this one can have astro_params as NOT None, and it will still be compatible. However the inverse is not true – if this one has astro_params as None, then all others must have it as None as well.

Parameters:

other (Self)

Return type:

bool

with_linear_redshifts(zmin: float = 5.5, zmax: float | None = None, step: float | None = None, nz: int | None = None) Self

Create a new InputParameters instance with linearly-spaced redshifts.

Parameters:
  • zmin – Minimum redshift of the node grid.

  • zmax – Maximum redshift of the node grid. Defaults to Z_HEAT_MAX from SimulationOptions.

  • zstep – Linear step size between consecutive redshifts. The grid will include zmin and extend up to at least zmax. Ignored when nz is provided.

  • nz – If given, produce exactly nz redshifts linearly spaced between zmin and zmax, overriding step.

Parameters:
  • zmin (float)

  • zmax (float | None)

  • step (float | None)

  • nz (int | None)

Return type:

Self

with_logspaced_redshifts(zmin: float = 5.5, zmax: float | None = None, step: float | None = None, zstep_factor: float | None = None, nz: int | None = None) Self

Create a new InputParameters instance with logspaced redshifts.

Parameters:
  • zmin – Minimum redshift of the node grid.

  • zmax – Maximum redshift of the node grid. Defaults to Z_HEAT_MAX from SimulationOptions.

  • step – Multiplicative step factor between consecutive (1 + z) values. Defaults to ZPRIME_STEP_FACTOR from SimulationOptions. Ignored when nz is provided.

  • nz – If given, produce exactly nz redshifts equally spaced in log(1 + z) between zmin and zmax, overriding step.

Parameters:
  • zmin (float)

  • zmax (float | None)

  • step (float | None)

  • zstep_factor (float | None)

  • nz (int | None)

Return type:

Self

astro_options: AstroOptions
astro_params: AstroParams
cosmo_params: CosmoParams
property cosmo_tables: CosmoTables

Cosmological tables derived from fundamental input parameters.

Return type:

CosmoTables

property evolution_required: bool

Whether evolution is required for these parameters.

Return type:

bool

matter_options: MatterOptions
node_redshifts
random_seed: int
simulation_options: SimulationOptions