Skip to content

Commit 1123a22

Browse files
authored
Merge pull request #25 from tlambert03/docs
add docs
2 parents 83acb87 + b00939b commit 1123a22

5 files changed

Lines changed: 171 additions & 2 deletions

File tree

.github/workflows/docs.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Deploy Documentation
2+
3+
on:
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
concurrency:
9+
group: ${{ github.workflow }}-${{ github.ref }}
10+
cancel-in-progress: true
11+
12+
permissions:
13+
contents: write
14+
15+
jobs:
16+
docs:
17+
name: Deploy Documentation
18+
runs-on: ubuntu-latest
19+
steps:
20+
- uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
- name: Configure Git Credentials
24+
run: |
25+
git config user.name github-actions[bot]
26+
git config user.email github-actions[bot]@users.noreply.github.com
27+
- uses: astral-sh/setup-uv@v6
28+
- name: Deploy documentation
29+
run: uv run --group docs mkdocs gh-deploy --strict --force

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ build
1111
dist
1212
.vscode
1313
docs/_build/
14+
site
1415

1516
# remove me to enforce synchrony across development environments
1617
uv.lock

docs/index.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
# spatial-graph
2+
3+
`spatial-graph` provides a data structure for directed and undirected graphs,
4+
where each node has an nD position (in time or space).
5+
6+
It leverages well-in-time compiled C++ code for efficient graph operations,
7+
coupled with an rtree implementation for fast spatial queries.
8+
9+
## Goals
10+
11+
- Support for arbitrary number of dimensions
12+
- Typed node identifiers and attributes
13+
- Any fixed-length type that is supported by `numpy`
14+
- Efficient node/edge queries by
15+
- ROI
16+
- kNN (by points / lines)
17+
- numpy-like interface for efficient:
18+
- Graph population and manipulation
19+
- Query results
20+
- Attribute access
21+
- Minimal memory footprint
22+
- Minimal dependencies
23+
- PYX API for graph algorithms in C/C++
24+
25+
## Basic Usage
26+
27+
Graph creation:
28+
29+
```python
30+
graph = sg.SpatialGraph(
31+
ndims=3,
32+
node_dtype="uint64",
33+
node_attr_dtypes={"position": "double[3]"},
34+
edge_attr_dtypes={"score": "float32"},
35+
position_attr="position",
36+
directed=False,
37+
)
38+
```
39+
40+
Adding nodes/edges:
41+
42+
```python
43+
graph.add_nodes(
44+
np.array([1, 2, 3, 4, 5], dtype="uint64"),
45+
position=np.array(
46+
[
47+
[0.1, 0.1, 0.1],
48+
[0.2, 0.2, 0.2],
49+
[0.3, 0.3, 0.3],
50+
[0.4, 0.4, 0.4],
51+
[0.5, 0.5, 0.5],
52+
],
53+
dtype="double",
54+
),
55+
)
56+
57+
graph.add_edges(
58+
np.array([[1, 2], [3, 4], [5, 1]], dtype="uint64"),
59+
score=np.array([0.2, 0.3, 0.4], dtype="float32"),
60+
)
61+
```
62+
63+
Query nodes/edges in ROI:
64+
65+
```python
66+
# nodes/edges will be numpy arrays of dtype uint64 and shape (n,)/(n, 2)
67+
nodes = graph.query_nodes_in_roi(np.array([[0.0, 0.0, 0.0], [0.25, 0.25, 0.25]]))
68+
edges = graph.query_edges_in_roi(np.array([[0.0, 0.0, 0.0], [0.25, 0.25, 0.25]]))
69+
```
70+
71+
Query nodes/edges by position:
72+
73+
```python
74+
nodes = graph.query_nearest_nodes(np.array([0.3, 0.3, 0.3]), k=3)
75+
edges = graph.query_nearest_edges(np.array([0.3, 0.3, 0.3]), k=3)
76+
```
77+
78+
Access node/edge attributes:
79+
80+
```python
81+
node_positions = graph.node_attrs[nodes].position
82+
edge_scores = graph.edge_attrs[edges].score
83+
```
84+
85+
Delete nodes/edges:
86+
87+
```python
88+
graph.remove_nodes(nodes[:1000])
89+
```
90+
91+
See the [API documentation](./reference) for more details.

mkdocs.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
site_name: "spatial-graph"
2+
site_url: https://github.com/funkelab/spatial_graph
3+
site_description: >-
4+
High performance spatial graph library for Python
5+
# Repository
6+
repo_name: funkelab/spatial_graph
7+
repo_url: https://github.com/funkelab/spatial_graph
8+
9+
theme:
10+
11+
name: material
12+
palette:
13+
scheme: default
14+
primary: pink
15+
features:
16+
- content.tabs.link
17+
- content.code.copy
18+
- content.code.annotate
19+
- navigation.instant
20+
21+
plugins:
22+
- search
23+
- api-autonav:
24+
modules: ["src/spatial_graph"]
25+
- mkdocstrings:
26+
handlers:
27+
python:
28+
inventories:
29+
- https://docs.python.org/3/objects.inv
30+
options:
31+
docstring_section_style: list # or "table"
32+
docstring_style: "numpy"
33+
filters: ["!^_"]
34+
heading_level: 1
35+
merge_init_into_class: true
36+
parameter_headings: true
37+
separate_signature: true
38+
show_root_heading: true
39+
show_signature_annotations: true
40+
show_symbol_type_heading: true
41+
show_symbol_type_toc: true
42+
summary: true

pyproject.toml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,20 @@ classifiers = [
3131
dependencies = ["witty>=v0.2.1", "CT3>=3.3.3", "numpy", "setuptools>=75.8.0"]
3232

3333
[dependency-groups]
34+
test = ["pytest>=8.3.5", "pytest-cov>=6.1.1"]
3435
dev = [
36+
{ include-group = "test" },
3537
"ipython>=8.18.1",
3638
"mypy>=1.15.0",
3739
"pre-commit>=4.2.0",
38-
"pytest>=8.3.5",
39-
"pytest-cov>=6.1.1",
4040
"ruff>=0.11.10",
4141
]
42+
docs = [
43+
"mkdocs>=1.6.1",
44+
"mkdocs-api-autonav>=0.3.0",
45+
"mkdocs-material>=9.6.15",
46+
"mkdocstrings-python>=1.16.12",
47+
]
4248

4349

4450
[project.urls]

0 commit comments

Comments
 (0)