Skip to content

Configuration

The filter selections are really a methodological definition: what counts as a crash and what you're baselining against. Bind that definition to a client once and every call inherits it; per-call args override individual fields.

Bind at construction

python
hb = HumanBaselines(config={
    "county": "travis",
    "outcome": "fatal",
    "ego_vehicle": ["cars", "light_trucks"],
})

hb.compute().rate                  # uses the bound definition
hb.compute(weather=["rain"]).rate  # override just one field for this call

The bound config is validated when the client is created; unknown fields or bad values raise immediately. It applies to all modes: each compute mode uses the subset of fields it understands (e.g. road_type only affects geofence, ci_method only route/depot), so one definition works across modes.

Inspect the effective definition

python
hb.config()    # full effective config for a mode (bound values + every default)
hb.changes()   # only the settings that differ from the mode's defaults

Both take an optional mode ("geofence" default, or "route" / "depot"), since each mode exposes different fields. config() is the complete definition a compute call would use; changes() is just your deviations.

Derive variants immutably

with_config() returns a new client with merged fields; the original is unchanged. The HTTP session is shared.

python
strict = hb.with_config(under_reporting="adjusted")   # new client; hb untouched

Version definitions as JSON

python
hb.save_config("fatal_cars.json")        # full snapshot (defaults filled) + a "mode" key

# Load it back; pass the path straight to the constructor:
hb2 = HumanBaselines(config="fatal_cars.json")
# HumanBaselines.from_config(path, api_key=...) is an equivalent, explicit alias.

save_config() writes the full effective config (every default filled in), so the file is a complete, self-documenting snapshot you can check into a repo, share, and diff, not just the deviations. The top-level "mode" key records which mode's field set it captured (geofence by default; pass mode for route/depot).

Reference

MemberDescription
config= (constructor)Bind a dict or a path to a JSON file.
config(mode="geofence")Full effective config for a mode.
changes(mode="geofence")Only deviations from the mode's defaults.
with_config(**fields)New client with merged config (immutable).
save_config(path, mode="geofence")Write the full config snapshot to JSON.
from_config(source, api_key=...)Construct from a saved definition (path or dict).

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