openairclim.gui.config_io

Configuration loading, validation, and saving logic.

Split into two validation stages so the sidebar can build an editable form as soon as a config is structurally sound, without forcing every referenced file to already exist:

  • parse_and_check_structure() — parse TOML, apply aliases, check required keys/types, fill in defaults. A failure here means the config can’t be safely edited (keys may be missing), so the caller should not build a form from it.

  • check_full_config() — run the core’s own full config check (core.read_config.check_config): structure, aircraft/contrail setup, and that every referenced inventory/response file actually exists. This function is run explicitly when a config file is loaded or when the user clicks the “validate” button.

openairclim.gui.config_io.blank_config()[source]

Return a configuration skeleton satisfying the required fields of core.config_model.Config, with everything the model can default itself (responses.*, temperature.*, metrics, parametric.*, inventories.base/rel_to_base, …) filled in by validate_config.

Only holds fields Config has no default for.

Returns:

Blank configuration dictionary with stringified paths.

Return type:

dict

openairclim.gui.config_io.check_full_config(working_dir, config)[source]

Run the core’s own full configuration check on a local config file.

Reuses core.read_config.check_config as-is. Operates on a deep copy, since check_config mutates/returns its input (migrates deprecated keys and merges in defaults in place). The live config being edited in the GUI shouldn’t change as a side effect of validating it.

Parameters:
  • working_dir (str) – Project working directory — paths inside the config are resolved relative to this, so the check runs with the cwd temporarily switched there.

  • config (dict) – Structurally-seeded configuration dictionary (e.g. state.edited_config).

Raises:

Exception – Whatever check_config raises for an invalid config (pydantic.ValidationError, ValueError, KeyError, FileNotFoundError, …).

openairclim.gui.config_io.check_required_fields(edited_config)[source]

Run every card’s required-field check against a config dict.

Lets other modules (the sidebar’s Validate button, run_full_validation below) run the exact same checks shown as ⚠️ icons on the Config tab’s card titles, without needing the cards to actually be rendered.

Parameters:

edited_config (dict) – Working configuration dict.

Returns:

(card_title, status_icon) tuples for cards with a

non-None status, in card order. Empty if nothing’s missing.

Return type:

list

openairclim.gui.config_io.default_repository_dir() → Path[source]

OpenAirClim’s shared repository data cache directory. Used as the implicit default for the background and responses section directories when left blank. This is also what core.read_config._resolve_repository_dirs does.

Returns:

The resolved shared cache directory (see

openairclim.repository.get_cache_dir).

Return type:

Path

openairclim.gui.config_io.parse_and_check_structure(working_dir, config_path)[source]

Load a TOML config file and validate its structure (keys/types).

Does not check that referenced files exist. This is done by check_files_exist().

Parameters:
  • working_dir (str) – Project working directory.

  • config_path (str) – Path to the config file, absolute or relative to working_dir.

Returns:

(config dict or None, list of error message strings).

Return type:

tuple

openairclim.gui.config_io.parse_toml_text(text)[source]

Parse and structurally validate a TOML config given as text.

Mirrors parse_and_check_structure(), for config content that hasn’t been saved to a file yet — e.g. hand-edited on the GUI’s “Config (Expert)” text tab.

Parameters:

text (str) – TOML config content.

Returns:

(config dict or None, list of error message strings).

Return type:

tuple

openairclim.gui.config_io.run_config(working_dir, config_path)[source]

Run OpenAirClim using a saved config file.

All paths inside a saved config (inventory dir, response dir, etc.) are relative to working_dir — exactly like check_files_exist, this temporarily changes into working_dir so they resolve correctly, then restores the original directory regardless of outcome.

Parameters:
  • working_dir (str) – Project working directory.

  • config_path (str) – Path to a saved config TOML file.

openairclim.gui.config_io.run_full_validation(state)[source]

Run the full validation pipeline against state.edited_config.

Parameters:

state (AppState) – Shared application state.

Returns:

(bool valid, str markdown status message).

Return type:

tuple