@@ -35,7 +35,7 @@ def _read_zarr_group_spatialdata_element(
3535 read_func : Callable [..., Any ],
3636 group_name : Literal ["images" , "labels" , "shapes" , "points" , "tables" ],
3737 element_type : Literal ["image" , "labels" , "shapes" , "points" , "tables" ],
38- element_container : dict [str , Raster_T ] | dict [str , DaskDataFrame ] | dict [str , GeoDataFrame ] | dict [str , AnnData ],
38+ element_container : ( dict [str , Raster_T ] | dict [str , DaskDataFrame ] | dict [str , GeoDataFrame ] | dict [str , AnnData ]) ,
3939 on_bad_files : Literal [BadFileHandleMethod .ERROR , BadFileHandleMethod .WARN ],
4040) -> None :
4141 with handle_read_errors (
@@ -80,7 +80,11 @@ def _read_zarr_group_spatialdata_element(
8080 logger .debug (f"Found { count } elements in { group } " )
8181
8282
83- def get_raster_format_for_read (group : zarr .Group , sdata_version : Literal ["0.1" , "0.2" ]) -> Format :
83+ def get_raster_format_for_read (
84+ group : zarr .Group ,
85+ sdata_version : Literal ["0.1" , "0.2" ],
86+ return_ome_zarr_format : bool = False ,
87+ ) -> Format :
8488 """Get raster format of stored raster data.
8589
8690 This checks the image or label element zarr group metadata to retrieve the format that is used by
@@ -92,18 +96,27 @@ def get_raster_format_for_read(group: zarr.Group, sdata_version: Literal["0.1",
9296 The zarr group of the raster element to be read.
9397 sdata_version
9498 The version of the SpatialData zarr store retrieved from the spatialdata attributes.
99+ return_ome_zarr_format
100+ Whether to return the ome-zarr Format or a SpatialData raster format class (which is a subclass of Format)
95101
96102 Returns
97103 -------
98104 The ome-zarr format to use for reading the raster element.
99105 """
100- from spatialdata ._io .format import sdata_zarr_version_to_ome_zarr_format
106+ from spatialdata ._io .format import (
107+ sdata_zarr_version_to_ome_zarr_format ,
108+ sdata_zarr_version_to_raster_format ,
109+ )
101110
102111 if sdata_version == "0.1" :
103112 group_version = group .metadata .attributes ["multiscales" ][0 ]["version" ]
104- if sdata_version == "0.2" :
113+ elif sdata_version == "0.2" :
105114 group_version = group .metadata .attributes ["ome" ]["version" ]
106- return sdata_zarr_version_to_ome_zarr_format [group_version ]
115+ else :
116+ raise ValueError (f"Unknown SpatialData zarr version { sdata_version } " )
117+ if return_ome_zarr_format :
118+ return sdata_zarr_version_to_ome_zarr_format [group_version ]
119+ return sdata_zarr_version_to_raster_format [group_version ]
107120
108121
109122def read_zarr (
@@ -146,7 +159,7 @@ def read_zarr(
146159 if sdata_version == "0.1" :
147160 warnings .warn (
148161 "SpatialData is not stored in the most current format. If you want to use Zarr v3"
149- ", please write the store to a new location." ,
162+ ", please write the store to a new location using `sdata.write()` ." ,
150163 UserWarning ,
151164 stacklevel = 2 ,
152165 )
@@ -177,7 +190,11 @@ def read_zarr(
177190 "shapes" : (_read_shapes , "shapes" , shapes ),
178191 "tables" : (_read_table , "tables" , tables ),
179192 }
180- for group_name , (read_func , element_type , element_container ) in group_readers .items ():
193+ for group_name , (
194+ read_func ,
195+ element_type ,
196+ element_container ,
197+ ) in group_readers .items ():
181198 _read_zarr_group_spatialdata_element (
182199 root_group = root_group ,
183200 root_store_path = root_store_path ,
0 commit comments