Skip to content

Conversation

m-albert
Copy link

@m-albert m-albert commented Jul 1, 2025

This PR implements a fix for #947.

Problem summary: spatialdata.transform transforms each of the scales of a multi-scale image and it can happen that (especially lower resolution) scales result in shape 0. One one hand it doesn't make sense to keep zero shape scales, on the other this leads to an error later on when the scale factors of the resulting image are extracted.

Fix proposed in this PR: scales resulting in zero shape are discarded, similarly to the postprocessing of bounding_box_query:

def _process_data_tree_query_result(query_result: DataTree) -> DataTree | None:
d = {}
for k, data_tree in query_result.items():
v = data_tree.values()
assert len(v) == 1
xdata = v.__iter__().__next__()
if 0 in xdata.shape:
if k == "scale0":
return None
else:
d[k] = xdata

In the case of 'scale0' resulting in zero shape, the PR proposes to raise an error.

Happy to work on any review points!

Copy link

codecov bot commented Jul 1, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.14%. Comparing base (7604a3d) to head (ba9fe16).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #948   +/-   ##
=======================================
  Coverage   92.14%   92.14%           
=======================================
  Files          48       48           
  Lines        7473     7477    +4     
=======================================
+ Hits         6886     6890    +4     
  Misses        587      587           
Files with missing lines Coverage Δ
src/spatialdata/_core/operations/transform.py 90.98% <100.00%> (+0.15%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant