Hex labelling of trajectory data.
| Hex region | OD connectivity |
|---|---|
![]() |
![]() |
| hex_aggregation.ipynb | hex_conn_dask.ipynb |
Maps lon/lat positions to a projected hexagonal grid and provides tools for aggregation and connectivity analysis.
hex_counts— heat maps and density aggregationhex_connectivity— origin-destination matriceshex_connectivity_power— multi-generation transport probabilitieshex_connectivity_dask— lazy dask-native connectivity for large datasets- Full dask support throughout
Explore the notebooks:
hex_conn.ipynb— Label NW Shelf trajectories, compute OD connectivity, visualise choropleth + edge overlay.hex_aggregation.ipynb— Grid construction, choropleth aggregation, and weighted edges.hex_grid_construction.ipynb— Rectangle and region hex grids.hex_analysis.ipynb— Analysis functions (hex_counts,hex_connectivity,hex_connectivity_power).hex_conn_dask.ipynb— Dask-native connectivity for large datasets.
pip install hextrajWith dask, scipy, and cartopy:
pip install hextraj[full]Or from source:
pip install git+https://github.com/willirath/hextraj.git@mainfrom hextraj import HexProj
hp = HexProj(lon_origin=-3.0, lat_origin=54.0, hex_size_meters=50_000)
# Label positions → int64 hex IDs
hex_ids = hp.label(lon, lat)
# Build a GeoDataFrame with Polygon geometries
gdf = hp.to_geodataframe(hp.region_of_hexes(region_polygon))
gdf["count"] = counts.reindex(gdf.index).fillna(0)
gdf.plot(column="count", cmap="YlOrRd")
