Skip to content

aeromaps.models.yaml_interpolator

YAML Interpolator Model for AeroMAPS

This module defines a generic interpolation model that can be used in AeroMAPS to interpolate values based on user-defined reference years and values specified in a YAML configuration file.

YAMLInterpolator

YAMLInterpolator(name, custom_data_type, *args, **kwargs)

Bases: AeroMAPSModel

Generic interpolation model called each time an AeroMapsCustomDataType is used in the YAML configuration file of generic energy models.

Parameters:

Name Type Description Default
name str

Name of the model instance.

required
custom_data_type AeroMapsCustomDataType

Custom data type instance containing interpolation parameters.

required

Attributes:

Name Type Description
input_names dict

Dictionary of input variable names populated at model initialisation before MDA chain creation.

output_names dict

Dictionary of output variable names populated at model initialisation before MDA chain creation.

Source code in aeromaps/models/yaml_interpolator.py
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def __init__(
    self,
    name,
    custom_data_type,
    *args,
    **kwargs,
):
    super().__init__(
        name=name,
        model_type="custom",
        # inputs/outputs are defined in __init__ rather than auto generated from compute() signature
        *args,
        **kwargs,
    )
    # Get the name of the resource
    self.value_name = name
    self.custom_data_type = custom_data_type

    self.input_names = {
        f"{self.value_name}_years": custom_data_type.years,
        f"{self.value_name}_values": custom_data_type.values,
    }

    self.output_names = {self.value_name: pd.Series([0.0])}

compute

compute(input_data)

Execute the interpolation based on input data.

Parameters:

Name Type Description Default
input_data

Dictionary containing all input data required for the computation, completed at model instantiation with information from yaml..

required

Returns:

Type Description
output_data

Dictionary containing all output data resulting from the computation. Contains outputs defined during model instantiation.

Source code in aeromaps/models/yaml_interpolator.py
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
def compute(self, input_data) -> dict:
    """
    Execute the interpolation based on input data.

    Parameters
    ----------
    input_data
        Dictionary containing all input data required for the computation, completed at model instantiation with information from yaml..

    Returns
    -------
    output_data
        Dictionary containing all output data resulting from the computation. Contains outputs defined during model instantiation.

    """
    try:
        interpolated_value = self._yaml_interpolation_function(
            reference_years=input_data[f"{self.value_name}_years"],
            reference_years_values=input_data[f"{self.value_name}_values"],
            prospection_start_year=self.prospection_start_year,
            end_year=self.end_year,
            method=self.custom_data_type.method,
            positive_constraint=self.custom_data_type.positive_constraint,
            model_name=self.value_name,
        )
    except Exception as e:
        raise RuntimeError(
            f"[YAMLInterpolator] Error while interpolating '{self.value_name}' "
            f"with method '{self.custom_data_type.method}' "
            f"(years and values lengths may mismatch): {e}"
        ) from e

    output_data = {self.value_name: interpolated_value}
    self._store_outputs(output_data)

    return output_data