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:
- 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_configas-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:
- 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.
- 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.list_nc_data_vars(filepath)[source]
List data variable names in a NetCDF file.
Used to discover the available scenario names inside a background concentration file (e.g. “SSP2-4.5”), which are stored as data variables rather than declared anywhere in the config.
- openairclim.gui.config_io.list_nc_files(directory_path)[source]
List NetCDF filenames in a directory.
- Parameters:
directory_path (Path) – Directory to scan.
- Returns:
- Sorted list of
.ncfilenames found, or an empty list if the directory does not exist.
- Sorted list of
- Return type:
- 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().
- 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.
- openairclim.gui.config_io.prepare_for_save(config, working_dir)[source]
Return a copy of config with directory paths made relative.
During editing, directory fields are kept as absolute paths so that they remain correct regardless of when the working directory happens to be set. This converts them back to working-dir-relative form, once, right before writing a portable TOML file.
- openairclim.gui.config_io.resolve_dir(working_dir, dir_str)[source]
Resolve a (possibly relative) directory string against working_dir.
- 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.
- openairclim.gui.config_io.run_full_validation(state)[source]
Run the full validation pipeline against
state.edited_config.
- openairclim.gui.config_io.to_relative(working_dir, absolute_path)[source]
Convert an absolute path to one relative to working_dir.
Uses “..” segments where necessary, so that directories outside working_dir still resolve correctly on another machine or OS, as long as their position relative to working_dir is preserved. Falls back to the absolute path unchanged only when no relative path can be computed at all (e.g. paths on different drives on Windows).