From a2505a96cb7b13838f82b9e79774980da81cb25d Mon Sep 17 00:00:00 2001 From: Julia Dark Date: Mon, 16 Sep 2024 12:17:29 -0400 Subject: [PATCH] Update Axis to a standard class - Do not use dataclass - for consistency we prefer attrs. - Remove ABC.meta - this is not an abstract base class. --- python-spec/src/somacore/coordinates.py | 33 ++++++++++++++++++++----- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/python-spec/src/somacore/coordinates.py b/python-spec/src/somacore/coordinates.py index 6acdfb1..520c240 100644 --- a/python-spec/src/somacore/coordinates.py +++ b/python-spec/src/somacore/coordinates.py @@ -2,15 +2,13 @@ import abc import collections.abc -from dataclasses import dataclass from typing import Any, Optional, Sequence, Tuple, Union import numpy as np import numpy.typing as npt -@dataclass -class Axis(metaclass=abc.ABCMeta): +class Axis: """A description of an axis of a coordinate system Args: @@ -21,9 +19,32 @@ class Axis(metaclass=abc.ABCMeta): Lifecycle: experimental """ - name: str - unit_name: Optional[str] = None - unit_scale: Optional[np.float64] = None + __slots__ = ("_name", "_unit_name", "_unit_scale") + + def __init__( + self, + name: str, + unit_name: Optional[str] = None, + unit_scale: Optional[np.float64] = None, + ): + self._name: str = name + self._unit_name: Optional[str] = unit_name + self._unit_scale: Optional[np.float64] = unit_scale + + @property + def name(self) -> str: + """Name of the axis.""" + return self._name + + @property + def unit_name(self) -> Optional[str]: + """Optional string name for the physical quantity the units are measured in.""" + return self._unit_name + + @property + def unit_scale(self) -> Optional[np.float64]: + """Optional scale for the physical quantity the units.""" + return self._unit_scale class CoordinateSpace(collections.abc.Sequence):