crashmap

Road-safety network screening (Highway Safety Manual): crash rate, critical rate, EPDO, Empirical Bayes, negative binomial SPFs, before-after studies and crash hotspots.

Version 0.1.2 · Python >=3.9 · MIT licence
pip install crashmap
PyPISourceIssuesChangelogCite (DOI)

crashmap

PyPI Python versions Pipeline License: MIT DOI Downloads

crashmap does road-safety network screening in Python: it ranks road segments, sliding windows and intersections by crash risk with the methods of the Highway Safety Manual (AASHTO 2010, Part B, Chapter 4), fits negative binomial safety performance functions (SPFs), computes Empirical Bayes (EB) estimates, evaluates treatments with before-after studies and finds crash hotspots.

It is written for road-safety engineers and analysts who identify high-risk sites (black spots) from crash records. The core needs only NumPy; SciPy, pandas and GeoPandas are optional.

pip install crashmap            # NumPy only
pip install "crashmap[all]"     # + SciPy, pandas, GeoPandas/Shapely

Quick start

import crashmap as cm

crashes = cm.read_crashes_csv("crashes.csv")           # x, y, severity, date ...
roads = cm.read_roads_geojson("roads.geojson")         # LineStrings with an "aadt" attribute

segments = cm.fixed_length_segments(roads, 500)        # 500 m sections
snap = cm.snap_to_lines(crashes, segments, max_distance=25)
print(snap.summary())                                  # good / fair / ambiguous / unmatched

sites = cm.build_segment_sites(segments, crashes, snap, years=5)
spf = cm.load_spf("spf.toml")                          # or cm.SPF.segment(a, b, k=...)
result = cm.screen(sites, "eb", spf=spf)

for row in result.top(10):                             # ties at the cut are kept
    print(row["rank"], row["id"], round(row["score"], 2), row["expected"])

cm.write_geojson(result, "ranked.geojson")
cm.write_report(result, "screening.html")

Coordinates must be planar (metres in a projected CRS). The CLI detects longitude/latitude input and projects it to a local metric frame (crashmap.LocalProjection); output GeoJSON is written back in lon/lat.

Command line

crashmap screen crashes.csv roads.geojson --method eb --spf spf.toml -o ranked.geojson --report report.html
crashmap screen crashes.csv roads.geojson --method critical-rate --segment-length 500
crashmap screen crashes.csv roads.geojson --site-type window --window 480 --step 160
crashmap screen crashes.csv roads.geojson --site-type intersection --max-distance 76 --method rate
crashmap fit-spf sites.csv --years 5 --length-unit km -o spf.toml --cure cure.csv
crashmap before-after treated.csv --method eb --k 0.4 -o result.json

crashmap <command> --help lists every option (column names, severity scale, --dayfirst dates, EPDO weights, confidence level, ...).

Methods

Method (screen(method=...)) Score (higher = more promising) Needs Reference
frequency Average crash frequency, crashes/year crashes HSM Ch. 4
rate Crashes per million vehicle-km (or -mi); per million entering vehicles at intersections AADT, length / entering volume HSM Ch. 4
critical-rate Observed minus critical rate, R_c = R_a + P sqrt(R_a/E) + 1/(2E) AADT, length / entering volume HSM Ch. 4
epdo EPDO average crash frequency, sum(w_s N_s)/years; default weights K 542, A/B/C 11, O 1 severity HSM Ch. 4
rsi Relative severity index: average crash cost (by severity or crash type) severity or type, costs HSM Ch. 4
excess-predicted (N_obs - N_pred)/years SPF HSM Ch. 4
eb Excess expected frequency (N_exp - N_pred)/years, N_exp = w N_pred + (1-w) N_obs, w = 1/(1 + k sum N_pred) SPF with k HSM Ch. 4; Part C App. A
proportion Probability that the share of a crash type exceeds the threshold proportion (Beta-binomial) crash type or severity HSM Ch. 4

Other building blocks:

Area Functions
Crash data read_crashes_csv, read_crashes_geojson, crashes_from_dataframe, CrashSet (KABCO severities, dates, crash types), normalize_severity (KABCO, fatal/serious/slight, labels, 1..5 codes), parse_datetime
Roads and sites read_roads_geojson, roads_from_geodataframe, fixed_length_segments, homogeneous_segments, sliding_windows, extract_intersections, build_segment_sites, build_window_sites, build_intersection_sites
Snapping snap_to_lines, snap_to_points with max_distance and quality flags good / fair / ambiguous / unmatched
SPFs SPF.segment (N = L exp(a + b ln AADT)), SPF.intersection (N = exp(a + b ln AADT_maj + c ln AADT_min)), custom forms, k constant or k/L, TOML/JSON I/O, fit_spf, fit_nb2 (pure-NumPy NB2 maximum likelihood), cure_plot
Before-after naive_before_after, comparison_group_before_after, eb_before_after -> CMF, standard error, confidence interval (Hauer 1997)
Spatial kde_grid / kde_at (planar KDE), network_kde (built-in simple NKDE or an optional nkde backend), getis_ord_gi_star with distance-band or touching weights
Ranking and output rank (min/max/dense/ordinal/average ties), top_n, to_markdown, to_html (escaped), ranked_geojson, write_geojson
Synthetic data synthetic_network, synthetic_sites, simulate_nb_counts -- crashes drawn from a known SPF

SPF files

[spf]
name = "Rural two-lane segments (HSM base model)"
form = "segment"          # N = L * exp(a + b ln AADT), crashes per year
a = -8.2276               # ln(365e-6) - 0.312
b = 1.0
k = 0.236
k_form = "per_length"     # k_i = k / L_i
length_unit = "mi"

form = "intersection" takes a, b, c; form = "custom" takes an intercept, an exposure variable and [[spf.terms]] tables with variable, coefficient and transform (ln or linear). fit_spf(...).spf.save("spf.toml") writes the same layout. SPFs must be calibrated to local conditions before use.

Validation

The test suite (98 % line coverage) checks the implementation against independent results; all data are synthetic.

Limitations

References

Related Geophilo SDKs

All packages: Geophilo SDK dashboard.

Citation

@software{eminoglu_crashmap,
  author  = {Eminoğlu, Yusuf},
  title   = {crashmap},
  year    = {2026},
  version = {0.1.2},
  doi     = {10.5281/zenodo.24065104},
  url     = {https://doi.org/10.5281/zenodo.24065104}
}

See CITATION.cff. MIT licensed, (c) 2026 Yusuf Eminoğlu.

Other Geophilo SDKs