Source code for GUIBRUSHR.core.config.parameters

"""
Parameter schema configuration module for GUIBRUSHR.

Provides a focused ``ParameterSchema`` class that loads the retrieval parameter
definitions from ``parameters.yaml`` and exposes the categorised parameter lists
used throughout the application.  This covers the parameter configuration block
that was previously part of the monolithic ``ConstantVariables`` class (lines
187-192).
"""

from pathlib import Path
from typing import Any, Dict, List

import yaml


def _load_yaml_config(file_path: str) -> Dict[str, Any]:
    """Load and parse a YAML configuration file.

    Parameters
    ----------
    file_path : str
        Absolute path to the YAML file.

    Returns
    -------
    Dict[str, Any]
        Parsed contents of the YAML file.

    Raises
    ------
    RuntimeError
        If the file cannot be opened or parsed.
    """
    try:
        with open(file_path, "r") as f:
            return yaml.safe_load(f)
    except Exception as e:
        raise RuntimeError(
            f"Failed to load YAML configuration {file_path}: {str(e)}"
        )


[docs] class ParameterSchema: """Retrieval parameter schema for GUIBRUSHR. Loads ``parameters.yaml`` from *configuration_yaml_path* and exposes the parameter dictionaries and categorised lists used during retrieval setup. Parameters ---------- configuration_yaml_path : str Absolute path to the directory that contains the YAML configuration files (the same value as :attr:`~GUIBRUSHR.General_Constants.FunctionsAndConstants.Constant_Variables.ConstantVariables.configuration_yaml_path`). Attributes ---------- PARAMS_DICT : Dict[str, Dict] Full parameter dictionary loaded from ``parameters.yaml``. Each key is a parameter name; each value is a dict of metadata fields (e.g. ``"multi"``, ``"label"``, ``"range_min"``, ``"range_max"``). PARAMS_LIST : List[str] Ordered list of all parameter names (keys of ``PARAMS_DICT``). LIST_MULTIPLE_PARAM : List[str] Parameters whose ``"multi"`` field is >= 1 (can be duplicated across instruments or species). LIST_DERIVATIVE_PARAMS : List[str] Parameters whose ``"multi"`` field equals 2 (derivative parameters). LIST_MOLECULAR_PARAMS : List[str] Parameters whose ``"multi"`` field equals 3 (molecular abundance parameters). LIST_INSTRUMENTAL_PARAMS : List[str] Parameters whose ``"multi"`` field equals 4 (instrument-specific parameters). """
[docs] def __init__(self, configuration_yaml_path: str) -> None: parameters_yaml: Dict[str, Any] = _load_yaml_config( str(Path(configuration_yaml_path, "parameters.yaml")) ) self.PARAMS_DICT: Dict[str, Dict] = parameters_yaml self.PARAMS_LIST: List[str] = list(self.PARAMS_DICT.keys()) self.LIST_MULTIPLE_PARAM: List[str] = [ key for key, details in self.PARAMS_DICT.items() if details["multi"] >= 1 ] self.LIST_DERIVATIVE_PARAMS: List[str] = [ key for key, details in self.PARAMS_DICT.items() if details["multi"] == 2 ] self.LIST_MOLECULAR_PARAMS: List[str] = [ key for key, details in self.PARAMS_DICT.items() if details["multi"] == 3 ] self.LIST_INSTRUMENTAL_PARAMS: List[str] = [ key for key, details in self.PARAMS_DICT.items() if details["multi"] == 4 ]