rizer.misc.yaml_utils#
Shared YAML-loading helpers.
Classes#
|
Functions#
|
Parse and convert YAML file. Also perform minimal validation. |
|
Convert CamelCase or PascalCase to snake_case. |
|
Convert a STONE-style typed block to a flat dict with |
Module Contents#
- class rizer.misc.yaml_utils.ScientificFloatLoader(stream)#
Bases:
yaml.SafeLoaderyaml.SafeLoaderthat also parses1e5-style numbers as float.PyYAML’s default float resolver requires a decimal point in the mantissa (
1.0e5) and treats1e5as a string. This loader extends the resolver pattern so values such as1e18or2e-3are returned as Python floats.
- rizer.misc.yaml_utils.parse_convert_yaml(path: str | pathlib.Path, expected_sections: list[str] | None = None) dict[str, Any]#
Parse and convert YAML file. Also perform minimal validation.
- Parameters:
path (
strorpathlib.Path) – Path to the YAML file containing the parameters.expected_sections (
listofstrorNone, optional) – List of expected top-level sections in the YAML file. If provided, the function will check that these sections are present in the YAML file. Default is None, which means no validation of sections will be performed.
- Returns:
A dictionary containing the parsed parameters from the YAML file.
- Return type:
- rizer.misc.yaml_utils.to_snake_case(name: str) str#
Convert CamelCase or PascalCase to snake_case.
Examples
>>> to_snake_case("RompeWeizel") 'rompe_weizel' >>> to_snake_case("LTEDischarge") 'lte_discharge' >>> to_snake_case("Constant") 'constant'
- rizer.misc.yaml_utils.extract_typed_block(block: dict[str, Any]) dict[str, Any]#
Convert a STONE-style typed block to a flat dict with
typekey.A typed block has exactly one key whose value is a dict of properties:
{"Trapezoidal": {"R_g": 1.0, "U_on": 10000}} -> {"type": "trapezoidal", "R_g": 1.0, "U_on": 10000} {"Constant": {}} -> {"type": "constant"}