py21cmfast.InitialConditions

class py21cmfast.InitialConditions

Bases: OutputStruct

A class representing an InitialConditions C-struct.

classmethod __init_subclass__()

Store subclasses for easy access.

compute(allow_already_computed=False)

Compute the function.

Parameters:

allow_already_computed (bool)

ensure_arrays_computed(*arrays, load=False)

Check if the given arrays are computed (not just initialized).

Return type:

bool

ensure_arrays_inited(*arrays, init=False)

Check if the given arrays are initialized (or computed).

Return type:

bool

ensure_input_computed(input_box, load=False)

Ensure all the inputs have been computed.

Parameters:
  • input_box (Self)

  • load (bool)

Return type:

bool

get(ary)

If possible, load an array from disk, storing it and returning the underlying array.

Parameters:

ary (str | py21cmfast.wrapper.arrays.Array)

get_full_size()

Return the size of the object in bytes.

This represents the size of the object if it is fully initialized/computed and all in memory. Equivalently, it is close to the file size on disk.

Return type:

int

get_required_input_arrays(input_box)

Return all input arrays required to compute this object.

Parameters:

input_box (OutputStruct)

Return type:

list[str]

load_all()

Load all possible arrays into memory.

classmethod new(inputs, **kw)

Create a new instance, given a set of input parameters.

Parameters:

inputs (py21cmfast.wrapper.inputs.InputParameters)

Return type:

Self

prepare(flush=None, keep=None, force=False)

Prepare the instance for being passed to another function.

This will flush all arrays in “flush” from memory, and ensure all arrays in “keep” are in memory. At least one of these must be provided. By default, the complement of the given parameter is all flushed/kept.

Parameters:
  • flush – Arrays to flush out of memory. Note that if no file is associated with this instance, these arrays will be lost forever.

  • keep – Arrays to keep or load into memory. Note that if these do not already exist, they will be loaded from file (if the file exists). Only one of flush and keep should be specified.

  • force – Whether to force flushing arrays even if no disk storage exists.

Parameters:
  • flush (collections.abc.Sequence[str] | None)

  • keep (collections.abc.Sequence[str] | None)

  • force (bool)

prepare_for_perturb(force=False)

Ensure the ICs have all the boxes loaded for perturb, but no extra.

Parameters:

force (bool)

prepare_for_spin_temp(force=False)

Ensure ICs have all boxes required for spin_temp, and no more.

Parameters:

force (bool)

pull_from_backend()

Sync the current state of the object with the underlying C-struct.

This will pull any primitives calculated in the backend to the python object. Arrays are passed in as pointers, and do not need to be copied back.

purge(force=False)

Flush all the boxes out of memory.

Parameters:

force – Whether to force the purge even if no disk storage exists.

push_to_backend()

Push the current state of the object with the underlying C-struct.

This will link any memory initialized by numpy in this object with the underlying C-struct, and also update the C struct with any values in the python object.

set(name, value)

Set the value of an array.

Parameters:
  • name (str)

  • value (Any)

summarize(indent=0)

Generate a string summary of the struct.

Parameters:

indent (int)

Return type:

str

__slots__ = ()
property arrays: dict[str, py21cmfast.wrapper.arrays.Array]

A dictionary of Array objects whose memory is shared between this object and the C backend.

Return type:

dict[str, py21cmfast.wrapper.arrays.Array]

property astro_options: py21cmfast.wrapper.inputs.AstroOptions

The AstroOptions object for this output struct.

Return type:

py21cmfast.wrapper.inputs.AstroOptions

property astro_params: py21cmfast.wrapper.inputs.AstroParams

The AstroParams object for this output struct.

Return type:

py21cmfast.wrapper.inputs.AstroParams

property cosmo_params: py21cmfast.wrapper.inputs.CosmoParams

The CosmoParams object for this output struct.

Return type:

py21cmfast.wrapper.inputs.CosmoParams

property cstruct: py21cmfast.wrapper.structs.StructWrapper

The object pointing to the memory accessed by C-code for this struct.

Return type:

py21cmfast.wrapper.structs.StructWrapper

dummy: bool
hires_density
hires_vx
hires_vx_2LPT
hires_vy
hires_vy_2LPT
hires_vz
hires_vz_2LPT
initial: bool
inputs: py21cmfast.wrapper.inputs.InputParameters
property is_computed: bool

Whether this instance has been computed at all.

This is true either if the current instance has called compute(), or if it has a current existing path pointing to stored data, or if such a path exists.

Just because the instance has been computed does not mean that all relevant quantities are available – some may have been purged from memory without writing. Use has() to check whether certain arrays are available.

Return type:

bool

lowres_density
lowres_vcb
lowres_vx
lowres_vx_2LPT
lowres_vy
lowres_vy_2LPT
lowres_vz
lowres_vz_2LPT
property matter_options: py21cmfast.wrapper.inputs.MatterOptions

The SimulationOptions object for this output struct.

Return type:

py21cmfast.wrapper.inputs.MatterOptions

property random_seed: int

The random seed for this particular instance.

Return type:

int

property simulation_options: py21cmfast.wrapper.inputs.SimulationOptions

The SimulationOptions object for this output struct.

Return type:

py21cmfast.wrapper.inputs.SimulationOptions

property struct: py21cmfast.wrapper.structs.StructWrapper

The python-wrapped struct associated with this input object.

Return type:

py21cmfast.wrapper.structs.StructWrapper