Skip to content

validate

Validate a config-declared scenario against the actual IAM output.

Supports the config-declared invocation model: the user lists regions/years in config and this fails loudly before any prep runs if they are not present in the IAM source.

validate_scenario_against_remind(loader, symbols, declared_regions, declared_years)

Raise if any declared region/year is absent from the IAM source.

Years are read from the coupled_years symbol; regions from the co2_price frame (any region-bearing symbol would do). Raises ValueError listing what is missing.

Source code in src/iampypsa/validate.py
def validate_scenario_against_remind(
    loader: RemindLoader,
    symbols: dict[str, Any],
    declared_regions: Sequence[str],
    declared_years: Sequence[int],
) -> None:
    """Raise if any declared region/year is absent from the IAM source.

    Years are read from the ``coupled_years`` symbol; regions from the ``co2_price`` frame
    (any region-bearing symbol would do). Raises ``ValueError`` listing what is missing.
    """
    years_frame = load_frame(loader, symbols["coupled_years"])
    available_years = {int(y) for y in years_frame["year"]}
    missing_years = {int(y) for y in declared_years} - available_years

    region_frame = load_frame(loader, symbols["co2_price"])
    available_regions = set(region_frame["region"])
    missing_regions = set(declared_regions) - available_regions

    problems = []
    if missing_regions:
        problems.append(f"regions {sorted(missing_regions)} (available: {sorted(available_regions)})")
    if missing_years:
        problems.append(f"years {sorted(missing_years)} (available: {sorted(available_years)})")
    if problems:
        raise ValueError(
            "Config-declared scenario disagrees with the IAM source: " + "; ".join(problems)
        )