15
15
from spatialdata import SpatialData
16
16
from spatialdata .models import SpatialElement
17
17
18
- from .._accessors import FetchAccessor , IterAccessor , DatasetAccessor
18
+ from ..accessors import FetchAccessor , IterAccessor , DatasetAccessor
19
19
from .._utils import find_stack_level
20
20
from ..reader import ReaderBase , SlideProperties
21
21
@@ -26,99 +26,80 @@ class WSIData(SpatialData):
26
26
and a whole slide image reader.
27
27
28
28
.. note::
29
- Use the :func:`open_wsi` function to create a WSIData object.
29
+ Use the :func:`open_wsi` function to create a WSIData object.
30
30
31
31
By default, the whole slide image is not attached to the SpatialData.
32
32
A thumbnail version of the whole slide image is attached for visualization purpose.
33
33
34
- The WSIData contains four main components:
35
-
36
34
.. list-table::
37
- :header-rows: 1
38
-
39
- * -
40
- - Whole slide image
41
- - Tissue contours
42
- - Tile locations
43
- - Features
44
-
45
- * - **SpatialData Slot**
46
- - :bdg-danger:`images`
47
- - :bdg-danger:`shapes`
48
- - :bdg-danger:`shapes`
49
- - :bdg-danger:`tables`
50
-
51
- * - **Default Key**
52
- - :bdg-info:`wsi_thumbnail`
53
- - :bdg-info:`tissues`
54
- - :bdg-info:`tiles`
55
- - :bdg-info:`\{feature_key\}_\{tile_key\}`
56
-
57
- * - | **Attributes**
58
- | **Slot**
59
- | **Key**
60
- - | :class:`SlideProperties <wsidata.reader.SlideProperties>`
61
- | :bdg-danger:`tables`
62
- | :bdg-info:`slide_properties`
63
- -
64
- - | :class:`TileSpec <wsidata.TileSpec>`
65
- | :bdg-danger:`tables`
66
- | :bdg-info:`tile_spec`
67
- -
68
-
69
- * - **Content**
70
- - | :class:`DataArray <xarray.DataArray>`
71
- | (c, y, x) format.
72
- - | :class:`GeoDataFrame <geopandas.GeoDataFrame>` with columns:
73
- | :bdg-black:`tissue_id`
74
- | :bdg-black:`geometry`
75
- - | :class:`GeoDataFrame <geopandas.GeoDataFrame>` with columns:
76
- | :bdg-black:`tile_id`
77
- | :bdg-black:`x`, :bdg-black:`y`
78
- | :bdg-black:`tissue_id`
79
- | :bdg-black:`geometry`
80
- - | :class:`AnnData <anndata.AnnData>` with:
81
- | :code:`X`: The feature matrix
82
- | :code:`varm`: :bdg-black:`agg_slide`, :bdg-black:`agg_tissue`
83
-
84
-
85
-
86
- You can interact with WSIData using the following accessors:
87
-
88
- - :class:`get <wsidata.GetAccessor>`: Access data from the WSIData object.
89
- - :class:`iter <wsidata.IterAccessor>`: Iterate over data in the WSIData object.
90
- - :class:`ds <wsidata.DatasetAccessor>`: Create deep learning datasets from the WSIData object.
91
- - To implement your own accessors, use :func:`register_wsidata_accessor <wsidata.register_wsidata_accessor>`.
92
-
93
- For analysis purpose, you can override two slide properties:
94
-
95
- - microns per pixel (mpp): Using the :meth:`set_mpp` method.
96
- - bounds: Using the :meth:`set_bounds` method.
97
-
98
- Parameters
99
- ----------
100
- reader : :class:`ReaderBase <wsidata.reader.ReaderBase>`
101
- A reader object that can interface with the whole slide image file.
102
- sdata : :class:`SpatialData <spatialdata.SpatialData>`
103
- A SpatialData object for storing analysis data.
104
- backed_file : str or Path
105
- Storage location to the SpatialData object.
106
- slide_properties_source : {'slide', 'sdata'}, default: 'sdata'
107
- The source of the slide properties.
108
-
109
- - "slide": load from the reader object.
110
- - "sdata": load from the SpatialData object.
111
-
112
- Attributes
113
- ----------
114
- properties : :class:`SlideProperties <wsidata.reader.SlideProperties>`
115
- The properties of the whole slide image.
116
- reader : :class:`ReaderBase <wsidata.reader.ReaderBase>`
117
- The reader object for interfacing with the whole slide image.
118
- sdata : :class:`SpatialData <spatialdata.SpatialData>`
119
- The SpatialData object containing the spatial data.
120
- backed_file : Path
121
- The path to the backed file.
35
+ :header-rows: 1
36
+
37
+ * - **Content**
38
+ - **Default key**
39
+ - **Slot**
40
+ - **Type**
41
+
42
+ * - Whole slide image
43
+ - :bdg-info:`wsi_thumbnail`
44
+ - :bdg-danger:`images`
45
+ - :class:`DataArray <xarray.DataArray>` (c, y, x) format
46
+
47
+ * - Slide Properties
48
+ - :bdg-info:`slide_properties`
49
+ - :bdg-danger:`attrs`
50
+ - :class:`SlideProperties <wsidata.reader.SlideProperties>`
51
+
52
+ * - Tissue contours
53
+ - :bdg-info:`tissues`
54
+ - :bdg-danger:`shapes`
55
+ - :class:`GeoDataFrame <geopandas.GeoDataFrame>`
56
+
57
+ * - Tile locations
58
+ - :bdg-info:`tiles`
59
+ - :bdg-danger:`shapes`
60
+ - :class:`GeoDataFrame <geopandas.GeoDataFrame>`
61
+
62
+ * - Tile specifications
63
+ - :bdg-info:`tile_spec`
64
+ - :bdg-danger:`attrs`
65
+ - :class:`TileSpec <wsidata.TileSpec>`
66
+
67
+ * - Features
68
+ - :bdg-info:`{feature_key}_{tile_key}`
69
+ - :bdg-danger:`tables`
70
+ - :class:`AnnData <anndata.AnnData>`
71
+
72
+
73
+ You can interact with WSIData using the following accessors:
74
+
75
+ - :class:`fetch <wsidata.FetchAccessor>`: Access data from the WSIData object.
76
+ - :class:`iter <wsidata.IterAccessor>`: Iterate over data in the WSIData object.
77
+ - :class:`ds <wsidata.DatasetAccessor>`: Create deep learning datasets from the WSIData object.
78
+ - To implement your own accessors, use :func:`register_wsidata_accessor <wsidata.register_wsidata_accessor>`.
79
+
80
+ For analysis purpose, you can override two slide properties:
81
+
82
+ - **microns per pixel (mpp)**: Using the :meth:`set_mpp` method.
83
+ - **bounds**: Using the :meth:`set_bounds` method.
84
+
85
+ Other Parameters
86
+ ----------------
87
+ reader : :class:`ReaderBase <wsidata.reader.ReaderBase>`
88
+ A reader object that can interface with the whole slide image file.
89
+ slide_properties_source : {'slide', 'sdata'}, default: 'sdata'
90
+ The source of the slide properties.
91
+
92
+ - "slide": load from the reader object.
93
+ - "sdata": load from the SpatialData object.
94
+
95
+ Attributes
96
+ ----------
97
+ properties : :class:`SlideProperties <wsidata.reader.SlideProperties>`
98
+ The properties of the whole slide image.
99
+ reader : :class:`ReaderBase <wsidata.reader.ReaderBase>`
100
+ The reader object for interfacing with the whole slide image.
101
+ wsi_store :
102
+ The store path for the whole slide image.
122
103
123
104
"""
124
105
@@ -186,9 +167,11 @@ def __repr__(self):
186
167
)
187
168
188
169
def set_exclude_elements (self , elements ):
170
+ """Set the elements to be excluded from serialize to the WSIData object on disk."""
189
171
self ._exclude_elements .update (elements )
190
172
191
173
def set_wsi_store (self , store : str | Path ):
174
+ """Set the on disk path for the WSIData."""
192
175
self ._wsi_store = Path (store )
193
176
194
177
def _gen_elements (
@@ -379,10 +362,17 @@ def ds(self):
379
362
class TileSpec :
380
363
"""Data class for storing tile specifications.
381
364
382
- # There are 3 levels of tile size that we should record:
383
- # 1. The destined tile size requested by the user
384
- # 2. The tile size used by the image reader to optimize the performance
385
- # 3. The actual tile size at the level 0
365
+ To enable efficient tils generation, there are 3 levels of tile size:
366
+
367
+ 1. The destined tile size and level requested by the user
368
+ 2. The tile size and level used by the image reader to optimize the performance
369
+ 3. The actual tile size at the level 0
370
+
371
+ This enables user to request tile size and level that are not exist in the image pyramids.
372
+ For example, if our slide is mpp=0.5 (20X) with pyramids of mpp=[0.5, 2.0, 4.0],
373
+ and user request mpp=1.0 (10X) with tile size 512x512. There is no direct level to read from,
374
+ we need to read from mpp=0.5 with tile size of 1024x1024 and downsample to 512x512.
375
+
386
376
387
377
Parameters
388
378
----------
@@ -404,7 +394,7 @@ class TileSpec:
404
394
tissue_name : str, optional
405
395
The name of the tissue.
406
396
407
- Properties
397
+ Attributes
408
398
----------
409
399
ops_{height, width} : int
410
400
The height/width of the tile when retrieving images.
0 commit comments