Skip to content

Commit f46d9b7

Browse files
authored
Fix scaling and shape issues in spatialdata reader (#50)
1 parent 3c70979 commit f46d9b7

File tree

9 files changed

+61
-13
lines changed

9 files changed

+61
-13
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ include = [
7474
packages = ["wsidata", "README.md", "LICENSE", "pyproject.toml"]
7575

7676
[tool.ruff]
77-
lint.ignore = ["F401"]
7877
lint.extend-select = ["I"]
7978
line-length = 88
8079

wsidata/_model/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
from .core import TileSpec, WSIData
2+
3+
__all__ = ["TileSpec", "WSIData"]

wsidata/accessors/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,10 @@
22
from .fetch import FetchAccessor
33
from .iter import IterAccessor
44
from .register import register_wsidata_accessor
5+
6+
__all__ = [
7+
"DatasetAccessor",
8+
"FetchAccessor",
9+
"IterAccessor",
10+
"register_wsidata_accessor",
11+
]

wsidata/dataset/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,10 @@
22
from .graph import graph_data
33
from .image import TileImagesDataset
44
from .multislides import FeaturesDatasetBuilder
5+
6+
__all__ = [
7+
"TileFeatureDataset",
8+
"TileImagesDataset",
9+
"FeaturesDatasetBuilder",
10+
"graph_data",
11+
]

wsidata/dataset/disk.py

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,9 @@
11
from .builder import FeaturesDatasetBuilder
22
from .sampler import InSlideUnderSampler, NoBalance, RandomUnderSampler
3+
4+
__all__ = [
5+
"FeaturesDatasetBuilder",
6+
"InSlideUnderSampler",
7+
"NoBalance",
8+
"RandomUnderSampler",
9+
]

wsidata/io/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,18 @@
1010
update_shapes_data,
1111
)
1212
from ._wsi import agg_wsi, concat_feature_anndata, open_wsi
13+
14+
__all__ = [
15+
"add_tiles",
16+
"add_table",
17+
"add_shapes",
18+
"add_tissues",
19+
"add_features",
20+
"agg_wsi",
21+
"add_agg_features",
22+
"concat_feature_anndata",
23+
"open_wsi",
24+
"subset_tiles",
25+
"sync_tile_spec",
26+
"update_shapes_data",
27+
]

wsidata/reader/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,18 @@
1717
from ._reader_datatree_zarr_v3 import to_datatree
1818
else:
1919
from ._reader_datatree_zarr_v2 import to_datatree
20+
21+
__all__ = [
22+
"version",
23+
"Version",
24+
"READERS",
25+
"ReaderBase",
26+
"OpenSlideReader",
27+
"SlideProperties",
28+
"BioFormatsReader",
29+
"CuCIMReader",
30+
"FastSlideReader",
31+
"SpatialDataImage2DReader",
32+
"TiffSlideReader",
33+
"to_datatree",
34+
]

wsidata/reader/spatialdata_image2d.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
from pathlib import Path
2-
from typing import TYPE_CHECKING, Union
1+
from typing import TYPE_CHECKING
32

43
import cv2
54

6-
from .base import AssociatedImages, ReaderBase, SlideProperties, convert_image
5+
from .base import ReaderBase, SlideProperties
76

87
if TYPE_CHECKING:
98
from spatialdata.models import Image2DModel
@@ -112,17 +111,16 @@ def get_region(
112111
img = self.img
113112

114113
downsample_factor = self.properties.level_downsample[level]
115-
# SpatialData coordinates must be translated to the respective level
116-
x = x / downsample_factor
117-
y = y / downsample_factor
118-
width = width / downsample_factor
119-
height = height / downsample_factor
120114
if self.is_multiscale:
121115
data = img.sel(
122-
y=slice(y, y + height), x=slice(x, x + width)
116+
y=slice(y, y + height * downsample_factor),
117+
x=slice(x, x + width * downsample_factor),
123118
).image.data.compute()
124119
else:
125-
data = img.sel(y=slice(y, y + height), x=slice(x, x + width)).data.compute()
120+
data = img.sel(
121+
y=slice(y, y + height * downsample_factor),
122+
x=slice(x, x + width * downsample_factor),
123+
).data.compute()
126124
return data.transpose(1, 2, 0)
127125

128126
def get_thumbnail(self, size, **kwargs):

0 commit comments

Comments
 (0)