Skip to content

compute

Compute a county-wide geofence crash rate, aggregated over S2 cells.

python
HumanBaselines.compute(
    selections: GeofenceSelections | dict | None = None,
    *,
    county: str | None = None,
    **filters,
) -> ComputeResult

Pass filters as keyword args, a GeofenceSelections model, or a dict; see filters three ways. You can't pass both selections and kwargs. Omitted filters use the API defaults; a bound config is inherited and overridden per call.

Example

python
from humanbaselines import HumanBaselines

hb = HumanBaselines()

r = hb.compute(
    county="travis",
    outcome="police_reported",
    severity=1,
    ego_vehicle=["cars", "light_trucks"],
    road_type=["arterial", "collector_local"],
    weather="any",
    crash_year=[2022],
)
print(r.rate, r.rate_low, r.rate_high)

Returns: ComputeResult

FieldTypeDescription
NfloatWeighted crash count (numerator).
D_milesfloatCalibrated VMT (denominator).
D_billionsfloatD_miles in billions.
ratefloatIncidents per million miles.
rate_low / rate_highfloat | None95% CI bounds.
rate_non_dynfloatPlain Σ/Σ rate (always present).
rate_dynfloat | NoneOperator-weighted rate, or None if not applicable.
multiplierfloat | NoneChen 2024 spatial multiplier, or None.
cellslist[PerCellResult]Per-S2-cell {s2_cell, count, vmt, mult_contrib}.
python
print(r.N, r.D_billions)
for c in r.cells[:3]:
    print(c.s2_cell, c.count, c.vmt)

See Methodology for how the rate and CI are derived, and Errors for failure handling.

Derived statistics only. Attribute every published figure. Maintained by Valgo.