You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This draft PR proposes contour-aware density quantification around polygon annotations in SpatialData.
It adds two related tools:
sq.tl.ring_density(...)
Computes inward/outward ring-based density profiles around polygon contours for cells or transcripts, using signed-distance semantics relative to the contour boundary.
sq.tl.smooth_density_by_distance(...)
Computes a continuous signed-distance density profile for transcripts using Gaussian kernel smoothing on signed distance, while keeping an area-normalized density interpretation.
The main motivation is to support workflows such as tumor boundary, lumen edge, or compartment-interface analyses where users want density profiles around annotated contours rather than only nearest-distance values.
This draft intentionally includes both a discrete ring-based summary and a continuous smooth alternative so the API direction can be reviewed together. I realize that issue #1160 scoped smoothing as out of scope for a minimal v1, so I would especially welcome feedback on whether the smooth method should be split into a follow-up PR or deferred.
How has this been tested?
Tested locally with:
focused synthetic tests for ring_density
focused synthetic tests for smooth_density_by_distance
Thanks for taking a look. I would especially appreciate feedback on three design questions:\n\n1. Does belong in as proposed?\n2. Should stay in this same PR for joint API review, or would you prefer it split or deferred?\n3. Does it make sense to eventually factor the signed-distance computation into a lower-level helper shared by both tools?\n\nI also generated local example figures for the ring-based and smooth profiles and can add them in a follow-up comment if that would be helpful.
❌ Patch coverage is 77.57732% with 87 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.77%. Comparing base (373228d) to head (cf1589a). ⚠️ Report is 1 commits behind head on main.
❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
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
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.
Description
This draft PR proposes contour-aware density quantification around polygon annotations in
SpatialData.It adds two related tools:
sq.tl.ring_density(...)Computes inward/outward ring-based density profiles around polygon contours for cells or transcripts, using signed-distance semantics relative to the contour boundary.
sq.tl.smooth_density_by_distance(...)Computes a continuous signed-distance density profile for transcripts using Gaussian kernel smoothing on signed distance, while keeping an area-normalized density interpretation.
The main motivation is to support workflows such as tumor boundary, lumen edge, or compartment-interface analyses where users want density profiles around annotated contours rather than only nearest-distance values.
This draft intentionally includes both a discrete ring-based summary and a continuous smooth alternative so the API direction can be reviewed together. I realize that issue #1160 scoped smoothing as out of scope for a minimal v1, so I would especially welcome feedback on whether the smooth method should be split into a follow-up PR or deferred.
How has this been tested?
Tested locally with:
ring_densitysmooth_density_by_distancepytest -q tests/tools/test_ring_density.py tests/tools/test_smooth_density_by_distance.pyThe smooth method tests cover:
.unsstorage whencopy=FalseI also ran a real-data smoke test on a local
SpatialDataobject with:protein_cluster_contoursassigned_structure == "Structure 4"VIMThis produced a continuous signed-distance output table with 23 contours and 33 distance grid points.
Closes
Closes #1160