lapbox.tyres

API reference

lapbox.tyres

Per-compound degradation, and degradation stint by stint.

Takes FastF1’s laps as they come (session.laps); the per-compound model also reads LapBox’s engineered lap columns. Read every rate with its laps (and, for the model, its r2): on low-wear circuits the slope is small next to the noise. See Tyre degradation.

Summary

TyreDegradationModel
One straight line per compound over every driver: fuel-corrected lap time against tyre age. The slope is the seconds lost per lap of tyre age.
CompoundDegradation
The fitted line for one compound.
stint_degradation
Fuel-corrected pace and degradation for every driver’s every stint.
compound_summary
How each compound behaved across the field, kindest-wearing first.

Per compound

TyreDegradationModelclass

from lapbox.tyres import TyreDegradationModel
TyreDegradationModel(*, min_laps=5, age_column='tyre_age', use_fuel_correction=True)

One straight line per compound over every driver: fuel-corrected lap time against tyre age. The slope is the seconds lost per lap of tyre age.

Parameters

min_laps: int = 5
Fewest laps a compound needs to be fitted (and at least two tyre ages).
age_column: str = 'tyre_age'
Column with tyre age in laps; falls back to stint_lap, then FastF1’s TyreLife.
use_fuel_correction: bool = True
Take the fuel effect off each lap when there is a fuel load to read.

Reads LapBox’s engineered laps (compound, lap_time_seconds, tyre_age or stint_lap, fuel_load_est with lap_number) or FastF1’s laps (Compound, LapTime, TyreLife, LapNumber). With FastF1’s laps, pit laps are dropped and the fuel load is the laps still to run; clean the laps first with LapCleaningPipeline. Fit one session at a time.

The fuel effect is fixed at FUEL_EFFECT_S_PER_LAP, not fitted: tyre age and fuel both move with the lap number, so a fitted fuel term couldn’t be told from wear. Only laps within 107 % of each driver’s best are fitted. Fitting each race’s first half and predicting the second half on 65 races of 2024–2026, this cut the median error from 0.79 to 0.64 s and was better in 71 % of races; how lap times change inside a stint was predicted no better.

TyreDegradationModel.fitmethod

method
TyreDegradationModel.fit(laps)

Fit a line per compound present in laps. Returns the model itself, so calls chain.

Parameters

laps: pd.DataFrame
Cleaned laps of one session.

Returns

TyreDegradationModel

Raises

  • ValueError: a compound, lap-time or tyre-age column is missing, or fuel_load_est changes from lap to lap with no lap number to say how much a lap burns.

TyreDegradationModel.compoundsproperty

property
TyreDegradationModel.compounds -> dict[str, CompoundDegradation]

The fitted compounds, by name.

TyreDegradationModel.degradation_ratemethod

method
TyreDegradationModel.degradation_rate(compound)

The fitted rate (s/lap) of a compound.

Parameters

compound: str
E.g. "HARD".

Returns

float

Raises

  • KeyError: the compound wasn’t fitted.

TyreDegradationModel.predict_time_lossmethod

method
TyreDegradationModel.predict_time_loss(compound, tyre_age)

Expected lap-time loss (s) at tyre_age against a fresh tyre: rate × age.

Parameters

compound: str
E.g. "HARD".
tyre_age: float
Laps.

Returns

float

Raises

  • KeyError: the compound wasn’t fitted.

TyreDegradationModel.summarymethod

method
TyreDegradationModel.summary()

One row per compound — compound, degradation_s_per_lap, intercept_s, fuel_coef, r2, laps — lowest rate first. Before a fit, an empty frame.

Returns

pd.DataFrame

CompoundDegradationdataclass

from lapbox.tyres import CompoundDegradation
class CompoundDegradation

The fitted line for one compound.

Fields

compound: str
The compound.
degradation_s_per_lap: float
Seconds lost per lap of tyre age. Can come out negative on low-wear circuits; clamp it before planning with it.
intercept_s: float
Lap time on a new tyre with the fuel all burned (s).
fuel_coef: float | None
The fuel correction applied, in seconds per unit of fuel: per kg with fuel_load_est, per lap still to run with FastF1’s laps. 0 when the load never falls (a fuel_load_est that stays constant, as LapBox’s does in practice and qualifying); None when no correction was made.
r2: float
R² of the fuel-corrected lap times against tyre age. It no longer counts the fuel burn as explained, so it is low; read it as how much tyre age explains.
laps: int
Laps fitted.

Stint by stint

stint_degradationfunction

from lapbox.tyres import stint_degradation
stint_degradation(laps, total_laps=None)

Fuel-corrected pace and degradation for every driver’s every stint.

Parameters

laps: pd.DataFrame
FastF1’s laps of one race; stints are FastF1’s Stint numbers.
total_laps: int | None = None
The race distance in laps; defaults to the highest lap number.

Returns

pd.DataFrame, one row per stint with at least three counted laps.

Columns

driver: str
The driver.
team: str | None
The team.
stint: int
FastF1’s stint number.
compound: str | None
The compound on the stint’s first lap.
laps: int
Laps counted: timed, not pit laps, within 107 % of the stint’s best raw lap.
median_corrected: float
Median fuel-corrected lap (s).
deg_per_lap: float
Slope of the corrected times against lap number (s/lap): the tyre falling away.

compound_summaryfunction

from lapbox.tyres import compound_summary
compound_summary(stints)

How each compound behaved across the field, kindest-wearing first.

Parameters

stints: pd.DataFrame
stint_degradation’s rows.

Returns

pd.DataFrame, lowest median degradation first. Stints with no compound are left out.

Columns

compound: str
The compound.
stints: int
Stints on it.
laps: int
Laps counted across them.
median_deg: float
Median of the stints’ slopes (s/lap): one ruined stint doesn’t define a compound.
best_deg: float
Lowest slope.
worst_deg: float
Highest slope.

These docs describe lapbox 0.1.0. Something wrong or missing? Open an issue.