← API Reference

elwood_spatial.network

Spatial network construction from GeoDataFrames. Builds distance-band neighbor graphs using libpysal, where each device is connected to others within a threshold distance.

Sensor networks at 5km, 7.5km, 12.5km, and 20km distance thresholds in the Methow Valley, WA

Network Type

Network = dict[str, dict[str, list]]
# Format: {device_id: {"neighbors": [...], "weights": [...]}}

build_network(gdf, threshold, id_column, ...)

Build a spatial network from a GeoDataFrame of device locations.

ParameterTypeDefaultDescription
gdfgpd.GeoDataFrameDevice locations with point geometry
thresholdfloatDistance threshold for neighbor inclusion
id_columnstrColumn containing device identifiers
max_neighborsint20Maximum neighbors per device
min_neighborsint3Minimum neighbors required
projected_crsstr | int | NoneNoneCRS to project to before distance calc

Returns Network.

import geopandas as gpd
from elwood_spatial.network import build_network

gdf = gpd.read_file("sensors.geojson")
network = build_network(gdf, threshold=50_000, id_column="sensor_id")

filter_network(network, active_ids, min_neighbors=3)

Filter a network to only include active devices, removing any that fall below the minimum neighbor count.

ParameterTypeDefaultDescription
networkNetworkFull network
active_idsset[str] | list[str]IDs of currently active devices
min_neighborsint3Minimum neighbors to retain a device

Returns Network.

get_neighbors(network, device_id)

Get the neighbor list for a device.

ParameterTypeDescription
networkNetworkSpatial network
device_idstrTarget device

Returns list[str]. Empty list if device not found.