Skip to content

Acropole

acropole

Array API implementation of the Acropole fuel-flow model.

ACROPOLE_DATA_VERSION

ACROPOLE_DATA_VERSION = '0.1.0'

ACROPOLE_MODEL_FILENAME

ACROPOLE_MODEL_FILENAME = 'acropole_model.npz'

ACROPOLE_AIRCRAFT_FILENAME

ACROPOLE_AIRCRAFT_FILENAME = 'acropole_aircraft.csv'

ACROPOLE_LICENSE_FILENAME

ACROPOLE_LICENSE_FILENAME = 'acropole_LICENSE.txt'

ACROPOLE_RELEASE_BASE_URL

ACROPOLE_RELEASE_BASE_URL = 'https://github.com/abc8747/aerocore/releases/download/v0.2.1'

data_dir

data_dir(cache_dir: Path | None = None) -> Path
Source code in src/aerocore/acropole.py
29
30
31
32
33
34
def data_dir(cache_dir: Path | None = None) -> Path:
    return (
        (cache_dir or default_cache_dir())
        / "acropole"
        / f"v{ACROPOLE_DATA_VERSION}"
    )

sync_data

sync_data(cache_dir: Path | None = None, force: bool = False, base_url: str = ACROPOLE_RELEASE_BASE_URL) -> tuple[Path, ...]

Download the prepared Acropole model, aircraft, and license files.

Requires optional dependency httpx.

Source code in src/aerocore/acropole.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
61
62
63
64
65
66
67
68
69
70
71
72
73
async def sync_data(
    cache_dir: Path | None = None,
    force: bool = False,
    base_url: str = ACROPOLE_RELEASE_BASE_URL,
) -> tuple[Path, ...]:
    """Download the prepared Acropole model, aircraft, and license files.

    Requires optional dependency `httpx`.
    """
    root = data_dir(cache_dir)
    root.mkdir(parents=True, exist_ok=True)
    paths = tuple(
        root / filename
        for filename in (
            ACROPOLE_MODEL_FILENAME,
            ACROPOLE_AIRCRAFT_FILENAME,
            ACROPOLE_LICENSE_FILENAME,
        )
    )
    pending = (
        paths if force else tuple(path for path in paths if not path.exists())
    )
    if not pending:
        return paths

    import httpx

    async with httpx.AsyncClient(follow_redirects=True) as client:
        for destination in pending:
            response = await client.get(
                f"{base_url.rstrip('/')}/{destination.name}"
            )
            response.raise_for_status()
            temporary = destination.with_name(f".{destination.name}.part")
            temporary.write_bytes(response.content)
            temporary.replace(destination)
    return paths

ArrayT

ArrayT = TypeVar('ArrayT')

AcropoleStandardisation

AcropoleStandardisation(minimums: ArrayT, maximums: ArrayT)

Bases: Generic[ArrayT]

minimums

minimums: ArrayT

maximums

maximums: ArrayT

AcropoleWeights

AcropoleWeights(weights: tuple[ArrayT, ...], biases: tuple[ArrayT, ...])

Bases: Generic[ArrayT]

weights

weights: tuple[ArrayT, ...]

biases

biases: tuple[ArrayT, ...]

AcropoleModel

AcropoleModel(standardisation: AcropoleStandardisation[ArrayT], weights: AcropoleWeights[ArrayT])

Bases: Generic[ArrayT]

standardisation

standardisation: AcropoleStandardisation[ArrayT]

weights

load_model

load_model(path: Path | None = None) -> AcropoleModel[NDArray[float32]]

Load model arrays from the Acropole cache.

Use aerocore.utils.tree_map to move to another device or type.

Source code in src/aerocore/acropole.py
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
def load_model(
    path: Path | None = None,
) -> AcropoleModel[npt.NDArray[np.float32]]:
    """Load model arrays from the Acropole cache.

    Use [`aerocore.utils.tree_map`][] to move to another device or type.
    """
    model_path = path or data_dir() / ACROPOLE_MODEL_FILENAME
    with np.load(model_path, allow_pickle=False) as archive:
        return AcropoleModel(
            standardisation=AcropoleStandardisation(
                minimums=archive["feature_minimums"],
                maximums=archive["feature_maximums"],
            ),
            weights=AcropoleWeights(
                weights=tuple(archive[f"weight_{index}"] for index in range(5)),
                biases=tuple(archive[f"bias_{index}"] for index in range(5)),
            ),
        )

