py21cmmc.likelihood.Likelihood1DPowerCoeval#
- class py21cmmc.likelihood.Likelihood1DPowerCoeval(n_psbins=None, min_k=0.1, max_k=1.0, logk=True, model_uncertainty=0.15, error_on_model=True, ignore_kperp_zero=True, ignore_kpar_zero=False, ignore_k_zero=False, name='', *args, **kwargs)[source]#
A Gaussian likelihood for the 1D power spectrum of a coeval cube.
Requires the
CoreCoevalModule
to be loaded to work, and inherently deals with the multiple-redshift cubes which that module produces.- Parameters:
datafile (str, optional) – Path to file containing data. See
LikelihoodBaseFile
for details.noisefile (str, optional) – Path to file containing noise data. See
LikelihoodBaseFile
for details.n_psbins (int, optional) – The number of bins for the spherically averaged power spectrum. By default automatically calculated from the number of cells.
min_k (float, optional) – The minimum k value at which to compare model and data (units 1/Mpc).
max_k (float, optional) – The maximum k value at which to compare model and data (units 1/Mpc).
logk (bool, optional) – Whether the power spectrum bins should be regular in logspace or linear space.
model_uncertainty (float, optional) – The amount of uncertainty in the modelling, per power spectral bin (as fraction of the amplitude).
error_on_model (bool, optional) – Whether the model_uncertainty is applied to the model, or the data.
ignore_kperp_zero (bool, optional) – Whether to ignore the kperp=0 when generating the power spectrum.
ignore_kpar_zero (bool, optional) – Whether to ignore the kpar=0 when generating the power spectrum.
ignore_k_zero (bool, optional) – Whether to ignore the
|k| = 0
mode when generating the power spectrum.
- Other Parameters:
**kwargs – All other parameters sent to
LikelihoodBaseFile
. In particular,datafile
,noisefile
,simulate
anduse_data
.
Notes
The
datafile
andnoisefile
have specific formatting required. Both should be .npz files. The datafile should have ‘k’ and ‘delta’ arrays in it (k-modes in 1/Mpc and power spectrum respectively) and the noisefile should have ‘k’ and ‘errs’ arrays in it (k-modes and their standard deviations respectively). Note that the latter is almost the default output of 21cmSense, except that 21cmSense has k in units of h/Mpc, whereas 21cmFAST/21CMMC use units of 1/Mpc.Warning
Please ensure that the data/noise is in the correct units for 21CMMC, as this class does not automatically convert units!
To make this more flexible, simply subclass this class, and overwrite the
_read_data()
or_read_noise()
methods, then use that likelihood instead of this in your likelihood chain. Both of these functions should return dictionaries in which the above entries exist. For example:>>> class MyCoevalLikelihood(Likelihood1DPowerCoeval): >>> def _read_data(self): >>> data = np.genfromtxt(self.datafile) >>> return {"k": data[:, 0], "p": data[:, 1]}
Also note that an extra method,
define_noise
may be used to define the noise properties dynamically (i.e. without reading it). This method will be called if available and simulate=True. It should have the signaturedefine_noise(self, ctx, model)
, wherectx
is the context with all cores having added their data, andmodel
is the output of thesimulate()
method.Methods
__init__
([n_psbins, min_k, max_k, logk, ...])computeLikelihood
(model)Compute the likelihood given a model.
compute_power
(brightness_temp, L, n_psbins)Compute power spectrum from coeval box.
Compute and return a model dictionary at the fiducial set of parameters.
reduce_data
(ctx)Reduce the data in the context to a list of models (one for each redshift).
setup
()Perform post-init setup.
store
(model, storage)Save elements of the model to the storage dict.
Attributes
Reference to the
LikelihoodComputationChain
containing this core.The first core that appears in the requirements.
Splines of data power spectra.
Splines of noise power spectra.
The PS core that is paired with this likelihood.
Names of the parameters of the full chain.
The redshifts of coeval simulations.