diff --git a/funlib/persistence/arrays/metadata.py b/funlib/persistence/arrays/metadata.py index b2eccc0..443922f 100644 --- a/funlib/persistence/arrays/metadata.py +++ b/funlib/persistence/arrays/metadata.py @@ -31,7 +31,7 @@ def __init__( def interleave_physical( self, physical: Sequence[int | str], non_physical: int | str | None ) -> Sequence[int | str | None]: - interleaved = [] + interleaved: list[int | str | None] = [] physical_ind = 0 for i, type in enumerate(self.types): if type in ["space", "time"]: @@ -43,7 +43,11 @@ def interleave_physical( @property def ome_scale(self) -> Sequence[int]: - return self.interleave_physical(self.voxel_size, 1) + return [ + x + for x in self.interleave_physical(self.voxel_size, 1) + if isinstance(x, int) + ] @property def ome_translate(self) -> Sequence[int]: @@ -51,11 +55,18 @@ def ome_translate(self) -> Sequence[int]: "funlib.persistence only supports ome-zarr with integer multiples of voxel_size as an offset." f"offset: {self.offset}, voxel_size:{self.voxel_size}, offset % voxel_size: {self.offset % self.voxel_size}" ) - return self.interleave_physical(self.offset / self.voxel_size, 0) + return [ + x + for x in self.interleave_physical(self.offset / self.voxel_size, 0) + if isinstance(x, int) + ] @property def ome_units(self) -> list[str | None]: - return self.interleave_physical(self.units, None) + return [ + str(x) if x is not None else None + for x in self.interleave_physical(self.units, None) + ] @property def offset(self) -> Coordinate: @@ -160,30 +171,7 @@ class OME_MetaDataFormat(BaseModel): class Config: extra = "forbid" - def fetch(self, data: dict[str | int, Any], keys: Sequence[str]): - current_key: str | int - current_key, *keys = keys - try: - current_key = int(current_key) - except ValueError: - pass - if isinstance(current_key, int): - return self.fetch(data[current_key], keys) - if len(keys) == 0: - return data.get(current_key, None) - elif isinstance(data, list): - assert current_key == "{dim}", current_key - values = [] - for sub_data in data: - try: - values.append(self.fetch(sub_data, keys)) - except KeyError: - values.append(None) - return values - else: - return self.fetch(data[current_key], keys) - - def strip_channels(self, types: list[str], to_strip: list[Sequence]) -> None: + def strip_channels(self, types: list[str], to_strip: list[list]) -> None: to_delete = [i for i, t in enumerate(types) if t not in ["space", "time"]][::-1] for ll in to_strip: if ll is not None and len(ll) == len(types): @@ -193,7 +181,6 @@ def strip_channels(self, types: list[str], to_strip: list[Sequence]) -> None: def parse( self, shape, - data: dict[str | int, Any], offset=None, voxel_size=None, axis_names=None, @@ -201,27 +188,6 @@ def parse( types=None, strict=False, ) -> MetaData: - offset = ( - offset - if offset is not None - else self.fetch(data, self.offset_attr.split("/")) - ) - voxel_size = ( - voxel_size - if voxel_size is not None - else self.fetch(data, self.voxel_size_attr.split("/")) - ) - axis_names = ( - axis_names - if axis_names is not None - else self.fetch(data, self.axis_names_attr.split("/")) - ) - units = ( - units if units is not None else self.fetch(data, self.units_attr.split("/")) - ) - types = ( - types if types is not None else self.fetch(data, self.types_attr.split("/")) - ) if types is not None: self.strip_channels(types, [offset, voxel_size, units]) @@ -278,7 +244,7 @@ def fetch(self, data: dict[str | int, Any], keys: Sequence[str]): else: return self.fetch(data[current_key], keys) - def strip_channels(self, types: list[str], to_strip: list[Sequence]) -> None: + def strip_channels(self, types: list[str], to_strip: list[list]) -> None: to_delete = [i for i, t in enumerate(types) if t not in ["space", "time"]][::-1] for ll in to_strip: if ll is not None and len(ll) == len(types): diff --git a/funlib/persistence/arrays/ome_datasets.py b/funlib/persistence/arrays/ome_datasets.py index 72ed664..df65801 100644 --- a/funlib/persistence/arrays/ome_datasets.py +++ b/funlib/persistence/arrays/ome_datasets.py @@ -96,7 +96,6 @@ def open_ome_ds( metadata = OME_MetaDataFormat().parse( dataset.shape, - {}, offset=list(base_translation), voxel_size=list(base_scale), axis_names=axis_names, @@ -196,7 +195,12 @@ def prepare_ome_ds( assert not store.exists(), "Store already exists!" metadata = MetaData( - shape, Coordinate(offset), Coordinate(voxel_size), axis_names, units, types + Coordinate(shape), + Coordinate(offset), + Coordinate(voxel_size), + list(axis_names) if axis_names is not None else None, + list(units) if units is not None else None, + list(types) if types is not None else None, ) axis_metadata = [ diff --git a/mypy.ini b/mypy.ini index 94c22b3..95da63d 100644 --- a/mypy.ini +++ b/mypy.ini @@ -11,4 +11,7 @@ ignore_missing_imports = True ignore_missing_imports = True [mypy-psycopg2.*] +ignore_missing_imports = True + +[mypy-iohub.*] ignore_missing_imports = True \ No newline at end of file