AcropoleEngineType

Bases: IntEnum

JET

JET = 0

TURBOPROP

TURBOPROP = 1

AcropoleAircraft

AcropoleAircraft(engine_type: AcropoleEngineType, wing_area: WingAreaM2[float], max_alt: MaximumOperatingPressureAltitudeFt[float], max_tas: MaximumOperatingTasKt[float], oew: OperatingEmptyWeightKg[float], max_tow: MaximumTakeoffWeightKg[float], fuel_flow_per_engine_to: MassFlowKgPSPEngine[float], engine_count: int, representative_engine: str | None = None, trained: bool | None = None)

engine_type

engine_type: AcropoleEngineType

wing_area

wing_area: WingAreaM2[float]

max_tas

max_tow

fuel_flow_per_engine_to

fuel_flow_per_engine_to: MassFlowKgPSPEngine[float]

engine_count

engine_count: int

representative_engine

representative_engine: str | None = None

trained

trained: bool | None = None

IcaoTypeCode

IcaoTypeCode: TypeAlias = str

AcropoleAircraftDatabase

AcropoleAircraftDatabase: TypeAlias = dict[IcaoTypeCode, AcropoleAircraft]

load_aircraft_database

load_aircraft_database(source: Path | Iterable[str] | None = None) -> AcropoleAircraftDatabase
Source code in src/aerocore/acropole.py
172
173
174
175
176
177
178
179
180
def load_aircraft_database(
    source: Path | Iterable[str] | None = None,
) -> AcropoleAircraftDatabase:
    if source is None:
        source = data_dir() / ACROPOLE_AIRCRAFT_FILENAME
    if isinstance(source, Path):
        with source.open(newline="", encoding="utf-8") as file:
            return _decode_aircraft_database(file)
    return _decode_aircraft_database(source)

fuel_flow

fuel_flow(model: AcropoleModel, aircraft: AcropoleAircraft, groundspeed: GsKt, altitude: PressureAltitudeFt, vertical_rate: VerticalRateFtMin, *, airspeed: TasKt | None = None, mass: MassKg | None = None, elapsed_time: DurationS | None = None, altitude_rate: VerticalRateFtS | None = None, groundspeed_rate: AccelerationKtS | None = None, airspeed_rate: AccelerationKtS | None = None, xp: ArrayApiNamespace) -> MassFlowKgPS

Predict fuel flow from caller-owned backend arrays.

Trajectory arrays must have identical shapes. The final axis represents samples ordered in time. When elapsed_time is provided, it must have the same shape, contain at least two samples, and be strictly increasing without duplicate timestamps.

The paper reports one-second QAR samples but does not specify a resampling interval or smoothing-window duration. The upstream implementation later recommended approximately four-second sampling. Callers are responsible for resampling, interpolation, and smoothing before calling this function.

Source code in src/aerocore/acropole.py
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
def fuel_flow(
    model: AcropoleModel,
    aircraft: AcropoleAircraft,
    groundspeed: t.GsKt,
    altitude: t.PressureAltitudeFt,
    vertical_rate: t.VerticalRateFtMin,
    *,
    airspeed: t.TasKt | None = None,
    mass: t.MassKg | None = None,
    elapsed_time: t.DurationS | None = None,
    altitude_rate: t.VerticalRateFtS | None = None,
    groundspeed_rate: t.AccelerationKtS | None = None,
    airspeed_rate: t.AccelerationKtS | None = None,
    xp: ArrayApiNamespace,
) -> t.MassFlowKgPS:
    """Predict fuel flow from caller-owned backend arrays.

    Trajectory arrays must have identical shapes. The final axis represents
    samples ordered in time. When `elapsed_time` is provided, it must have the
    same shape, contain at least two samples, and be strictly increasing without
    duplicate timestamps.

    The paper reports one-second QAR samples but does not specify a
    resampling interval or smoothing-window duration. The upstream
    implementation later recommended approximately four-second sampling.
    Callers are responsible for resampling, interpolation, and
    smoothing before calling this function.
    """
    features = input_features(
        aircraft,
        groundspeed,
        altitude,
        vertical_rate,
        airspeed=airspeed,
        mass=mass,
        elapsed_time=elapsed_time,
        altitude_rate=altitude_rate,
        groundspeed_rate=groundspeed_rate,
        airspeed_rate=airspeed_rate,
        xp=xp,
    )
    standardised = standardise(model.standardisation, features)
    normalised_flow = predict_standardised(model.weights, standardised, xp=xp)
    fuel_scale = aircraft.fuel_flow_per_engine_to * aircraft.engine_count
    return normalised_flow * fuel_scale

