py21cmmc.core.CoreCoevalModule#
- class py21cmmc.core.CoreCoevalModule(redshift, user_params=None, flag_options=None, astro_params=None, cosmo_params=None, regenerate=True, change_seed_every_iter=False, ctx_variables=('brightness_temp', 'xH_box'), initial_conditions_seed=None, global_params=None, **io_options)[source]#
A Core Module which evaluates coeval cubes at given redshift.
On each iteration, this module will add to the context:
init
: anInitialConditions
instanceperturb
: aPerturbedField
instancexHI
: anIonizedBox
instancebrightness_temp
: aBrightnessTemp
instance
- Parameters:
redshift (float or array_like) – The redshift(s) at which to evaluate the coeval cubes.
user_params (dict or
UserParams
) – Parameters affecting the overall dimensions of the cubes.flag_options (dict or
FlagOptions
) – Options affecting choices for how the reionization is calculated.astro_params (dict or
AstroParams
) – Astrophysical parameters of reionization.Note
None of the parameters provided here affect the MCMC as such; they merely provide a background model on which the MCMC will be performed. Thus for example, passing
HII_EFF_FACTOR=30
inastro_params
here will be over-written per-iteration ifHII_EFF_FACTOR
is also passed as aparameter
to an MCMC routine using this core module.cosmo_params (dict or
CosmoParams
) – Cosmological parameters of the simulations. Likeastro_params
, these are the fiducial parameters, but may be updated during an MCMC.regenerate (bool, optional) – Whether to force regeneration of simulations, even if matching cached data is found.
do_spin_temp (bool, optional) – Whether to use spin temperature in the calculation, or assume the saturated limit.
z_step_factor (float, optional) – How large the logarithmic steps between redshift are (if required).
z_heat_max (float, optional) – Controls the global Z_HEAT_MAX parameter, which specifies the maximum redshift up to which heating sources are required to specify the ionization field. Beyond this, the ionization field is specified directly from the perturbed density field.
ctx_variables (list of str, optional) – A list of strings. The strings must correspond to any (pickleable) member of
py21cmfast.Coeval
. These will be stored in the context on every iteration. Omitting as many as possible is useful in that it reduces the memory that needs to be transmitted to each process. Furthermore, in-built pickling has a restriction that arrays cannot be larger than 4GiB, which can be easily over-run. Some typical options are: * “brightness_temp” * “xH_box” * “density” * “velocity” * “Gamma12_box”initial_conditions_seed (int, optional) – If not change_seeds_every_iter, then this will define the random seed on which the initial conditions for _all_ iterations is based. By default, a seed will be chosen at random, _unless_ initial conditions exist in cache that match the parameters of this instance (and
regenerate
is False). In this case, the seed of the existing box will be adopted.
- Other Parameters:
store (dict, optional) – The (derived) quantities/blobs to store in the MCMC chain, default empty. See Notes below for details.
cache_dir (str, optional) – The directory in which to search for the boxes and write them. By default, this is the directory given by
direc
in the configuration file,~/.21CMMC/config.yml
. Note that for reading data, while the specifieddirec
is searched first, the default directory will also be searched if no appropriate data is found indirec
.cache_ionize (bool, optional) – Whether to cache ionization data sets (done before parameter retention step). Default False.
Notes
The
store
keyword is a dictionary, where each key specifies the name of the resulting data entry in the samples object, and the value is a callable which receives thecontext
, and returns a value from it.Note
the
store
callable is saved to the core instance, which must be pickleable in order to use multiprocessing. Thus it is generally unwise to use alambda
function as the callable.This means that the context can be inspected and arbitrarily summarised before storage. In particular, this allows for taking slices of arrays and saving them. One thing to note is that the context is dictionary-like, but is not a dictionary. The elements of the context are only available by using the
get
method, rather than directly subscripting the object like a normal dictionary.Warning
Only scalars and arrays are supported for storage in the chain itself.
Methods
__init__
(redshift[, user_params, ...])build_model_data
(ctx)Compute all data defined by this core and add it to the context.
Generate random mock data.
prepare_storage
(ctx, storage)Add variables to dict which cosmoHammer will automatically store with the chain.
setup
()Perform setup of the core.
simulate_mock
(ctx)Generate all mock data and add it to the context.
Attributes
Reference to the
LikelihoodComputationChain
containing this core.The first core that appears in the requirements.
Names of the parameters of the full chain.