Skip to content

aeromaps.models.impacts.generic_energy_model.common.energy_carriers_manager

EnergyCarrierMetadata dataclass

EnergyCarrierMetadata(name=None, aircraft_type=None, default=False, mandate_type=None, energy_origin=None, resources_used=None, resources_used_processes=None, cost_model=None, environmental_model=None)

Dataclass to hold metadata for an energy carrier.

Attributes:

Name Type Description
name str

Name of the energy carrier.

aircraft_type str

Type of aircraft the energy carrier is associated with.

default bool

Indicates if this is the default energy carrier for the aircraft type.

mandate_type str

Type of mandate the energy carrier obeys to (share, volume)

energy_origin str

Origin of the energy (e.g., renewable, fossil).

resources_used List[str]

List of resources used by the energy carrier.

resources_used_processes dict

Dictionary mapping resources used by associated processes.

cost_model str

Type of cost model used (e.g., top-down, bottom-up).

environmental_model str

Type of environmental model used (e.g., top-down, bottom-up).

EnergyCarrierManager

EnergyCarrierManager(carriers=None)

Manager class to handle a collection of energy carriers and provide methods to add and retrieve them based on various criteria.

Attributes:

Name Type Description
carriers List[EnergyCarrierMetadata]

List of energy carrier metadata instances.

Initialize the EnergyCarrierManager with an optional list of energy carriers.

Parameters:

Name Type Description Default
carriers List[EnergyCarrierMetadata]

Initial list of energy carrier metadata instances.

None
Source code in aeromaps/models/impacts/generic_energy_model/common/energy_carriers_manager.py
53
54
55
56
57
58
59
60
61
62
def __init__(self, carriers: List[EnergyCarrierMetadata] = None):
    """
    Initialize the EnergyCarrierManager with an optional list of energy carriers.

    Parameters
    ----------
    carriers : List[EnergyCarrierMetadata], optional
        Initial list of energy carrier metadata instances.
    """
    self.carriers = carriers if carriers is not None else []

add

add(carrier)

Add a new energy carrier to the manager.

Parameters:

Name Type Description Default
carrier EnergyCarrierMetadata

Energy carrier metadata instance to add.

required
Source code in aeromaps/models/impacts/generic_energy_model/common/energy_carriers_manager.py
64
65
66
67
68
69
70
71
72
73
def add(self, carrier: EnergyCarrierMetadata):
    """
    Add a new energy carrier to the manager.

    Parameters
    ----------
    carrier
        Energy carrier metadata instance to add.
    """
    self.carriers.append(carrier)

get

get(**criteria)

Retrieve energy carriers that match all specified criteria.

Parameters:

Name Type Description Default
criteria

Keyword arguments used to match attributes of energy carriers; only carriers matching all provided criteria are returned.

{}

Returns:

Type Description
matches

Energy carrier metadata instances that match the given criteria.

Source code in aeromaps/models/impacts/generic_energy_model/common/energy_carriers_manager.py
 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
def get(self, **criteria) -> List[EnergyCarrierMetadata]:
    """
    Retrieve energy carriers that match all specified criteria.

    Parameters
    ----------
    criteria
        Keyword arguments used to match attributes of energy carriers; only carriers matching all provided criteria are returned.

    Returns
    -------
    matches
        Energy carrier metadata instances that match the given criteria.
    """
    return [
        c
        for c in self.carriers
        if all(
            val in getattr(c, attr, {}).values()
            if isinstance(getattr(c, attr, None), dict)
            else val in getattr(c, attr, [])
            if isinstance(getattr(c, attr, None), list)
            else getattr(c, attr, None) == val
            for attr, val in criteria.items()
        )
    ]

get_all

get_all()

Return all energy carriers managed by this object.

Returns:

Type Description
carriers

All energy carrier metadata instances stored in the manager.

Source code in aeromaps/models/impacts/generic_energy_model/common/energy_carriers_manager.py
102
103
104
105
106
107
108
109
110
111
def get_all(self):
    """
    Return all energy carriers managed by this object.

    Returns
    -------
    carriers
        All energy carrier metadata instances stored in the manager.
    """
    return self.carriers

get_all_types

get_all_types(parameter)

Retrieve unique values of a specified attribute across all energy carriers.

Parameters:

Name Type Description Default
parameter str

Name of the attribute to aggregate unique values for.

required

Returns:

Type Description
values

Unique values of the specified parameter across all energy carriers.

Source code in aeromaps/models/impacts/generic_energy_model/common/energy_carriers_manager.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
def get_all_types(self, parameter: str) -> List:
    """
    Retrieve unique values of a specified attribute across all energy carriers.

    Parameters
    ----------
    parameter
        Name of the attribute to aggregate unique values for.

    Returns
    -------
    values
        Unique values of the specified parameter across all energy carriers.
    """
    return list(
        {
            getattr(carrier, parameter, None)
            for carrier in self.carriers
            if getattr(carrier, parameter, None) is not None
        }
    )

build_pathways_manager

build_pathways_manager(energy_carriers_data, energy_processes_data=None)

Build a manager from the raw contents of the energy-carrier YAML.

Split out of AeroMAPSProcess so that results loaded from committed JSON can carry a manager too. The pathway metadata the plots need is entirely declared in the YAML, so it does not require running the model, and without it every pathway-aware plot falls back to an empty figure.

Parameters:

Name Type Description Default
energy_carriers_data dict

Parsed energy-carrier YAML, one entry per pathway.

required
energy_processes_data dict

Parsed processes YAML, used to map each pathway's processes onto the resource each of them consumes.

None

Returns:

Type Description
EnergyCarrierManager

Manager holding one metadata entry per declared pathway.

Source code in aeromaps/models/impacts/generic_energy_model/common/energy_carriers_manager.py
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
def build_pathways_manager(energy_carriers_data, energy_processes_data=None):
    """Build a manager from the raw contents of the energy-carrier YAML.

    Split out of ``AeroMAPSProcess`` so that results loaded from committed JSON
    can carry a manager too. The pathway metadata the plots need is entirely
    declared in the YAML, so it does not require running the model, and without
    it every pathway-aware plot falls back to an empty figure.

    Parameters
    ----------
    energy_carriers_data : dict
        Parsed energy-carrier YAML, one entry per pathway.
    energy_processes_data : dict, optional
        Parsed processes YAML, used to map each pathway's processes onto the
        resource each of them consumes.

    Returns
    -------
    EnergyCarrierManager
        Manager holding one metadata entry per declared pathway.
    """
    processes = energy_processes_data or {}
    manager = EnergyCarrierManager()
    for pathway, pathway_data in energy_carriers_data.items():
        if "name" not in pathway_data or "inputs" not in pathway_data:
            raise ValueError(f"pathway {pathway!r} must declare both a name and inputs")
        technical = pathway_data.get("inputs", {}).get("technical", {})
        manager.add(
            EnergyCarrierMetadata(
                name=pathway,
                aircraft_type=pathway_data.get("aircraft_type"),
                default=pathway_data.get("default"),
                mandate_type=pathway_data.get("inputs").get("mandate", {}).get("mandate_type"),
                energy_origin=pathway_data.get("energy_origin"),
                resources_used=technical.get("resource_names", []),
                resources_used_processes={
                    name: (
                        list(
                            processes.get(name, {})
                            .get("inputs", {})
                            .get("technical", {})
                            .get(f"{name}_resource_names", [])
                        )
                        or [None]
                    )[0]
                    for name in technical.get("processes_names", [])
                },
                cost_model=pathway_data.get("cost_model"),
                environmental_model=pathway_data.get("environmental_model"),
            )
        )
    return manager