From 722a238ee00856f2c724e94b38f6e6f28f66759c Mon Sep 17 00:00:00 2001 From: Julia Dark Date: Tue, 12 Nov 2024 20:11:20 -0500 Subject: [PATCH] Update return for MultiscaleImage transform to/from level 0 Return the `IdentityTransform` when the user asks for the transform from the resolution level 0 array. --- apis/python/src/tiledbsoma/_multiscale_image.py | 11 +++++++++++ apis/python/tests/test_multiscale_image.py | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/apis/python/src/tiledbsoma/_multiscale_image.py b/apis/python/src/tiledbsoma/_multiscale_image.py index b67b9b088b..42ff1b1237 100644 --- a/apis/python/src/tiledbsoma/_multiscale_image.py +++ b/apis/python/src/tiledbsoma/_multiscale_image.py @@ -17,6 +17,7 @@ from somacore import ( CoordinateSpace, CoordinateTransform, + IdentityTransform, ScaleTransform, options, ) @@ -630,6 +631,11 @@ def get_transform_from_level(self, level: Union[int, str]) -> ScaleTransform: Lifecycle: Experimental. """ + if level == 0 or level == self._level_properties(0).name: + return IdentityTransform( + input_axes=self._coord_space.axis_names, + output_axes=self._coord_space.axis_names, + ) level_shape = self._level_properties(level).shape base_shape = self._levels[0].shape axis_indexer = self._axis_order() @@ -649,6 +655,11 @@ def get_transform_to_level(self, level: Union[int, str]) -> ScaleTransform: Lifecycle: Experimental. """ + if level == 0 or level == self._level_properties(0).name: + return IdentityTransform( + input_axes=self._coord_space.axis_names, + output_axes=self._coord_space.axis_names, + ) level_shape = self._level_properties(level).shape base_shape = self._levels[0].shape axis_indexer = self._axis_order() diff --git a/apis/python/tests/test_multiscale_image.py b/apis/python/tests/test_multiscale_image.py index 60895cda2d..a0d9b1b521 100644 --- a/apis/python/tests/test_multiscale_image.py +++ b/apis/python/tests/test_multiscale_image.py @@ -6,7 +6,7 @@ import pytest import tiledbsoma as soma -from tiledbsoma import ScaleTransform +from tiledbsoma import IdentityTransform, ScaleTransform def test_multiscale_image_bad_create(tmp_path): @@ -113,6 +113,8 @@ def test_multiscale_basic(tmp_path): to_level = image.get_transform_to_level from_level = image.get_transform_from_level + assert isinstance(to_level(0), IdentityTransform) + assert isinstance(from_level(0), IdentityTransform) assert np.array_equal(to_level(0).scale_factors, [1, 1]) assert np.array_equal(to_level(1).scale_factors, [0.5, 0.5]) assert np.array_equal(to_level(2).scale_factors, [0.0625, 0.0625])