Skip to content

halocat.config_io

config_io

YAML config loader that can override halocat.config at runtime.

Only the knobs that the pipeline reads at call time (e.g. R_EDGES and MASS_BINS from halocat.config) can be overridden this way — see pipeline.run_single for the list of references.

load_xi_hh_config

load_xi_hh_config(path: str) -> dict

Load the YAML file and return a dict with 'r_edges' and 'mass_bins'.

Source code in halocat/config_io.py
def load_xi_hh_config(path: str) -> dict:
    """Load the YAML file and return a dict with 'r_edges' and 'mass_bins'."""
    if not os.path.exists(path):
        raise FileNotFoundError(path)
    with open(path) as f:
        raw = yaml.safe_load(f) or {}

    if "r_binning" not in raw:
        raise KeyError(f"{path}: missing 'r_binning' block")
    if "mass_bins" not in raw:
        raise KeyError(f"{path}: missing 'mass_bins' block")

    return {
        "r_edges": _parse_r_edges(raw["r_binning"]),
        "mass_bins": _parse_mass_bins(raw["mass_bins"]),
    }

apply_xi_hh_config

apply_xi_hh_config(path: str, logger=None) -> dict

Load path and monkey-patch halocat.config in place.

After this call, C.R_EDGES and C.MASS_BINS will hold the values from the YAML file, so anything that reads them at call time (pipeline.run_singletpcf.measure_xi_hh) picks up the override.

Returns the parsed dict (the same thing load_xi_hh_config returns).

Source code in halocat/config_io.py
def apply_xi_hh_config(path: str, logger=None) -> dict:
    """Load ``path`` and monkey-patch ``halocat.config`` in place.

    After this call, ``C.R_EDGES`` and ``C.MASS_BINS`` will hold the values
    from the YAML file, so anything that reads them at call time
    (``pipeline.run_single`` → ``tpcf.measure_xi_hh``) picks up the override.

    Returns the parsed dict (the same thing ``load_xi_hh_config`` returns).
    """
    cfg = load_xi_hh_config(path)
    C.R_EDGES = cfg["r_edges"]
    C.MASS_BINS = list(cfg["mass_bins"])
    if logger is not None:
        logger.info(
            f"xi_hh config applied from {path}: "
            f"{len(C.R_EDGES) - 1} r-bins "
            f"[{C.R_EDGES[0]:.3f}, {C.R_EDGES[-1]:.3f}], "
            f"{len(C.MASS_BINS)} mass bins"
        )
    return cfg