Skip to content

aerocm.metrics.aviation_climate_metrics_calculation

Main interface to calculate climate metrics for aviation emissions using different climate models.

AviationClimateMetricsCalculation

AviationClimateMetricsCalculation(climate_model, start_year, time_horizon, species_profile, profile_start_year=None, species_list=[], species_inventory=None, species_settings=None, model_settings=None)

Class to calculate climate metrics for aviation emissions using a specified climate model.

Parameters:

Name Type Description Default
climate_model str | ClimateModel | Callable

The climate model to use. Can be a registered name (e.g. "FaIR), an instance of a ClimateModel subclass, or a custom callable function.

required
start_year int

The start year of the simulation.

required
time_horizon int | list

The time horizon(s) for the climate metrics calculation (in years).

required
species_profile str

The type of emission profile to use for non-CO2 species. Options are 'pulse', 'step', 'combined', or 'scenario'.

required
profile_start_year int | None

The year when the emission profile starts. Required for 'pulse', 'step', and 'combined' profiles.

None
species_list list

List of non-CO2 species to include in the calculation (e.g. ["Contrails", "Soot"]).

[]
species_inventory dict | None

A dictionary containing emission profiles for each species when using the 'scenario' profile.

None
species_settings dict | None

A dictionary containing settings for each species.

None
model_settings dict | None

A dictionary containing settings for the climate model.

None

Attributes:

Name Type Description
available_climate_models list

List of supported climate model names.

available_species_profile list

List of supported species profile types.

Example
>>> import numpy as np
>>> from aerocm.metrics.aviation_climate_metrics_calculation import AviationClimateMetricsCalculation
>>> climate_model = "FaIR"
>>> start_year = 1940
>>> time_horizon = [20, 50, 100]
>>> species_profile = 'pulse'
>>> profile_start_year = 2020
>>> species_list = ["Contrails", "Soot"]
>>> results = AviationClimateMetricsCalculation(
...     climate_model,
...     start_year,
...     time_horizon,
...     species_profile,
...     profile_start_year,
...     species_list
... ).run()
Source code in aerocm/metrics/aviation_climate_metrics_calculation.py
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 __init__(
        self,
        climate_model: str | ClimateModel | Callable,
        start_year: int,
        time_horizon: int | list,
        species_profile: str,
        profile_start_year: int | None = None,
        species_list: list = [],
        species_inventory: dict | None = None,
        species_settings: dict | None = None,
        model_settings: dict | None = None
):
    self.climate_model = climate_model
    self.start_year = start_year
    self.time_horizon = time_horizon
    self.species_profile = species_profile
    self.profile_start_year = profile_start_year
    self.species_list = species_list
    self.species_inventory = species_inventory
    self.species_settings = species_settings
    self.model_settings = model_settings

    # --- Validate data ---
    self.validate_model_profile()

run

run(include_absolute_metrics=False, return_df=False)

Run the climate metric calculation.

Parameters:

Name Type Description Default
include_absolute_metrics bool

If True, includes absolute metrics in the output, by default False (only relative metrics).

False
return_df bool

If True, returns the results as a pandas DataFrame, by default False (returns a dictionary).

False

Returns:

Type Description
dict | DataFrame

Results of the climate metrics calculation.

Source code in aerocm/metrics/aviation_climate_metrics_calculation.py
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
def run(self, include_absolute_metrics: bool = False, return_df: bool = False) -> dict | pd.DataFrame:
    """
    Run the climate metric calculation.

    Parameters
    ----------
    include_absolute_metrics : bool, optional
        If True, includes absolute metrics in the output, by default False (only relative metrics).

    return_df : bool, optional
        If True, returns the results as a pandas DataFrame, by default False (returns a dictionary).

    Returns
    -------
    dict | pd.DataFrame
        Results of the climate metrics calculation.
    """

    # --- Extract simulation parameters ---
    climate_model = self.climate_model
    start_year = self.start_year
    time_horizon = self.time_horizon
    species_profile = self.species_profile
    profile_start_year = self.profile_start_year
    species_list = self.species_list
    species_inventory = self.species_inventory
    species_settings = self.species_settings
    model_settings = self.model_settings

    if climate_model == "FaIR":
        co2_unit_value = 1*10**10
        species_unit_value = {"Contrails": 1*10**10,
                              "NOx - ST O3 increase": 1*10**10,
                              "NOx - CH4 decrease and induced": 1*10**10,
                              "H2O": 1*10**12,
                              "Soot": 1*10**14,
                              "Sulfur": 1*10**10
        }
    else:
        co2_unit_value = 1
        species_unit_value = {"Contrails": 1,
                              "NOx - ST O3 increase": 1,
                              "NOx - CH4 decrease and induced": 1,
                              "H2O": 1,
                              "Soot": 1,
                              "Sulfur": 1
        }

    if type(time_horizon) == int or type(time_horizon) == float:
        time_horizon = [time_horizon]

    time_horizon_max = max(time_horizon)

    if species_profile == "pulse" or species_profile == "step":
        profile = species_profile
        co2_inventory = {
            "CO2": emission_profile_function(start_year,
                                             profile_start_year,
                                             time_horizon_max,
                                             profile=profile,
                                             unit_value=co2_unit_value
                                             )
        }
        non_co2_inventory = {
            specie: emission_profile_function(start_year,
                                              profile_start_year,
                                              time_horizon_max,
                                              profile=profile,
                                              unit_value=species_unit_value[specie]
                                              )
            for specie in species_list
        }
    elif species_profile == "combined":
        co2_inventory = {
            "CO2": emission_profile_function(start_year,
                                             profile_start_year,
                                             time_horizon_max,
                                             profile="pulse",
                                             unit_value=co2_unit_value
                                             )
        }
        non_co2_inventory = {
            specie: emission_profile_function(start_year,
                                              profile_start_year,
                                              time_horizon_max,
                                              profile="step",
                                              unit_value=species_unit_value[specie]
                                              )
            for specie in species_list
        }
    elif species_profile == "scenario":
        co2_inventory = {"CO2": species_inventory["CO2"]}
        non_co2_inventory = {specie: params for specie, params in species_inventory.items() if specie != 'CO2'}
        species_list = [k for k in species_inventory.keys() if k != "CO2"]

    if species_profile != "scenario":
        end_year = profile_start_year + time_horizon_max
    else:
        first_key = next(iter(species_inventory))
        first_value = species_inventory[first_key]
        size = len(first_value)
        end_year = size + start_year - 1

    # -- Run model for CO2 ---
    full_co2_climate_simulation_results = AviationClimateSimulation(
        climate_model=climate_model,
        start_year=start_year,
        end_year=end_year,
        species_inventory=co2_inventory,
        species_settings=species_settings,
        model_settings=model_settings).run()

    # -- Run model for all species ---
    full_non_co2_climate_simulation = AviationClimateSimulation(
        climate_model=climate_model,
        start_year=start_year,
        end_year=end_year,
        species_inventory=non_co2_inventory,
        species_settings=species_settings,
        model_settings=model_settings)
    full_non_co2_climate_simulation_results = full_non_co2_climate_simulation.run()
    non_co2_species_settings = full_non_co2_climate_simulation.species_settings

    # -- Remove useless data and divide by unit values --
    co2_climate_simulation_results = {
        "CO2": {key: value / co2_unit_value
                for key, value in full_co2_climate_simulation_results["CO2"].items()}
    }
    non_co2_climate_simulation_results = {
        specie: {key: value / species_unit_value[specie]
                for key, value in full_non_co2_climate_simulation_results[specie].items()}
        for specie in species_list
    }

    # --- Calculate metrics for each time horizon ---
    results = {}

    for H in time_horizon:

        # --- Absolute metrics ---
        results_H_absolute = {}

        # CO2
        agwp_rf_co2, agwp_erf_co2, aegwp_rf_co2, aegwp_erf_co2, agtp_co2, iagtp_co2, atr_co2 = absolute_metrics(
            co2_climate_simulation_results["CO2"]["radiative_forcing"][
            :end_year - start_year + 1 - (time_horizon_max - H)],
            co2_climate_simulation_results["CO2"]["effective_radiative_forcing"][
            :end_year - start_year + 1 - (time_horizon_max - H)],
            1.0,
            co2_climate_simulation_results["CO2"]["temperature"][
            :end_year - start_year + 1 - (time_horizon_max - H)],
            H
        )

        results_H_absolute["CO2"] = {
            "agwp_rf": agwp_rf_co2,
            "agwp_erf": agwp_erf_co2,
            "aegwp_rf": aegwp_rf_co2,
            "aegwp_erf": aegwp_erf_co2,
            "agtp": agtp_co2,
            "iagtp": iagtp_co2,
            "atr": atr_co2
        }

        # Non-CO2 species
        for specie in species_list:
            agwp_rf, agwp_erf, aegwp_rf, aegwp_erf, agtp, iagtp, atr = absolute_metrics(
                non_co2_climate_simulation_results[specie]["radiative_forcing"][
                :end_year - start_year + 1 - (time_horizon_max - H)],
                non_co2_climate_simulation_results[specie]["effective_radiative_forcing"][
                :end_year - start_year + 1 - (time_horizon_max - H)],
                non_co2_species_settings[specie]["efficacy_erf"],
                non_co2_climate_simulation_results[specie]["temperature"][
                :end_year - start_year + 1 - (time_horizon_max - H)],
                H
            )

            results_H_absolute[specie] = {
                "agwp_rf": agwp_rf,
                "agwp_erf": agwp_erf,
                "aegwp_rf": aegwp_rf,
                "aegwp_erf": aegwp_erf,
                "agtp": agtp,
                "iagtp": iagtp,
                "atr": atr
            }

        # --- Relative metrics ---
        results_H_relative = {}

        for specie in species_list + ["CO2"]:
            gwp_rf, gwp_erf, egwp_rf, egwp_erf, gtp, igtp, ratr = relative_metrics(
                results_H_absolute["CO2"]["agwp_rf"],
                results_H_absolute["CO2"]["agwp_erf"],
                results_H_absolute["CO2"]["aegwp_rf"],
                results_H_absolute["CO2"]["aegwp_erf"],
                results_H_absolute["CO2"]["agtp"],
                results_H_absolute["CO2"]["iagtp"],
                results_H_absolute["CO2"]["atr"],
                results_H_absolute[specie]["agwp_rf"],
                results_H_absolute[specie]["agwp_erf"],
                results_H_absolute[specie]["aegwp_rf"],
                results_H_absolute[specie]["aegwp_erf"],
                results_H_absolute[specie]["agtp"],
                results_H_absolute[specie]["iagtp"],
                results_H_absolute[specie]["atr"]
            )

            results_H_relative[specie] = {
                "gwp_rf": gwp_rf,
                "gwp_erf": gwp_erf,
                "egwp_rf": egwp_rf,
                "egwp_erf": egwp_erf,
                "gtp": gtp,
                "igtp": igtp,
                "ratr": ratr
            }

        if include_absolute_metrics:
            results[H] = {
                specie: {
                    **results_H_absolute[specie],
                    **results_H_relative[specie]
                }
                for specie in species_list + ["CO2"]
            }
        else:
            results[H] = {
                specie: {
                    **results_H_relative[specie]
                }
                for specie in species_list  # Exclude CO2 if only relative metrics are requested (values are 1.0)
            }

    if return_df:
        flatten_dicts = []
        for H, species_dict in results.items():
            for specie, metrics in species_dict.items():
                flatten_dict = {"time_horizon": H, "species": specie, **{k: float(v) for k, v in metrics.items()}}
                flatten_dicts.append(flatten_dict)

        results = pd.DataFrame(flatten_dicts)

    return results

validate_model_profile

validate_model_profile()

Validate the selected climate model and species profile.

Raises:

Type Description
ValueError

If the climate model or species profile is not recognized.

Source code in aerocm/metrics/aviation_climate_metrics_calculation.py
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
def validate_model_profile(self):
    """
    Validate the selected climate model and species profile.

    Raises
    ------
    ValueError
        If the climate model or species profile is not recognized.
    """
    model = self.climate_model
    species_profile = self.species_profile

    if model == "GWP*":
        warnings.warn(f"The '{model}' climate model is not recommended for calculating aviation climate metrics.")

    is_registered_name = species_profile in self.available_species_profile

    if not is_registered_name:
        raise ValueError(
            f"Species profile must be one of {self.available_species_profile}"
            )