# connectivity-core
Multi-resolution landscape connectivity on in-memory raster arrays: habitat and PARC
connectedness, the Bioclimatic Ecosystem Resilience Index (BERI), and fractional pixel
coverage of polygons. This crate is the numerical engine of the
[`eco-connectivity`](https://pypi.org/project/eco-connectivity/) Python package; see
[Valavi et al. (2026)](https://doi.org/10.32942/X2S68V) for the method.
It has no Python, GDAL or file I/O dependencies. Callers read rasters, pass `ndarray` arrays
of one tile, and handle file formats, tiling and post-processing such as Connected Habitat.
```toml
[dependencies]
connectivity-core = "0.1"
```
It requires Rust 1.86 or later.
```rust
use connectivity_core::ndarray::Array2;
use connectivity_core::{connectivity, level_transforms, Config, Inputs};
let levels = [1, 2, 4];
// rasterio/affine (a, b, c, d, e, f) order; projected grids in metres
let transforms = level_transforms((100.0, 0.0, 500_000.0, 0.0, -100.0, 6_000_000.0), &levels, (0, 0));
let inputs = Inputs { condition: &condition, mask: &mask, traversal: None, transgrids: None, transforms: &transforms };
let config = Config { levels: &levels, outer_window: 5, ..Config::default() };
let connectedness = connectivity(&inputs, &config)?;
```
## Public API
- `connectivity(&Inputs, &Config)`: connectedness, or BERI when `Inputs::transgrids` holds the
current climate followed by future scenarios (each `(rows, cols, bands)`). Returns an array
with the condition array's shape, NaN where the mask is `true`.
- `Inputs`: borrowed condition, mask, optional traversal and transgrids, and level transforms.
- `Config`: levels, lambdas (km), `is_geo`, `max_cost`, window sizes, global tile offsets,
window mode and PARC `pa_to_pa` gating. `Config::default()` matches the Python defaults.
- `pixel_coverage(&[Polygon], &Affine, nrows, ncols)`: fraction of each pixel covered by
polygons with holes.
- `Affine` and `level_transforms`: (row, col) to world transforms and the per-level transforms
of a tile, anchored to the full raster's grid.
- `WindowMode`: circular or square annuli.
The crate documentation covers array shapes, mask semantics, BERI scenario and band order,
coordinate units, tile offsets, the preparation and post-processing left to callers, and the
error and panic conditions. Work runs on the current Rayon thread pool; results are
bit-identical for any number of threads on the same build and platform.
`cargo run --release -p connectivity-core --example synthetic` runs every indicator on
synthetic arrays.
## Versioning and releases
The crate is versioned independently of the Python package (`eco-connectivity` 2.4.0 uses
`connectivity-core` 0.1.0). Core releases are tagged `connectivity-core-vX.Y.Z`; Python
releases keep `vX.Y.Z` tags, and only those publish to PyPI. Changes to the crate are listed
in [CHANGELOG.md](https://github.com/csiro/connectivity/blob/main/crates/connectivity-core/CHANGELOG.md).
## License
MIT