openairclim.core.read_config
Reads a config file, checks that it is complete and correct, and creates the output directory.
Configuration checking runs in two layers, split across two modules:
Structural validation (
openairclim.core.config_model) — types, required/optional keys, valid option strings, and defaults, enforced by the pydanticConfigschema. Pure in-memory validation: nothing here touches the filesystem, and it doesn’t need aircraft/inventory/response files to actually exist. Entered viavalidate_config().Everything that needs the filesystem or cross-references other data (this module) — merging in an optional aircraft csv file, and checking that referenced files actually exist.
check_config() runs both layers in order:
validate_config()— validate structure/types, migrate deprecated keys (seeALIAS_MAP), and fill in defaults. Inline[aircraft.<id>]entries are validated here too, derivingG_250/PMrelfrom sub-values where possible (seeAircraftEntry); ifoutput.run_metricsis set,metrics.types/t_0/Hare checked for completeness and consistency withtime.range._resolve_repository_dirs()- ifbackground.dir/responses.dirwere left unset, fill them in with OpenAirClim’s shared repository data cache directory (openairclim.repository.get_cache_dir()). Only resolves the path; doesn’t check whether it actually contains the required files or download anything. Downloads only ever happen via an explicitoac-download-datacall to prevent surprise network calls.load_ac_data()- ifaircraft.fileis set, load that csv, validate each row (AircraftCsvRow), and merge it intoconfig["aircraft"]— raising if an aircraft identifier is defined both inline and in the csv._check_reserved_aircraft_ids()- reject aircraft identifiers that collide with core’s own internal bookkeeping ("TOTAL","BASE_*")._check_required_contrail_vars()- if"cont"is an output species, every aircraft identifier must end up with completeG_250/b/PMreldata, from either source._check_required_files()- every response, background, emission inventory and base inventory file the (now fully resolved) config references must actually exist on disk. If a missing file lives under the resolved repository data cache, the error points atoac-download-data.
create_output_dir() is a separate step, not part of check_config()
— it’s only run once a config has passed all of the above (see
get_config()), since it can create or wipe the output directory.
- openairclim.core.read_config.check_config(config)[source]
Checks if configuration is complete and correct.
- openairclim.core.read_config.classify_response_types(config, species_arr)[source]
Classifies species into categories based on their response types defined in the config
- Parameters:
- Returns:
- A tuple of lists. list (species_rf) contains species with response type ‘rf’,
i.e. a response file must be given comprising the response surface from emissions to RF, list (species_tau) contains species with response type ‘tau’, i.e. a response file must be given comprising the response surface from emissions to inverse species lifetime.
- Return type:
- Raises:
KeyError – If no valid response type is defined in the configuration for a species.
- openairclim.core.read_config.classify_species(config)[source]
Classifies output species by response modelling method.
- openairclim.core.read_config.create_output_dir(config)[source]
Check for existing output directory, results file, overwrite and run_oac settings. Create new output directory if needed.
- openairclim.core.read_config.get_config(file_name)[source]
load_config, check_config and create_output_dir
- openairclim.core.read_config.load_ac_data(config: dict) dict[source]
Load and validate aircraft identifier parameters from a separate csv file. Parameters defined within the config file are checked by config_model.validate_config.
- Parameters:
config (dict) – Configuration dictionary
- Raises:
FileNotFoundError – File does not exist
KeyError – If the “ac” column does not exist
ValueError – If a duplicate identifier is found within the csv file; if an aircraft’s data is invalid or has G_250/PMrel that can’t be derived from sub-values (see AircraftCsvRow in config_model.py); or if an aircraft is defined both inline in the config file and in the csv file
- Returns:
Configuration dictionary modified in-place
- Return type: