compute_batch
Compute a county-wide geofence crash rate across several counties in one request — built for comparing counties side by side without firing a separate compute call (and downloading a full per-cell breakdown) for each.
HumanBaselines.compute_batch(
counties: list[str],
selections: GeofenceSelections | dict | None = None,
*,
summary_only: bool = True,
**filters,
) -> BatchComputeResultThe same (bound + per-call) filters are applied to every county in counties. Pass filters as keyword args, a GeofenceSelections model, or a dict — same rules as compute.
The batch is summary-only by default (cells omitted), since the whole point is lightweight multi-county comparison. Set summary_only=False if you need each county's per-cell breakdown.
A county whose compute fails — for example a filter value it doesn't support (denominator_vmt="hpms" outside California) — comes back with error set instead of failing the whole call, so one bad county never sinks the batch.
Example
from humanbaselines import HumanBaselines
hb = HumanBaselines()
batch = hb.compute_batch(
["travis", "houston", "sf", "la"],
outcome="police_reported",
ego_vehicle=["cars", "light_trucks"],
road_type=["arterial", "collector_local"],
)
for item in batch.results:
if item.result:
print(item.county, round(item.result.rate, 3))
else:
print(item.county, "→ error:", item.error)Returns: BatchComputeResult
| Field | Type | Description |
|---|---|---|
results | list[BatchItemResult] | One entry per requested county, in the same order as counties. |
Each BatchItemResult has:
| Field | Type | Description |
|---|---|---|
county | str | The county this entry is for. |
result | ComputeResult | None | The rate result, or None if this county errored. cells is empty unless summary_only=False. |
error | str | None | Error message when result is None; otherwise None. |
See Methodology for how each rate is derived, and Errors for failure handling (transport-level errors still raise; per-county failures are reported inline via error).