cosmosis_utils module

Contains utility functions for creating and post-processing CosmoSIS grids.

cosmosis_utils.combine_chain_output(input_dir, chain_subdir_mask='chain{i}', filemask='_{n}.tgz', clean=True)

Combine output from multiple chains into a single directory without clashing filenames.

Parameters
  • input_dir (str) – Path to directory containing all the chain subdirectories.

  • chain_subdir_mask (str) – Chain subdirectory name with chain number replaced with {i}.

  • filemask (str) – Filemask of files within chains, with number replaced with {n}.

  • clean (bool, optional) – Whether to delete chain subdirectories afterwards (default True).

cosmosis_utils.extract_data(input_dir, filemask='_*.tgz', params_filename='cosmological_parameters/values.txt', nodelete=False, target_filenames=None, nbin_3x2=None, nbin_shear=None)

Takes a directory full of CosmoSIS output (i.e. _0.tgz etc), extracts the desired output and throws away the rest.

Either takes a predetermined list of target filenames, or automatically generates it for a tomographic 3x2pt or shear-only set of power spectra, depending on the values of target_filenames, nbin_3x2 and nbin_shear. Exactly one of these three must be set.

Parameters
  • input_dir (str) – Path to the directory containing the tar files.

  • filemask (str, optional) – Mask matching file names to extract. Defaults to ‘_*.tgz’.

  • params_filename (str, optional) – Path to the file containing cosmological parameters within each tar file. Defaults to ‘cosmological_parameters/values.txt’.

  • nodelete (bool, optional) – Whether to retain the tar files after extraction (False) or delete them (True, default).

  • target_filenames (list, optional) – List of filenames to extract, e.g. [‘shear_cl/ell.txt’, ‘shear_cl/bin_1_1.txt’].

  • nbin_3x2 (int, None) – Number of redshift bins to auto-generate target filenames for a 3x2pt analysis.

  • nbin_shear (int, None) – Number of redshift bins to auto-generate target filenames for a shear-only analysis.

cosmosis_utils.generate_chain_input(params, n_chains, output_dir)

Generate a custom number of chain text files for input to the list sampler in cosmosis, covering a whole regular N-dimensional grid.

Parameters
  • params (dict) – Dictionary containing one sub-dictionary for each parameter to be varied. Each subdirectory should contain three items: min (minimum value), max (maximum value) and steps (number of steps including endpoints) - see example below.

  • n_chains (int) – Number of chains to output.

  • output_dir (str) – Path to output directory where the text files will be saved.

Example for params:

params = {
    'cosmological_parameters--w': {
        'min': -1.5,
        'max': -0.5,
        'steps': 41
    },
    'cosmological_parameters--wa': {
        'min': -1.0,
        'max': 1.0,
        'steps': 51
    }
}