Skip to content

feat: add opt-in rasterization tiles - #1166

Open
stanbot8 wants to merge 2 commits into
scverse:mainfrom
stanbot8:feat/987-raster-output-tiling
Open

stanbot8 wants to merge 2 commits into
scverse:mainfrom
stanbot8:feat/987-raster-output-tiling

Conversation

@stanbot8

@stanbot8 stanbot8 commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A large rasterization canvas can exceed available memory. Compute tiled raster shape and fill metadata 1 time before tile graph construction. Closes #987.

Design

The rasterization path can create 1 output canvas for the complete target extent. An enabled tile size bounds each rasterization canvas and preserves output coordinates and tile boundaries.

The implementation changes src/spatialdata/_core/operations/rasterize.py.

Limitations

  • Tiling is opt-in.
  • Smaller tiles create more tasks.

Tests

The baseline failed, and the candidate passed the same reproducer. The focused A/B reproducer passed on the candidate. The upstream CI test matrix passed. The repository quality checks passed in CI.

The tests are in tests/core/operations/test_rasterize.py.

Commands
python -m pytest tests/core/operations/test_rasterize.py -q
ruff check src/spatialdata/_core/operations/rasterize.py tests/core/operations/test_rasterize.py

@codecov

codecov Bot commented Jul 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.55%. Comparing base (eb4fb3d) to head (6d80ac6).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1166      +/-   ##
==========================================
+ Coverage   92.44%   92.55%   +0.11%     
==========================================
  Files          51       51              
  Lines        7820     7901      +81     
==========================================
+ Hits         7229     7313      +84     
+ Misses        591      588       -3     
Files with missing lines Coverage Δ
src/spatialdata/_core/operations/rasterize.py 92.87% <100.00%> (+2.27%) ⬆️

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

@stanbot8
stanbot8 force-pushed the feat/987-raster-output-tiling branch from aab46d8 to 6d80ac6 Compare July 25, 2026 16:11
jan-glx added a commit that referenced this pull request Nov 23, 2026
2 implementations exist. This implementation uses 1 canvas and only
removes the label-count limit. The [other
implementation](#1166) adds
opt-in output tiles after this commit to limit output memory. Compare
the limitations.

### Summary

In [issue 987](#987),
`rasterize(..., return_regions_as_labels=True)` rejects more than
`65,535` labels. Select the output dtype from the maximum label. Closes
#987.

### Design

Use the existing `_get_uint_dtype()` helper, as proposed in the
[maintainer
direction](#187 (comment)).
Small outputs remain `uint16`. Larger outputs use `uint32` or `uint64`
only when required.

The implementation changes
[`src/spatialdata/_core/operations/rasterize.py`](https://github.com/stanbot8/spatialdata/blob/72250aa686c4be535f6d19038f9e0c13a0f2fb9e/src/spatialdata/_core/operations/rasterize.py).

### Limitations

This implementation uses 1 canvas. It removes the label-count limit, but
it does not bound output memory.

### Tests

1 boundary test rasterizes `65,536` indexed points. It preserves label
`65,536` in `uint32` output.

The focused rasterization suites pass with `28` tests. The complete
suite passes with `1,365` tests, `7` skips, and `1` expected failure. An
isolated installed wheel passes the same boundary case.

The test is in
[`tests/core/operations/test_rasterize.py`](https://github.com/stanbot8/spatialdata/blob/72250aa686c4be535f6d19038f9e0c13a0f2fb9e/tests/core/operations/test_rasterize.py).

<details>
<summary>Commands</summary>

```console
uv run pytest tests/core/operations/test_rasterize.py::test_rasterize_points_selects_label_dtype -q
```

</details>

---------

Co-authored-by: Jan Gleixner <jan.gleixner+git@gmail.com>
Co-authored-by: Jan Gleixner <j.gleixner@dkfz-heidelberg.de>

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.

exceeding rasterize's maximum label index

1 participant