NEDAS.config.parse_config module
- NEDAS.config.parse_config.convert_notation(data)[source]
Parse values in data, convert strings to appropriate types if possible.
Goes through the data recursively if it is a list or a dictionary. If the string can be interpreted as a scientific notation, inf, or boolean flag, convert it to the appropriate type.
- Parameters:
data (any) – The data to be converted.
- Returns:
The converted data.
- Return type:
any
- NEDAS.config.parse_config.str2bool(data: str) int[source]
Convert a string to a boolean value (0 or 1).
- NEDAS.config.parse_config.parse_config(code_dir: str = '.', config_file: str | None = None, parse_args: bool = False, **kwargs)[source]
Load configuration from YAML files and runtime arguments.
This function loads configuration settings from a default YAML file, located in code_dir/default.yml. If config_file is provided, then values defined in that file will overwrite those in the default YAML file. If additional key=value pairs are provided, either through runtime command-line arguments or as kwargs, those will also overwrite the existing values.
The default YAML file also serves as a template for the ArgumentParser, which parses the key-value pairs, if the value is not None, parser will add the argument with type and default value in the help message.
- Parameters:
code_dir (str, optional) – Directory containing the default.yml file. Default is the current directory.
config_file (str, optional) – Alternative YAML config file to overwrite default settings.
parse_args (bool, optional) – If True, parse runtime arguments with argparse. Default is False.
**kwargs – Additional configuration key-value pairs that can overwrite existing settings.
- Returns:
A dictionary containing all configuration variables.
- Return type:
dict