Metadata-Version: 2.4
Name: hextraj
Version: 2026.4.23.3
Summary: Hex labelling of trajectory data
Author-email: Willi Rath <wrath@geomar.de>
License: 
        The MIT License (MIT)
        Copyright (c) 2023, Willi Rath
        
        Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
        
Project-URL: Homepage, https://github.com/willirath/hextraj
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy
Requires-Dist: pyproj
Requires-Dist: xarray
Requires-Dist: geopandas
Requires-Dist: shapely
Provides-Extra: full
Requires-Dist: dask; extra == "full"
Requires-Dist: scipy; extra == "full"
Requires-Dist: cartopy; extra == "full"
Provides-Extra: dev
Requires-Dist: hextraj[full]; extra == "dev"
Requires-Dist: pytest; extra == "dev"
Requires-Dist: pytest-cov; extra == "dev"
Dynamic: license-file

# hextraj

[![PyPI](https://img.shields.io/pypi/v/hextraj)](https://pypi.org/project/hextraj/)
[![License:MIT](https://img.shields.io/badge/License-MIT-lightgray.svg?style=flt-square)](LICENSE)
[![Docs](https://img.shields.io/badge/docs-GitHub%20Pages-blue)](https://willirath.github.io/hextraj/)

Hex labelling of trajectory data.

| Hex region | OD connectivity |
|:---:|:---:|
| ![Hex region example](figures/hex_region_example.png) | ![OD connectivity example](figures/hex_conn_dask_example.png) |
| [hex_aggregation.ipynb](notebooks/hex_aggregation.ipynb) | [hex_conn_dask.ipynb](notebooks/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 aggregation
- `hex_connectivity` — origin-destination matrices
- `hex_connectivity_power` — multi-generation transport probabilities
- `hex_connectivity_dask` — lazy dask-native connectivity for large datasets
- Full dask support throughout

## Getting started

Explore the notebooks:

- [`hex_conn.ipynb`](notebooks/hex_conn.ipynb) — Label NW Shelf trajectories, compute OD connectivity, visualise choropleth + edge overlay.
- [`hex_aggregation.ipynb`](notebooks/hex_aggregation.ipynb) — Grid construction, choropleth aggregation, and weighted edges.
- [`hex_grid_construction.ipynb`](notebooks/hex_grid_construction.ipynb) — Rectangle and region hex grids.
- [`hex_analysis.ipynb`](notebooks/hex_analysis.ipynb) — Analysis functions (`hex_counts`, `hex_connectivity`, `hex_connectivity_power`).
- [`hex_conn_dask.ipynb`](notebooks/hex_conn_dask.ipynb) — Dask-native connectivity for large datasets.

## Installation

```shell
pip install hextraj
```

With dask, scipy, and cartopy:

```shell
pip install hextraj[full]
```

Or from source:

```shell
pip install git+https://github.com/willirath/hextraj.git@main
```

## Quick example

```python
from 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")
```
