Exemple #1
0
def analyze(config):
    """ Analyzes the data, i.e. a thin wrapper to firecrown

    Parameters:
    ----------
    config : dict
        The yaml parsed dictional of the input yaml file
    """

    ana_config = config["analyze"]
    config, data = firecrown.parse(firecrown_sanitize(ana_config))
    firecrown.run_cosmosis(config, data,
                           pathlib.Path(config["cosmosis"]["output_dir"]))
Exemple #2
0
def generate(config):
    """Generates data using dictionary based config.

    Parameters:
    ----------
    config : dict
        The yaml parsed dictional of the input yaml file
    """

    verbose = config["verbose"]
    gen_config = config["generate"]
    gen_config["verbose"] = verbose

    capabilities = [("two_point", "firecrown.ccl.two_point",
                     two_point_template, two_point_insert)]
    process = []

    # we now loop over generate config items and try
    # to pick out those items that correspond to a firecrown
    # sections. We find those by requiring that they have a
    # "module" attribute (e.g.
    # two_point.module = firecrown.ccl.two_point). But to check
    # for this robustly, we first check if the thing is really a
    # dictionary.
    for dname, ddict in gen_config.items():
        if isinstance(ddict, dict) and "module" in ddict:
            for name, moduleid, gen_template, gen_insert in capabilities:
                if ddict["module"] == moduleid:
                    if verbose:
                        print("Generating %s template for section %s..." %
                              (name, dname))
                    process.append((dname, name, gen_insert))
                    gen_config[dname]["verbose"] = verbose
                    gen_template(gen_config[dname])
                continue

    if verbose:
        print("Stoking the bird for predictions...")

    config, data = firecrown.parse(firecrown_sanitize(gen_config))
    cosmo = firecrown.get_ccl_cosmology(config["parameters"])
    firecrown.compute_loglike(cosmo=cosmo, data=data)

    for dname, name, gen_insert in process:
        if verbose:
            print("Writing %s data for section %s..." % (name, dname))
        gen_insert(gen_config[dname], data)
Exemple #3
0
def figure_of_merit(sacc_data, what, galaxy_tracer_bias):
    import firecrown

    ntot = len(sacc_data.tracers)
    nbin = ntot // 2 if what == "3x2" else ntot
    tracer_type = get_tracer_type(nbin, what)

    # Load the baseline configuration
    config = yaml.safe_load(open(default_config_path))

    # Override pieces of the configuration.
    # Start with the tracer list.
    sourcename = []
    if what == "gg" or what == "3x2":
        for b in range(nbin):
            config['parameters'][f'bias_{b}'] = galaxy_tracer_bias[b]
            config['two_point']['sources'][f'lens_{b}'] = {
                'kind': 'NumberCountsSource',
                'sacc_tracer': f'lens_{b}',
                'bias': f'bias_{b}',
                'systematics': {}
            }
            sourcename.append(f"lens_{b}")
    if what == "ww" or what == "3x2":
        for b in range(nbin):
            config['two_point']['sources'][f'source_{b}'] = {
                'kind': 'WLSource',
                'sacc_tracer': f'source_{b}',
                'systematics': {}
            }
            sourcename.append(f"source_{b}")

    def corrtype(i, j, tracer_type):
        tt = tracer_type[i] + tracer_type[j]
        if tt == 'gg':
            return "galaxy_density_cl"
        elif tt == 'ww':
            return "galaxy_shear_cl_ee"
        else:
            return "galaxy_shearDensity_cl_e"

    # Override pieces of the configuration.
    # Then the statistics list (all pairs).
    config['two_point']['statistics'] = {
        f'cl_{i}_{j}': {
            'sources': [sourcename[i], sourcename[j]],
            'sacc_data_type': corrtype(i, j, tracer_type)
        }
        for i in range(ntot) for j in range(i, ntot)
    }

    # The C_ell values going into the data vector (all of them)
    config['two_point']['likelihood']['data_vector'] = [
        f'cl_{i}_{j}' for i in range(ntot) for j in range(i, ntot)
    ]

    # and finally override the sacc_data object itself.
    config['two_point']['sacc_data'] = sacc_data

    # Now run firecrown in a temporary directory
    # and load the resulting fisher matrix
    conf, data = firecrown.parse(config)
    with tempfile.TemporaryDirectory() as tmp:
        firecrown.run_cosmosis(conf, data, pathlib.Path(tmp))
        fisher_matrix = np.loadtxt(f'{tmp}/chain.txt')

    # Pull out the correct indices.  We would like to use
    # w0 - wa but can't yet because
    param_names = list(config['cosmosis']['parameters'].keys())
    i = param_names.index('Omega_c')
    j = param_names.index('sigma8')

    # Convert the Fisher matrix to a covariance
    covmat = np.linalg.inv(fisher_matrix)

    # Pull out the 2x2 chunk of the covariance matrix
    covmat_chunk = covmat[:, [i, j]][[i, j], :]

    # And get the FoM, the inverse area of the 2 sigma contour
    # area.
    area = 6.17 * np.pi * np.sqrt(np.linalg.det(covmat_chunk))
    fom = 1 / area

    return fom