input_features

input_features(aircraft: AcropoleAircraft, groundspeed: GsKt, altitude: PressureAltitudeFt, vertical_rate: VerticalRateFtMin, *, airspeed: TasKt | None = None, mass: MassKg | None = None, elapsed_time: DurationS | None = None, altitude_rate: VerticalRateFtS | None = None, groundspeed_rate: AccelerationKtS | None = None, airspeed_rate: AccelerationKtS | None = None, xp: ArrayApiNamespace)
Source code in src/aerocore/acropole.py
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
def input_features(
    aircraft: AcropoleAircraft,
    groundspeed: t.GsKt,
    altitude: t.PressureAltitudeFt,
    vertical_rate: t.VerticalRateFtMin,
    *,
    airspeed: t.TasKt | None = None,
    mass: t.MassKg | None = None,
    elapsed_time: t.DurationS | None = None,
    altitude_rate: t.VerticalRateFtS | None = None,
    groundspeed_rate: t.AccelerationKtS | None = None,
    airspeed_rate: t.AccelerationKtS | None = None,
    xp: ArrayApiNamespace,
):
    airspeed = groundspeed if airspeed is None else airspeed
    zeros = xp.zeros_like(groundspeed)

    normalised_mass = (
        zeros - 1
        if mass is None
        else (mass - aircraft.oew) / (aircraft.max_tow - aircraft.oew)
    )

    if elapsed_time is None:
        altitude_rate = (
            vertical_rate / 60 if altitude_rate is None else altitude_rate
        )
        groundspeed_rate = (
            zeros if groundspeed_rate is None else groundspeed_rate
        )
        airspeed_rate = zeros if airspeed_rate is None else airspeed_rate
    else:
        delta_time = _diff_bfill(elapsed_time, xp=xp)
        altitude_rate = (
            _diff_bfill(altitude, xp=xp) / delta_time
            if altitude_rate is None
            else altitude_rate
        )
        groundspeed_rate = (
            _diff_bfill(groundspeed, xp=xp) / delta_time
            if groundspeed_rate is None
            else groundspeed_rate
        )
        airspeed_rate = (
            _diff_bfill(airspeed, xp=xp) / delta_time
            if airspeed_rate is None
            else airspeed_rate
        )

    return xp.stack(
        (
            zeros + int(aircraft.engine_type),
            altitude_rate,
            groundspeed_rate,
            airspeed_rate,
            zeros + aircraft.wing_area,
            zeros + aircraft.max_alt,
            zeros + aircraft.max_tas,
            altitude,
            groundspeed,
            airspeed,
            vertical_rate,
            normalised_mass,
        ),
        axis=-1,
    )

standardise

standardise(standardisation: AcropoleStandardisation, features)
Source code in src/aerocore/acropole.py
311
312
313
314
315
316
317
def standardise(
    standardisation: AcropoleStandardisation,
    features,
):
    return (features - standardisation.minimums) / (
        standardisation.maximums - standardisation.minimums
    )

predict_standardised

predict_standardised(weights: AcropoleWeights, features_standardised, *, xp: ArrayApiNamespace)

Return the raw normalised fuel-flow prediction.

Source code in src/aerocore/acropole.py
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
def predict_standardised(
    weights: AcropoleWeights,
    features_standardised,
    *,
    xp: ArrayApiNamespace,
):
    """Return the raw normalised fuel-flow prediction."""
    hidden = features_standardised
    for weight, bias in zip(weights.weights[:-1], weights.biases[:-1]):
        activation = hidden @ weight + bias
        hidden = xp.maximum(activation, xp.zeros_like(activation))

    logits = hidden @ weights.weights[-1] + weights.biases[-1]
    one = xp.ones_like(logits[..., 0])
    # very negative logits may overflow exp; the sigmoid still converges to 0.
    return one / (one + xp.exp(-logits[..., 0]))