From 4bb424a3e4fefbcc3d4abac63e8fb0d2d9f15604 Mon Sep 17 00:00:00 2001 From: Davis Vann Bennett Date: Thu, 17 Jun 2021 14:14:47 -0400 Subject: [PATCH] actually remove metadata, and remove unused deps --- pyproject.toml | 2 - src/xarray_multiscale/metadata/__init__.py | 0 src/xarray_multiscale/metadata/cosem_ome.py | 47 --------------- .../metadata/neuroglancer.py | 37 ------------ src/xarray_multiscale/metadata/util.py | 58 ------------------- 5 files changed, 144 deletions(-) delete mode 100644 src/xarray_multiscale/metadata/__init__.py delete mode 100644 src/xarray_multiscale/metadata/cosem_ome.py delete mode 100644 src/xarray_multiscale/metadata/neuroglancer.py delete mode 100644 src/xarray_multiscale/metadata/util.py diff --git a/pyproject.toml b/pyproject.toml index 757f188..6f604e7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,8 +11,6 @@ mypy = "^0.790" scipy = "^1.5.4" numpy = "^1.19.4" dask = "^^2020.12.0" -cytoolz = "^0.11.0" -dacite = "^1.6.0" [tool.poetry.dev-dependencies] pytest = "^5.2" diff --git a/src/xarray_multiscale/metadata/__init__.py b/src/xarray_multiscale/metadata/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/xarray_multiscale/metadata/cosem_ome.py b/src/xarray_multiscale/metadata/cosem_ome.py deleted file mode 100644 index 5354731..0000000 --- a/src/xarray_multiscale/metadata/cosem_ome.py +++ /dev/null @@ -1,47 +0,0 @@ -from dataclasses import dataclass, asdict -from typing import Sequence -from xarray import DataArray -from .util import BaseMeta, SpatialTransform -from typing import Optional - - -@dataclass -class ScaleMeta(BaseMeta): - path: str - transform: SpatialTransform - - -@dataclass -class MultiscaleMeta(BaseMeta): - datasets: Sequence[ScaleMeta] - - -@dataclass -class GroupMeta(BaseMeta): - name: str - multiscales: Sequence[MultiscaleMeta] - - @classmethod - def fromDataArraySequence( - cls, dataarrays: Sequence[DataArray], paths: Sequence[str] - ): - name: str = str(dataarrays[0].name) - multiscales = [ - MultiscaleMeta( - datasets=[ - ScaleMeta(path=path, transform=SpatialTransform.fromDataArray(arr)) - for path, arr in zip(paths, dataarrays) - ] - ) - ] - return cls(name=name, multiscales=multiscales) - - -@dataclass -class ArrayMeta(BaseMeta): - name: Optional[str] - transform: SpatialTransform - - @classmethod - def fromDataArray(cls, data: DataArray) -> "ArrayMeta": - return cls(name=str(data.name), transform=SpatialTransform.fromDataArray(data)) diff --git a/src/xarray_multiscale/metadata/neuroglancer.py b/src/xarray_multiscale/metadata/neuroglancer.py deleted file mode 100644 index 2329dbb..0000000 --- a/src/xarray_multiscale/metadata/neuroglancer.py +++ /dev/null @@ -1,37 +0,0 @@ -from typing import Sequence -from dataclasses import dataclass - -from xarray.core.dataarray import DataArray -from typing import Union, List -import numpy as np -from xarray_multiscale.metadata.util import BaseMeta, SpatialTransform - - -@dataclass -class PixelResolution(BaseMeta): - # fortran-ordered - dimensions: Sequence[float] - unit: Union[str, None] - - -@dataclass -class GroupMeta(BaseMeta): - # see https://github.com/google/neuroglancer/issues/176#issuecomment-553027775 - # these properties must be stored in the opposite order of C-contiguous axis indexing - axes: Sequence[Union[str, None]] - units: Sequence[Union[str, None]] - scales: Sequence[Sequence[int]] - pixelResolution: PixelResolution - - @classmethod - def fromDataArraySequence(cls, dataarrays: Sequence[DataArray]) -> "GroupMeta": - transforms = [ - SpatialTransform.fromDataArray(array, reverse_axes=True) - for array in dataarrays - ] - pixelresolution = PixelResolution(transforms[0].scale, transforms[0].units[0]) - scales: List[List[int]] = [ - np.round(np.divide(t.scale, transforms[0].scale)).astype("int").tolist() - for t in transforms - ] - return cls(transforms[0].axes, transforms[0].units, scales, pixelresolution) diff --git a/src/xarray_multiscale/metadata/util.py b/src/xarray_multiscale/metadata/util.py deleted file mode 100644 index eaa7ff7..0000000 --- a/src/xarray_multiscale/metadata/util.py +++ /dev/null @@ -1,58 +0,0 @@ -from dataclasses import dataclass, asdict -from typing import Sequence, Union, Dict, Any, Optional -from xarray import DataArray -from dacite import from_dict - - -def infer_c_or_f_contiguous(array: Any) -> str: - data_order = "C" - if hasattr(array, "order"): - data_order = array.order - elif hasattr(array, "flags"): - if array.flags["F_CONTIGUOUS"] and not array.flags["C_CONTIGUOUS"]: - data_order = "F" - return data_order - - -@dataclass -class BaseMeta: - def asdict(self): - return asdict(self) - - -@dataclass -class SpatialTransform(BaseMeta): - axes: Sequence[str] - units: Sequence[Union[str, None]] - translate: Sequence[float] - scale: Sequence[float] - - def __post_init__(self): - assert ( - len(self.axes) == len(self.units) == len(self.translate) == len(self.scale) - ) - - @classmethod - def fromDataArray( - cls, dataarray: DataArray, reverse_axes=False - ) -> "SpatialTransform": - """ - Generate a spatial transform from a DataArray. - """ - - orderer = slice(None) - if reverse_axes: - orderer = slice(-1, None, -1) - axes = [str(d) for d in dataarray.dims[orderer]] - units = [dataarray.coords[ax].attrs.get("units") for ax in axes] - translate = [float(dataarray.coords[ax][0]) for ax in axes] - scale = [ - abs(float(dataarray.coords[ax][1]) - float(dataarray.coords[ax][0])) - for ax in axes - ] - - return cls(axes=axes, units=units, translate=translate, scale=scale) - - @classmethod - def fromDict(cls, d: Dict[str, Any]): - return from_dict(cls, d)