Skip to content

aeromaps.models.parameters

Utilities for loading, storing, and converting AeroMAPSProcess self.parameters.

Parameters

Container for AeroMAPSProcess input parameters TODO: is that the most appropriate description?

to_dict

to_dict()

Return a dictionary representation of the parameters.

Returns:

Type Description
data

Dictionary mapping attribute names to their values.

Source code in aeromaps/models/parameters.py
18
19
20
21
22
23
24
25
26
27
def to_dict(self):
    """
    Return a dictionary representation of the parameters.

    Returns
    -------
    data
        Dictionary mapping attribute names to their values.
    """
    return self.__dict__

from_dict

from_dict(data)

Update attributes from a dictionary.

Parameters:

Name Type Description Default
data

Dictionary of parameter names and values to set on the instance.

required
Source code in aeromaps/models/parameters.py
29
30
31
32
33
34
35
36
37
38
39
def from_dict(self, data):
    """
    Update attributes from a dictionary.

    Parameters
    ----------
    data
        Dictionary of parameter names and values to set on the instance.
    """
    for key, value in data.items():
        setattr(self, key, value)

write_json

write_json(file_name='parameters.json')

Write parameters to a JSON file.

Parameters:

Name Type Description Default
file_name

Path to the output JSON file.

'parameters.json'
Source code in aeromaps/models/parameters.py
41
42
43
44
45
46
47
48
49
50
51
def write_json(self, file_name="parameters.json"):
    """
    Write parameters to a JSON file.

    Parameters
    ----------
    file_name
        Path to the output JSON file.
    """
    with open(file_name, "w", encoding="utf-8") as f:
        dump(self.to_dict(), f, ignore_nan=True, ensure_ascii=False, indent=4)

read_json

read_json(file_name='parameters.json')

Read parameters from a JSON file and update the instance.

Parameters:

Name Type Description Default
file_name

Path to the input JSON file.

'parameters.json'
Source code in aeromaps/models/parameters.py
53
54
55
56
57
58
59
60
61
62
63
64
65
def read_json(self, file_name="parameters.json"):
    """
    Read parameters from a JSON file and update the instance.

    Parameters
    ----------
    file_name
        Path to the input JSON file.
    """
    data = _dict_from_json(file_name=file_name)

    # Old reference data is kept
    self.from_dict(data)

read_json_direct

read_json_direct(parameters_dict)

Load parameters from a dictionary-like object and update the instance.

Parameters:

Name Type Description Default
parameters_dict

Dictionary or object containing parameter keys and values.

required
Source code in aeromaps/models/parameters.py
67
68
69
70
71
72
73
74
75
76
77
78
79
def read_json_direct(self, parameters_dict):
    """
    Load parameters from a dictionary-like object and update the instance.

    Parameters
    ----------
    parameters_dict
        Dictionary or object containing parameter keys and values.
    """
    data = _dict_from_parameters_dict(parameters_dict)

    # Old reference data is kept
    self.from_dict(data)