Skip to content

Commit 80a931d

Browse files
committed
fix wrong dimension _compute_chunks(); cover with test
1 parent a7a2b92 commit 80a931d

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

src/spatialdata_io/readers/_utils/_image.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,14 @@ def _compute_chunks(
3939
Array of shape (n_tiles_x, n_tiles_y, 4). Each entry defines a tile
4040
as (x, y, width, height).
4141
"""
42-
# TODO: check x -> 1 and y -> 0?
43-
x_positions, widths = _compute_chunk_sizes_positions(shape[1], chunk_size[1])
44-
y_positions, heights = _compute_chunk_sizes_positions(shape[0], chunk_size[0])
42+
x_positions, widths = _compute_chunk_sizes_positions(shape[0], chunk_size[0])
43+
y_positions, heights = _compute_chunk_sizes_positions(shape[1], chunk_size[1])
4544

4645
# Generate the tiles
4746
tiles = np.array(
4847
[
49-
[[x, y, w, h] for x, w in zip(x_positions, widths, strict=True)]
50-
for y, h in zip(y_positions, heights, strict=True)
48+
[[x, y, w, h] for y, h in zip(y_positions, heights, strict=True)]
49+
for x, w in zip(x_positions, widths, strict=True)
5150
],
5251
dtype=int,
5352
)

tests/readers/test_utils_image.py

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010

1111
@pytest.mark.parametrize(
12-
("size", "chunk", "positions", "lengths"),
12+
("size", "chunk", "expected_positions", "expected_lengths"),
1313
[
1414
(300, 100, np.array([0, 100, 200]), np.array([100, 100, 100])),
1515
(300, 200, np.array([0, 200]), np.array([200, 100])),
@@ -18,12 +18,12 @@
1818
def test_compute_chunk_sizes_positions(
1919
size: int,
2020
chunk: int,
21-
positions: NDArray[np.number],
22-
lengths: NDArray[np.number],
21+
expected_positions: NDArray[np.number],
22+
expected_lengths: NDArray[np.number],
2323
) -> None:
2424
computed_positions, computed_lengths = _compute_chunk_sizes_positions(size, chunk)
25-
assert (positions == computed_positions).all()
26-
assert (lengths == computed_lengths).all()
25+
assert (expected_positions == computed_positions).all()
26+
assert (expected_lengths == computed_lengths).all()
2727

2828

2929
@pytest.mark.parametrize(
@@ -33,13 +33,24 @@ def test_compute_chunk_sizes_positions(
3333
(
3434
(2, 2),
3535
(1, 1),
36-
np.array([[[0, 0, 1, 1], [1, 0, 1, 1]], [[0, 1, 1, 1], [1, 1, 1, 1]]]),
36+
np.array(
37+
[
38+
[[0, 0, 1, 1], [0, 1, 1, 1]],
39+
[[1, 0, 1, 1], [1, 1, 1, 1]],
40+
]
41+
),
3742
),
3843
# Different tile sizes
3944
(
40-
(3, 3),
41-
(2, 2),
42-
np.array([[[0, 0, 2, 2], [2, 0, 1, 2]], [[0, 2, 2, 1], [2, 2, 1, 1]]]),
45+
(300, 300),
46+
(100, 200),
47+
np.array(
48+
[
49+
[[0, 0, 100, 200], [0, 200, 100, 100]],
50+
[[100, 0, 100, 200], [100, 200, 100, 100]],
51+
[[200, 0, 100, 200], [200, 200, 100, 100]],
52+
]
53+
),
4354
),
4455
],
4556
)

0 commit comments

Comments
 (0)