Grid and Population Input Plugin
1. Overview
Regional accessibility studies evaluate how the transportation network serves an entire metropolitan area or state rather than a single origin-destination pair. To do this systematically, BAMBAM uses the grid input plugin to convert a single study-area boundary polygon (extent) into a uniform spatial grid of origin cells and attach resident population counts to each cell.
- Hexagonal Spatial Tessellation (H3): BAMBAM uses the H3 hierarchical hexagonal spatial index (by default, resolution 8, where each hexagon covers approximately \(0.74\text{ km}^2\) with an average edge length of \(0.53\text{ km}\)). Hexagons minimize orientation bias and have uniform adjacency distances to all six neighbors.
- Areal-Weighted Population Disaggregation: To evaluate population-weighted regional access, BAMBAM fetches U.S. Census American Community Survey (ACS) population counts (paired with TIGER/Line census geometries) and apportions them onto the H3 grid cells. When an H3 hexagon \(i\) intersects a set of census polygons \(c \in C\), the grid cell’s population \(P_i\) is computed assuming uniform spatial distribution within each census unit: \[P_i = \sum_{c \in C} P_c \cdot \frac{\text{Area}(i \cap c)}{\text{Area}(c)}\]
2. Setup
Configuring the grid Input Plugin in bambam.toml
In bambam.toml, the grid input plugin is placed at the start of [[plugin.input_plugins]] (before trip_modes):
[[plugin.input_plugins]]
type = "grid"
extent_format = "wkt"
grid = { type = "h3", resolution = 8 }
[plugin.input_plugins.population_source]
type = "acs"
acs_type = "five_year"
acs_year = 2022
acs_resolution = "census_tract"
acs_categories = ["B01001_001E"]
Key configuration parameters:
extent_format: Format of the"extent"polygon in the input query JSON ("wkt"forPOLYGON ((...))orMULTIPOLYGON (((...)))).grid: Grid tessellation system and resolution (type = "h3",resolution = 0..15). Common resolutions for regional studies are7(\(5.16\text{ km}^2\)),\(0.74\text{ km}^2\)), and8(9(~\(0.11\text{ km}^2\)).population_source(optional):type = "acs": Downloads U.S. Census ACS tables viabamcensus(requiresCENSUS_API_TOKENin the environment).acs_type:"five_year"(5-year ACS estimates, covering all tracts/block groups) or"one_year"(1-year ACS estimates).acs_year: Survey year (e.g.,2022or2024).acs_resolution: Census geographic granularity ("census_tract","block_group","county", or"state").acs_categories: List of ACS variable codes to sum (e.g.,["B01001_001E"]for total population).
Optional: Pre-Processing the Grid Offline (bambam_util preprocess_grid)
For very large multi-state studies or HPC runs where compute nodes lack internet access, you can pre-generate the H3 grid and ACS population dataset ahead of time using bambam_util preprocess_grid:
export CENSUS_API_TOKEN="<your-census-api-key>"
./rust/target/release/bambam_util preprocess_grid \
--acs-type five-year \
--acs-year 2022 \
--acs-resolution census-tract \
--acs-categories "B01001_001E" \
--extent-format wkt \
--grid-resolution 8 \
--extent-file query/denver_470_extent.txt \
--output-file denver_buf/preprocessed_grid.jsonl
This writes a newline-delimited JSON query file where each line already contains grid_id, origin_x, origin_y, geometry, and population. When passing a pre-processed query file to bambam (with --newline-delimited), the grid input plugin detects that origin_x and origin_y are already present and passes the rows straight through without re-querying the Census API.
Running BAMBAM
To run with on-the-fly grid generation from an extent query JSON (query/denver_extent.json):
export CENSUS_API_TOKEN="<your-census-api-key>"
cd denver_buf
../rust/target/release/bambam \
--config-file bambam.toml \
--query-file ../query/denver_extent.json
3. What Happens
- Query Validation & Template Extraction:
- The
gridplugin inspects the incoming query JSON. If the query contains"origin_x"and"origin_y"(a point query), the plugin is a no-op. If the query contains"extent", the plugin parses the WKTPOLYGONorMULTIPOLYGONand preserves any additional user keys on the JSON object as a template.
- The
- H3 Polyfill & Centroid Extraction:
- BAMBAM fills the polygon extent with H3 cells at the configured
resolution. - For each H3 cell, it creates a query object populated with:
grid_id: The hexadecimal H3 index string (e.g.,"88268cda01fffff").origin_xandorigin_y: The longitude and latitude of the hexagon’s centroid.geometry: The WKT boundary polygon of the H3 hexagon.
- BAMBAM fills the polygon extent with H3 cells at the configured
- Census ACS Download & Spatial Intersection:
- When
population_sourceis configured, BAMBAM identifies which U.S. states intersect the study extent, downloads the requested ACS table (B01001_001E) and TIGER/Line census tract polygons, and indexes them in a polygonal R-tree. - Across all CPU threads in parallel, each H3 hexagon’s boundary
geometryis intersected with the census tract R-tree to compute the area-proportionedpopulationfield, which is attached to the grid row and carried through toresult.csvandresult.json.
- When