Skip to content

Commit d5da376

Browse files
committed
fix: remove finite check from transform matrix and update transform method
1 parent c9e74a2 commit d5da376

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

src/ndv/models/_array_display_model.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,6 @@ def transform(self, matrix: np.ndarray) -> None:
218218
ary = np.asarray(matrix)
219219
if ary.shape != (4, 4):
220220
raise ValueError("Transform matrix must be 4x4.")
221-
if not np.all(np.isfinite(ary)):
222-
raise ValueError("Transform matrix must be finite.")
223221
# Decompose the matrix into scale and translation
224222
# Note: this assumes a proper affine transformation matrix
225223
self.scale = tuple(np.sqrt(np.sum(ary[:3, i] ** 2)) for i in range(3))[::-1]

src/ndv/views/_vispy/_array_canvas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ def set_colormap(self, cmap: _cmap.Colormap) -> None:
9999
self._visual.cmap = cmap.to_vispy()
100100

101101
def transform(self) -> np.ndarray:
102-
return self._visual.transform # type: ignore [no-any-return]
102+
return self._visual.transform.matrix # type: ignore [no-any-return]
103103

104104
def set_transform(self, transform: np.ndarray) -> None:
105105
self._visual.transform = MatrixTransform(transform.T)

src/ndv/views/bases/_graphics/_canvas_elements.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ def colormap(self) -> _cmap.Colormap: ...
6464
@abstractmethod
6565
def set_colormap(self, cmap: _cmap.Colormap) -> None: ...
6666
@abstractmethod
67+
def transform(self) -> np.ndarray: ...
68+
@abstractmethod
6769
def set_transform(self, transform: np.ndarray) -> None: ...
6870

6971
# -- LutView methods -- #

tests/test_controller.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from unittest.mock import MagicMock, Mock, patch
88

99
import numpy as np
10+
import numpy.testing as npt
1011
import pytest
1112

1213
from ndv._types import (
@@ -411,3 +412,17 @@ def assert_rgb_magic_works(rgb_data: np.ndarray) -> None:
411412

412413
rgba_data = np.ones((1, 2, 3, 4, 4), dtype=np.uint8)
413414
assert_rgb_magic_works(rgba_data)
415+
416+
417+
@pytest.mark.usefixtures("any_app")
418+
def test_scale() -> None:
419+
data = np.empty((8, 64, 64))
420+
viewer = ArrayViewer(data, scale=(3, 1, 1))
421+
viewer._request_data()
422+
viewer._request_data()
423+
viewer._request_data()
424+
assert viewer.display_model.scale == (3, 1, 1)
425+
handles = viewer._lut_controllers[None].handles
426+
viewer._join()
427+
tform = handles[0].transform()
428+
npt.assert_array_equal(tform, np.diag((1.0, 1, 3, 1)))

0 commit comments

Comments
 (0)