11from __future__ import annotations
22
3+ from collections .abc import Iterator
34from typing import Any
45
6+ import ome_zarr .format
57import zarr
68from anndata import AnnData
7- from ome_zarr .format import CurrentFormat
9+ from ome_zarr .format import CurrentFormat , Format , FormatV01 , FormatV02 , FormatV03 , FormatV04
810from pandas .api .types import CategoricalDtype
911from shapely import GeometryType
1012
@@ -120,6 +122,22 @@ def validate_coordinate_transformations(
120122 def spatialdata_format_version (self ) -> str :
121123 return "0.1"
122124
125+ @property
126+ def version (self ) -> str :
127+ return "0.4"
128+
129+
130+ class RasterFormatV02 (RasterFormatV01 ):
131+ @property
132+ def spatialdata_format_version (self ) -> str :
133+ return "0.2"
134+
135+ @property
136+ def version (self ) -> str :
137+ # 0.1 -> 0.2 changed the version string for the NGFF format, from 0.4 to 0.6-dev-spatialdata as discussed here
138+ # https://github.com/scverse/spatialdata/pull/849
139+ return "0.4-dev-spatialdata"
140+
123141
124142class ShapesFormatV01 (SpatialDataFormat ):
125143 """Formatter for shapes."""
@@ -211,7 +229,7 @@ def validate_table(
211229 raise ValueError ("`table.obs[instance_key]` must not contain null values, but it does." )
212230
213231
214- CurrentRasterFormat = RasterFormatV01
232+ CurrentRasterFormat = RasterFormatV02
215233CurrentShapesFormat = ShapesFormatV02
216234CurrentPointsFormat = PointsFormatV01
217235CurrentTablesFormat = TablesFormatV01
@@ -229,12 +247,29 @@ def validate_table(
229247}
230248RasterFormats = {
231249 "0.1" : RasterFormatV01 (),
250+ "0.2" : RasterFormatV02 (),
232251}
233252SpatialDataContainerFormats = {
234253 "0.1" : SpatialDataContainerFormatV01 (),
235254}
236255
237256
257+ def format_implementations () -> Iterator [Format ]:
258+ """Return an instance of each format implementation, newest to oldest."""
259+ yield RasterFormatV02 ()
260+ # yield RasterFormatV01() # same format string as FormatV04
261+ yield FormatV04 ()
262+ yield FormatV03 ()
263+ yield FormatV02 ()
264+ yield FormatV01 ()
265+
266+
267+ # monkeypatch the ome_zarr.format module to include the SpatialDataFormat (we want to use the APIs from ome_zarr to
268+ # read, but signal that the format we are using is a dev version of NGFF, since it builds on some open PR that are
269+ # not released yet)
270+ ome_zarr .format .format_implementations = format_implementations
271+
272+
238273def _parse_formats (formats : SpatialDataFormat | list [SpatialDataFormat ] | None ) -> dict [str , SpatialDataFormat ]:
239274 parsed = {
240275 "raster" : CurrentRasterFormat (),
0 commit comments