Add render_graph for spatial connectivity visualization#592
Open
Add render_graph for spatial connectivity visualization#592
Conversation
Three visual regression tests covering the highest-value scenarios: - Basic graph overlay on shapes (KNN connectivity edges) - Graph overlay on labels with background image (most common real-world case) - Group-filtered graph (only edges between specified cell types) Tests will fail until render_graph is implemented. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Adds `sdata.pl.render_graph()` to render spatial graph edges from adjacency matrices stored in table.obsp, using element centroids for coordinates. Supports shapes, points, and labels elements via spatialdata.get_centroids(). Key features: - connectivity_key accepts full obsp key or prefix (auto-resolves) - element and table_name auto-discovered when unambiguous - groups + group_key filtering (both-endpoints semantics) - Rasterized LineCollection for performance - No networkx dependency (direct sparse matrix to line segments) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Drop **kwargs from render_graph() and _render_graph() — the deferred execution pattern can't forward arbitrary kwargs, matching how other render functions use kwargs.get() for named options only - Add adjacency matrix shape validation against table.n_obs to catch subset graphs stored in multi-region tables - Fix CS dispatch to use get_transformation() for element-level CS membership instead of type-level has_shapes/has_labels flags - Vectorize edge filtering: replace Python-loop set lookups with numpy boolean arrays (has_coord + np.isin for groups) - Remove dead line (dict overwritten immediately) - Use triu(k=1) to skip self-loops at the sparse level Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Auto-discovery: render_graph() with no args finds the single table/element - Empty graph: zero-edge adjacency matrix renders without error - Error paths: missing obsp key, missing element, groups without group_key Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
AnnData rejects mismatched obsp matrices at assignment time, making this check dead code. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Initial baselines were generated on macOS/arm64. Matplotlib anti-aliasing produces subtly different output on Linux, causing CI failures with RMS values 27-37 (tolerance 15). CI-generated images are byte-identical across Python 3.11, 3.14-stable, and 3.14-pre. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #592 +/- ##
==========================================
+ Coverage 76.30% 76.40% +0.09%
==========================================
Files 11 11
Lines 3229 3352 +123
Branches 757 784 +27
==========================================
+ Hits 2464 2561 +97
- Misses 465 477 +12
- Partials 300 314 +14
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sdata.pl.render_graph()to render spatial graph edges from adjacency matrices stored intable.obsp, using element centroids for coordinates viaspatialdata.get_centroids()groups+group_keyfiltering (both-endpoints semantics) and auto-discovery of element/table when unambiguousAPI
Implementation details
connectivity_keyaccepts full obsp key or prefix (auto-resolves"spatial"→"spatial_connectivities")LineCollection