Skip to content

Conversation

@stephenwilliams22
Copy link
Collaborator

@stephenwilliams22 stephenwilliams22 commented Oct 6, 2025

This pr adds support for cell segmentation in Visium HD which was added in Space Ranger 4.0.

Features include

  • Updating and refactoring the visium_hd function
  • Default loading of Visium HD cell segmentations
  • New parameters
    • load_segmentations_only which disables bin loading
    • load_nucleus_segmentations which loads nucleus segmentations and calculates a nucleus only expression matrix

spatial data structure will look something like

SpatialData object
├── Images
│     ├── 'hd_hires_image': DataArray[cyx] (3, 5394, 6000)
│     └── 'hd_lowres_image': DataArray[cyx] (3, 540, 600)
├── Shapes
│     ├── 'hd_cell_segmentations': GeoDataFrame shape: (612, 2) (2D shapes)
│     └── 'hd_nucleus_segmentations': GeoDataFrame shape: (950, 2) (2D shapes)
└── Tables
      ├── 'cell_segmentations': AnnData (612, 32285)
      └── 'nucleus_segmentations': AnnData (950, 32285)
with coordinate systems:
    ▸ 'hd_downscaled_hires', with elements:
        hd_hires_image (Images), hd_cell_segmentations (Shapes), hd_nucleus_segmentations (Shapes)
    ▸ 'hd_downscaled_lowres', with elements:
        hd_lowres_image (Images), hd_cell_segmentations (Shapes), hd_nucleus_segmentations (Shapes)

To do based on submission guidelines

@codecov-commenter
Copy link

codecov-commenter commented Oct 6, 2025

Codecov Report

❌ Patch coverage is 8.38323% with 153 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.24%. Comparing base (595eea7) to head (0e891ec).
⚠️ Report is 8 commits behind head on main.

Files with missing lines Patch % Lines
src/spatialdata_io/readers/visium_hd.py 4.37% 153 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #328      +/-   ##
==========================================
- Coverage   49.06%   48.24%   -0.83%     
==========================================
  Files          26       26              
  Lines        2686     2794     +108     
==========================================
+ Hits         1318     1348      +30     
- Misses       1368     1446      +78     
Files with missing lines Coverage Δ
src/spatialdata_io/__main__.py 86.03% <ø> (ø)
src/spatialdata_io/_constants/_constants.py 100.00% <100.00%> (ø)
src/spatialdata_io/readers/visium_hd.py 15.43% <4.37%> (+0.29%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@stephenwilliams22
Copy link
Collaborator Author

@LucaMarconato please let me know if my vignette should go someplace else but I thought it would be good to have one.

Comment on lines +47 to +71

# TODO: Replace with the actual Visium HD test dataset folder name
# This dataset name is used to locate the test data in the './data/' directory.
# See https://github.com/scverse/spatialdata-io/blob/main/.github/workflows/prepare_test_data.yaml
# for instructions on how to download and place the data on disk.
DATASET_FOLDER = "Visium_HD_Mouse_Brain_Chunk"
DATASET_ID = "visium_hd_tiny"


@skip_if_below_python_version()
def test_visium_hd_data_extent() -> None:
"""Check the spatial extent of the loaded Visium HD data."""
f = Path("./data") / DATASET_FOLDER
if not f.is_dir():
pytest.skip(f"Test data not found at '{f}'. Skipping extent test.")

sdata = visium_hd(f, dataset_id=DATASET_ID)
extent = get_extent(sdata, exact=False)
extent = {ax: (math.floor(extent[ax][0]), math.ceil(extent[ax][1])) for ax in extent}

# TODO: Replace with the actual expected extent of your test data
expected_extent = "{'x': (1000, 7000), 'y': (2000, 8000)}"
assert str(extent) == expected_extent


Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to update these once tiny test is added

@LucaMarconato
Copy link
Member

Thanks @stephenwilliams22! We can review the vignette here, but before merging please move it to the spatialdata-notebooks repo, in this folder.

If you would like we could add the vignette in gallery in the docs.

@stephenwilliams22
Copy link
Collaborator Author

stephenwilliams22 commented Oct 13, 2025

Thanks @stephenwilliams22! We can review the vignette here, but before merging please move it to the spatialdata-notebooks repo, in this folder.

If you would like we could add the vignette in gallery in the docs.

Perfect. moved here scverse/spatialdata-notebooks#152

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants