Skip to content

aeromaps.models.impacts.life_cycle_assessment.life_cycle_assessment_default

Default model for Life Cycle Assessment (LCA) of air transportation systems

LifeCycleAssessmentDefault

LifeCycleAssessmentDefault(name='life_cycle_assessment_default', json_file=None, split_by=None, *args, **kwargs)

Bases: AeroMAPSModel

Model to load LCA pre-compiled expressions from a JSON file. Compared to the LifeCycleAssessmentCustom model, this model does not require the user to install LCA-specific packages and is disconnected from the ecoinvent database. It is therefore easier to use and deploy, but less flexible as the user cannot modify the LCA model structure.

Parameters:

Name Type Description Default
name str

Name of the model instance.

'life_cycle_assessment_default'
json_file str

Path to the JSON file containing the pre-compiled LCA model.

None
split_by str

Axis to split the results by (e.g., "phase"). If None, total results are provided.

None

Attributes:

Name Type Description
model Model

The LCA model loaded from the JSON file.

methods List[tuple]

List of impact assessment methods available in the model.

axis_keys List[str] or None

List of keys for the specified axis, if applicable.

params_names List[str]

List of parameter names required by the LCA model.

xarray_lca DataArray

Xarray DataArray storing the LCA results after computation.

Source code in aeromaps/models/impacts/life_cycle_assessment/life_cycle_assessment_default.py
 58
 59
 60
 61
 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
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
def __init__(
    self,
    name: str = "life_cycle_assessment_default",
    json_file: str = None,
    split_by: str = None,
    *args,
    **kwargs,
):
    super().__init__(
        name=name,
        model_type="custom",
        # inputs/outputs are defined in __init__ rather than auto generated from compute() signature
        *args,
        **kwargs,
    )

    # Instantiate LCA model from JSON file
    if json_file is None:
        raise ValueError("JSON file is missing.")

    # Get methods names, axis keys, and parameters names
    self.axis = split_by if split_by else TOTAL_AXIS_KEY

    print("===== LCA Default Model Import =====")
    self.model = Model.from_file(json_file, axis=self.axis, progress_bar=True)
    self.methods = [ast.literal_eval(s) for s in self.model.impacts.keys()]
    self.axis_keys = None
    expr = self.model.expressions[self.axis][str(self.methods[0])].expr
    if isinstance(expr, dict):
        self.axis_keys = list(expr.keys())
    self.params_names = list(self.model.params.keys())
    print("====================================")

    # Initialize empty xarray to store results after compute
    self.xarray_lca = xr.DataArray()

    # --- Add LCA parameters as inputs of this AeroMAPSModel ---
    self._skip_data_type_validation = True  # see aeromaps/core/gemseo.py
    self.input_names = []
    self.output_names = []

    for x in self.params_names:
        # Years of simulation are directly taken from AeroMAPS timeline and not as an input parameter
        if x == KEY_YEAR:
            continue

        self.input_names.append(x)
        self.input_names.append(x + "_reference_years")
        self.input_names.append(x + "_reference_years_values")

        self.default_input_data[x] = np.nan
        self.default_input_data[x + "_reference_years"] = np.nan
        self.default_input_data[x + "_reference_years_values"] = np.nan

    # --- Add LCA impact categories the outputs to the AeroMAPSModel ---
    if self.axis_keys:
        for method in self.methods:
            for phase in self.axis_keys:
                method_with_axis = method + (phase,)
                self.output_names.append(tuple_to_varname(method_with_axis))
    else:
        for method in self.methods:
            self.output_names.append(tuple_to_varname(method))

compute

compute(input_data)

Main compute method for the LCA model.

Parameters:

Name Type Description Default
input_data dict

Dictionary containing input parameter values.

required

Returns:

Name Type Description
output_data dict

Dictionary containing LCA results as pd.Series for each impact category.

Source code in aeromaps/models/impacts/life_cycle_assessment/life_cycle_assessment_default.py
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
def compute(self, input_data) -> dict:
    """
    Main compute method for the LCA model.

    Parameters
    ----------
    input_data : dict
        Dictionary containing input parameter values.

    Returns
    -------
    output_data : dict
        Dictionary containing LCA results as pd.Series for each impact category.
    """
    # --- Assign values to parameters ---
    params_dict = self._get_param_values(input_data)

    # --- Calculate impacts for all parameters at once ---
    res = self._multi_lca_algebraic_json(**params_dict)

    # --- Store xarray to enable user to access data after process calculation ---
    res["params"] = params_dict[KEY_YEAR]  # replace param index by actual years
    res = res.rename({"params": KEY_YEAR})  # rename 'params' dimension to 'year'
    self.xarray_lca = res

    # --- Convert xarray to pd.Series to enable connection with other models ---
    output_data = self._convert_xarray_to_series(res)
    self._store_outputs(output_data)

    return output_data