Skip to content

xenium: place an H&E image without an alignment CSV by an affine fit to its keypoints - #447

Open
timtreis wants to merge 2 commits into
scverse:mainfrom
timtreis:xenium-he-keypoints
Open

timtreis wants to merge 2 commits into
scverse:mainfrom
timtreis:xenium-he-keypoints

Conversation

@timtreis

@timtreis timtreis commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

xenium() leaves an H&E image without an alignment CSV at the identity transformation. When the bundle has <sample>_keypoints.csv, the reader now fits an affine to the keypoints and uses it, which is the least-squares fit that Xenium Explorer writes to the alignment CSV. An alignment CSV still takes precedence, and unusable keypoints give a warning and the identity, as before.

We fit an affine instead of a similarity transform, because the scans we tested have about 0.2% anisotropy. A similarity fit left about 22 px of residual, and the affine left under 8 px.

We hit this on the Atera WTA preview bundles, which ship keypoints but no alignment CSV. We haven't checked public Xenium bundles. The reader also skips macOS ._ files when it collects the aligned images.

Tests: new tests cover the fit, the precedence of the alignment CSV and the unusable cases (other columns, fewer than 3 rows, NaN rows, collinear points, another sample's keypoints). On main, 9 of the 10 new cases fail. The other 17 local failures in tests/test_xenium.py are example bundles that CI downloads.

…its keypoints

Xenium Explorer's alignment CSV is the least-squares fit to the
keypoints the user placed. When a bundle has <sample>_he_image.ome.tif
and <sample>_keypoints.csv but no alignment CSV, fit that affine and set
it as the global transformation. The keypoints must have the four
Xenium Explorer columns, at least 3 finite rows and points that aren't
collinear; otherwise warn and leave the image at Identity, as before.
A full affine rather than a similarity, because scans with 0.2%
anisotropy leave about 22 px of error under a similarity fit.

The aligned-image search now skips macOS ._ sidecar files, which were
read as TIFFs and failed.
@codecov-commenter

codecov-commenter commented Nov 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.70%. Comparing base (51ef276) to head (ad61064).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #447      +/-   ##
==========================================
+ Coverage   66.60%   67.70%   +1.09%     
==========================================
  Files          26       26              
  Lines        3345     3372      +27     
==========================================
+ Hits         2228     2283      +55     
+ Misses       1117     1089      -28     
Files with missing lines Coverage Δ
src/spatialdata_io/readers/xenium.py 85.07% <100.00%> (+6.54%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

2 participants