Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[python] Return identity for MultiscaleImage transform to/from level 0 #3323

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions apis/python/src/tiledbsoma/_multiscale_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from somacore import (
CoordinateSpace,
CoordinateTransform,
IdentityTransform,
ScaleTransform,
options,
)
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
4 changes: 3 additions & 1 deletion apis/python/tests/test_multiscale_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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])
Expand Down
Loading