Skip to content

aeromaps.utils.yaml

aeromaps_custom_data_type_constructor

aeromaps_custom_data_type_constructor(loader, node)

Custom constructor to handle specific interpolation input types in yaml files.

Parameters:

Name Type Description Default
loader Loader

The YAML loader instance.

required
node Node

The YAML node to be constructed.

required
Source code in aeromaps/utils/yaml.py
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
def aeromaps_custom_data_type_constructor(loader, node):
    """
    Custom constructor to handle specific interpolation input types in yaml files.

    Parameters
    ----------
    loader : yaml.Loader
        The YAML loader instance.
    node : yaml.Node
        The YAML node to be constructed.
    """
    value = loader.construct_mapping(node, deep=True)
    return AeroMapsCustomDataType(value)

read_yaml_file

read_yaml_file(file_name='parameters.yaml')

Example function to read a YAML file and returns its contents as a dictionary.

Parameters:

Name Type Description Default
file_name str

The path to the YAML file to be read (default is "parameters.yaml").

'parameters.yaml'

Returns:

Type Description
dict

The contents of the YAML file as a dictionary.

Source code in aeromaps/utils/yaml.py
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def read_yaml_file(file_name="parameters.yaml"):
    """
    Example function to read a YAML file and returns its contents as a dictionary.

    Parameters
    ----------
    file_name : str
        The path to the YAML file to be read (default is "parameters.yaml").

    Returns
    -------
    dict
        The contents of the YAML file as a dictionary.
    """
    try:
        with open(file_name, "r", encoding="utf-8") as file:
            data = yaml.load(file, Loader=yaml.Loader)
            return data if isinstance(data, dict) else {}
    except Exception as e:
        print(f"Error reading YAML file: {e}")
        return {}