Skip to content

Commit

Permalink
Update Axis to a standard class
Browse files Browse the repository at this point in the history
- Do not use dataclass - for consistency we prefer attrs.
- Remove ABC.meta - this is not an abstract base class.
  • Loading branch information
jp-dark committed Sep 16, 2024
1 parent afe2e54 commit a2505a9
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions python-spec/src/somacore/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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):
Expand Down

0 comments on commit a2505a9

Please sign in to comment.