compute_batch
Compute a region-wide geofence crash rate across several regions in one request. It compares regions side by side without a separate compute call, and a full per-cell download, for each one.
HumanBaselines.compute_batch(
regions: list[str],
selections: GeofenceSelections | dict | None = None,
*,
summary_only: bool = True,
**filters,
) -> BatchComputeResultThe same bound and per-call filters are applied to every region in regions. Pass filters as keyword args, a GeofenceSelections model, or a dict, under the same rules as compute.
The batch is summary-only by default, so cells is omitted. Set summary_only=False if you need each region's per-cell breakdown.
A region whose compute fails, for example on a filter value it does not support such as denominator_vmt="hpms" outside California, comes back with error set rather than failing the whole call.
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.region, round(item.result.rate, 3))
else:
print(item.region, "→ error:", item.error)Returns: BatchComputeResult
| Field | Type | Description |
|---|---|---|
results | list[BatchItemResult] | One entry per requested region, in the same order as regions. |
Each BatchItemResult has:
| Field | Type | Description |
|---|---|---|
region | str | The region this entry is for. |
result | ComputeResult | None | The rate result, or None if this region 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, while per-region failures are reported inline via error.