scverse / scverse/squidpy

speed up _resolve_data in spatial neighbors when working with spatialdata

Open
#1,199 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
598
Forks
121
Avg merge
3d 11h
Merged PRs (30d)
3

Description

Description of feature

I have a SpatialData object with about 20 samples and in total ~10M cells, stored as shapes.

When calculating gr.spatial_neighbors_radius this takes about 5minutes (3min after #1198). Of these 5 minutes, 1:30min are spent in the _resolve_data function. This means (after the optimization in #1198) 50% of the time is spent on retrieving information from the spatialdata object. Specifically, it seems to be the compute_centroids() function that takes most of the time.

On the one hand, this can surely be optimized. On the other hand, I was wondering if caching would be an appropriate solution here. The centroids are required for all graph-based functions in squidpy and there's no point in recalculating them every time. Mabye they could be added as a points layer to spatialdata?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at _resolve_data and profile spatial_neighbors_radius, focusing on the compute_centroids() work described in the issue and the optimization from #1198. Compare optimizing centroid retrieval with caching or adding centroids as a points layer to SpatialData. Done means the spatial_neighbors_radius benchmark is measurably faster without changing its results.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data, performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.